Skip to content

Commit

Permalink
Added proper netcore support for C++/CLI projects.
Browse files Browse the repository at this point in the history
- Fixed tests.
  • Loading branch information
Michel-Olivier Rousseau committed Dec 13, 2023
1 parent 0aa2ebf commit c0e75d6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions Sharpmake.Generators/VisualStudio/Vcxproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,17 @@ private void GenerateImpl(GenerationContext context, IList<string> 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);

Expand All @@ -454,20 +465,9 @@ private void GenerateImpl(GenerationContext context, IList<string> generatedFile
{
context.Configuration = conf;

string clrSupportString = FileGeneratorUtilities.RemoveLineTag;

if (!conf.IsFastBuild && clrSupport)
{
var dotnetFrameWork = firstConf.Target.GetFragment<DotNetFramework>();

// .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);
Expand Down Expand Up @@ -622,7 +622,6 @@ private void GenerateImpl(GenerationContext context, IList<string> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public abstract partial class BasePlatform
<TranslateIncludes>[options.TranslateIncludes]</TranslateIncludes>
<CharacterSet>[options.CharacterSet]</CharacterSet>
<UseOfMfc>[options.UseOfMfc]</UseOfMfc>
<CLRSupport>[clrSupport]</CLRSupport>
<WholeProgramOptimization>[options.WholeProgramOptimization]</WholeProgramOptimization>
<PlatformToolset>[options.PlatformToolset]</PlatformToolset>
<TrackFileAccess>[options.TrackFileAccess]</TrackFileAccess>
Expand Down
10 changes: 9 additions & 1 deletion Sharpmake/Options.Vc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
/// Common Language RunTime Support for .NET Core
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
ClrNetCoreSupport // clr:netcore
}

public enum MfcSupport
Expand Down
2 changes: 2 additions & 0 deletions samples/CPPCLI/projects.sharpmake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>true</CLRSupport>
<WholeProgramOptimization>false</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>true</CLRSupport>
<WholeProgramOptimization>false</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>true</CLRSupport>
<WholeProgramOptimization>false</WholeProgramOptimization>
<PlatformToolset>v142</PlatformToolset>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>true</CLRSupport>
<WholeProgramOptimization>false</WholeProgramOptimization>
<PlatformToolset>v142</PlatformToolset>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down

0 comments on commit c0e75d6

Please sign in to comment.