Skip to content

Commit

Permalink
Initial support for vs2022.
Browse files Browse the repository at this point in the history
  • Loading branch information
belkiss committed Aug 12, 2021
1 parent fde1180 commit 877113e
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 199 deletions.
8 changes: 6 additions & 2 deletions Sharpmake.Generators/FastBuild/Bff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,6 @@ List<string> skipFiles
case Options.Vc.General.PlatformToolset.LLVM:
case Options.Vc.General.PlatformToolset.ClangCL:
// <!-- Set the value of _MSC_VER to claim for compatibility -->
// TODO: figure out what version number to put there
// maybe use the DevEnv value
string mscVer = Options.GetString<Options.Clang.Compiler.MscVersion>(conf);
if (string.IsNullOrEmpty(mscVer))
{
Expand All @@ -745,6 +743,9 @@ List<string> skipFiles
case Options.Vc.General.PlatformToolset.v142:
mscVer = "1920";
break;
case Options.Vc.General.PlatformToolset.v143:
mscVer = "1930";
break;
default:
throw new Error("LLVMVcPlatformToolset! Platform toolset override '{0}' not supported", overridenPlatformToolset);
}
Expand All @@ -759,6 +760,9 @@ List<string> skipFiles
case DevEnv.vs2019:
mscVer = "1920";
break;
case DevEnv.vs2022:
mscVer = "1930";
break;
default:
throw new Error("Clang-cl used with unsupported DevEnv: " + context.DevelopmentEnvironment.ToString());
}
Expand Down
12 changes: 8 additions & 4 deletions Sharpmake.Generators/GeneratorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public void InitializeBuilder(Builder builder)
}
else
{
switch (configurations[0].Target.GetFragment<DevEnv>())
DevEnv devEnv = configurations[0].Target.GetFragment<DevEnv>();
switch (devEnv)
{
case DevEnv.make:
{
Expand All @@ -101,6 +102,7 @@ public void InitializeBuilder(Builder builder)
case DevEnv.vs2015:
case DevEnv.vs2017:
case DevEnv.vs2019:
case DevEnv.vs2022:
{
VcxprojGenerator.Generate(builder, project, configurations, projectFile, generatedFiles, skipFiles);
BffGenerator.Generate(builder, project, configurations, projectFile, generatedFiles, skipFiles);
Expand All @@ -114,7 +116,7 @@ public void InitializeBuilder(Builder builder)
}
default:
{
throw new Error("Generate called with unknown DevEnv: " + configurations[0].Target.GetFragment<DevEnv>());
throw new Error("Generate called with unknown DevEnv: " + devEnv);
}
}
}
Expand All @@ -137,7 +139,8 @@ public void InitializeBuilder(Builder builder)
}
else
{
switch (configurations[0].Target.GetFragment<DevEnv>())
DevEnv devEnv = configurations[0].Target.GetFragment<DevEnv>();
switch (devEnv)
{
case DevEnv.make:
{
Expand All @@ -150,6 +153,7 @@ public void InitializeBuilder(Builder builder)
case DevEnv.vs2015:
case DevEnv.vs2017:
case DevEnv.vs2019:
case DevEnv.vs2022:
{
if (UtilityMethods.HasFastBuildConfig(configurations))
{
Expand All @@ -161,7 +165,7 @@ public void InitializeBuilder(Builder builder)
}
default:
{
throw new Error("Generate called with unknown DevEnv: " + configurations[0].Target.GetFragment<DevEnv>());
throw new Error("Generate called with unknown DevEnv: " + devEnv);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Sharpmake.Generators/VisualStudio/Csproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,7 @@ List<string> skipFiles
break;
case DevEnv.vs2017:
case DevEnv.vs2019:
case DevEnv.vs2022:
Write(Template.Project.ProjectBeginVs2017, writer, resolver);
break;
default:
Expand Down
31 changes: 10 additions & 21 deletions Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG
Options.Option(Options.Vc.Compiler.EnableAsan.Enable, () => { context.Options["EnableASAN"] = "true"; context.CommandLineOptions["EnableASAN"] = "/fsanitize=address"; })
);

if (context.DevelopmentEnvironment == DevEnv.vs2017 || context.DevelopmentEnvironment == DevEnv.vs2019)
if (context.DevelopmentEnvironment.IsVisualStudio() && context.DevelopmentEnvironment >= DevEnv.vs2017)
{
//Options.Vc.Compiler.DefineCPlusPlus. See: https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
// Disable /Zc:__cplusplus-
Expand Down Expand Up @@ -1143,20 +1143,14 @@ private static void SelectDebugInformationOption(IGenerationContext context, Pro

private static void SelectPreferredToolArchitecture(IGenerationContext context)
{
switch (context.DevelopmentEnvironment)
if (context.DevelopmentEnvironment.IsVisualStudio())
{
case DevEnv.vs2015:
case DevEnv.vs2017:
case DevEnv.vs2019:
{
context.SelectOption
(
Options.Option(Options.Vc.General.PreferredToolArchitecture.Default, () => { context.Options["PreferredToolArchitecture"] = FileGeneratorUtilities.RemoveLineTag; }),
Options.Option(Options.Vc.General.PreferredToolArchitecture.x86, () => { context.Options["PreferredToolArchitecture"] = "x86"; }),
Options.Option(Options.Vc.General.PreferredToolArchitecture.x64, () => { context.Options["PreferredToolArchitecture"] = "x64"; })
);
}
break;
context.SelectOption
(
Options.Option(Options.Vc.General.PreferredToolArchitecture.Default, () => { context.Options["PreferredToolArchitecture"] = FileGeneratorUtilities.RemoveLineTag; }),
Options.Option(Options.Vc.General.PreferredToolArchitecture.x86, () => { context.Options["PreferredToolArchitecture"] = "x86"; }),
Options.Option(Options.Vc.General.PreferredToolArchitecture.x64, () => { context.Options["PreferredToolArchitecture"] = "x64"; })
);
}
}

Expand Down Expand Up @@ -2100,17 +2094,12 @@ private static void SelectGenerateManifestOption(IGenerationContext context, Pro
private static void SelectGenerateDebugInformationOption(IGenerationContext context, ProjectOptionsGenerationContext optionsContext)
{
//GenerateDebugInformation="false"
// VS2012-VS2013
// GenerateDebugInformation.Enable GenerateDebugInformation="true" /DEBUG
// GenerateDebugInformation.Disable GenerateDebugInformation="false"
// (GenerateFullProgramDatabaseFile is ignored, there can only be full pdb files)
//
// VS2015
// GenerateDebugInformation.Enable GenerateDebugInformation="true" /DEBUG
// GenerateDebugInformation.EnableFastLink GenerateDebugInformation="DebugFastLink" /DEBUG:FASTLINK
// Disable GenerateDebugInformation="No"
//
// VS2017-VS2019
// VS2017-VS2022
// Enable GenerateDebugInformation="true" /DEBUG
// EnableFastLink GenerateDebugInformation="DebugFastLink" /DEBUG:FASTLINK
// Disable GenerateDebugInformation="No"
Expand Down Expand Up @@ -2140,7 +2129,7 @@ private static void SelectGenerateDebugInformationOption(IGenerationContext cont
else
{
if (isMicrosoftPlatform && forceFullPDB &&
((context.DevelopmentEnvironment == DevEnv.vs2017) || (context.DevelopmentEnvironment == DevEnv.vs2019)))
(context.DevelopmentEnvironment.IsVisualStudio() && context.DevelopmentEnvironment >= DevEnv.vs2017))
{
context.Options["LinkerGenerateDebugInformation"] = "DebugFull";
context.CommandLineOptions["LinkerGenerateDebugInformation"] = "/DEBUG:FULL";
Expand Down
5 changes: 5 additions & 0 deletions Sharpmake.Generators/VisualStudio/Sln.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public static class Solution
# Visual Studio Version 16
VisualStudioVersion = 16.0.29424.173
MinimumVisualStudioVersion = 10.0.40219.1
";

public static string HeaderBeginVs2022 =
@"Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
";

public static string ProjectBegin =
Expand Down
6 changes: 4 additions & 2 deletions Sharpmake.Generators/VisualStudio/Sln.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,11 @@ private SolutionFolder GetSolutionFolder(string names)
case DevEnv.vs2019:
fileGenerator.Write(Template.Solution.HeaderBeginVs2019);
break;
default:
Console.WriteLine("Unsupported DevEnv for solution " + solutionConfigurations[0].Target.GetFragment<DevEnv>());
case DevEnv.vs2022:
fileGenerator.Write(Template.Solution.HeaderBeginVs2022);
break;
default:
throw new Error($"Unsupported DevEnv {devEnv} for solution {solution.Name}");
}

SolutionFolder masterBffFolder = null;
Expand Down
5 changes: 3 additions & 2 deletions Sharpmake.Generators/VisualStudio/Vcxproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ private static string GetVCTargetsPathOverride(DevEnv devEnv)
switch (devEnv)
{
case DevEnv.vs2017:
return Path.Combine(devEnv.GetVisualStudioDir(), @"Common7\IDE\VC\VCTargets\");
case DevEnv.vs2019:
return Path.Combine(devEnv.GetVisualStudioDir(), @"MSBuild\Microsoft\VC\v160\");
case DevEnv.vs2022:
return devEnv.GetVCTargetsPath();
default:
throw new NotImplementedException("VCTargetsPath redirection for " + devEnv);
}
Expand All @@ -230,6 +230,7 @@ private static string GetMSBuildExtensionsPathOverride(DevEnv devEnv)
{
case DevEnv.vs2017:
case DevEnv.vs2019:
case DevEnv.vs2022:
return Path.Combine(devEnv.GetVisualStudioDir(), @"MSBuild\");
default:
throw new NotImplementedException("MSBuildExtensionsPath redirection for " + devEnv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ public override void GeneratePlatformSpecificProjectDescription(IVcxprojGenerati
{
case DevEnv.vs2017:
case DevEnv.vs2019:
case DevEnv.vs2022:
{
// _PlatformFolder override is not enough for android, we need to know the AdditionalVCTargetsPath
// Note that AdditionalVCTargetsPath is not officially supported by vs2017, but we use the variable anyway for convenience and consistency
if (!string.IsNullOrEmpty(MSBuildGlobalSettings.GetCppPlatformFolder(devEnv, SharpmakePlatform)))
throw new Error("SetCppPlatformFolder is not supported by AndroidPlatform correctly: use of MSBuildGlobalSettings.SetCppPlatformFolder should be replaced by use of MSBuildGlobalSettings.SetAdditionalVCTargetsPath.");
throw new Error($"SetCppPlatformFolder is not supported by {devEnv}: use of MSBuildGlobalSettings.SetCppPlatformFolder should be replaced by use of MSBuildGlobalSettings.SetAdditionalVCTargetsPath.");

string additionalVCTargetsPath = MSBuildGlobalSettings.GetAdditionalVCTargetsPath(devEnv, SharpmakePlatform);
if (!string.IsNullOrEmpty(additionalVCTargetsPath))
Expand Down Expand Up @@ -183,7 +184,7 @@ public override void GenerateProjectPlatformSdkDirectoryDescription(IVcxprojGene
base.GenerateProjectPlatformSdkDirectoryDescription(context, generator);

var devEnv = context.DevelopmentEnvironmentsRange.MinDevEnv;
if (devEnv == DevEnv.vs2019)
if (devEnv.IsVisualStudio() && devEnv >= DevEnv.vs2019)
{
string additionalVCTargetsPath = MSBuildGlobalSettings.GetAdditionalVCTargetsPath(devEnv, SharpmakePlatform);
if (!string.IsNullOrEmpty(additionalVCTargetsPath))
Expand All @@ -196,7 +197,7 @@ public override void GeneratePostDefaultPropsImport(IVcxprojGenerationContext co
base.GeneratePostDefaultPropsImport(context, generator);

var devEnv = context.DevelopmentEnvironmentsRange.MinDevEnv;
if (devEnv == DevEnv.vs2017 || devEnv == DevEnv.vs2019)
if (devEnv.IsVisualStudio() && devEnv >= DevEnv.vs2017)
{
// in case we've written an additional vc targets path, we need to set a couple of properties to avoid a warning
if (!string.IsNullOrEmpty(MSBuildGlobalSettings.GetAdditionalVCTargetsPath(devEnv, SharpmakePlatform)))
Expand Down
Loading

0 comments on commit 877113e

Please sign in to comment.