From 8ec95e7683322ba89b78418d51fac8bb1125bd15 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Wed, 4 Aug 2021 10:27:32 +0200 Subject: [PATCH 01/26] Make the version unofficial. --- Sharpmake.Application/Properties/AssemblyInfo.cs | 2 +- Sharpmake.Generators/Properties/AssemblyInfo.cs | 2 +- .../Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs | 2 +- Sharpmake/Properties/AssemblyInfo.cs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sharpmake.Application/Properties/AssemblyInfo.cs b/Sharpmake.Application/Properties/AssemblyInfo.cs index 86788f24c..0f778c32f 100644 --- a/Sharpmake.Application/Properties/AssemblyInfo.cs +++ b/Sharpmake.Application/Properties/AssemblyInfo.cs @@ -43,4 +43,4 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.17.1.0")] +[assembly: AssemblyVersion("0.17.1.*")] diff --git a/Sharpmake.Generators/Properties/AssemblyInfo.cs b/Sharpmake.Generators/Properties/AssemblyInfo.cs index 1be7d119c..aa6984fe8 100644 --- a/Sharpmake.Generators/Properties/AssemblyInfo.cs +++ b/Sharpmake.Generators/Properties/AssemblyInfo.cs @@ -44,6 +44,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.17.1.0")] +[assembly: AssemblyVersion("0.17.1.*")] [assembly: InternalsVisibleTo("Sharpmake")] diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs index 60cbde30a..ee91c4972 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs @@ -44,6 +44,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.17.1.0")] +[assembly: AssemblyVersion("0.17.1.*")] [assembly: SharpmakeExtension] diff --git a/Sharpmake/Properties/AssemblyInfo.cs b/Sharpmake/Properties/AssemblyInfo.cs index 021e7eba9..ff33ad58b 100644 --- a/Sharpmake/Properties/AssemblyInfo.cs +++ b/Sharpmake/Properties/AssemblyInfo.cs @@ -44,9 +44,9 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.17.1.0")] +[assembly: AssemblyVersion("0.17.1.*")] #pragma warning disable CS7035 -[assembly: AssemblyFileVersion("0.17.1.0 (LocalBuild)")] +[assembly: AssemblyFileVersion("0.17.1.* (LocalBuild)")] #pragma warning restore [assembly: InternalsVisibleTo("Sharpmake.Application")] From 88a627b65a2a51e38e6d2f09898eff85f10e0027 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Fri, 6 Aug 2021 13:14:51 +0200 Subject: [PATCH 02/26] Add use of libuuid in the HelloLinux sample to showcase how to do it. --- samples/HelloLinux/codebase/exe/exe.sharpmake.cs | 2 ++ samples/HelloLinux/codebase/exe/main.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/samples/HelloLinux/codebase/exe/exe.sharpmake.cs b/samples/HelloLinux/codebase/exe/exe.sharpmake.cs index 3205c5890..c5f4665dd 100644 --- a/samples/HelloLinux/codebase/exe/exe.sharpmake.cs +++ b/samples/HelloLinux/codebase/exe/exe.sharpmake.cs @@ -38,6 +38,8 @@ public override void ConfigureAll(Configuration conf, CommonTarget target) // note: because we write in makefiles we double the $ to escape it conf.AdditionalLinkerOptions.Add("-Wl,-rpath='$$ORIGIN'"); + conf.LibraryFiles.Add("libuuid.so"); + conf.AddPrivateDependency(target); conf.AddPrivateDependency(target); diff --git a/samples/HelloLinux/codebase/exe/main.cpp b/samples/HelloLinux/codebase/exe/main.cpp index 86912aed5..0dee36994 100644 --- a/samples/HelloLinux/codebase/exe/main.cpp +++ b/samples/HelloLinux/codebase/exe/main.cpp @@ -3,6 +3,8 @@ #include "util_static_lib2.h" #include "sub folder/useless_static_lib2.h" +#include + int main(int, char**) { std::cout << "Hello Linux World, from " CREATION_DATE "!" << std::endl; @@ -23,6 +25,18 @@ int main(int, char**) "!" << std::endl; #endif + { + uuid_t uuid; + uuid_generate(uuid); + + char* uuidString = new char[37]; + uuid_unparse(uuid, uuidString); + + std::cout << "- Here's a random UUID: " << uuidString << std::endl; + + delete [] uuidString; + } + std::vector someArray(5, 6); // from dll1 From 399e5e8220e1eaf82de1c216aaa667025fd2e3e6 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Fri, 6 Aug 2021 14:43:04 +0200 Subject: [PATCH 03/26] [Makefile] Fix regression on library prefixes, we now fixup the lib names same as the other generators. --- Sharpmake.Generators/Generic/Makefile.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Sharpmake.Generators/Generic/Makefile.cs b/Sharpmake.Generators/Generic/Makefile.cs index 66928b181..372b696fb 100644 --- a/Sharpmake.Generators/Generic/Makefile.cs +++ b/Sharpmake.Generators/Generic/Makefile.cs @@ -562,14 +562,15 @@ private Options.ExplicitOptions GenerateOptions(Project.Configuration conf, File options["OutputFile"] = conf.TargetFileFullNameWithExtension.Replace(" ", @"\ "); // DependenciesLibraryFiles - OrderableStrings dependenciesLibraryFiles = new OrderableStrings(conf.DependenciesLibraryFiles); - PathMakeUnix(dependenciesLibraryFiles); + var dependenciesLibraryFiles = new OrderableStrings(conf.DependenciesLibraryFiles); + FixupLibraryNames(dependenciesLibraryFiles); dependenciesLibraryFiles.InsertPrefix("-l:"); dependenciesLibraryFiles.Sort(); options["DependenciesLibraryFiles"] = dependenciesLibraryFiles.JoinStrings(" "); // LibraryFiles OrderableStrings libraryFiles = new OrderableStrings(conf.LibraryFiles); + FixupLibraryNames(libraryFiles); libraryFiles.InsertPrefix("-l:"); libraryFiles.Sort(); options["LibraryFiles"] = libraryFiles.JoinStrings(" "); @@ -696,6 +697,22 @@ private string GetOutputDirectory(Project.Configuration conf, FileInfo projectFi return Util.PathGetRelative(projectFileInfo.DirectoryName, conf.TargetPath); } + private static void FixupLibraryNames(IList paths) + { + for (int i = 0; i < paths.Count; ++i) + { + string libraryName = PathMakeUnix(paths[i]); + // We've got two kinds of way of listing a library: + // - With a filename without extension we must add the potential prefix and potential extension. + // - With a filename with a static or shared lib extension (eg. .a/.so), we shouldn't touch it as it's already set by the script. + string extension = Path.GetExtension(libraryName).ToLowerInvariant(); + if (extension != ".a" && extension != ".so") + paths[i] = "lib" + libraryName + ".a"; + else + paths[i] = libraryName; + } + } + #endregion #region Utils From d2eff512d13436273d9279bc84da9ef484bb2955 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Sat, 7 Aug 2021 17:38:37 +0200 Subject: [PATCH 04/26] Add link to libm.a --- samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs | 2 ++ samples/HelloLinux/codebase/dll1/util_dll.cpp | 9 ++++++--- samples/HelloLinux/codebase/dll1/util_dll.h | 2 +- samples/HelloLinux/codebase/exe/main.cpp | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs b/samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs index 98bd4a16b..34286fda1 100644 --- a/samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs +++ b/samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs @@ -40,6 +40,8 @@ public override void ConfigureAll(Configuration conf, CommonTarget target) conf.Defines.Add("UTIL_DLL_EXPORT"); conf.ExportDefines.Add("UTIL_DLL_IMPORT"); + conf.LibraryFiles.Add("m"); + conf.IncludePaths.Add(SourceRootPath); conf.AddPrivateDependency(target); diff --git a/samples/HelloLinux/codebase/dll1/util_dll.cpp b/samples/HelloLinux/codebase/dll1/util_dll.cpp index 73e079cb4..13b0e59a9 100644 --- a/samples/HelloLinux/codebase/dll1/util_dll.cpp +++ b/samples/HelloLinux/codebase/dll1/util_dll.cpp @@ -1,10 +1,11 @@ #include "precomp.h" #include "util_dll.h" -#include "src/util_static_lib1.h" +#include #include +#include "src/util_static_lib1.h" -int UtilDll1::ComputeSum(const std::vector& someInts) +int UtilDll1::ComputeMagicNumber(const std::vector& someInts) { int acc = 0; for (int item : someInts) @@ -27,7 +28,9 @@ int UtilDll1::ComputeSum(const std::vector& someInts) #endif acc += static_lib1_utils::GetRandomPosition(); - + + acc += cosf(M_PI); + return acc; } diff --git a/samples/HelloLinux/codebase/dll1/util_dll.h b/samples/HelloLinux/codebase/dll1/util_dll.h index 3cdb40a16..cef4c7c4f 100644 --- a/samples/HelloLinux/codebase/dll1/util_dll.h +++ b/samples/HelloLinux/codebase/dll1/util_dll.h @@ -13,6 +13,6 @@ struct UtilDll1 { - UTIL_DLL int ComputeSum(const std::vector& someInts); + UTIL_DLL int ComputeMagicNumber(const std::vector& someInts); }; diff --git a/samples/HelloLinux/codebase/exe/main.cpp b/samples/HelloLinux/codebase/exe/main.cpp index 0dee36994..3442de522 100644 --- a/samples/HelloLinux/codebase/exe/main.cpp +++ b/samples/HelloLinux/codebase/exe/main.cpp @@ -41,7 +41,7 @@ int main(int, char**) // from dll1 UtilDll1 utilityDll; - utilityDll.ComputeSum(someArray); + utilityDll.ComputeMagicNumber(someArray); // from static_lib2 Util2 utilityStatic; From b22f1628b2e67004d1c83f1e1d0755c690904468 Mon Sep 17 00:00:00 2001 From: Thierry Jouin Date: Sat, 7 Aug 2021 18:03:00 +0000 Subject: [PATCH 05/26] Add UseWpf / UseWindForms in C# projects options --- .../VisualStudio/Csproj.Template.cs | 2 ++ Sharpmake.Generators/VisualStudio/Csproj.cs | 12 ++++++++++++ Sharpmake/Options.CSharp.cs | 14 ++++++++++++++ .../HelloWorld.sharpmake.cs | 9 +++++++++ .../helloworld/HelloWorld.vs2017.netcore2_1.csproj | 1 + .../helloworld/HelloWorld.vs2019.netcore3_1.csproj | 1 + 6 files changed, 39 insertions(+) diff --git a/Sharpmake.Generators/VisualStudio/Csproj.Template.cs b/Sharpmake.Generators/VisualStudio/Csproj.Template.cs index a75d464b2..4198a155e 100644 --- a/Sharpmake.Generators/VisualStudio/Csproj.Template.cs +++ b/Sharpmake.Generators/VisualStudio/Csproj.Template.cs @@ -112,6 +112,8 @@ public static class Project [GeneratedAssemblyConfigTemplate.GenerateAssemblyInformationalVersionAttribute] [NugetRestoreProjectStyleString] [options.ProductVersion] + [options.UseWpf] + [options.UseWindowsForms] "; diff --git a/Sharpmake.Generators/VisualStudio/Csproj.cs b/Sharpmake.Generators/VisualStudio/Csproj.cs index c77076612..61fa2128f 100644 --- a/Sharpmake.Generators/VisualStudio/Csproj.cs +++ b/Sharpmake.Generators/VisualStudio/Csproj.cs @@ -3442,6 +3442,18 @@ private Options.ExplicitOptions GenerateOptions(CSharpProject project, Project.C options["CopyVsixExtensionLocation"] = Options.StringOption.Get(conf); options["ProductVersion"] = Options.StringOption.Get(conf); + SelectOption + ( + Options.Option(Options.CSharp.UseWpf.Enabled, () => { options["UseWpf"] = "true"; }), + Options.Option(Options.CSharp.UseWpf.Disabled, () => { options["UseWpf"] = RemoveLineTag; }) + ); + + SelectOption + ( + Options.Option(Options.CSharp.UseWindowsForms.Enabled, () => { options["UseWindowsForms"] = "true"; }), + Options.Option(Options.CSharp.UseWindowsForms.Disabled, () => { options["UseWindowsForms"] = RemoveLineTag; }) + ); + // concat defines, don't add options.Defines since they are automatically added by VS Strings defines = new Strings(); defines.AddRange(options.ExplicitDefines); diff --git a/Sharpmake/Options.CSharp.cs b/Sharpmake/Options.CSharp.cs index 25a6b3695..e5d743d4d 100644 --- a/Sharpmake/Options.CSharp.cs +++ b/Sharpmake/Options.CSharp.cs @@ -181,6 +181,20 @@ public enum ProduceReferenceAssembly Disabled } + public enum UseWpf + { + Enabled, + [Default] + Disabled + } + + public enum UseWindowsForms + { + Enabled, + [Default] + Disabled + } + public class UpdateInterval : IntOption { public UpdateInterval(int interval) diff --git a/samples/NetCore/DotNetCoreFrameworkHelloWorld/HelloWorld.sharpmake.cs b/samples/NetCore/DotNetCoreFrameworkHelloWorld/HelloWorld.sharpmake.cs index 0c5db3d9c..3b034d08e 100644 --- a/samples/NetCore/DotNetCoreFrameworkHelloWorld/HelloWorld.sharpmake.cs +++ b/samples/NetCore/DotNetCoreFrameworkHelloWorld/HelloWorld.sharpmake.cs @@ -61,6 +61,15 @@ public virtual void ConfigureAll(Configuration conf, Target target) conf.ProjectFileName = "[project.Name].[target.DevEnv].[target.Framework]"; conf.ProjectPath = @"[project.RootPath]"; + if (target.Framework.HasFlag(DotNetFramework.netcore3_1)) + { + conf.Options.Add(Options.CSharp.UseWpf.Enabled); + } + else + { + conf.Options.Add(Options.CSharp.UseWindowsForms.Enabled); + } + conf.Options.Add(Sharpmake.Options.CSharp.TreatWarningsAsErrors.Enabled); } } diff --git a/samples/NetCore/DotNetCoreFrameworkHelloWorld/reference/projects/helloworld/HelloWorld.vs2017.netcore2_1.csproj b/samples/NetCore/DotNetCoreFrameworkHelloWorld/reference/projects/helloworld/HelloWorld.vs2017.netcore2_1.csproj index 9f82aba71..d9a66c8c8 100644 --- a/samples/NetCore/DotNetCoreFrameworkHelloWorld/reference/projects/helloworld/HelloWorld.vs2017.netcore2_1.csproj +++ b/samples/NetCore/DotNetCoreFrameworkHelloWorld/reference/projects/helloworld/HelloWorld.vs2017.netcore2_1.csproj @@ -10,6 +10,7 @@ netcoreapp2.1 512 true + true AnyCPU diff --git a/samples/NetCore/DotNetCoreFrameworkHelloWorld/reference/projects/helloworld/HelloWorld.vs2019.netcore3_1.csproj b/samples/NetCore/DotNetCoreFrameworkHelloWorld/reference/projects/helloworld/HelloWorld.vs2019.netcore3_1.csproj index 764a27395..13b92d789 100644 --- a/samples/NetCore/DotNetCoreFrameworkHelloWorld/reference/projects/helloworld/HelloWorld.vs2019.netcore3_1.csproj +++ b/samples/NetCore/DotNetCoreFrameworkHelloWorld/reference/projects/helloworld/HelloWorld.vs2019.netcore3_1.csproj @@ -10,6 +10,7 @@ netcoreapp3.1 512 true + true AnyCPU From 81318bad02b1c9a7047a94b869dc2b0d00567087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Parent?= Date: Thu, 12 Aug 2021 13:45:01 +0000 Subject: [PATCH 06/26] [AndroidProj] Fix regression by setting AndroidAppLibName without the platform prefix and the file extension --- Sharpmake.Generators/VisualStudio/Androidproj.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sharpmake.Generators/VisualStudio/Androidproj.cs b/Sharpmake.Generators/VisualStudio/Androidproj.cs index bff91f7d1..b088b9c20 100644 --- a/Sharpmake.Generators/VisualStudio/Androidproj.cs +++ b/Sharpmake.Generators/VisualStudio/Androidproj.cs @@ -432,7 +432,7 @@ private void GenerateOptions(GenerationContext context) if (appLibConf.Output != Project.Configuration.OutputType.Dll) throw new Error("Cannot use configuration \"{0}\" as app lib for package configuration \"{1}\". Output type must be set to dynamic library.", appLibConf, conf); - options["AndroidAppLibName"] = appLibConf.TargetFileFullName; + options["AndroidAppLibName"] = appLibConf.TargetFilePrefix + appLibConf.TargetFileName + appLibConf.TargetFileSuffix; } else { From 877113e0a3d8992dd22aebcc33cf141d9020490a Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Thu, 12 Aug 2021 17:19:48 +0200 Subject: [PATCH 07/26] Initial support for vs2022. --- Sharpmake.Generators/FastBuild/Bff.cs | 8 +- Sharpmake.Generators/GeneratorManager.cs | 12 +- Sharpmake.Generators/VisualStudio/Csproj.cs | 1 + .../VisualStudio/ProjectOptionsGenerator.cs | 31 ++-- .../VisualStudio/Sln.Template.cs | 5 + Sharpmake.Generators/VisualStudio/Sln.cs | 6 +- Sharpmake.Generators/VisualStudio/Vcxproj.cs | 5 +- .../Android/AndroidPlatform.cs | 7 +- .../Windows/Win64Platform.cs | 165 ++++++++---------- Sharpmake/ExtensionMethods.cs | 148 ++++++++++------ Sharpmake/KitsRootPaths.cs | 1 + Sharpmake/MSBuildGlobalSettings.cs | 8 +- Sharpmake/Options.Vc.cs | 2 + Sharpmake/Target.cs | 13 +- Sharpmake/Util.cs | 20 +-- 15 files changed, 233 insertions(+), 199 deletions(-) diff --git a/Sharpmake.Generators/FastBuild/Bff.cs b/Sharpmake.Generators/FastBuild/Bff.cs index c7d066407..4c6120c26 100644 --- a/Sharpmake.Generators/FastBuild/Bff.cs +++ b/Sharpmake.Generators/FastBuild/Bff.cs @@ -726,8 +726,6 @@ List skipFiles case Options.Vc.General.PlatformToolset.LLVM: case Options.Vc.General.PlatformToolset.ClangCL: // - // TODO: figure out what version number to put there - // maybe use the DevEnv value string mscVer = Options.GetString(conf); if (string.IsNullOrEmpty(mscVer)) { @@ -745,6 +743,9 @@ List 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); } @@ -759,6 +760,9 @@ List 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()); } diff --git a/Sharpmake.Generators/GeneratorManager.cs b/Sharpmake.Generators/GeneratorManager.cs index 150d15694..e48ad7354 100644 --- a/Sharpmake.Generators/GeneratorManager.cs +++ b/Sharpmake.Generators/GeneratorManager.cs @@ -88,7 +88,8 @@ public void Generate(Builder builder, } else { - switch (configurations[0].Target.GetFragment()) + DevEnv devEnv = configurations[0].Target.GetFragment(); + switch (devEnv) { case DevEnv.make: { @@ -101,6 +102,7 @@ public void Generate(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); @@ -114,7 +116,7 @@ public void Generate(Builder builder, } default: { - throw new Error("Generate called with unknown DevEnv: " + configurations[0].Target.GetFragment()); + throw new Error("Generate called with unknown DevEnv: " + devEnv); } } } @@ -137,7 +139,8 @@ public void Generate(Builder builder, } else { - switch (configurations[0].Target.GetFragment()) + DevEnv devEnv = configurations[0].Target.GetFragment(); + switch (devEnv) { case DevEnv.make: { @@ -150,6 +153,7 @@ public void Generate(Builder builder, case DevEnv.vs2015: case DevEnv.vs2017: case DevEnv.vs2019: + case DevEnv.vs2022: { if (UtilityMethods.HasFastBuildConfig(configurations)) { @@ -161,7 +165,7 @@ public void Generate(Builder builder, } default: { - throw new Error("Generate called with unknown DevEnv: " + configurations[0].Target.GetFragment()); + throw new Error("Generate called with unknown DevEnv: " + devEnv); } } } diff --git a/Sharpmake.Generators/VisualStudio/Csproj.cs b/Sharpmake.Generators/VisualStudio/Csproj.cs index 61fa2128f..7d0744cff 100644 --- a/Sharpmake.Generators/VisualStudio/Csproj.cs +++ b/Sharpmake.Generators/VisualStudio/Csproj.cs @@ -1190,6 +1190,7 @@ List skipFiles break; case DevEnv.vs2017: case DevEnv.vs2019: + case DevEnv.vs2022: Write(Template.Project.ProjectBeginVs2017, writer, resolver); break; default: diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index 7fe934fcd..afa56a298 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -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- @@ -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"; }) + ); } } @@ -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" @@ -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"; diff --git a/Sharpmake.Generators/VisualStudio/Sln.Template.cs b/Sharpmake.Generators/VisualStudio/Sln.Template.cs index aa43e3602..7ec7668c8 100644 --- a/Sharpmake.Generators/VisualStudio/Sln.Template.cs +++ b/Sharpmake.Generators/VisualStudio/Sln.Template.cs @@ -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 = diff --git a/Sharpmake.Generators/VisualStudio/Sln.cs b/Sharpmake.Generators/VisualStudio/Sln.cs index 0248b0d95..39f584ae4 100644 --- a/Sharpmake.Generators/VisualStudio/Sln.cs +++ b/Sharpmake.Generators/VisualStudio/Sln.cs @@ -302,9 +302,11 @@ out bool updated case DevEnv.vs2019: fileGenerator.Write(Template.Solution.HeaderBeginVs2019); break; - default: - Console.WriteLine("Unsupported DevEnv for solution " + solutionConfigurations[0].Target.GetFragment()); + case DevEnv.vs2022: + fileGenerator.Write(Template.Solution.HeaderBeginVs2022); break; + default: + throw new Error($"Unsupported DevEnv {devEnv} for solution {solution.Name}"); } SolutionFolder masterBffFolder = null; diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.cs index a680760ca..10e333e30 100644 --- a/Sharpmake.Generators/VisualStudio/Vcxproj.cs +++ b/Sharpmake.Generators/VisualStudio/Vcxproj.cs @@ -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); } @@ -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); diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Android/AndroidPlatform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Android/AndroidPlatform.cs index d5cc74624..f588bdf35 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Android/AndroidPlatform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Android/AndroidPlatform.cs @@ -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)) @@ -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)) @@ -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))) diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs index 20302ef5d..d14c3a2ab 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs @@ -142,17 +142,6 @@ bool useCCompiler case Options.Vc.General.PlatformToolset.Default: compilerDevEnv = devEnv; break; - case Options.Vc.General.PlatformToolset.v140: - case Options.Vc.General.PlatformToolset.v140_xp: - compilerDevEnv = DevEnv.vs2015; - break; - case Options.Vc.General.PlatformToolset.v141: - case Options.Vc.General.PlatformToolset.v141_xp: - compilerDevEnv = DevEnv.vs2017; - break; - case Options.Vc.General.PlatformToolset.v142: - compilerDevEnv = DevEnv.vs2019; - break; case Options.Vc.General.PlatformToolset.LLVM: case Options.Vc.General.PlatformToolset.ClangCL: @@ -166,7 +155,8 @@ bool useCCompiler break; default: - throw new ArgumentOutOfRangeException(); + compilerDevEnv = platformToolset.GetDefaultDevEnvForToolset(); + break; } if (compilerDevEnv.HasValue) @@ -198,81 +188,77 @@ bool useCCompiler @"$ExecutableRootPath$\1033\clui.dll" ); - switch (compilerDevEnv) + if (compilerDevEnv.Value.IsVisualStudio()) { - case DevEnv.vs2015: - case DevEnv.vs2017: - case DevEnv.vs2019: - { - string systemDllPath = FastBuildSettings.SystemDllRoot; - if (systemDllPath == null) - { - var windowsTargetPlatformVersion = KitsRootPaths.GetWindowsTargetPlatformVersionForDevEnv(compilerDevEnv.Value); - string redistDirectory; - if (windowsTargetPlatformVersion <= Options.Vc.General.WindowsTargetPlatformVersion.v10_0_17134_0) - redistDirectory = @"Redist\ucrt\DLLs\x64\"; - else - redistDirectory = $@"Redist\{windowsTargetPlatformVersion.ToVersionString()}\ucrt\DLLs\x64\"; - - systemDllPath = Path.Combine(KitsRootPaths.GetRoot(KitsRootEnum.KitsRoot10), redistDirectory); - } - - if (!Path.IsPathRooted(systemDllPath)) - systemDllPath = Util.SimplifyPath(Path.Combine(projectRootPath, systemDllPath)); - - extraFiles.Add( - @"$ExecutableRootPath$\msobj140.dll", - @"$ExecutableRootPath$\mspft140.dll", - @"$ExecutableRootPath$\mspdb140.dll" - ); - - if (compilerDevEnv.Value == DevEnv.vs2015) - { - extraFiles.Add( - @"$ExecutableRootPath$\vcvars64.bat", - Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC140.CRT\concrt140.dll"), - Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC140.CRT\msvcp140.dll"), - Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC140.CRT\vccorlib140.dll"), - Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC140.CRT\vcruntime140.dll"), - Path.Combine(systemDllPath, "ucrtbase.dll") - ); - } - else - { - extraFiles.Add( - @"$ExecutableRootPath$\mspdbcore.dll", - @"$ExecutableRootPath$\msvcdis140.dll", - @"$ExecutableRootPath$\msvcp140.dll", - @"$ExecutableRootPath$\pgodb140.dll", - @"$ExecutableRootPath$\vcruntime140.dll", - Path.Combine(platformToolSetPath, @"Auxiliary\Build\vcvars64.bat") - ); - } - - if (compilerDevEnv.Value == DevEnv.vs2019) - { - Version toolsVersion = compilerDevEnv.Value.GetVisualStudioVCToolsVersion(); - - if (toolsVersion >= new Version("14.22.27905")) // 16.3.2 - extraFiles.Add(@"$ExecutableRootPath$\tbbmalloc.dll"); - - if (toolsVersion >= new Version("14.25.28610")) // 16.5 - extraFiles.Add(@"$ExecutableRootPath$\vcruntime140_1.dll"); - - if (toolsVersion >= new Version("14.28.29333")) // 16.8 - extraFiles.Add(@"$ExecutableRootPath$\msvcp140_atomic_wait.dll"); - } - - try - { - foreach (string p in Util.DirectoryGetFiles(systemDllPath, "api-ms-win-*.dll")) - extraFiles.Add(p); - } - catch { } - } - break; - default: - throw new NotImplementedException("This devEnv (" + compilerDevEnv.Value + ") is not supported!"); + string systemDllPath = FastBuildSettings.SystemDllRoot; + if (systemDllPath == null) + { + var windowsTargetPlatformVersion = KitsRootPaths.GetWindowsTargetPlatformVersionForDevEnv(compilerDevEnv.Value); + string redistDirectory; + if (windowsTargetPlatformVersion <= Options.Vc.General.WindowsTargetPlatformVersion.v10_0_17134_0) + redistDirectory = @"Redist\ucrt\DLLs\x64\"; + else + redistDirectory = $@"Redist\{windowsTargetPlatformVersion.ToVersionString()}\ucrt\DLLs\x64\"; + + systemDllPath = Path.Combine(KitsRootPaths.GetRoot(KitsRootEnum.KitsRoot10), redistDirectory); + } + + if (!Path.IsPathRooted(systemDllPath)) + systemDllPath = Util.SimplifyPath(Path.Combine(projectRootPath, systemDllPath)); + + extraFiles.Add( + @"$ExecutableRootPath$\msobj140.dll", + @"$ExecutableRootPath$\mspft140.dll", + @"$ExecutableRootPath$\mspdb140.dll" + ); + + if (compilerDevEnv.Value == DevEnv.vs2015) + { + extraFiles.Add( + @"$ExecutableRootPath$\vcvars64.bat", + Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC140.CRT\concrt140.dll"), + Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC140.CRT\msvcp140.dll"), + Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC140.CRT\vccorlib140.dll"), + Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC140.CRT\vcruntime140.dll"), + Path.Combine(systemDllPath, "ucrtbase.dll") + ); + } + else + { + extraFiles.Add( + @"$ExecutableRootPath$\mspdbcore.dll", + @"$ExecutableRootPath$\msvcdis140.dll", + @"$ExecutableRootPath$\msvcp140.dll", + @"$ExecutableRootPath$\pgodb140.dll", + @"$ExecutableRootPath$\vcruntime140.dll", + Path.Combine(platformToolSetPath, @"Auxiliary\Build\vcvars64.bat") + ); + } + + if (compilerDevEnv.Value >= DevEnv.vs2019) + { + Version toolsVersion = compilerDevEnv.Value.GetVisualStudioVCToolsVersion(); + + if (toolsVersion >= new Version("14.22.27905")) // 16.3.2 + extraFiles.Add(@"$ExecutableRootPath$\tbbmalloc.dll"); + + if (toolsVersion >= new Version("14.25.28610")) // 16.5 + extraFiles.Add(@"$ExecutableRootPath$\vcruntime140_1.dll"); + + if (toolsVersion >= new Version("14.28.29333")) // 16.8 + extraFiles.Add(@"$ExecutableRootPath$\msvcp140_atomic_wait.dll"); + } + + try + { + foreach (string p in Util.DirectoryGetFiles(systemDllPath, "api-ms-win-*.dll")) + extraFiles.Add(p); + } + catch { } + } + else + { + throw new NotImplementedException("This devEnv (" + compilerDevEnv.Value + ") is not supported!"); } } @@ -439,14 +425,15 @@ public override void GeneratePlatformSpecificProjectDescription(IVcxprojGenerati } break; case DevEnv.vs2019: + case DevEnv.vs2022: { // Note1: _PlatformFolder override is deprecated starting with vs2019, so we write AdditionalVCTargetsPath instead - // Note2: MSBuildGlobalSettings.SetCppPlatformFolder for vs2019 is no more the valid way to handle it. Older buildtools packages can anyway contain it, and need upgrade. + // Note2: MSBuildGlobalSettings.SetCppPlatformFolder for vs2019 and above is no more the valid way to handle it. if (!string.IsNullOrEmpty(MSBuildGlobalSettings.GetCppPlatformFolder(devEnv, Platform.win64))) - throw new Error("SetCppPlatformFolder is not supported by VS2019 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."); - // vs2019 use AdditionalVCTargetsPath + // vs2019 and up use AdditionalVCTargetsPath string additionalVCTargetsPath = MSBuildGlobalSettings.GetAdditionalVCTargetsPath(devEnv, Platform.win64); if (!string.IsNullOrEmpty(additionalVCTargetsPath)) { diff --git a/Sharpmake/ExtensionMethods.cs b/Sharpmake/ExtensionMethods.cs index 959cfc196..17cf72095 100644 --- a/Sharpmake/ExtensionMethods.cs +++ b/Sharpmake/ExtensionMethods.cs @@ -203,6 +203,8 @@ public static string GetVisualProjectToolsVersionString(this DevEnv visualVersio return "15.0"; case DevEnv.vs2019: return "16.0"; + case DevEnv.vs2022: + return "17.0"; default: throw new Error("DevEnv " + visualVersion + " not recognized!"); } @@ -218,6 +220,8 @@ public static int GetVisualMajorVersion(this DevEnv visualVersion) return 15; case DevEnv.vs2019: return 16; + case DevEnv.vs2022: + return 17; default: throw new NotImplementedException("DevEnv " + visualVersion + " not recognized!"); } @@ -238,6 +242,8 @@ public static string GetDefaultPlatformToolset(this DevEnv visualVersion) return "v141"; case DevEnv.vs2019: return "v142"; + case DevEnv.vs2022: + return "v143"; default: throw new Error("DevEnv " + visualVersion + " not recognized!"); } @@ -253,6 +259,8 @@ public static string GetVSYear(this DevEnv visualVersion) return "2017"; case DevEnv.vs2019: return "2019"; + case DevEnv.vs2022: + return "2022"; default: throw new Error("DevEnv " + visualVersion + " not recognized!"); } @@ -280,6 +288,9 @@ public static bool OverridenVisualStudioDir(this DevEnv visualVersion) private static readonly ConcurrentDictionary, string> s_visualStudioDirectories = new ConcurrentDictionary, string>(); public static string GetVisualStudioDir(this DevEnv visualVersion, bool ignoreVisualStudioPathOverride = false) { + if (!visualVersion.IsVisualStudio()) + throw new Error($"{visualVersion} is not a visual studio version!"); + // TODO: Replace Tuple with ValueTuple once we support C# 8 because ValueTuple is // allocated on the stack. That should be faster here. string visualStudioDirectory = s_visualStudioDirectories.GetOrAdd(Tuple.Create(visualVersion, ignoreVisualStudioPathOverride), devEnv => @@ -295,17 +306,21 @@ public static string GetVisualStudioDir(this DevEnv visualVersion, bool ignoreVi string installDir = Util.GetVisualStudioInstallPathFromQuery(visualVersion); if (string.IsNullOrEmpty(installDir)) { - switch (visualVersion) + // try again but this time including previews + installDir = Util.GetVisualStudioInstallPathFromQuery(visualVersion, allowPrereleaseVersions: true); + if (string.IsNullOrEmpty(installDir)) // arbitrary fallback { - case DevEnv.vs2017: - case DevEnv.vs2019: + if (visualVersion > DevEnv.vs2015) + { installDir = @"Microsoft Visual Studio\" + GetVSYear(visualVersion) + @"\Professional"; - break; - default: + } + else + { installDir = string.Format(@"Microsoft Visual Studio {0}", visualVersion.GetVisualVersionString()); - break; + } + string rootDir = Environment.GetFolderPath(visualVersion < DevEnv.vs2022 ? Environment.SpecialFolder.ProgramFilesX86 : Environment.SpecialFolder.ProgramFiles); + installDir = Path.Combine(rootDir, installDir); } - installDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), installDir); } return Util.SimplifyPath(installDir); }); @@ -321,6 +336,8 @@ private static string GetDefaultCompilerVersion(this DevEnv visualVersion) return "14.10.25017"; case DevEnv.vs2019: return "14.20.27404"; + case DevEnv.vs2022: + return "14.30.30423"; // from Preview3 default: throw new Error("DevEnv " + visualVersion + " not recognized for default compiler version"); } @@ -329,19 +346,20 @@ private static string GetDefaultCompilerVersion(this DevEnv visualVersion) private static readonly ConcurrentDictionary s_visualStudioVCRootPathCache = new ConcurrentDictionary(); public static string GetVisualStudioVCRootPath(this DevEnv visualVersion) { + if (!visualVersion.IsVisualStudio()) + throw new Error($"{visualVersion} is not a visual studio version!"); + string visualStudioVCRootPath = s_visualStudioVCRootPathCache.GetOrAdd(visualVersion, devEnv => { string vsDir = visualVersion.GetVisualStudioDir(); - switch (visualVersion) + if (visualVersion > DevEnv.vs2015) { - case DevEnv.vs2015: - return Path.Combine(vsDir, "VC"); - - case DevEnv.vs2017: - case DevEnv.vs2019: - return Path.Combine(vsDir, @"VC\Tools\MSVC", visualVersion.GetVisualStudioVCToolsVersion().ToString()); + return Path.Combine(vsDir, @"VC\Tools\MSVC", visualVersion.GetVisualStudioVCToolsVersion().ToString()); + } + else + { + return Path.Combine(vsDir, "VC"); } - throw new ArgumentOutOfRangeException("VS version not recognized " + visualVersion); }); return visualStudioVCRootPath; @@ -350,33 +368,50 @@ public static string GetVisualStudioVCRootPath(this DevEnv visualVersion) private static readonly ConcurrentDictionary s_visualStudioVCToolsVersionCache = new ConcurrentDictionary(); public static Version GetVisualStudioVCToolsVersion(this DevEnv visualVersion) { + if (!visualVersion.IsVisualStudio()) + throw new Error($"{visualVersion} is not a visual studio version!"); + Version version = s_visualStudioVCToolsVersionCache.GetOrAdd(visualVersion, devEnv => { - string vsDir = visualVersion.GetVisualStudioDir(); - switch (visualVersion) + string versionString = visualVersion.GetDefaultCompilerVersion(); // default fallback + try { - case DevEnv.vs2017: - case DevEnv.vs2019: - string versionString = visualVersion.GetDefaultCompilerVersion(); // default fallback - try - { - string toolchainFile = Path.Combine(vsDir, "VC", "Auxiliary", "Build", "Microsoft.VCToolsVersion.default.txt"); - if (File.Exists(toolchainFile)) - { - using (StreamReader file = new StreamReader(toolchainFile)) - versionString = file.ReadLine().Trim(); - } - } - catch { } - - return new Version(versionString); + string toolchainFile = Path.Combine(visualVersion.GetVisualStudioDir(), "VC", "Auxiliary", "Build", "Microsoft.VCToolsVersion.default.txt"); + if (File.Exists(toolchainFile)) + { + using (StreamReader file = new StreamReader(toolchainFile)) + versionString = file.ReadLine().Trim(); + } } - throw new ArgumentOutOfRangeException("VS version not recognized " + visualVersion); + catch { } + + return new Version(versionString); }); return version; } + /// + /// Will return the name of the root directory in MSBuild under Microsoft/VC for a particular devenv, + /// since it uses yet another versioning pattern than the toolchain + /// + /// The visual studio version to convert + /// The name of the directory for that version + public static string GetMSBuildVCDirVersion(this DevEnv visualVersion) + { + switch (visualVersion) + { + case DevEnv.vs2017: + return "v150"; + case DevEnv.vs2019: + return "v160"; + case DevEnv.vs2022: + return "v170"; + default: + throw new Error("DevEnv " + visualVersion + " not supported!"); + } + } + public static string GetVCTargetsPath(this DevEnv visualVersion) { if (!visualVersion.IsVisualStudio()) @@ -390,7 +425,8 @@ public static string GetVCTargetsPath(this DevEnv visualVersion) case DevEnv.vs2017: return Path.Combine(visualVersion.GetVisualStudioDir(), @"Common7\IDE\VC\VCTargets"); case DevEnv.vs2019: - return Path.Combine(visualVersion.GetVisualStudioDir(), @"MSBuild\Microsoft\VC\v160"); + case DevEnv.vs2022: + return Path.Combine(visualVersion.GetVisualStudioDir(), @"MSBuild\Microsoft\VC\", visualVersion.GetMSBuildVCDirVersion()); default: throw new ArgumentOutOfRangeException(nameof(visualVersion), visualVersion, null); } @@ -404,6 +440,8 @@ private static string GetDefaultRedistVersion(this DevEnv visualVersion) return "14.16.27012"; case DevEnv.vs2019: return "14.24.28127"; + case DevEnv.vs2022: + return "14.30.30423"; // from Preview3 default: throw new Error("DevEnv " + visualVersion + " not recognized for default compiler version"); } @@ -415,25 +453,19 @@ public static Version GetVisualStudioVCRedistVersion(this DevEnv visualVersion) Version version = s_visualStudioVCRedistVersionCache.GetOrAdd(visualVersion, devEnv => { string vsDir = visualVersion.GetVisualStudioDir(); - switch (visualVersion) + string versionString = visualVersion.GetDefaultRedistVersion(); // default fallback + try { - case DevEnv.vs2017: - case DevEnv.vs2019: - string versionString = visualVersion.GetDefaultRedistVersion(); // default fallback - try - { - string toolchainFile = Path.Combine(vsDir, "VC", "Auxiliary", "Build", "Microsoft.VCRedistVersion.default.txt"); - if (File.Exists(toolchainFile)) - { - using (StreamReader file = new StreamReader(toolchainFile)) - versionString = file.ReadLine().Trim(); - } - } - catch { } - - return new Version(versionString); + string toolchainFile = Path.Combine(vsDir, "VC", "Auxiliary", "Build", "Microsoft.VCRedistVersion.default.txt"); + if (File.Exists(toolchainFile)) + { + using (StreamReader file = new StreamReader(toolchainFile)) + versionString = file.ReadLine().Trim(); + } } - throw new ArgumentOutOfRangeException("VS version not recognized " + visualVersion); + catch { } + + return new Version(versionString); }); return version; @@ -450,6 +482,7 @@ public static string GetVisualStudioBinPath(this DevEnv visualVersion, Platform } case DevEnv.vs2017: case DevEnv.vs2019: + case DevEnv.vs2022: { string targetPlatform = (platform == Platform.win64) ? "x64" : "x86"; string compilerHost = Environment.Is64BitOperatingSystem ? "HostX64" : "HostX86"; @@ -602,7 +635,7 @@ public static string GetWindowsLibraryPath(this DevEnv visualVersion, Platform p { string visualStudioVCDir = Util.EnsureTrailingSeparator(visualVersion.GetVisualStudioVCRootPath()); string subDir = platform == Platform.win64 ? @"\amd64" : ""; - if ((visualVersion == DevEnv.vs2017) || (visualVersion == DevEnv.vs2019)) + if (visualVersion.IsVisualStudio() && visualVersion >= DevEnv.vs2017) subDir = platform == Platform.win64 ? @"\x64" : @"\x86"; string visualStudioLib = string.Format(@"{0}lib{1};{0}atlmfc\lib{1};", visualStudioVCDir, subDir); @@ -714,6 +747,8 @@ public static bool IsDefaultToolsetForDevEnv(this Options.Vc.General.PlatformToo return visualVersion == DevEnv.vs2017; case Options.Vc.General.PlatformToolset.v142: return visualVersion == DevEnv.vs2019; + case Options.Vc.General.PlatformToolset.v143: + return visualVersion == DevEnv.vs2022; case Options.Vc.General.PlatformToolset.v140_xp: case Options.Vc.General.PlatformToolset.v141_xp: case Options.Vc.General.PlatformToolset.LLVM: @@ -739,6 +774,8 @@ public static bool IsDefaultToolsetForDevEnv(this Options.Vc.General.PlatformToo return DevEnv.vs2017; case Options.Vc.General.PlatformToolset.v142: return DevEnv.vs2019; + case Options.Vc.General.PlatformToolset.v143: + return DevEnv.vs2022; case Options.Vc.General.PlatformToolset.LLVM: case Options.Vc.General.PlatformToolset.ClangCL: return null; @@ -763,6 +800,10 @@ public static void GetVcPathKeysFromDevEnv(this DevEnv devEnv, out string vcTarg vcTargetsPathKey = "VCTargetsPath16"; vcRootPathKey = "VCInstallDir_160"; break; + case DevEnv.vs2022: + vcTargetsPathKey = "VCTargetsPath17"; + vcRootPathKey = "VCInstallDir_160"; // LCTODO: Preview3 still uses 160!!! + break; default: throw new NotImplementedException("Please implement redirection of toolchain for " + devEnv); } @@ -796,6 +837,7 @@ private static bool IsAbiCompatibleWithVS2015(this DevEnv devEnv) case DevEnv.vs2015: case DevEnv.vs2017: case DevEnv.vs2019: + case DevEnv.vs2022: return true; default: return false; @@ -823,7 +865,7 @@ public static bool IsAbiCompatibleWith(this DevEnv devEnv, DevEnv other) if (devEnv == other) return true; - // VS2017 and VS2019 are guaranteed by Microsoft to be ABI-compatible with VS2015 for C++. + // VS2017/VS2019/VS2022 are guaranteed by Microsoft to be ABI-compatible with VS2015 for C++. if (devEnv.IsAbiCompatibleWithVS2015() && other.IsAbiCompatibleWithVS2015()) return true; diff --git a/Sharpmake/KitsRootPaths.cs b/Sharpmake/KitsRootPaths.cs index 0cfb59aad..0292e26bb 100644 --- a/Sharpmake/KitsRootPaths.cs +++ b/Sharpmake/KitsRootPaths.cs @@ -47,6 +47,7 @@ public KitsRootPaths() s_defaultKitsRootForDevEnv[DevEnv.vs2015] = Tuple.Create(KitsRootEnum.KitsRoot81, Options.Vc.General.WindowsTargetPlatformVersion.v8_1); s_defaultKitsRootForDevEnv[DevEnv.vs2017] = Tuple.Create(KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_10586_0); s_defaultKitsRootForDevEnv[DevEnv.vs2019] = Tuple.Create(KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_16299_0); + s_defaultKitsRootForDevEnv[DevEnv.vs2022] = Tuple.Create(KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0); } public static string GetRoot(KitsRootEnum kitsRoot) diff --git a/Sharpmake/MSBuildGlobalSettings.cs b/Sharpmake/MSBuildGlobalSettings.cs index 88f04bccb..3a1f16448 100644 --- a/Sharpmake/MSBuildGlobalSettings.cs +++ b/Sharpmake/MSBuildGlobalSettings.cs @@ -95,7 +95,7 @@ public static string GetCppPlatformFolder(DevEnv devEnv, string platform) } - // additionalVCTargetsPath (vs2019) + // additionalVCTargetsPath (vs2019+) private static readonly ConcurrentDictionary, string> s_additionalVCTargetsPath = new ConcurrentDictionary, string>(); /// @@ -113,7 +113,7 @@ public static void SetAdditionalVCTargetsPath(DevEnv devEnv, Platform platform, /// /// Allows setting MSBuild vc target path used for a custom platform passed as a string and Visual Studio version. - /// This is typically used if you want to add platform specific files with vs2019 as the older way of doing it through _PlatformFolder is deprecated. + /// This is typically used if you want to add platform specific files with vs2019+ as the older way of doing it through _PlatformFolder is deprecated. /// /// Visual studio version affected /// Platform affected @@ -140,7 +140,7 @@ public static void ResetAdditionalVCTargetsPath(DevEnv devEnv, string platform) /// /// Get the MSBuild Additional VC targets path used for a known sharpmake platform and Visual studio version. - /// This is typically used if you want to add platform specific files with vs2019 as the older way of doing it through _PlatformFolder is deprecated. + /// This is typically used if you want to add platform specific files with vs2019+ as the older way of doing it through _PlatformFolder is deprecated. /// /// Visual studio version affected /// Platform affected @@ -152,7 +152,7 @@ public static string GetAdditionalVCTargetsPath(DevEnv devEnv, Platform platform /// /// Get the MSBuild Additional VC targets path used for a custom platform passed as a string and Visual studio version. - /// This is typically used if you want to add platform specific files with vs2019 as the older way of doing it through _PlatformFolder is deprecated. + /// This is typically used if you want to add platform specific files with vs2019+ as the older way of doing it through _PlatformFolder is deprecated. /// /// Visual studio version affected /// Platform affected diff --git a/Sharpmake/Options.Vc.cs b/Sharpmake/Options.Vc.cs index 9f83ab38b..c86094770 100644 --- a/Sharpmake/Options.Vc.cs +++ b/Sharpmake/Options.Vc.cs @@ -41,6 +41,8 @@ public enum PlatformToolset v141_xp, // Visual Studio 2017 - Windows XP [DevEnvVersion(minimum = DevEnv.vs2019)] v142, // Visual Studio 2019 + [DevEnvVersion(minimum = DevEnv.vs2022)] + v143, // Visual Studio 2022 [DevEnvVersion(minimum = DevEnv.vs2017)] LLVM, // LLVM from Visual Studio 2017 [DevEnvVersion(minimum = DevEnv.vs2019)] diff --git a/Sharpmake/Target.cs b/Sharpmake/Target.cs index 411d5329b..a6accf684 100644 --- a/Sharpmake/Target.cs +++ b/Sharpmake/Target.cs @@ -44,26 +44,31 @@ public enum DevEnv /// vs2019 = 1 << 5, + /// + /// Visual Studio 2022 + /// + vs2022 = 1 << 6, + /// /// iOS project with Xcode. /// - xcode4ios = 1 << 6, + xcode4ios = 1 << 7, /// /// Eclipse. /// - eclipse = 1 << 7, + eclipse = 1 << 8, /// /// GNU Makefiles. /// - make = 1 << 8, + make = 1 << 9, /// /// All supported Visual Studio versions. /// [CompositeFragment] - VisualStudio = vs2015 | vs2017 | vs2019, + VisualStudio = vs2015 | vs2017 | vs2019 | vs2022, [Obsolete("Sharpmake doesn't support vs2010 anymore.")] vs2010 = -1, diff --git a/Sharpmake/Util.cs b/Sharpmake/Util.cs index bf8f565b7..9f11a8e1a 100644 --- a/Sharpmake/Util.cs +++ b/Sharpmake/Util.cs @@ -1272,19 +1272,7 @@ public static string GetToolVersionString(DevEnv env, DotNetFramework desiredFra public static string GetToolVersionString(DevEnv env) { - switch (env) - { - case DevEnv.vs2015: - case DevEnv.vs2017: - case DevEnv.vs2019: - return env.GetVisualProjectToolsVersionString(); - case DevEnv.xcode4ios: - throw new NotSupportedException("XCode does not support Tool Version. "); - case DevEnv.eclipse: - throw new NotSupportedException("Eclipse does not support Tool Version. "); - default: - throw new NotImplementedException(string.Format("ToolVersion not set for Visual Studio {0}", env)); - } + return env.GetVisualProjectToolsVersionString(); } public enum FileCopyDestReadOnlyPolicy : byte @@ -1351,11 +1339,13 @@ public static string GetProjectFileExtension(Project.Configuration conf) extension = ".androidproj"; else { - switch (conf.Target.GetFragment()) + DevEnv devEnv = conf.Target.GetFragment(); + switch (devEnv) { case DevEnv.vs2015: case DevEnv.vs2017: case DevEnv.vs2019: + case DevEnv.vs2022: { extension = ".vcxproj"; } @@ -1371,7 +1361,7 @@ public static string GetProjectFileExtension(Project.Configuration conf) return ".make"; default: - throw new NotImplementedException("GetProjectFileExtension called with unknown DevEnv: " + conf.Target.GetFragment()); + throw new NotImplementedException("GetProjectFileExtension called with unknown DevEnv: " + devEnv); } } return extension; From e05948f2047bbef0c85819611b04046a7a57dcdd Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Thu, 12 Aug 2021 17:32:07 +0200 Subject: [PATCH 08/26] Fix unit-test exception type --- Sharpmake.UnitTests/UtilTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sharpmake.UnitTests/UtilTest.cs b/Sharpmake.UnitTests/UtilTest.cs index 4f827e92b..19bb45ce3 100644 --- a/Sharpmake.UnitTests/UtilTest.cs +++ b/Sharpmake.UnitTests/UtilTest.cs @@ -449,9 +449,9 @@ public class ProjectEnvironment [Test] public void GetToolVersionStringException() { - Assert.Catch(() => Util.GetToolVersionString(DevEnv.xcode4ios)); - Assert.Catch(() => Util.GetToolVersionString(DevEnv.eclipse)); - Assert.Catch(() => Util.GetToolVersionString(DevEnv.make)); + Assert.Catch(() => Util.GetToolVersionString(DevEnv.xcode4ios)); + Assert.Catch(() => Util.GetToolVersionString(DevEnv.eclipse)); + Assert.Catch(() => Util.GetToolVersionString(DevEnv.make)); } /// From 62f11eb03f5730dc2e02d250ad275b9b77cc2815 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Aug 2021 18:01:13 +0200 Subject: [PATCH 09/26] Bump Microsoft.CodeAnalysis.CSharp from 3.10.0 to 3.11.0 in /Sharpmake (#139) Bumps [Microsoft.CodeAnalysis.CSharp](https://github.com/dotnet/roslyn) from 3.10.0 to 3.11.0. - [Release notes](https://github.com/dotnet/roslyn/releases) - [Changelog](https://github.com/dotnet/roslyn/blob/main/docs/Breaking%20API%20Changes.md) - [Commits](https://github.com/dotnet/roslyn/commits) --- updated-dependencies: - dependency-name: Microsoft.CodeAnalysis.CSharp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Sharpmake/Sharpmake.csproj | 2 +- Sharpmake/Sharpmake.sharpmake.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sharpmake/Sharpmake.csproj b/Sharpmake/Sharpmake.csproj index c824a403b..b0835bb8b 100644 --- a/Sharpmake/Sharpmake.csproj +++ b/Sharpmake/Sharpmake.csproj @@ -136,7 +136,7 @@ - + diff --git a/Sharpmake/Sharpmake.sharpmake.cs b/Sharpmake/Sharpmake.sharpmake.cs index fcf7508a5..5eed9ed65 100644 --- a/Sharpmake/Sharpmake.sharpmake.cs +++ b/Sharpmake/Sharpmake.sharpmake.cs @@ -24,7 +24,7 @@ public override void ConfigureAll(Configuration conf, Target target) conf.Options.Add(Options.CSharp.AllowUnsafeBlocks.Enabled); - conf.ReferencesByNuGetPackage.Add("Microsoft.CodeAnalysis.CSharp", "3.10.0"); + conf.ReferencesByNuGetPackage.Add("Microsoft.CodeAnalysis.CSharp", "3.11.0"); conf.ReferencesByNuGetPackage.Add("Microsoft.VisualStudio.Setup.Configuration.Interop", "2.3.2262-g94fae01e"); } } From 333b13ca5df9865718cc76b12b869ff76c38c2b6 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Thu, 12 Aug 2021 18:57:48 +0200 Subject: [PATCH 10/26] Resolve conf.IncludeSystemPaths against the SourceRootPath, same as Include and IncludePrivate --- Sharpmake/Project.Configuration.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sharpmake/Project.Configuration.cs b/Sharpmake/Project.Configuration.cs index e906db1d1..f8e675334 100644 --- a/Sharpmake/Project.Configuration.cs +++ b/Sharpmake/Project.Configuration.cs @@ -2351,6 +2351,7 @@ internal void Resolve(Resolver resolver) Util.ResolvePath(Project.SourceRootPath, ref SourceFilesBuildExclude); Util.ResolvePath(Project.SourceRootPath, ref IncludePaths); Util.ResolvePath(Project.SourceRootPath, ref IncludePrivatePaths); + Util.ResolvePath(Project.SourceRootPath, ref IncludeSystemPaths); Util.ResolvePath(Project.SourceRootPath, ref PrecompSourceExclude); Util.ResolvePath(Project.SourceRootPath, ref PrecompSourceExcludeFolders); Util.ResolvePath(Project.SourceRootPath, ref ConsumeWinRTExtensions); From 68b5587418a255a18ef88bceadf8cbc59e04de0e Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Fri, 13 Aug 2021 09:53:51 +0200 Subject: [PATCH 11/26] Add support for Windows 10 SDK (10.0.20348.0), version 2104/21H1 --- Sharpmake/ExtensionMethods.cs | 2 ++ Sharpmake/Options.Vc.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/Sharpmake/ExtensionMethods.cs b/Sharpmake/ExtensionMethods.cs index 17cf72095..c4f6e98b3 100644 --- a/Sharpmake/ExtensionMethods.cs +++ b/Sharpmake/ExtensionMethods.cs @@ -730,6 +730,8 @@ public static string ToVersionString(this Options.Vc.General.WindowsTargetPlatfo return "10.0.18362.0"; case Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0: return "10.0.19041.0"; + case Options.Vc.General.WindowsTargetPlatformVersion.v10_0_20348_0: + return "10.0.20348.0"; case Options.Vc.General.WindowsTargetPlatformVersion.Latest: return "$(LatestTargetPlatformVersion)"; default: diff --git a/Sharpmake/Options.Vc.cs b/Sharpmake/Options.Vc.cs index c86094770..c9bb755f7 100644 --- a/Sharpmake/Options.Vc.cs +++ b/Sharpmake/Options.Vc.cs @@ -83,6 +83,7 @@ public enum WindowsTargetPlatformVersion v10_0_17763_0, // 1809, October 2018 Update v10_0_18362_0, // 1903, May 2019 Update v10_0_19041_0, // 2004, May 2020 Update + v10_0_20348_0, // 2104/21H1 Latest, // latest available in host machine } From 2e3fa81dafe4c35631a4158bf8ab63fb2ab052a9 Mon Sep 17 00:00:00 2001 From: Guillaume BUCHLE Date: Tue, 11 Aug 2020 14:24:55 -0400 Subject: [PATCH 12/26] [XCode] Fix output and intermediate dirs $OBJROOT is changed juste before building by XCode, so $CONFIGURATION_TEMP_DIR was not the one wanted. The reason is that some values like $OBJROOT or $SYMROOT are project specific and not target specific (according to https://pewpewthespells.com/blog/buildsettings.html#objroot). So XCode use the value defined in the project configs and not the target configs. To set output paths, intermediate paths, per target and configuration we need to directly set the dedicated variable, like $CONFIGURATION_TEMP_DIR for example Delete some redundancy --- Sharpmake.Generators/Apple/XCodeProj.Template.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sharpmake.Generators/Apple/XCodeProj.Template.cs b/Sharpmake.Generators/Apple/XCodeProj.Template.cs index 9aeee263d..67ffd759f 100644 --- a/Sharpmake.Generators/Apple/XCodeProj.Template.cs +++ b/Sharpmake.Generators/Apple/XCodeProj.Template.cs @@ -248,7 +248,7 @@ private static class Template CODE_SIGN_IDENTITY = ""[item.Options.CodeSigningIdentity]""; ""CODE_SIGN_IDENTITY[sdk=iphoneos*]"" = ""[item.Options.CodeSigningIdentity]""; CONFIGURATION_BUILD_DIR = ""[item.Options.BuildDirectory]""; - CONFIGURATION_TEMP_DIR = ""$(OBJROOT)""; + CONFIGURATION_TEMP_DIR = ""[item.Configuration.IntermediatePath]""; COPY_PHASE_STRIP = [item.Options.StripDebugSymbolsDuringCopy]; DEAD_CODE_STRIPPING = [item.Options.DeadStripping]; DEBUG_INFORMATION_FORMAT = [item.Options.DebugInformationFormat]; From e1999e87a8d897984f47463a5205182447b878a1 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Fri, 13 Aug 2021 17:46:41 +0200 Subject: [PATCH 13/26] Add new CppLanguageStandard.CPP20 entry in Options.Vc to allow enabling C++20 in vs2019+ --- .../VisualStudio/ProjectOptionsGenerator.cs | 1 + Sharpmake/Options.Vc.cs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index afa56a298..c74a04d04 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -360,6 +360,7 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG Options.Option(Options.Vc.Compiler.CppLanguageStandard.CPP11, () => { context.Options["LanguageStandard"] = FileGeneratorUtilities.RemoveLineTag; context.CommandLineOptions["LanguageStandard"] = FileGeneratorUtilities.RemoveLineTag; }), Options.Option(Options.Vc.Compiler.CppLanguageStandard.CPP14, () => { context.Options["LanguageStandard"] = "stdcpp14"; context.CommandLineOptions["LanguageStandard"] = "/std:c++14"; }), Options.Option(Options.Vc.Compiler.CppLanguageStandard.CPP17, () => { context.Options["LanguageStandard"] = "stdcpp17"; context.CommandLineOptions["LanguageStandard"] = "/std:c++17"; }), + Options.Option(Options.Vc.Compiler.CppLanguageStandard.CPP20, () => { context.Options["LanguageStandard"] = "stdcpp20"; context.CommandLineOptions["LanguageStandard"] = "/std:c++20"; }), Options.Option(Options.Vc.Compiler.CppLanguageStandard.GNU98, () => { context.Options["LanguageStandard"] = FileGeneratorUtilities.RemoveLineTag; context.CommandLineOptions["LanguageStandard"] = FileGeneratorUtilities.RemoveLineTag; }), Options.Option(Options.Vc.Compiler.CppLanguageStandard.GNU11, () => { context.Options["LanguageStandard"] = FileGeneratorUtilities.RemoveLineTag; context.CommandLineOptions["LanguageStandard"] = FileGeneratorUtilities.RemoveLineTag; }), Options.Option(Options.Vc.Compiler.CppLanguageStandard.GNU14, () => { context.Options["LanguageStandard"] = "stdcpp14"; context.CommandLineOptions["LanguageStandard"] = "/std:c++14"; }), diff --git a/Sharpmake/Options.Vc.cs b/Sharpmake/Options.Vc.cs index c9bb755f7..97165fabf 100644 --- a/Sharpmake/Options.Vc.cs +++ b/Sharpmake/Options.Vc.cs @@ -1143,6 +1143,12 @@ public enum CppLanguageStandard [DevEnvVersion(minimum = DevEnv.vs2017)] CPP17, + /// + /// ISO C++20 Standard + /// + [DevEnvVersion(minimum = DevEnv.vs2019)] + CPP20, + GNU98, GNU11, [DevEnvVersion(minimum = DevEnv.vs2015)] From 506aa1d279bfb436875b95f289124cdf761178a9 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Fri, 13 Aug 2021 17:48:46 +0200 Subject: [PATCH 14/26] Add new TranslateIncludes option in Options.Vc for vs2019+ --- Sharpmake.Generators/FastBuild/Bff.Template.cs | 1 + .../VisualStudio/ProjectOptionsGenerator.cs | 5 +++++ .../BasePlatform.Vcxproj.Template.cs | 1 + Sharpmake/Options.Vc.cs | 13 +++++++++++++ 4 files changed, 20 insertions(+) diff --git a/Sharpmake.Generators/FastBuild/Bff.Template.cs b/Sharpmake.Generators/FastBuild/Bff.Template.cs index abd22b945..e2dd6ed8d 100644 --- a/Sharpmake.Generators/FastBuild/Bff.Template.cs +++ b/Sharpmake.Generators/FastBuild/Bff.Template.cs @@ -411,6 +411,7 @@ public static class ConfigurationFile + ' /errorReport:queue' // Character Set // --------------------------- + + ' [cmdLineOptions.TranslateIncludes]' + ' [cmdLineOptions.CharacterSet]' // Additional compiler options //-------------------------- diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index c74a04d04..e20264682 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -498,6 +498,11 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG Options.Option(Options.Vc.General.DiagnosticsFormat.ColumnInfo, () => { context.Options["DiagnosticsFormat"] = "Column"; context.CommandLineOptions["DiagnosticsFormat"] = "/diagnostics:column"; }) ); + context.SelectOption + ( + Options.Option(Options.Vc.General.TreatAngleIncludeAsExternal.Enable, () => { context.Options["TreatAngleIncludeAsExternal"] = "true"; context.CommandLineOptions["TreatAngleIncludeAsExternal"] = "/external:anglebrackets"; }), + Options.Option(Options.Vc.General.TreatAngleIncludeAsExternal.Disable, () => { context.Options["TreatAngleIncludeAsExternal"] = FileGeneratorUtilities.RemoveLineTag; context.CommandLineOptions["TreatAngleIncludeAsExternal"] = FileGeneratorUtilities.RemoveLineTag; }) + ); context.Options["TrackFileAccess"] = FileGeneratorUtilities.RemoveLineTag; diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs index b8f7ac61b..b825b737b 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs @@ -175,6 +175,7 @@ public abstract partial class BasePlatform [options.ConfigurationType] [options.UseDebugLibraries] [options.PreferredToolArchitecture] + [options.TranslateIncludes] [options.CharacterSet] [options.UseOfMfc] [clrSupport] diff --git a/Sharpmake/Options.Vc.cs b/Sharpmake/Options.Vc.cs index 97165fabf..d1aa2a555 100644 --- a/Sharpmake/Options.Vc.cs +++ b/Sharpmake/Options.Vc.cs @@ -87,6 +87,19 @@ public enum WindowsTargetPlatformVersion Latest, // latest available in host machine } + /// + /// Translate Includes to Imports + /// + /// + /// Enables the compiler to translate #include directives into import directives for the available header units. (/translateInclude) + /// + public enum TranslateIncludes + { + Enable, + [Default] + Disable + } + /// /// Character Set /// From f5d24c06b47a46828390bcf78f7c15ef099b0cab Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Fri, 13 Aug 2021 17:49:10 +0200 Subject: [PATCH 15/26] Add support for /external:I and associated options with vs2019+ --- .../FastBuild/Bff.Template.cs | 29 +------ .../VisualStudio/ProjectOptionsGenerator.cs | 70 ++++++++++++++--- .../BasePlatform.Vcxproj.Template.cs | 11 +++ .../Windows/BaseWindowsPlatform.cs | 21 ++++- .../Windows/Win64Platform.cs | 9 ++- Sharpmake/Options.Vc.cs | 78 ++++++++++++++++++- 6 files changed, 178 insertions(+), 40 deletions(-) diff --git a/Sharpmake.Generators/FastBuild/Bff.Template.cs b/Sharpmake.Generators/FastBuild/Bff.Template.cs index e2dd6ed8d..edbb64a4d 100644 --- a/Sharpmake.Generators/FastBuild/Bff.Template.cs +++ b/Sharpmake.Generators/FastBuild/Bff.Template.cs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; - namespace Sharpmake.Generators.FastBuild { public partial class Bff @@ -334,20 +332,14 @@ public static class ConfigurationFile public static string MasmCompilerExtraOptions = @" .CompilerExtraOptions = '' - // General options - // --------------------------- + ' /nologo' + ' /W3' + ' /errorReport:queue' - // Preprocessor options - // --------------------------- + ' [cmdLineOptions.PreprocessorDefinitions]' "; public static string CPPCompilerExtraOptions = @" .CompilerExtraOptions = '' - // General options - // --------------------------- + ' [cmdLineOptions.AdditionalIncludeDirectories]' + ' [cmdLineOptions.AdditionalUsingDirectories]' + ' [cmdLineOptions.DebugInformationFormat]' @@ -356,22 +348,17 @@ public static class ConfigurationFile + ' [cmdLineOptions.SuppressStartupBanner]' + ' [cmdLineOptions.WarningLevel]' + ' [cmdLineOptions.TreatWarningAsError]' + + ' [cmdLineOptions.ExternalWarningLevel]' + ' [cmdLineOptions.DiagnosticsFormat]' + ' [cmdLineOptions.EnableASAN]' + ' [fastBuildCompileAsC]' - // Multi-threaded build is already handled by FASTBuild - // + ' [cmdLineOptions.MultiProcessorCompilation]' + ' [cmdLineOptions.ConfigurationType]' - // Preprocessor options - // --------------------------- + ' [cmdLineOptions.PreprocessorDefinitions]' + ' [cmdLineOptions.UndefinePreprocessorDefinitions]' + ' [cmdLineOptions.UndefineAllPreprocessorDefinitions]' + ' [cmdLineOptions.IgnoreStandardIncludePath]' + ' [cmdLineOptions.GeneratePreprocessedFile]' + ' [cmdLineOptions.KeepComments]' - // Code Generation options - // --------------------------- + ' [cmdLineOptions.StringPooling]' + ' [cmdLineOptions.MinimalRebuild]' + ' [cmdLineOptions.ExceptionHandling]' @@ -387,8 +374,6 @@ public static class ConfigurationFile + ' [cmdLineOptions.CompilerCreateHotpatchableImage]' + ' [cmdLineOptions.SupportJustMyCode]' + ' [cmdLineOptions.SpectreMitigation]' - // Language options - // --------------------------- + ' [cmdLineOptions.DisableLanguageExtensions]' + ' [cmdLineOptions.TreatWChar_tAsBuiltInType]' + ' [cmdLineOptions.ForceConformanceInForLoopScope]' @@ -398,30 +383,22 @@ public static class ConfigurationFile + ' [cmdLineOptions.LanguageStandard_C]' + ' [cmdLineOptions.LanguageStandard]' + ' [cmdLineOptions.ConformanceMode]' - // Output Files options - // --------------------------- + ' [cmdLineOptions.CompilerProgramDatabaseFile]' - // Advanced options - // --------------------------- + ' [cmdLineOptions.CallingConvention]' + ' [cmdLineOptions.DisableSpecificWarnings]' + ' [cmdLineOptions.ForcedIncludeFiles]' + ' [fastBuildSourceFileType]' + ' [fastBuildAdditionalCompilerOptionsFromCode]' + ' /errorReport:queue' - // Character Set - // --------------------------- + ' [cmdLineOptions.TranslateIncludes]' + + ' [cmdLineOptions.TreatAngleIncludeAsExternal]' + + ' [cmdLineOptions.ExternalTemplatesDiagnostics]' + ' [cmdLineOptions.CharacterSet]' - // Additional compiler options - //-------------------------- + ' [options.AdditionalCompilerOptions]' + ' [fastBuildCompilerForceUsing]' "; public static string CPPCompilerOptimizationOptions = @" - // Optimizations options - // --------------------- .CompilerOptimizations = '' + ' [cmdLineOptions.Optimization]' + ' [cmdLineOptions.InlineFunctionExpansion]' diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index e20264682..04c2ab78c 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -382,6 +382,12 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG // Compiler section + context.SelectOption + ( + Options.Option(Options.Vc.General.TranslateIncludes.Enable, () => { context.Options["TranslateIncludes"] = "true"; context.CommandLineOptions["TranslateIncludes"] = "/translateInclude"; }), + Options.Option(Options.Vc.General.TranslateIncludes.Disable, () => { context.Options["TranslateIncludes"] = FileGeneratorUtilities.RemoveLineTag; context.CommandLineOptions["TranslateIncludes"] = FileGeneratorUtilities.RemoveLineTag; }) + ); + //Options.Vc.General.CommonLanguageRuntimeSupport. context.SelectOption ( @@ -416,12 +422,46 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG optionsContext.PlatformVcxproj.SelectApplicationFormatOptions(context); optionsContext.PlatformVcxproj.SelectBuildType(context); - context.Options["ExecutablePath"] = FileGeneratorUtilities.RemoveLineTag; - context.Options["IncludePath"] = FileGeneratorUtilities.RemoveLineTag; - context.Options["LibraryPath"] = FileGeneratorUtilities.RemoveLineTag; - context.Options["ExcludePath"] = FileGeneratorUtilities.RemoveLineTag; - context.Options["AdditionalUsingDirectories"] = FileGeneratorUtilities.RemoveLineTag; + // Visual C++ Directories + { + // Path to use when searching for executable files while building a VC++ project. Corresponds to environment variable PATH. + context.Options["ExecutablePath"] = FileGeneratorUtilities.RemoveLineTag; + + // Path to use when searching for include files while building a VC++ project. Corresponds to environment variable INCLUDE. + context.Options["IncludePath"] = FileGeneratorUtilities.RemoveLineTag; + + // Vs2019+: Path to treat as external/system during compilation and skip in build up-to-date check. + context.Options["ExternalIncludePath"] = FileGeneratorUtilities.RemoveLineTag; + + // Path to use when searching for metadata files while building a VC++ project. Corresponds to environment variable LIBPATH. + context.Options["ReferencePath"] = FileGeneratorUtilities.RemoveLineTag; + + // Path to use when searching for library files while building a VC++ project. Corresponds to environment variable LIB. + context.Options["LibraryPath"] = FileGeneratorUtilities.RemoveLineTag; + + // Path to use when searching for winmd metadata files while building a VC++ project. Gets concatenated with 'Reference Directories' into LIBPATH. + context.Options["LibraryWPath"] = FileGeneratorUtilities.RemoveLineTag; + + // Path to use when searching for source files to use for Intellisense. + context.Options["SourcePath"] = FileGeneratorUtilities.RemoveLineTag; + + // Path to skip when searching for scan dependencies. + context.Options["ExcludePath"] = FileGeneratorUtilities.RemoveLineTag; + + // One or more directories to automatically add to the include path in the referencing projects. + context.Options["PublicIncludeDirectories"] = FileGeneratorUtilities.RemoveLineTag; + + // Specifies if directories or all project header files should be automatically added to the include path in the referencing projects. + context.Options["AllProjectIncludesArePublic"] = FileGeneratorUtilities.RemoveLineTag; + // One or more this project directories containing c++ module and/or header unit sources to make automatically available in the referencing projects. + context.Options["PublicModuleDirectories"] = FileGeneratorUtilities.RemoveLineTag; + + // Specifies if all project modules and header units should be automatically available in the referencing projects. + context.Options["AllProjectBMIsArePublic"] = FileGeneratorUtilities.RemoveLineTag; + } + + context.Options["AdditionalUsingDirectories"] = FileGeneratorUtilities.RemoveLineTag; optionsContext.PlatformVcxproj.SetupSdkOptions(context); bool writeResourceCompileTag = optionsContext.PlatformVcxproj.GetResourceIncludePaths(context).Any(); @@ -457,9 +497,6 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG SelectDebugInformationOption(context, optionsContext); - //Options.Vc.General.UseDebugLibraries. - // Disable WarnAsError="false" - // Enable WarnAsError="true" /WX context.SelectOption ( Options.Option(Options.Vc.General.UseDebugLibraries.Disabled, () => { context.Options["UseDebugLibraries"] = "false"; }), @@ -504,6 +541,22 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG Options.Option(Options.Vc.General.TreatAngleIncludeAsExternal.Disable, () => { context.Options["TreatAngleIncludeAsExternal"] = FileGeneratorUtilities.RemoveLineTag; context.CommandLineOptions["TreatAngleIncludeAsExternal"] = FileGeneratorUtilities.RemoveLineTag; }) ); + context.SelectOption + ( + Options.Option(Options.Vc.General.ExternalWarningLevel.Level0, () => { context.Options["ExternalWarningLevel"] = "TurnOffAllWarnings"; context.CommandLineOptions["ExternalWarningLevel"] = "/external:W0"; }), + Options.Option(Options.Vc.General.ExternalWarningLevel.Level1, () => { context.Options["ExternalWarningLevel"] = "Level1"; context.CommandLineOptions["ExternalWarningLevel"] = "/external:W1"; }), + Options.Option(Options.Vc.General.ExternalWarningLevel.Level2, () => { context.Options["ExternalWarningLevel"] = "Level2"; context.CommandLineOptions["ExternalWarningLevel"] = "/external:W2"; }), + Options.Option(Options.Vc.General.ExternalWarningLevel.Level3, () => { context.Options["ExternalWarningLevel"] = "Level3"; context.CommandLineOptions["ExternalWarningLevel"] = "/external:W3"; }), + Options.Option(Options.Vc.General.ExternalWarningLevel.Level4, () => { context.Options["ExternalWarningLevel"] = "Level4"; context.CommandLineOptions["ExternalWarningLevel"] = "/external:W4"; }), + Options.Option(Options.Vc.General.ExternalWarningLevel.InheritWarningLevel, () => { context.Options["ExternalWarningLevel"] = FileGeneratorUtilities.RemoveLineTag; context.CommandLineOptions["ExternalWarningLevel"] = FileGeneratorUtilities.RemoveLineTag; }) + ); + + context.SelectOption + ( + Options.Option(Options.Vc.General.ExternalTemplatesDiagnostics.Enable, () => { context.Options["ExternalTemplatesDiagnostics"] = "true"; context.CommandLineOptions["ExternalTemplatesDiagnostics"] = "/external:templates-"; }), + Options.Option(Options.Vc.General.ExternalTemplatesDiagnostics.Disable, () => { context.Options["ExternalTemplatesDiagnostics"] = FileGeneratorUtilities.RemoveLineTag; context.CommandLineOptions["ExternalTemplatesDiagnostics"] = FileGeneratorUtilities.RemoveLineTag; }) + ); + context.Options["TrackFileAccess"] = FileGeneratorUtilities.RemoveLineTag; if (context.DevelopmentEnvironment.IsVisualStudio()) @@ -512,7 +565,6 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG SelectPlatformToolsetOption(context, optionsContext); } - // Compiler.SuppressStartupBanner context.CommandLineOptions["SuppressStartupBanner"] = "/nologo"; diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs index b825b737b..e96a87e26 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs @@ -186,6 +186,9 @@ public abstract partial class BasePlatform [options.WindowsTargetPlatformVersion] [options.SpectreMitigation] [options.EnableASAN] + [options.TreatAngleIncludeAsExternal] + [options.ExternalWarningLevel] + [options.ExternalTemplatesDiagnostics] "; @@ -208,8 +211,16 @@ public abstract partial class BasePlatform [options.CustomBuildStepAfterTargets] [options.ExecutablePath] [options.IncludePath] + [options.ExternalIncludePath] + [options.ReferencePath] [options.LibraryPath] + [options.LibraryWPath] + [options.SourcePath] [options.ExcludePath] + [options.PublicIncludeDirectories] + [options.AllProjectIncludesArePublic] + [options.PublicModuleDirectories] + [options.AllProjectBMIsArePublic] [options.DisableFastUpToDateCheck] [options.EnableManagedIncrementalBuild] [options.UseClangCl] diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/BaseWindowsPlatform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/BaseWindowsPlatform.cs index 03390723c..ee0355c2d 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/BaseWindowsPlatform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/BaseWindowsPlatform.cs @@ -114,10 +114,25 @@ public override void SetupSdkOptions(IGenerationContext context) if (systemIncludes.Count > 0) { systemIncludes.Sort(); - if (context.Options["IncludePath"] == FileGeneratorUtilities.RemoveLineTag) - context.Options["IncludePath"] = "$(VC_IncludePath);$(WindowsSDK_IncludePath);" + systemIncludes.JoinStrings(";"); + string systemIncludesString = Util.PathGetRelative(context.ProjectDirectory, systemIncludes).JoinStrings(";"); + + // this option is mandatory when using /external:I with msvc, so if the user has selected it + // we consider that the vcxproj supports ExternalIncludePath + if (Options.HasOption(conf)) + { + if (context.Options["ExternalIncludePath"] == FileGeneratorUtilities.RemoveLineTag) + context.Options["ExternalIncludePath"] = systemIncludesString; + else + context.Options["ExternalIncludePath"] += ";" + systemIncludesString; + + } else - context.Options["IncludePath"] += ";" + systemIncludes.JoinStrings(";"); + { + if (context.Options["IncludePath"] == FileGeneratorUtilities.RemoveLineTag) + context.Options["IncludePath"] = "$(VC_IncludePath);$(WindowsSDK_IncludePath);" + systemIncludesString; + else + context.Options["IncludePath"] += ";" + systemIncludesString; + } } } #endregion diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs index d14c3a2ab..03c882593 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs @@ -375,6 +375,7 @@ protected override IEnumerable GetPlatformIncludePathsWithPre if (platformToolset.IsLLVMToolchain() && Options.GetObject(context.Configuration) == Options.Vc.LLVM.UseClangCl.Enable) { + // when using clang-cl, mark MSVC includes, so they are properly recognized includePrefix = "/clang:-isystem"; Options.Vc.General.PlatformToolset overridenPlatformToolset = Options.Vc.General.PlatformToolset.Default; @@ -387,8 +388,14 @@ protected override IEnumerable GetPlatformIncludePathsWithPre string clangIncludePath = platformToolset == Options.Vc.General.PlatformToolset.ClangCL ? ClangForWindows.GetWindowsClangIncludePath(devEnv) : ClangForWindows.GetWindowsClangIncludePath(); includes.Add(new IncludeWithPrefix(includePrefix, clangIncludePath)); } + else + { + // this option is mandatory when using /external:I with msvc, so if the user has selected it + // we consider that the vcxproj supports ExternalIncludePath + if (Options.HasOption(context.Configuration)) + includePrefix = "/external:I"; + } - // when using clang-cl, mark MSVC includes, so they are properly recognized IEnumerable msvcIncludePaths = EnumerateSemiColonSeparatedString(devEnv.GetWindowsIncludePath()); includes.AddRange(msvcIncludePaths.Select(path => new IncludeWithPrefix(includePrefix, path))); diff --git a/Sharpmake/Options.Vc.cs b/Sharpmake/Options.Vc.cs index d1aa2a555..69498a3fb 100644 --- a/Sharpmake/Options.Vc.cs +++ b/Sharpmake/Options.Vc.cs @@ -299,6 +299,82 @@ public enum DiagnosticsFormat Classic } + /// + /// Treat Files Included with Angle Brackets as External + /// + /// + /// Specifies whether to treat files included with angle brackets as external. (/external:anglebrackets) + /// + public enum TreatAngleIncludeAsExternal + { + [DevEnvVersion(minimum = DevEnv.vs2019)] + Enable, + [Default] + Disable + } + + /// + /// External Header Warning Level + /// + /// + /// Select how strict you want the compiler to be about code errors in external headers. (/external:W0 - /external:W4) + /// + public enum ExternalWarningLevel + { + /// + /// Turn Off All Warnings + /// + /// + /// Level 0 disables all warnings. + /// + [DevEnvVersion(minimum = DevEnv.vs2019)] + Level0, + + /// + /// Level 1 displays severe warnings. Level 1 is the default warning level at the command line. + /// + [DevEnvVersion(minimum = DevEnv.vs2019)] + Level1, + + /// + /// Level 2 displays all level 1 warnings and warnings less severe than level 1. + /// + [DevEnvVersion(minimum = DevEnv.vs2019)] + Level2, + + /// + /// Level 3 displays all level 2 warnings and all other warnings recommended for production purposes. + /// + [DevEnvVersion(minimum = DevEnv.vs2019)] + Level3, + + /// + /// Level 4 displays all level 3 warnings plus informational warnings, which in most cases can be safely ignored. + /// + [DevEnvVersion(minimum = DevEnv.vs2019)] + Level4, + + /// + /// Inherit Project Warning Level + /// + [Default] + InheritWarningLevel + } + + /// + /// Template Diagnostics in External Headers + /// + /// + /// Specifies whether to evaluate warning level across template instantiation chain. (/external:templates-) + /// + public enum ExternalTemplatesDiagnostics + { + [DevEnvVersion(minimum = DevEnv.vs2019)] + Enable, + [Default] + Disable + } + /// /// Enable Managed Incremental Build /// @@ -1135,7 +1211,7 @@ public AdditionalUsingDirectories(params string[] dirs) /// C++ Language Standard /// /// - /// Determines the C++ language standard the compiler will enforce. It is recommended to use the latest version when possible. (/std:c++14, /std:c++17, /std:c++latest) + /// Determines the C++ language standard the compiler will enforce. It is recommended to use the latest version when possible. (/std:c++14, /std:c++17, /std:c++20, /std:c++latest) /// public enum CppLanguageStandard { From 3464e97beaf199b12fd06f03d4f426f0f4d102bd Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Sat, 14 Aug 2021 13:09:20 +0200 Subject: [PATCH 16/26] [CSharp] Add support for warning level 5 with Options.CSharp.WarningLevel.Level5 --- Sharpmake.Generators/VisualStudio/Csproj.cs | 3 ++- Sharpmake/Options.CSharp.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sharpmake.Generators/VisualStudio/Csproj.cs b/Sharpmake.Generators/VisualStudio/Csproj.cs index 7d0744cff..7d3cd3e91 100644 --- a/Sharpmake.Generators/VisualStudio/Csproj.cs +++ b/Sharpmake.Generators/VisualStudio/Csproj.cs @@ -3218,7 +3218,8 @@ private Options.ExplicitOptions GenerateOptions(CSharpProject project, Project.C Options.Option(Options.CSharp.WarningLevel.Level1, () => { options["WarningLevel"] = "1"; }), Options.Option(Options.CSharp.WarningLevel.Level2, () => { options["WarningLevel"] = "2"; }), Options.Option(Options.CSharp.WarningLevel.Level3, () => { options["WarningLevel"] = "3"; }), - Options.Option(Options.CSharp.WarningLevel.Level4, () => { options["WarningLevel"] = "4"; }) + Options.Option(Options.CSharp.WarningLevel.Level4, () => { options["WarningLevel"] = "4"; }), + Options.Option(Options.CSharp.WarningLevel.Level5, () => { options["WarningLevel"] = "5"; }) ); // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version#c-language-version-reference diff --git a/Sharpmake/Options.CSharp.cs b/Sharpmake/Options.CSharp.cs index e5d743d4d..07f1c5b40 100644 --- a/Sharpmake/Options.CSharp.cs +++ b/Sharpmake/Options.CSharp.cs @@ -433,7 +433,8 @@ public enum WarningLevel Level2, Level3, [Default] - Level4 + Level4, + Level5 } public enum DebugSymbols From 1bca8c61a99b7f7dbebcc2b76505b2d5c3a66cac Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Sat, 14 Aug 2021 13:13:36 +0200 Subject: [PATCH 17/26] [C#] Fix DotNetOS fragment handling and add a sample to demonstrate how to use it --- .github/workflows/actions.yml | 9 + Sharpmake.Generators/VisualStudio/Csproj.cs | 49 ++-- .../HelloWorld.sharpmake.cs | 219 ++++++++++++++++++ .../HelloWorldLib/HelloWorldWriter.cs | 17 ++ .../HelloWorldMultiframeworks/Program.cs | 10 + .../Properties/AssemblyInfo.cs | 14 ++ samples/Sharpmake.Samples.sharpmake.cs | 11 + 7 files changed, 307 insertions(+), 22 deletions(-) create mode 100644 samples/NetCore/DotNetOSMultiFrameworksHelloWorld/HelloWorld.sharpmake.cs create mode 100644 samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldLib/HelloWorldWriter.cs create mode 100644 samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Program.cs create mode 100644 samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Properties/AssemblyInfo.cs diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index de5eac190..54f371184 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -286,6 +286,15 @@ jobs: dotnet "projects\helloworldmultiframeworks\output\anycpu\${{ matrix.configuration }}\netcoreapp3.1\HelloWorldMultiFrameworks.dll" & "projects\helloworldmultiframeworks\output\anycpu\${{ matrix.configuration }}\net461\HelloWorldMultiFrameworks.exe" + - name: NetCore/DotNetOSMultiFrameworksHelloWorld ${{ matrix.configuration }} + if: runner.os == 'Windows' + working-directory: 'samples/NetCore/DotNetOSMultiFrameworksHelloWorld' + run: | + & $env:SHARPMAKE_EXE "/sources('HelloWorld.sharpmake.cs')" + & $env:COMPILE_BATCH codebase\temp\solutions\OSMultiFrameworksHelloWorldSolution.sln "${{ matrix.configuration }}" "Any CPU" + & "codebase\temp\bin\anycpu_${{ matrix.configuration }}\net5.0-windows\HelloWorldExe.exe" + & "codebase\temp\bin\anycpu_${{ matrix.configuration }}\net472\HelloWorldExe.exe" + - name: PackageReferences ${{ matrix.configuration }} if: runner.os == 'Windows' working-directory: 'samples/PackageReferences' diff --git a/Sharpmake.Generators/VisualStudio/Csproj.cs b/Sharpmake.Generators/VisualStudio/Csproj.cs index 7d3cd3e91..8b611466f 100644 --- a/Sharpmake.Generators/VisualStudio/Csproj.cs +++ b/Sharpmake.Generators/VisualStudio/Csproj.cs @@ -172,22 +172,8 @@ internal class TargetFrameworksCondition : UniqueList, IResolvableConditio public string ResolveCondition(Resolver resolver) { - var targetFrameworks = TargetFrameworks.Select(tuple => - { - var dotNetFramework = tuple.Item1; - var dotNetOS = tuple.Item2; - var dotNetOSVersion = tuple.Item3; - - if (dotNetOS == DotNetOS.Default) - { - if (!string.IsNullOrEmpty(dotNetOSVersion)) - throw new Error(); - return dotNetFramework.ToFolderName(); - } - - return dotNetFramework.ToFolderName() + "-" + dotNetOS.ToString() + dotNetOSVersion; - }); - using (resolver.NewScopedParameter("targetFramework", string.Join(";", targetFrameworks))) + string targetFrameworks = GetTargetFrameworksString(TargetFrameworks.ToArray()); + using (resolver.NewScopedParameter("targetFramework", targetFrameworks)) { return resolver.Resolve(Template.ItemGroups.ItemGroupTargetFrameworkCondition); } @@ -1065,16 +1051,18 @@ List skipFiles // Need to sort by name and platform List configurations = unsortedConfigurations.OrderBy(conf => conf.Name + conf.Platform).ToList(); - var projectFrameworks = configurations.Select( + var projectFrameworksPerConf = configurations.ToDictionary( + conf => conf, conf => { var dotNetFramework = conf.Target.GetFragment(); DotNetOS dotNetOS; - if (!conf.Target.TryGetFragment(out dotNetOS)) + if (!conf.Target.TryGetFragment(out dotNetOS)) dotNetOS = DotNetOS.Default; return Tuple.Create(dotNetFramework, dotNetOS, conf.DotNetOSVersionSuffix); } - ).Distinct().ToList(); + ); + var projectFrameworks = projectFrameworksPerConf.Values.Distinct().ToList(); itemGroups.SetTargetFrameworks(projectFrameworks); // valid that 2 conf name in the same project don't have the same name @@ -1172,8 +1160,7 @@ List skipFiles if (isNetCoreProjectSchema) { Write(Template.Project.ProjectBeginNetCore, writer, resolver); - - targetFrameworkString = string.Join(";", projectFrameworks.Select(tuple => tuple.Item1.ToFolderName())); + targetFrameworkString = GetTargetFrameworksString(projectFrameworks.ToArray()); } else { @@ -1360,7 +1347,7 @@ List skipFiles using (resolver.NewScopedParameter("platformName", Util.GetPlatformString(conf.Platform, conf.Project, conf.Target))) using (resolver.NewScopedParameter("conf", conf)) using (resolver.NewScopedParameter("project", project)) - using (resolver.NewScopedParameter("targetFramework", conf.Target.GetFragment().ToFolderName())) + using (resolver.NewScopedParameter("targetFramework", GetTargetFrameworksString(projectFrameworksPerConf[conf]))) using (resolver.NewScopedParameter("projectConfigurationCondition", projectConfigurationCondition)) using (resolver.NewScopedParameter("target", conf.Target)) using (resolver.NewScopedParameter("options", options[conf])) @@ -1580,6 +1567,24 @@ List skipFiles writer.Close(); } + private static string GetTargetFrameworksString(params Tuple[] projectFrameworks) + { + return string.Join(";", projectFrameworks.Select(tuple => { + var dotNetFramework = tuple.Item1; + var dotNetOS = tuple.Item2; + var dotNetOSVersion = tuple.Item3; + + if (dotNetOS == DotNetOS.Default || dotNetOS == 0) + { + if (!string.IsNullOrEmpty(dotNetOSVersion)) + throw new Error($"Can't set a {nameof(dotNetOSVersion)} ({dotNetOSVersion}) with {nameof(dotNetOS)} set to Default"); + return dotNetFramework.ToFolderName(); + } + + return dotNetFramework.ToFolderName() + "-" + dotNetOS.ToString() + dotNetOSVersion; + })); + } + public void AddPreImportCustomProperties(Dictionary properties, CSharpProject cSharpProject, string projectPath) { if (!string.IsNullOrEmpty(cSharpProject.BaseIntermediateOutputPath)) diff --git a/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/HelloWorld.sharpmake.cs b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/HelloWorld.sharpmake.cs new file mode 100644 index 000000000..4d05a5660 --- /dev/null +++ b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/HelloWorld.sharpmake.cs @@ -0,0 +1,219 @@ +// Copyright (c) 2021 Ubisoft Entertainment +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using Sharpmake; +namespace NetCore.DotNetOSMultiFrameworksHelloWorld +{ + public static class Globals + { + // branch root path relative to current sharpmake file location + public const string RelativeRootPath = @".\codebase"; + public static string RootDirectory; + public static string TmpDirectory { get { return Path.Combine(RootDirectory, "temp"); } } + public static string OutputDirectory { get { return Path.Combine(TmpDirectory, "bin"); } } + } + + [DebuggerDisplay("\"{Platform}_{DevEnv}\" {Name}")] + public class CommonTarget : Sharpmake.ITarget + { + public Platform Platform; + public DevEnv DevEnv; + public Optimization Optimization; + public DotNetFramework DotNetFramework; + public DotNetOS DotNetOS; + + public CommonTarget() { } + + public CommonTarget( + Platform platform, + DevEnv devEnv, + Optimization optimization, + DotNetFramework dotNetFramework, + DotNetOS dotNetOS + ) + { + Platform = platform; + DevEnv = devEnv; + Optimization = optimization; + DotNetFramework = dotNetFramework; + DotNetOS = dotNetOS; + } + + public override string Name + { + get + { + var nameParts = new List + { + Optimization.ToString() + }; + return string.Join(" ", nameParts); + } + } + + /// + /// returns a string usable as a directory name, to use for instance for the intermediate path + /// + public string DirectoryName + { + get + { + var dirNameParts = new List(); + + dirNameParts.Add(Platform.ToString()); + dirNameParts.Add(Optimization.ToString()); + + return string.Join("_", dirNameParts); + } + } + + public static CommonTarget[] GetDefaultTargets(DotNetOS dotNetOS = DotNetOS.Default) + { + var netFrameworkTarget = new CommonTarget( + Platform.anycpu, + DevEnv.vs2019, + Optimization.Debug | Optimization.Release, + DotNetFramework.v4_7_2, + dotNetOS: 0 // OS is not applicable for .net framework + ); + + var netCoreTarget = new CommonTarget( + Platform.anycpu, + DevEnv.vs2019, + Optimization.Debug | Optimization.Release, + DotNetFramework.net5_0, + dotNetOS: dotNetOS + ); + + return new[] { netFrameworkTarget, netCoreTarget }; + } + + public ITarget ToDefaultDotNetOSTarget() + { + return ToSpecificDotNetOSTarget(DotNetOS.Default); + } + + public ITarget ToSpecificDotNetOSTarget(DotNetOS dotNetOS) + { + if (DotNetOS == 0 || DotNetOS == dotNetOS) + return this; + + return Clone(dotNetOS); + } + } + + public abstract class CommonCSharpProject : CSharpProject + { + protected CommonCSharpProject() + : base(typeof(CommonTarget)) + { + RootPath = Globals.RootDirectory; + } + + [ConfigurePriority(-100)] + [Configure] + public virtual void ConfigureAll(Configuration conf, CommonTarget target) + { + conf.ProjectFileName = "[project.Name].[target.DevEnv]"; + conf.ProjectPath = @"[project.SourceRootPath]"; + + conf.IntermediatePath = Path.Combine(Globals.TmpDirectory, @"obj\[target.DirectoryName]\[project.Name]"); + conf.TargetLibraryPath = Path.Combine(Globals.TmpDirectory, @"lib\[target.DirectoryName]\[project.Name]"); + conf.TargetPath = Path.Combine(Globals.OutputDirectory, "[target.DirectoryName]"); + + conf.Options.Add(Options.CSharp.WarningLevel.Level5); + conf.Options.Add(Options.CSharp.TreatWarningsAsErrors.Enabled); + } + } + + [Generate] + public class HelloWorldLib : CommonCSharpProject + { + public HelloWorldLib() + { + SourceRootPath = @"[project.RootPath]\[project.Name]"; + AddTargets(CommonTarget.GetDefaultTargets()); + } + + public override void ConfigureAll(Configuration conf, CommonTarget target) + { + base.ConfigureAll(conf, target); + + conf.Output = Configuration.OutputType.DotNetClassLibrary; + + if (target.DotNetFramework.IsDotNetFramework()) + conf.ReferencesByName.Add("System"); + + if (target.DotNetFramework.IsDotNetCore()) + conf.ReferencesByNuGetPackage.Add("System.Text.Encoding.CodePages", "4.5.0"); + } + } + + [Sharpmake.Generate] + public class HelloWorldExe : CommonCSharpProject + { + public HelloWorldExe() + { + SourceRootPath = @"[project.RootPath]\HelloWorldMultiframeworks"; + AddTargets(CommonTarget.GetDefaultTargets(DotNetOS.windows)); + } + + public override void ConfigureAll(Configuration conf, CommonTarget target) + { + base.ConfigureAll(conf, target); + conf.Output = Configuration.OutputType.DotNetConsoleApp; + conf.AddPrivateDependency(target.ToDefaultDotNetOSTarget()); + } + } + + [Generate] + public class OSMultiFrameworksHelloWorldSolution : CSharpSolution + { + public OSMultiFrameworksHelloWorldSolution() + : base(typeof(CommonTarget)) + { + AddTargets(CommonTarget.GetDefaultTargets()); + } + + [Configure] + public void ConfigureAll(Configuration conf, CommonTarget target) + { + conf.SolutionFileName = Name; + conf.SolutionPath = Path.Combine(Globals.TmpDirectory, "solutions"); + + conf.AddProject(target.ToSpecificDotNetOSTarget(DotNetOS.windows)); + } + } + + public static class Main + { + private static void ConfigureRootDirectory() + { + FileInfo fileInfo = Util.GetCurrentSharpmakeFileInfo(); + string rootDirectory = Path.Combine(fileInfo.DirectoryName, Globals.RelativeRootPath); + Globals.RootDirectory = Util.SimplifyPath(rootDirectory); + } + + [Sharpmake.Main] + public static void SharpmakeMain(Arguments arguments) + { + ConfigureRootDirectory(); + + arguments.Generate(); + } + } +} diff --git a/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldLib/HelloWorldWriter.cs b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldLib/HelloWorldWriter.cs new file mode 100644 index 000000000..01963f919 --- /dev/null +++ b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldLib/HelloWorldWriter.cs @@ -0,0 +1,17 @@ +using System; +using System.Reflection; + +namespace HelloWorld +{ + public static class HelloWorldWriter + { + private static readonly string s_framework = Assembly.GetEntryAssembly()?.GetCustomAttribute()?.FrameworkName; + private static readonly string s_frameworkDisplayName = Assembly.GetEntryAssembly()?.GetCustomAttribute()?.FrameworkDisplayName; + private static string CompiledWithFramework() => !string.IsNullOrEmpty(s_frameworkDisplayName) ? s_frameworkDisplayName : !string.IsNullOrEmpty(s_framework) ? s_framework : "Unknown"; + + public static void WriteHelloWorldLine() + { + Console.WriteLine($"Hello World - {CompiledWithFramework()}!"); + } + } +} diff --git a/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Program.cs b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Program.cs new file mode 100644 index 000000000..8dbbd67e6 --- /dev/null +++ b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Program.cs @@ -0,0 +1,10 @@ +namespace HelloWorldMultiframeworks +{ + class Program + { + static void Main(string[] args) + { + HelloWorld.HelloWorldWriter.WriteHelloWorldLine(); + } + } +} diff --git a/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Properties/AssemblyInfo.cs b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..a91083181 --- /dev/null +++ b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Properties/AssemblyInfo.cs @@ -0,0 +1,14 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +[assembly: AssemblyTitle("HelloWorld")] +[assembly: AssemblyDescription("Dummy description")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Ubisoft")] +[assembly: AssemblyProduct("Sharpmake")] +[assembly: AssemblyCopyright("Copyright © Ubisoft 2020")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/samples/Sharpmake.Samples.sharpmake.cs b/samples/Sharpmake.Samples.sharpmake.cs index e015eaeb9..f4f97bc3a 100644 --- a/samples/Sharpmake.Samples.sharpmake.cs +++ b/samples/Sharpmake.Samples.sharpmake.cs @@ -159,6 +159,17 @@ public DotNetMultiFrameworksHelloWorldProject() } } + [Generate] + public class DotNetOSMultiFrameworksHelloWorldProject : SampleProject + { + public DotNetOSMultiFrameworksHelloWorldProject() + { + Name = "DotNetOSMultiFrameworksHelloWorld"; + SharpmakeMainFile = "HelloWorld.sharpmake.cs"; + SourceRootPath = @"[project.SharpmakeCsPath]\NetCore\[project.Name]"; + } + } + [Generate] public class FastBuildSimpleExecutable : SampleProject { From 97c6212ac4dbb31cdd296ef3cea1691320bd06bb Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Sat, 14 Aug 2021 18:08:39 +0200 Subject: [PATCH 18/26] Fix rc compilation with external includes, we now always use the includes prefixed with the default prefix --- Sharpmake.Generators/FastBuild/Bff.cs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Sharpmake.Generators/FastBuild/Bff.cs b/Sharpmake.Generators/FastBuild/Bff.cs index 4c6120c26..4bbb90b20 100644 --- a/Sharpmake.Generators/FastBuild/Bff.cs +++ b/Sharpmake.Generators/FastBuild/Bff.cs @@ -1455,18 +1455,10 @@ private static void FillIncludeDirectoriesOptions(BffGenerationContext context) var resourceDirs = new List(); resourceDirs.AddRange(resourceIncludePaths.Select(p => CmdLineConvertIncludePathsFunc(context, context.EnvironmentVariableResolver, p, defaultCmdLineIncludePrefix))); - if (Options.GetObject(context.Configuration).IsLLVMToolchain() && - Options.GetObject(context.Configuration) == Options.Vc.LLVM.UseClangCl.Enable) - { - // with LLVM as toolchain, we are still using the default resource compiler, so we need the default include prefix - // TODO: this is not great, ideally we would need the prefix to be per "compiler", and a platform can have many - var platformIncludePathsDefaultPrefix = platformIncludePaths.Select(p => CmdLineConvertIncludePathsFunc(context, context.EnvironmentVariableResolver, p.Path, defaultCmdLineIncludePrefix)); - resourceDirs.AddRange(platformIncludePathsDefaultPrefix); - } - else - { - resourceDirs.AddRange(platformIncludePathsPrefixed); - } + // with LLVM as toolchain, we are still using the default resource compiler, so we need the default include prefix + // TODO: this is not great, ideally we would need the prefix to be per "compiler", and a platform can have many + var platformIncludePathsDefaultPrefix = platformIncludePaths.Select(p => CmdLineConvertIncludePathsFunc(context, context.EnvironmentVariableResolver, p.Path, defaultCmdLineIncludePrefix)); + resourceDirs.AddRange(platformIncludePathsDefaultPrefix); if (resourceDirs.Any()) context.CommandLineOptions["AdditionalResourceIncludeDirectories"] = string.Join($"'{Environment.NewLine} + ' ", resourceDirs); From 9416e544388cceaa3708703698f95f2223a57d63 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Sat, 14 Aug 2021 19:19:19 +0200 Subject: [PATCH 19/26] Fix include system paths with non win64 platforms --- .../Sharpmake.CommonPlatforms/BasePlatform.cs | 2 ++ .../Windows/Win64Platform.cs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.cs index 97537c15a..f0c7523f8 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.cs @@ -506,6 +506,8 @@ protected virtual IEnumerable GetIncludePathsImpl(IGenerationContext con includePaths.AddRange(context.Configuration.IncludePrivatePaths); includePaths.AddRange(context.Configuration.IncludePaths); includePaths.AddRange(context.Configuration.DependenciesIncludePaths); + includePaths.AddRange(context.Configuration.IncludeSystemPaths); + includePaths.AddRange(context.Configuration.DependenciesIncludeSystemPaths); includePaths.Sort(); return includePaths; diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs index 03c882593..8ce9aba9b 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs @@ -365,6 +365,17 @@ public override void SelectPlatformAdditionalDependenciesOptions(IGenerationCont context.Options["AdditionalDependencies"] += ";%(AdditionalDependencies)"; } + protected override IEnumerable GetIncludePathsImpl(IGenerationContext context) + { + var includePaths = new OrderableStrings(); + includePaths.AddRange(context.Configuration.IncludePrivatePaths); + includePaths.AddRange(context.Configuration.IncludePaths); + includePaths.AddRange(context.Configuration.DependenciesIncludePaths); + + includePaths.Sort(); + return includePaths; + } + protected override IEnumerable GetPlatformIncludePathsWithPrefixImpl(IGenerationContext context) { var includes = new List(); From da3834f17055fd8b4ebce99519cdd53d97c6af95 Mon Sep 17 00:00:00 2001 From: Guillaume Buchle Date: Mon, 16 Aug 2021 12:42:56 +0000 Subject: [PATCH 20/26] Clarify logs level (Error, Warning, ...) --- Sharpmake.Application/Program.cs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/Sharpmake.Application/Program.cs b/Sharpmake.Application/Program.cs index 1cb01f9c0..2e0f05814 100644 --- a/Sharpmake.Application/Program.cs +++ b/Sharpmake.Application/Program.cs @@ -91,18 +91,11 @@ public static void DebugWrite(string format, params object[] args) DebugWrite(string.Format(format, args)); } - public static void DebugWrite(string message) + public static void DebugWrite(string msg) { if (DebugEnable) { - TimeSpan span = DateTime.Now - s_startTime; - - string prefix = string.Format("[{0:00}:{1:00}] ", span.Minutes, span.Seconds); - message = prefix + message; - - Console.Write(message); - if (Debugger.IsAttached) - Trace.Write(message); + LogWrite(msg); } } @@ -125,9 +118,7 @@ public static void WarningWrite(string format, params object[] args) public static void WarningWrite(string msg) { Interlocked.Increment(ref s_warningCount); - Console.Write(msg); - if (Debugger.IsAttached) - Trace.Write(msg); + LogWrite("[WARNING]" + msg); } public static void WarningWriteLine(string format, params object[] args) @@ -148,9 +139,7 @@ public static void ErrorWrite(string format, params object[] args) public static void ErrorWrite(string msg) { Interlocked.Increment(ref s_errorCount); - Console.Write(msg); - if (Debugger.IsAttached) - Trace.Write(msg); + LogWrite("[ERROR]" + msg); } public static void ErrorWriteLine(string format, params object[] args) From c003b490bfbc0638eab6f89ae157991ee98b892e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Aug 2021 20:03:35 +0200 Subject: [PATCH 21/26] Bump jurplel/install-qt-action from 2.13.2 to 2.14.0 (#140) Bumps [jurplel/install-qt-action](https://github.com/jurplel/install-qt-action) from 2.13.2 to 2.14.0. - [Release notes](https://github.com/jurplel/install-qt-action/releases) - [Commits](https://github.com/jurplel/install-qt-action/compare/v2.13.2...v2.14.0) --- updated-dependencies: - dependency-name: jurplel/install-qt-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 54f371184..83cfca82b 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -307,7 +307,7 @@ jobs: - name: Install Qt if: runner.os == 'Windows' - uses: jurplel/install-qt-action@v2.13.2 + uses: jurplel/install-qt-action@v2.14.0 - name: QTFileCustomBuild ${{ matrix.configuration }} if: runner.os == 'Windows' From 8ed52a44aeecdd336f40ee76264eb779d5a95e41 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Wed, 18 Aug 2021 11:32:23 +0200 Subject: [PATCH 22/26] Add a utility method ClearFragmentMasks, to allow resetting the fragment masks --- Sharpmake/Configurable.cs | 5 +++++ Sharpmake/Target.cs | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/Sharpmake/Configurable.cs b/Sharpmake/Configurable.cs index 50dcd48ad..13fba9be6 100644 --- a/Sharpmake/Configurable.cs +++ b/Sharpmake/Configurable.cs @@ -130,6 +130,11 @@ public void ClearTargets() Targets.ClearTargets(); } + public void ClearFragmentMasks() + { + Targets.ClearFragmentMasks(); + } + private static bool FilterMethodForTarget(MethodInfo configure, ITarget target) { Configure configureAttribute = ConfigureCollection.GetConfigureAttribute(configure, inherit: true); diff --git a/Sharpmake/Target.cs b/Sharpmake/Target.cs index a6accf684..fd6339812 100644 --- a/Sharpmake/Target.cs +++ b/Sharpmake/Target.cs @@ -751,6 +751,14 @@ public void AddFragmentMask(params object[] masks) } } + /// + /// This method will remove all the masks that were added, if any + /// + public void ClearFragmentMasks() + { + _fragmentMasks = null; + } + /// /// The global fragment mask will add the mask or and it with previously existing masks /// From 147795a571cdbc609a4c7720da18ad00cd91c653 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Wed, 18 Aug 2021 11:33:57 +0200 Subject: [PATCH 23/26] Verify that the fragment masks that are added can be applied on the target --- Sharpmake/Configurable.cs | 9 ++++++++- Sharpmake/Target.cs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Sharpmake/Configurable.cs b/Sharpmake/Configurable.cs index 13fba9be6..f8c3ee2de 100644 --- a/Sharpmake/Configurable.cs +++ b/Sharpmake/Configurable.cs @@ -122,7 +122,14 @@ public void AddTargets(Targets targets, [CallerFilePath] string sourceFilePath = public void AddFragmentMask(params object[] masks) { - Targets.AddFragmentMask(masks); + try + { + Targets.AddFragmentMask(masks); + } + catch (Error e) + { + throw new Error("Error adding mask to class {0}: {1}", Util.ToNiceTypeName(GetType()), e.Message); + } } public void ClearTargets() diff --git a/Sharpmake/Target.cs b/Sharpmake/Target.cs index fd6339812..5d74d7b9d 100644 --- a/Sharpmake/Target.cs +++ b/Sharpmake/Target.cs @@ -730,10 +730,25 @@ internal bool IsFragmentValueValid(Type fragmentType, int fragmentValue) public void AddFragmentMask(params object[] masks) { + var fragmentTypes = TargetType.GetFields(); + foreach (var mask in masks) { Type maskType = mask.GetType(); ITarget.ValidFragmentType(maskType); + if (!fragmentTypes.Any(fragmentType => fragmentType.FieldType == maskType)) + { + throw new Error( + "Fragment mask type '{0}' is not present in this target, here is the list of valid types:\n- {1}", + maskType, + string.Join( + "\n- ", + fragmentTypes + .Select(fragmentType => Util.ToNiceTypeName(fragmentType.FieldType)) + .OrderBy(type => type, StringComparer.InvariantCultureIgnoreCase) + ) + ); + } List maskValues; if (_fragmentMasks == null || !_fragmentMasks.TryGetValue(maskType, out maskValues)) From 33aa68594c633b02a6fdfe9796db044822a8fce2 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Mon, 23 Aug 2021 09:53:22 +0200 Subject: [PATCH 24/26] Formatting fixes --- Sharpmake.Generators/VisualStudio/Csproj.cs | 3 ++- .../Sharpmake.CommonPlatforms/Windows/BaseWindowsPlatform.cs | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sharpmake.Generators/VisualStudio/Csproj.cs b/Sharpmake.Generators/VisualStudio/Csproj.cs index 8b611466f..5c6e4e9be 100644 --- a/Sharpmake.Generators/VisualStudio/Csproj.cs +++ b/Sharpmake.Generators/VisualStudio/Csproj.cs @@ -1569,7 +1569,8 @@ List skipFiles private static string GetTargetFrameworksString(params Tuple[] projectFrameworks) { - return string.Join(";", projectFrameworks.Select(tuple => { + return string.Join(";", projectFrameworks.Select(tuple => + { var dotNetFramework = tuple.Item1; var dotNetOS = tuple.Item2; var dotNetOSVersion = tuple.Item3; diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/BaseWindowsPlatform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/BaseWindowsPlatform.cs index ee0355c2d..9b4941b4b 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/BaseWindowsPlatform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/BaseWindowsPlatform.cs @@ -124,7 +124,6 @@ public override void SetupSdkOptions(IGenerationContext context) context.Options["ExternalIncludePath"] = systemIncludesString; else context.Options["ExternalIncludePath"] += ";" + systemIncludesString; - } else { From d9021e4ecd6fd059d986aaf2d79974a566dfb976 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Mon, 23 Aug 2021 09:56:22 +0200 Subject: [PATCH 25/26] Update copyrights --- Sharpmake/Configurable.cs | 2 +- samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs | 2 +- samples/HelloLinux/codebase/exe/exe.sharpmake.cs | 2 +- .../HelloWorldMultiframeworks/Properties/AssemblyInfo.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sharpmake/Configurable.cs b/Sharpmake/Configurable.cs index f8c3ee2de..e83f76648 100644 --- a/Sharpmake/Configurable.cs +++ b/Sharpmake/Configurable.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Ubisoft Entertainment +// Copyright (c) 2017-2021 Ubisoft Entertainment // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs b/samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs index 34286fda1..0be63a592 100644 --- a/samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs +++ b/samples/HelloLinux/codebase/dll1/dll1.sharpmake.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Ubisoft Entertainment +// Copyright (c) 2020-2021 Ubisoft Entertainment // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/samples/HelloLinux/codebase/exe/exe.sharpmake.cs b/samples/HelloLinux/codebase/exe/exe.sharpmake.cs index c5f4665dd..6d75cb2f5 100644 --- a/samples/HelloLinux/codebase/exe/exe.sharpmake.cs +++ b/samples/HelloLinux/codebase/exe/exe.sharpmake.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Ubisoft Entertainment +// Copyright (c) 2020-2021 Ubisoft Entertainment // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Properties/AssemblyInfo.cs b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Properties/AssemblyInfo.cs index a91083181..79e89405c 100644 --- a/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Properties/AssemblyInfo.cs +++ b/samples/NetCore/DotNetOSMultiFrameworksHelloWorld/codebase/HelloWorldMultiframeworks/Properties/AssemblyInfo.cs @@ -8,7 +8,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Ubisoft")] [assembly: AssemblyProduct("Sharpmake")] -[assembly: AssemblyCopyright("Copyright © Ubisoft 2020")] +[assembly: AssemblyCopyright("Copyright © Ubisoft 2021")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] From a017c34c84b8cc70cf1a87ccf90649c9a559ba6c Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Mon, 23 Aug 2021 09:57:01 +0200 Subject: [PATCH 26/26] Bump version number to 0.17.2 --- Sharpmake.Application/Properties/AssemblyInfo.cs | 2 +- Sharpmake.Generators/Properties/AssemblyInfo.cs | 2 +- .../Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs | 2 +- Sharpmake/Properties/AssemblyInfo.cs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sharpmake.Application/Properties/AssemblyInfo.cs b/Sharpmake.Application/Properties/AssemblyInfo.cs index 0f778c32f..8ccbb9649 100644 --- a/Sharpmake.Application/Properties/AssemblyInfo.cs +++ b/Sharpmake.Application/Properties/AssemblyInfo.cs @@ -43,4 +43,4 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.17.1.*")] +[assembly: AssemblyVersion("0.17.2.0")] diff --git a/Sharpmake.Generators/Properties/AssemblyInfo.cs b/Sharpmake.Generators/Properties/AssemblyInfo.cs index aa6984fe8..0668c12d7 100644 --- a/Sharpmake.Generators/Properties/AssemblyInfo.cs +++ b/Sharpmake.Generators/Properties/AssemblyInfo.cs @@ -44,6 +44,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.17.1.*")] +[assembly: AssemblyVersion("0.17.2.0")] [assembly: InternalsVisibleTo("Sharpmake")] diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs index ee91c4972..098921be9 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Properties/AssemblyInfo.cs @@ -44,6 +44,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.17.1.*")] +[assembly: AssemblyVersion("0.17.2.0")] [assembly: SharpmakeExtension] diff --git a/Sharpmake/Properties/AssemblyInfo.cs b/Sharpmake/Properties/AssemblyInfo.cs index ff33ad58b..c3b574270 100644 --- a/Sharpmake/Properties/AssemblyInfo.cs +++ b/Sharpmake/Properties/AssemblyInfo.cs @@ -44,9 +44,9 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.17.1.*")] +[assembly: AssemblyVersion("0.17.2.0")] #pragma warning disable CS7035 -[assembly: AssemblyFileVersion("0.17.1.* (LocalBuild)")] +[assembly: AssemblyFileVersion("0.17.2.0 (LocalBuild)")] #pragma warning restore [assembly: InternalsVisibleTo("Sharpmake.Application")]