From 063aa6f4082201e2623daeedc90ef00bb7c34537 Mon Sep 17 00:00:00 2001 From: Vignesh Gunasekaran Date: Sun, 6 Oct 2024 17:28:18 +0200 Subject: [PATCH 1/2] Added compiler option "Sharpmake.Options.Vc.Compiler.UseStandardConformingPreprocessor" to set the additional option "/Zc:preprocessor" https://learn.microsoft.com/en-us/cpp/build/reference/zc-preprocessor?view=msvc-170 --- .../VisualStudio/ProjectOptionsGenerator.cs | 10 ++++++++++ Sharpmake/Options.Vc.cs | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index effe3fad2..28adb76ac 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -695,6 +695,16 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG Options.Option(Options.Vc.Compiler.KeepComment.Enable, () => { context.Options["KeepComments"] = "true"; context.CommandLineOptions["KeepComments"] = "/C"; }) ); + //Options.Vc.Compiler.UseStandardConformingPreprocessor. See: https://learn.microsoft.com/en-us/cpp/build/reference/zc-preprocessor?view=msvc-170 + // Disable /Zc:preprocessor- + // Enable /Zc:preprocessor + context.SelectOption + ( + Options.Option(Options.Vc.Compiler.UseStandardConformingPreprocessor.Default, () => { }), + Options.Option(Options.Vc.Compiler.UseStandardConformingPreprocessor.Disable, () => { context.Configuration.AdditionalCompilerOptions.Add("/Zc:preprocessor-"); }), + Options.Option(Options.Vc.Compiler.UseStandardConformingPreprocessor.Enable, () => { context.Configuration.AdditionalCompilerOptions.Add("/Zc:preprocessor"); }) + ); + //Options.Vc.Compiler.StringPooling. // Disable StringPooling="false" // Enable StringPooling="true" /GF diff --git a/Sharpmake/Options.Vc.cs b/Sharpmake/Options.Vc.cs index 77d04b209..4be0fbbb0 100644 --- a/Sharpmake/Options.Vc.cs +++ b/Sharpmake/Options.Vc.cs @@ -679,6 +679,17 @@ public enum KeepComment Enable } + /// + /// Enables a token-based preprocessor that conforms to C99 and C++11 and later standards. + /// + public enum UseStandardConformingPreprocessor + { + [Default] + Default, + Disable, + Enable + } + /// /// Enables the compiler to create a single read-only copy of identical strings in the program image and in memory during execution, resulting in smaller programs, an optimization called string pooling. /O1, /O2, and /ZI automatically set /GF option. /// From 340b024f13bd3ca33ccc49cac7ecf6a9e8bfc3ef Mon Sep 17 00:00:00 2001 From: Vignesh Gunasekaran Date: Sun, 13 Oct 2024 13:12:07 +0200 Subject: [PATCH 2/2] Added compiler option "Sharpmake.Options.Vc.Compiler.UseStandardConformingPreprocessor", which: * adds the additional command line argument "/Zc:preprocessor[-]" * sets the "UseStandardPreprocessor" option in vcxproj --- Sharpmake.Generators/FastBuild/Bff.Template.cs | 1 + .../VisualStudio/ProjectOptionsGenerator.cs | 18 +++++++++++++++--- .../BasePlatform.Vcxproj.Template.cs | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Sharpmake.Generators/FastBuild/Bff.Template.cs b/Sharpmake.Generators/FastBuild/Bff.Template.cs index fd96e8052..7ac863ebb 100644 --- a/Sharpmake.Generators/FastBuild/Bff.Template.cs +++ b/Sharpmake.Generators/FastBuild/Bff.Template.cs @@ -355,6 +355,7 @@ public static class ConfigurationFile + ' [cmdLineOptions.IgnoreStandardIncludePath]' + ' [cmdLineOptions.GeneratePreprocessedFile]' + ' [cmdLineOptions.KeepComments]' + + ' [cmdLineOptions.UseStandardConformingPreprocessor]' + ' [cmdLineOptions.StringPooling]' + ' [cmdLineOptions.MinimalRebuild]' + ' [cmdLineOptions.ExceptionHandling]' diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index 28adb76ac..a27b5f8ca 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -700,9 +700,21 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG // Enable /Zc:preprocessor context.SelectOption ( - Options.Option(Options.Vc.Compiler.UseStandardConformingPreprocessor.Default, () => { }), - Options.Option(Options.Vc.Compiler.UseStandardConformingPreprocessor.Disable, () => { context.Configuration.AdditionalCompilerOptions.Add("/Zc:preprocessor-"); }), - Options.Option(Options.Vc.Compiler.UseStandardConformingPreprocessor.Enable, () => { context.Configuration.AdditionalCompilerOptions.Add("/Zc:preprocessor"); }) + Options.Option(Options.Vc.Compiler.UseStandardConformingPreprocessor.Default, () => + { + context.Options["UseStandardConformingPreprocessor"] = FileGeneratorUtilities.RemoveLineTag; + context.CommandLineOptions["UseStandardConformingPreprocessor"] = FileGeneratorUtilities.RemoveLineTag; + }), + Options.Option(Options.Vc.Compiler.UseStandardConformingPreprocessor.Disable, () => + { + context.Options["UseStandardConformingPreprocessor"] = "false"; + context.CommandLineOptions["UseStandardConformingPreprocessor"] = "/Zc:preprocessor-"; + }), + Options.Option(Options.Vc.Compiler.UseStandardConformingPreprocessor.Enable, () => + { + context.Options["UseStandardConformingPreprocessor"] = "true"; + context.CommandLineOptions["UseStandardConformingPreprocessor"] = "/Zc:preprocessor"; + }) ); //Options.Vc.Compiler.StringPooling. diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs index 3be0f4b37..9cca39e9d 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs @@ -35,6 +35,7 @@ public abstract partial class BasePlatform [options.GeneratePreprocessedFile] [options.PreprocessSuppressLineNumbers] [options.KeepComments] + [options.UseStandardConformingPreprocessor] [options.StringPooling] [options.MinimalRebuild] [options.ExceptionHandling]