public override void SetupSdkOptions(IGenerationContext context)
            {
                var conf   = context.Configuration;
                var devEnv = context.DevelopmentEnvironment;

                // vs2012 and vs2013 do not support overriding windows kits using the underlying variables
                // so we need to change the VC++ directories path.
                // We need to override the executable path for vs2015 because WindowsKit UAP.props does not
                // correctly set the WindowsSDK_ExecutablePath to the bin folder of its current version.
                if ((devEnv == DevEnv.vs2012 || devEnv == DevEnv.vs2013 || devEnv == DevEnv.vs2015) && !KitsRootPaths.UsesDefaultKitRoot(devEnv))
                {
                    var options = context.Options;
                    options["ExecutablePath"] = devEnv.GetWindowsExecutablePath(conf.Platform);
                    if (devEnv != DevEnv.vs2015)
                    {
                        options["IncludePath"] = devEnv.GetWindowsIncludePath();
                        options["LibraryPath"] = devEnv.GetWindowsLibraryPath(conf.Platform, Util.IsDotNet(conf) ? conf.Target.GetFragment <DotNetFramework>() : default(DotNetFramework?));
                        options["ExcludePath"] = devEnv.GetWindowsIncludePath();
                    }
                }

                Options.Vc.General.PlatformToolset platformToolset = Options.GetObject <Options.Vc.General.PlatformToolset>(conf);
                if (platformToolset.IsLLVMToolchain())
                {
                    Options.Vc.General.PlatformToolset overridenPlatformToolset = Options.Vc.General.PlatformToolset.Default;
                    if (Options.WithArgOption <Options.Vc.General.PlatformToolset> .Get <Options.Clang.Compiler.LLVMVcPlatformToolset>(conf, ref overridenPlatformToolset))
                    {
                        platformToolset = overridenPlatformToolset;
                    }

                    devEnv = platformToolset.GetDefaultDevEnvForToolset() ?? devEnv;

                    context.Options["ExecutablePath"] = ClangForWindows.GetWindowsClangExecutablePath() + ";" + devEnv.GetWindowsExecutablePath(conf.Platform);
                    if (Options.GetObject <Options.Vc.LLVM.UseClangCl>(conf) == Options.Vc.LLVM.UseClangCl.Enable)
                    {
                        context.Options["IncludePath"] = ClangForWindows.GetWindowsClangIncludePath() + ";" + devEnv.GetWindowsIncludePath();
                        context.Options["LibraryPath"] = ClangForWindows.GetWindowsClangLibraryPath() + ";" + devEnv.GetWindowsLibraryPath(conf.Platform, Util.IsDotNet(conf) ? conf.Target.GetFragment <DotNetFramework>() : default(DotNetFramework?));
                    }
                }

                var systemIncludes = new OrderableStrings(conf.DependenciesIncludeSystemPaths);

                systemIncludes.AddRange(conf.IncludeSystemPaths);
                if (systemIncludes.Count > 0)
                {
                    systemIncludes.Sort();
                    if (context.Options["IncludePath"] == FileGeneratorUtilities.RemoveLineTag)
                    {
                        context.Options["IncludePath"] = "$(VC_IncludePath);$(WindowsSDK_IncludePath);" + systemIncludes.JoinStrings(";");
                    }
                    else
                    {
                        context.Options["IncludePath"] += ";" + systemIncludes.JoinStrings(";");
                    }
                }
            }
Ejemplo n.º 2
0
            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.LLVM:
                    case Options.Vc.General.PlatformToolset.ClangCL:

                        platformToolSetPath = platformToolset == Options.Vc.General.PlatformToolset.ClangCL ? ClangForWindows.Settings.LLVMInstallDirVsEmbedded(devEnv) : 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:
                        compilerDevEnv = platformToolset.GetDefaultDevEnvForToolset();
                        break;
                    }

                    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"
                            );

                        if (compilerDevEnv.Value.IsVisualStudio())
                        {
                            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!");
                        }
                    }

                    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);
            }
Ejemplo n.º 3
0
            public override void SetupSdkOptions(IGenerationContext context)
            {
                var conf   = context.Configuration;
                var devEnv = context.DevelopmentEnvironment;

                // We need to override the executable path for vs2015 because WindowsKit UAP.props does not
                // correctly set the WindowsSDK_ExecutablePath to the bin folder of its current version.
                if (devEnv == DevEnv.vs2015 && !KitsRootPaths.UsesDefaultKitRoot(devEnv))
                {
                    context.Options["ExecutablePath"] = devEnv.GetWindowsExecutablePath(conf.Platform);
                }

                Options.Vc.General.PlatformToolset platformToolset = Options.GetObject <Options.Vc.General.PlatformToolset>(conf);
                if (Options.Vc.General.PlatformToolset.LLVM == platformToolset)
                {
                    Options.Vc.General.PlatformToolset overridenPlatformToolset = Options.Vc.General.PlatformToolset.Default;
                    if (Options.WithArgOption <Options.Vc.General.PlatformToolset> .Get <Options.Clang.Compiler.LLVMVcPlatformToolset>(conf, ref overridenPlatformToolset))
                    {
                        platformToolset = overridenPlatformToolset;
                    }

                    devEnv = platformToolset.GetDefaultDevEnvForToolset() ?? devEnv;

                    context.Options["ExecutablePath"] = ClangForWindows.GetWindowsClangExecutablePath() + ";" + devEnv.GetWindowsExecutablePath(conf.Platform);
                    if (Options.GetObject <Options.Vc.LLVM.UseClangCl>(conf) == Options.Vc.LLVM.UseClangCl.Enable)
                    {
                        context.Options["IncludePath"] = ClangForWindows.GetWindowsClangIncludePath() + ";" + devEnv.GetWindowsIncludePath();
                        context.Options["LibraryPath"] = ClangForWindows.GetWindowsClangLibraryPath() + ";" + devEnv.GetWindowsLibraryPath(conf.Platform, Util.IsDotNet(conf) ? conf.Target.GetFragment <DotNetFramework>() : default(DotNetFramework?));
                    }
                }

                var systemIncludes = new OrderableStrings(conf.DependenciesIncludeSystemPaths);

                systemIncludes.AddRange(conf.IncludeSystemPaths);
                if (systemIncludes.Count > 0)
                {
                    systemIncludes.Sort();
                    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 <Options.Vc.General.ExternalWarningLevel>(conf))
                    {
                        if (context.Options["ExternalIncludePath"] == FileGeneratorUtilities.RemoveLineTag)
                        {
                            context.Options["ExternalIncludePath"] = systemIncludesString;
                        }
                        else
                        {
                            context.Options["ExternalIncludePath"] += ";" + systemIncludesString;
                        }
                    }
                    else
                    {
                        if (context.Options["IncludePath"] == FileGeneratorUtilities.RemoveLineTag)
                        {
                            context.Options["IncludePath"] = "$(VC_IncludePath);$(WindowsSDK_IncludePath);" + systemIncludesString;
                        }
                        else
                        {
                            context.Options["IncludePath"] += ";" + systemIncludesString;
                        }
                    }
                }
            }