public virtual void SelectPreprocessorDefinitionsVcxproj(IVcxprojGenerationContext context) { // concat defines, don't add options.Defines since they are automatically added by VS var defines = new Strings(); defines.AddRange(context.Options.ExplicitDefines); defines.AddRange(context.Configuration.Defines); context.Options["PreprocessorDefinitions"] = defines.JoinStrings(";"); }
protected void FixupPrecompiledHeaderOptions(IGenerationContext context) { var options = context.Options; var cmdLineOptions = context.CommandLineOptions; var conf = context.Configuration; if (options["UsePrecompiledHeader"] == "NotUsing") { options["UsePrecompiledHeader"] = FileGeneratorUtilities.RemoveLineTag; } else { Strings pathsToConsider = new Strings(context.ProjectSourceCapitalized); pathsToConsider.AddRange(context.Project.AdditionalSourceRootPaths); pathsToConsider.AddRange(GetIncludePaths(context)); string pchFileSourceRelative = context.Options["PrecompiledHeaderThrough"]; string pchFileVcxprojRelative = null; bool foundPchInclude = false; foreach (var includePath in pathsToConsider) { var pchFile = Util.PathGetAbsolute(includePath, pchFileSourceRelative); if (conf.Project.ResolvedSourceFiles.Contains(pchFile)) { pchFileVcxprojRelative = Util.PathGetRelative(context.ProjectDirectory, pchFile, true); foundPchInclude = true; break; } } if (!foundPchInclude) { foreach (var includePath in pathsToConsider) { var pchFile = Util.PathGetAbsolute(includePath, pchFileSourceRelative); if (Util.FileExists(pchFile)) { pchFileVcxprojRelative = Util.PathGetRelative(context.ProjectDirectory, pchFile, true); foundPchInclude = true; break; } } } if (!foundPchInclude) { throw new Error($"Sharpmake couldn't locate the PCH '{pchFileSourceRelative}' in {conf}"); } context.Options["PrecompiledHeaderThrough"] = pchFileVcxprojRelative; } }
public virtual void SelectPreprocessorDefinitionsBff(IBffGenerationContext context) { var platformDescriptor = PlatformRegistry.Get <IPlatformDescriptor>(context.Configuration.Platform); string platformDefineSwitch = platformDescriptor.IsUsingClang ? "-D" : "/D"; var defines = new Strings(); defines.AddRange(context.Options.ExplicitDefines); defines.AddRange(context.Configuration.Defines); if (defines.Count > 0) { var fastBuildDefines = new List <string>(); foreach (string define in defines.SortedValues) { if (!string.IsNullOrWhiteSpace(define)) { fastBuildDefines.Add(string.Format(@"{0}{1}{2}{1}", platformDefineSwitch, Util.DoubleQuotes, define.Replace(Util.DoubleQuotes, Util.EscapedDoubleQuotes))); } } context.CommandLineOptions["PreprocessorDefinitions"] = string.Join($"'{Environment.NewLine} + ' ", fastBuildDefines); } else { context.CommandLineOptions["PreprocessorDefinitions"] = FileGeneratorUtilities.RemoveLineTag; } Strings resourceDefines = Options.GetStrings <Options.Vc.ResourceCompiler.PreprocessorDefinitions>(context.Configuration); if (resourceDefines.Any()) { var fastBuildDefines = new List <string>(); foreach (string resourceDefine in resourceDefines.SortedValues) { if (!string.IsNullOrWhiteSpace(resourceDefine)) { fastBuildDefines.Add(string.Format(@"""{0}{1}""", platformDefineSwitch, resourceDefine.Replace(Util.DoubleQuotes, Util.EscapedDoubleQuotes))); } } context.CommandLineOptions["ResourcePreprocessorDefinitions"] = string.Join($"'{Environment.NewLine} + ' ", fastBuildDefines); } else { context.CommandLineOptions["ResourcePreprocessorDefinitions"] = FileGeneratorUtilities.RemoveLineTag; } }
public override void GeneratePlatformReferences(IVcxprojGenerationContext context, IFileGenerator generator) { // Write SDKReferences on durango if needed // TODO: add a consistency check between configurations Strings sdkReferences = new Strings(); foreach (var conf in context.ProjectConfigurations) { if (conf.Platform == Platform.durango) { sdkReferences.AddRange(Sharpmake.Options.GetStrings <Options.SDKReferences>(conf)); } } if (sdkReferences.Count > 0) { generator.Write(_sdkReferencesBegin); foreach (string sdkReference in sdkReferences) { using (generator.Declare("sdkReferenceInclude", sdkReference)) { generator.Write(_sdkReference); } } generator.Write(_sdkReferencesEnd); } }
public static string[] DirectoryGetFilesWithWildcards(string path) { if (!IsPathWithWildcards(path)) { throw new ArgumentException("Path doesn't contains wildcard"); } var currentFolderList = new Strings(); int firstWildcardIndex = path.IndexOfAny(Util.WildcardCharacters); int firstSeparatorIndex = path.LastIndexOfAny(Util._pathSeparators, firstWildcardIndex); string[] wildcardsPart = path.Substring(firstSeparatorIndex + 1).Split(Util._pathSeparators, StringSplitOptions.RemoveEmptyEntries); currentFolderList.Add(firstSeparatorIndex == -1 ? "." : path.Substring(0, firstSeparatorIndex)); // Iterate over folders' part for (int i = 0; i < wildcardsPart.Length - 1; ++i) { currentFolderList = ListFileSystemItemWithWildcardInFolderList(wildcardsPart[i], currentFolderList, DirectoryGetDirectories, DirectoryExists); } // Handle last item of the wildcard part, that is a file var result = ListFileSystemItemWithWildcardInFolderList(wildcardsPart.Last(), currentFolderList, DirectoryGetFiles, FileExists); // Cleanup path var cleanResult = new Strings(); cleanResult.AddRange(result.Select(SimplifyPath)); return(cleanResult.ToArray()); }
internal static Strings ListFileSystemItemWithWildcardInFolderList(string currentWildcardPart, Strings currentFolderList, Func <string, string, SearchOption, string[]> getItemFunc, Func <string, bool> existItemFunc) { var result = new Strings(); if (IsPathWithWildcards(currentWildcardPart)) { foreach (string currentPath in currentFolderList) { result.AddRange(getItemFunc(currentPath, currentWildcardPart, SearchOption.TopDirectoryOnly)); } } else { foreach (string currentPath in currentFolderList) { string filePath = Path.Combine(currentPath, currentWildcardPart); if (existItemFunc(filePath)) { result.Add(filePath); } } } return(result); }
public static Strings GetStrings <T>(Configuration conf) where T : Strings { List <object> options = conf.Options; Strings values = new Strings(); for (int i = options.Count - 1; i >= 0; --i) { Strings option = options[i] as Strings; if (option is T) { values.AddRange(option); } } return(values); }
private CompilerSettings GetMasterCompilerSettings(IDictionary <string, CompilerSettings> masterCompilerSettings, string compilerName, DevEnv devEnv, string projectRootPath, bool useCCompiler) { CompilerSettings compilerSettings; if (masterCompilerSettings.ContainsKey(compilerName)) { compilerSettings = masterCompilerSettings[compilerName]; } else { var fastBuildSettings = PlatformRegistry.Get <IFastBuildCompilerSettings>(Platform.linux); string binPath; if (!fastBuildSettings.BinPath.TryGetValue(devEnv, out binPath)) { binPath = ClangForWindows.GetWindowsClangExecutablePath(); } string pathToCompiler = Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, binPath)); Strings extraFiles = new Strings(); { Strings userExtraFiles; if (fastBuildSettings.ExtraFiles.TryGetValue(devEnv, out userExtraFiles)) { extraFiles.AddRange(userExtraFiles); } } var compilerFamily = Sharpmake.CompilerFamily.Clang; var compilerFamilyKey = new FastBuildCompilerKey(devEnv); if (!fastBuildSettings.CompilerFamily.TryGetValue(compilerFamilyKey, out compilerFamily)) { compilerFamily = Sharpmake.CompilerFamily.Clang; } string executable = useCCompiler ? @"$ExecutableRootPath$\clang.exe" : @"$ExecutableRootPath$\clang++.exe"; compilerSettings = new CompilerSettings(compilerName, compilerFamily, Platform.linux, extraFiles, executable, pathToCompiler, devEnv, new Dictionary <string, CompilerSettings.Configuration>()); masterCompilerSettings.Add(compilerName, compilerSettings); } return(compilerSettings); }
public CompilerSettings GetMasterCompilerSettings( IDictionary <string, CompilerSettings> masterCompilerSettings, string compilerName, DevEnv devEnv, string projectRootPath, Options.Vc.General.PlatformToolset platformToolset, bool useCCompiler ) { CompilerSettings compilerSettings; if (masterCompilerSettings.ContainsKey(compilerName)) { compilerSettings = masterCompilerSettings[compilerName]; } else { DevEnv?compilerDevEnv = null; string platformToolSetPath = null; string pathToCompiler = null; string compilerExeName = null; var compilerFamily = Sharpmake.CompilerFamily.Auto; var fastBuildSettings = PlatformRegistry.Get <IFastBuildCompilerSettings>(Platform.win64); switch (platformToolset) { case Options.Vc.General.PlatformToolset.Default: compilerDevEnv = devEnv; break; case Options.Vc.General.PlatformToolset.v100: compilerDevEnv = DevEnv.vs2010; break; case Options.Vc.General.PlatformToolset.v110: case Options.Vc.General.PlatformToolset.v110_xp: compilerDevEnv = DevEnv.vs2012; break; case Options.Vc.General.PlatformToolset.v120: case Options.Vc.General.PlatformToolset.v120_xp: compilerDevEnv = DevEnv.vs2013; 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_vs2012: case Options.Vc.General.PlatformToolset.LLVM_vs2014: case Options.Vc.General.PlatformToolset.LLVM: platformToolSetPath = ClangForWindows.Settings.LLVMInstallDir; pathToCompiler = Path.Combine(platformToolSetPath, "bin"); compilerExeName = "clang-cl.exe"; var compilerFamilyKey = new FastBuildWindowsCompilerFamilyKey(devEnv, platformToolset); if (!fastBuildSettings.CompilerFamily.TryGetValue(compilerFamilyKey, out compilerFamily)) { compilerFamily = Sharpmake.CompilerFamily.ClangCl; } break; default: throw new ArgumentOutOfRangeException(); } if (compilerDevEnv.HasValue) { platformToolSetPath = Path.Combine(compilerDevEnv.Value.GetVisualStudioDir(), "VC"); pathToCompiler = compilerDevEnv.Value.GetVisualStudioBinPath(Platform.win64); compilerExeName = "cl.exe"; var compilerFamilyKey = new FastBuildWindowsCompilerFamilyKey(devEnv, platformToolset); if (!fastBuildSettings.CompilerFamily.TryGetValue(compilerFamilyKey, out compilerFamily)) { compilerFamily = Sharpmake.CompilerFamily.MSVC; } } Strings extraFiles = new Strings(); { Strings userExtraFiles; if (fastBuildSettings.ExtraFiles.TryGetValue(devEnv, out userExtraFiles)) { extraFiles.AddRange(userExtraFiles); } } if (compilerDevEnv.HasValue) { extraFiles.Add( @"$ExecutableRootPath$\c1.dll", @"$ExecutableRootPath$\c1xx.dll", @"$ExecutableRootPath$\c2.dll", @"$ExecutableRootPath$\mspdbcore.dll", @"$ExecutableRootPath$\mspdbsrv.exe", @"$ExecutableRootPath$\1033\clui.dll" ); switch (devEnv) { case DevEnv.vs2012: { extraFiles.Add( @"$ExecutableRootPath$\c1ast.dll", @"$ExecutableRootPath$\c1xxast.dll", @"$ExecutableRootPath$\mspft110.dll", @"$ExecutableRootPath$\msobj110.dll", @"$ExecutableRootPath$\mspdb110.dll", Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC110.CRT\msvcp110.dll"), Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC110.CRT\msvcr110.dll"), Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC110.CRT\vccorlib110.dll") ); } break; case DevEnv.vs2013: { extraFiles.Add( @"$ExecutableRootPath$\c1ast.dll", @"$ExecutableRootPath$\c1xxast.dll", @"$ExecutableRootPath$\mspft120.dll", @"$ExecutableRootPath$\msobj120.dll", @"$ExecutableRootPath$\mspdb120.dll", Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC120.CRT\msvcp120.dll"), Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC120.CRT\msvcr120.dll"), Path.Combine(platformToolSetPath, @"redist\x64\Microsoft.VC120.CRT\vccorlib120.dll") ); } break; case DevEnv.vs2015: case DevEnv.vs2017: case DevEnv.vs2019: { string systemDllPath = FastBuildSettings.SystemDllRoot; if (systemDllPath == null) { var windowsTargetPlatformVersion = KitsRootPaths.GetWindowsTargetPlatformVersionForDevEnv(devEnv); 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 (devEnv == 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 (devEnv == DevEnv.vs2019) { Version toolsVersion = devEnv.GetVisualStudioVCToolsVersion(); if (toolsVersion >= new Version("14.22.27905")) { extraFiles.Add(@"$ExecutableRootPath$\tbbmalloc.dll"); } if (toolsVersion >= new Version("14.25.28610")) { extraFiles.Add(@"$ExecutableRootPath$\vcruntime140_1.dll"); } } try { foreach (string p in Util.DirectoryGetFiles(systemDllPath, "api-ms-win-*.dll")) { extraFiles.Add(p); } } catch { } } break; default: throw new NotImplementedException("This devEnv (" + devEnv + ") is not supported!"); } } string executable = Path.Combine("$ExecutableRootPath$", compilerExeName); compilerSettings = new CompilerSettings(compilerName, compilerFamily, Platform.win64, extraFiles, executable, pathToCompiler, devEnv, new Dictionary <string, CompilerSettings.Configuration>()); masterCompilerSettings.Add(compilerName, compilerSettings); } return(compilerSettings); }