From c0e75d63c0b1b0825d281fd7bc27cf74529b9b15 Mon Sep 17 00:00:00 2001 From: Michel-Olivier Rousseau Date: Wed, 13 Dec 2023 10:44:27 -0500 Subject: [PATCH] Added proper netcore support for C++/CLI projects. - Fixed tests. --- .../VisualStudio/ProjectOptionsGenerator.cs | 3 ++- Sharpmake.Generators/VisualStudio/Vcxproj.cs | 23 +++++++++---------- .../BasePlatform.Vcxproj.Template.cs | 1 - Sharpmake/Options.Vc.cs | 10 +++++++- samples/CPPCLI/projects.sharpmake.cs | 2 ++ .../projects/clrcppproj.vs2017.v4_6_2.vcxproj | 4 ++-- .../projects/clrcppproj.vs2019.v4_7_2.vcxproj | 4 ++-- 7 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index f3d822f6b..effe3fad2 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -419,7 +419,8 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG Options.Option(Options.Vc.General.CommonLanguageRuntimeSupport.NoClrSupport, () => { context.Options["CLRSupport"] = FileGeneratorUtilities.RemoveLineTag; context.CommandLineOptions["CLRSupport"] = FileGeneratorUtilities.RemoveLineTag; }), Options.Option(Options.Vc.General.CommonLanguageRuntimeSupport.ClrSupport, () => { context.Options["CLRSupport"] = "true"; context.CommandLineOptions["CLRSupport"] = "/clr"; }), Options.Option(Options.Vc.General.CommonLanguageRuntimeSupport.PureMsilClrSupport, () => { context.Options["CLRSupport"] = "Pure"; context.CommandLineOptions["CLRSupport"] = "/clr:pure"; }), - Options.Option(Options.Vc.General.CommonLanguageRuntimeSupport.SafeMsilClrSupport, () => { context.Options["CLRSupport"] = "Safe"; context.CommandLineOptions["CLRSupport"] = "/clr:safe"; }) + Options.Option(Options.Vc.General.CommonLanguageRuntimeSupport.SafeMsilClrSupport, () => { context.Options["CLRSupport"] = "Safe"; context.CommandLineOptions["CLRSupport"] = "/clr:safe"; }), + Options.Option(Options.Vc.General.CommonLanguageRuntimeSupport.ClrNetCoreSupport, () => { context.Options["CLRSupport"] = "NetCore"; context.CommandLineOptions["CLRSupport"] = "/clr:netcore"; }) ); context.SelectOption diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.cs index ab9dff620..e299f8f5d 100644 --- a/Sharpmake.Generators/VisualStudio/Vcxproj.cs +++ b/Sharpmake.Generators/VisualStudio/Vcxproj.cs @@ -431,6 +431,17 @@ private void GenerateImpl(GenerationContext context, IList generatedFile fileGenerator.Write(Template.Project.PropertyGroupEnd); // xml end header + if (clrSupport && firstConf.FrameworkReferences.Count > 0) + { + fileGenerator.Write(Template.Project.ItemGroupBegin); + + foreach (var frameworkReference in firstConf.FrameworkReferences) + using (fileGenerator.Declare("include", frameworkReference)) + fileGenerator.Write(CSproj.Template.ItemGroups.FrameworkReference); + + fileGenerator.Write(Template.Project.ItemGroupEnd); + } + foreach (var platform in context.PresentPlatforms.Values) platform.GeneratePlatformSpecificProjectDescription(context, fileGenerator); @@ -454,20 +465,9 @@ private void GenerateImpl(GenerationContext context, IList generatedFile { context.Configuration = conf; - string clrSupportString = FileGeneratorUtilities.RemoveLineTag; - - if (!conf.IsFastBuild && clrSupport) - { - var dotnetFrameWork = firstConf.Target.GetFragment(); - - // .Net Core requires "NetCore" instead of "true", see: https://docs.microsoft.com/en-us/dotnet/core/porting/cpp-cli - clrSupportString = dotnetFrameWork.IsDotNetCore() ? "NetCore" : clrSupport.ToString().ToLower(); - } - using (fileGenerator.Declare("platformName", Util.GetPlatformString(conf.Platform, conf.Project, conf.Target))) using (fileGenerator.Declare("conf", conf)) using (fileGenerator.Declare("options", context.ProjectConfigurationOptions[conf])) - using (fileGenerator.Declare("clrSupport", clrSupportString)) { var platformVcxproj = context.PresentPlatforms[conf.Platform]; platformVcxproj.GenerateProjectConfigurationGeneral(context, fileGenerator); @@ -622,7 +622,6 @@ private void GenerateImpl(GenerationContext context, IList generatedFile using (fileGenerator.Declare("project", conf.Project)) using (fileGenerator.Declare("target", conf.Target)) using (fileGenerator.Declare("options", context.ProjectConfigurationOptions[conf])) - using (fileGenerator.Declare("clrSupport", !clrSupport ? FileGeneratorUtilities.RemoveLineTag : clrSupport.ToString().ToLower())) using (fileGenerator.Declare("compileAsManaged", compileAsManagedString)) { fileGenerator.Write(Template.Project.ProjectConfigurationBeginItemDefinition); diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs index 603cc07db..ada2700c1 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs @@ -175,7 +175,6 @@ public abstract partial class BasePlatform [options.TranslateIncludes] [options.CharacterSet] [options.UseOfMfc] - [clrSupport] [options.WholeProgramOptimization] [options.PlatformToolset] [options.TrackFileAccess] diff --git a/Sharpmake/Options.Vc.cs b/Sharpmake/Options.Vc.cs index 2b22eec74..77d04b209 100644 --- a/Sharpmake/Options.Vc.cs +++ b/Sharpmake/Options.Vc.cs @@ -419,7 +419,15 @@ public enum CommonLanguageRuntimeSupport SafeMsilClrSupport, // clr:safe [Obsolete("This option is not supported by msvc anymore.", true)] - SafeMsilClrSupportOldSyntax // clr:oldSyntax + SafeMsilClrSupportOldSyntax, // clr:oldSyntax + + /// + /// Common Language RunTime Support for .NET Core + /// + /// + /// Creates metadata and code for the component using the latest cross-platform .NET framework, also known as .NET Core. The metadata can be consumed by other .NET Core applications. And, the option enables the component to consume types and data in the metadata of other .NET Core components. + /// + ClrNetCoreSupport // clr:netcore } public enum MfcSupport diff --git a/samples/CPPCLI/projects.sharpmake.cs b/samples/CPPCLI/projects.sharpmake.cs index 6f37ff5d2..a46ba187c 100644 --- a/samples/CPPCLI/projects.sharpmake.cs +++ b/samples/CPPCLI/projects.sharpmake.cs @@ -112,6 +112,8 @@ public override void ConfigureAll(Configuration conf, Target target) // Force RTTI to be enabled conf.Options.Add(Sharpmake.Options.Vc.Compiler.RTTI.Enable); + + conf.Options.Add(Sharpmake.Options.Vc.General.CommonLanguageRuntimeSupport.ClrSupport); } } diff --git a/samples/CPPCLI/reference/projects/clrcppproj.vs2017.v4_6_2.vcxproj b/samples/CPPCLI/reference/projects/clrcppproj.vs2017.v4_6_2.vcxproj index d903841a7..a0dac1fb0 100644 --- a/samples/CPPCLI/reference/projects/clrcppproj.vs2017.v4_6_2.vcxproj +++ b/samples/CPPCLI/reference/projects/clrcppproj.vs2017.v4_6_2.vcxproj @@ -26,17 +26,17 @@ DynamicLibrary true MultiByte - true false v141 + true DynamicLibrary false MultiByte - true false v141 + true diff --git a/samples/CPPCLI/reference/projects/clrcppproj.vs2019.v4_7_2.vcxproj b/samples/CPPCLI/reference/projects/clrcppproj.vs2019.v4_7_2.vcxproj index 070d244df..4e7bd0cc9 100644 --- a/samples/CPPCLI/reference/projects/clrcppproj.vs2019.v4_7_2.vcxproj +++ b/samples/CPPCLI/reference/projects/clrcppproj.vs2019.v4_7_2.vcxproj @@ -26,17 +26,17 @@ DynamicLibrary true MultiByte - true false v142 + true DynamicLibrary false MultiByte - true false v142 + true