Exemplo n.º 1
0
            protected override IEnumerable <IncludeWithPrefix> GetPlatformIncludePathsWithPrefixImpl(IGenerationContext context)
            {
                var    includes      = new List <IncludeWithPrefix>();
                string includePrefix = "/I";

                if (Options.GetObject <Options.Vc.General.PlatformToolset>(context.Configuration).IsLLVMToolchain() && Options.GetObject <Options.Vc.LLVM.UseClangCl>(context.Configuration) == Options.Vc.LLVM.UseClangCl.Enable)
                {
                    includePrefix = "/clang:-isystem";
                    string clangIncludePath = ClangForWindows.GetWindowsClangIncludePath();
                    includes.Add(new IncludeWithPrefix(includePrefix, clangIncludePath));
                }

                // when using clang-cl, mark MSVC includes, so they are properly recognized
                IEnumerable <string> msvcIncludePaths = EnumerateSemiColonSeparatedString(context.DevelopmentEnvironment.GetWindowsIncludePath());

                includes.AddRange(msvcIncludePaths.Select(path => new IncludeWithPrefix(includePrefix, path)));

                // Additional system includes
                OrderableStrings SystemIncludes = new OrderableStrings(context.Configuration.DependenciesIncludeSystemPaths);

                SystemIncludes.AddRange(context.Configuration.IncludeSystemPaths);
                if (SystemIncludes.Count > 0)
                {
                    SystemIncludes.Sort();
                    includes.AddRange(SystemIncludes.Select(path => new IncludeWithPrefix(includePrefix, path)));
                }
                return(includes);
            }
Exemplo n.º 2
0
            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();
                    }
                }

                if (Options.GetObject <Options.Vc.General.PlatformToolset>(conf).IsLLVMToolchain())
                {
                    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?));
                    }
                }
            }
            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(";");
                    }
                }
            }
Exemplo n.º 4
0
            public override void GeneratePlatformSpecificProjectDescription(IVcxprojGenerationContext context, IFileGenerator generator)
            {
                if (!ClangForWindows.Settings.OverridenLLVMInstallDir)
                {
                    return;
                }

                if (context.DevelopmentEnvironmentsRange.MinDevEnv != context.DevelopmentEnvironmentsRange.MaxDevEnv)
                {
                    throw new Error("Different vs versions not supported in the same vcxproj");
                }

                DevEnv uniqueDevEnv = context.DevelopmentEnvironmentsRange.MinDevEnv;

                using (generator.Declare("platformName", SimplePlatformString))
                {
                    generator.Write(Vcxproj.Template.Project.ProjectDescriptionStartPlatformConditional);
                    {
                        switch (uniqueDevEnv)
                        {
                        case DevEnv.vs2017:
                        {
                            string platformFolder = MSBuildGlobalSettings.GetCppPlatformFolder(context.DevelopmentEnvironmentsRange.MinDevEnv, Platform.win64);
                            if (!string.IsNullOrEmpty(platformFolder))
                            {
                                using (generator.Declare("platformFolder", Util.EnsureTrailingSeparator(platformFolder)))         // _PlatformFolder require the path to end with a "\"
                                    generator.Write(Vcxproj.Template.Project.PlatformFolderOverride);
                            }
                        }
                        break;

                        case DevEnv.vs2019:
                        {
                            // 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.

                            if (!string.IsNullOrEmpty(MSBuildGlobalSettings.GetCppPlatformFolder(uniqueDevEnv, Platform.win64)))
                            {
                                throw new Error("SetCppPlatformFolder is not supported by VS2019 correctly: use of MSBuildGlobalSettings.SetCppPlatformFolder should be replaced by use of MSBuildGlobalSettings.SetAdditionalVCTargetsPath.");
                            }
                            // vs2019 use AdditionalVCTargetsPath
                            string additionalVCTargetsPath = MSBuildGlobalSettings.GetAdditionalVCTargetsPath(uniqueDevEnv, Platform.win64);
                            using (generator.Declare("additionalVCTargetsPath", Util.EnsureTrailingSeparator(additionalVCTargetsPath)))         // the path shall end with a "\"
                                generator.Write(Vcxproj.Template.Project.AdditionalVCTargetsPath);
                        }
                        break;

                        default:
                            throw new Error(uniqueDevEnv + " is not supported.");
                        }
                        ClangForWindows.WriteLLVMOverrides(context, generator);
                    }
                    generator.Write(Vcxproj.Template.Project.PropertyGroupEnd);
                }
            }
Exemplo n.º 5
0
            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);
            }
Exemplo n.º 6
0
            protected override IEnumerable <IncludeWithPrefix> GetPlatformIncludePathsWithPrefixImpl(IGenerationContext context)
            {
                const string         cmdLineIncludePrefix = "/I";
                IEnumerable <string> msvcIncludePaths     = EnumerateSemiColonSeparatedString(context.DevelopmentEnvironment.GetWindowsIncludePath());

                if (Options.GetObject <Options.Vc.General.PlatformToolset>(context.Configuration).IsLLVMToolchain() && Options.GetObject <Options.Vc.LLVM.UseClangCl>(context.Configuration) == Options.Vc.LLVM.UseClangCl.Enable)
                {
                    var includes = new List <IncludeWithPrefix>();

                    string clangIncludePath = ClangForWindows.GetWindowsClangIncludePath();
                    includes.Add(new IncludeWithPrefix(cmdLineIncludePrefix, clangIncludePath));

                    // when using clang-cl, mark MSVC includes, so they are properly recognized
                    const string msvcCmdLineIncludePrefix = "/imsvc";
                    includes.AddRange(msvcIncludePaths.Select(msvcIncludePath => new IncludeWithPrefix(msvcCmdLineIncludePrefix, msvcIncludePath)));

                    return(includes);
                }

                return(msvcIncludePaths.Select(includePath => new IncludeWithPrefix(cmdLineIncludePrefix, includePath)));
            }
Exemplo n.º 7
0
            public override void GeneratePlatformSpecificProjectDescription(IVcxprojGenerationContext context, IFileGenerator generator)
            {
                string propertyGroups = string.Empty;

                // MSBuild override when mixing devenvs in the same vcxproj is not supported,
                // but before throwing an exception check if we have some override
                for (DevEnv devEnv = context.DevelopmentEnvironmentsRange.MinDevEnv; devEnv <= context.DevelopmentEnvironmentsRange.MaxDevEnv; devEnv = (DevEnv)((int)devEnv << 1))
                {
                    switch (devEnv)
                    {
                    case DevEnv.vs2015:
                    case DevEnv.vs2017:
                    {
                        string platformFolder = MSBuildGlobalSettings.GetCppPlatformFolder(devEnv, Platform.win64);
                        if (!string.IsNullOrEmpty(platformFolder))
                        {
                            using (generator.Declare("platformFolder", Util.EnsureTrailingSeparator(platformFolder)))         // _PlatformFolder require the path to end with a "\"
                                propertyGroups += generator.Resolver.Resolve(Vcxproj.Template.Project.PlatformFolderOverride);
                        }
                    }
                    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 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 {devEnv}: use of MSBuildGlobalSettings.SetCppPlatformFolder should be replaced by use of MSBuildGlobalSettings.SetAdditionalVCTargetsPath.");
                        }

                        // vs2019 and up use AdditionalVCTargetsPath
                        string additionalVCTargetsPath = MSBuildGlobalSettings.GetAdditionalVCTargetsPath(devEnv, Platform.win64);
                        if (!string.IsNullOrEmpty(additionalVCTargetsPath))
                        {
                            using (generator.Declare("additionalVCTargetsPath", Util.EnsureTrailingSeparator(additionalVCTargetsPath)))         // the path shall end with a "\"
                                propertyGroups += generator.Resolver.Resolve(Vcxproj.Template.Project.AdditionalVCTargetsPath);
                        }
                    }
                    break;
                    }
                }

                string llvmOverrideSection = ClangForWindows.GetLLVMOverridesSection(context, generator.Resolver);

                if (!string.IsNullOrEmpty(llvmOverrideSection))
                {
                    propertyGroups += llvmOverrideSection;
                }

                if (!string.IsNullOrEmpty(propertyGroups))
                {
                    if (context.DevelopmentEnvironmentsRange.MinDevEnv != context.DevelopmentEnvironmentsRange.MaxDevEnv)
                    {
                        throw new Error("Different vs versions not supported in the same vcxproj");
                    }

                    using (generator.Declare("platformName", SimplePlatformString))
                    {
                        generator.Write(Vcxproj.Template.Project.ProjectDescriptionStartPlatformConditional);
                        generator.WriteVerbatim(propertyGroups);
                        generator.Write(Vcxproj.Template.Project.PropertyGroupEnd);
                    }
                }
            }
Exemplo n.º 8
0
            protected override IEnumerable <IncludeWithPrefix> GetPlatformIncludePathsWithPrefixImpl(IGenerationContext context)
            {
                var    includes      = new List <IncludeWithPrefix>();
                string includePrefix = "/I";

                var    platformToolset = Options.GetObject <Options.Vc.General.PlatformToolset>(context.Configuration);
                DevEnv devEnv          = platformToolset.GetDefaultDevEnvForToolset() ?? context.DevelopmentEnvironment;

                if (platformToolset.IsLLVMToolchain() && Options.GetObject <Options.Vc.LLVM.UseClangCl>(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;
                    if (Options.WithArgOption <Options.Vc.General.PlatformToolset> .Get <Options.Clang.Compiler.LLVMVcPlatformToolset>(context.Configuration, ref overridenPlatformToolset))
                    {
                        platformToolset = overridenPlatformToolset;
                        devEnv          = platformToolset.GetDefaultDevEnvForToolset() ?? context.DevelopmentEnvironment;
                    }

                    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 <Options.Vc.General.ExternalWarningLevel>(context.Configuration))
                    {
                        includePrefix = "/external:I";
                    }
                }

                IEnumerable <string> msvcIncludePaths = EnumerateSemiColonSeparatedString(devEnv.GetWindowsIncludePath());

                includes.AddRange(msvcIncludePaths.Select(path => new IncludeWithPrefix(includePrefix, path)));

                // Additional system includes
                OrderableStrings SystemIncludes = new OrderableStrings(context.Configuration.DependenciesIncludeSystemPaths);

                SystemIncludes.AddRange(context.Configuration.IncludeSystemPaths);
                if (SystemIncludes.Count > 0)
                {
                    SystemIncludes.Sort();
                    includes.AddRange(SystemIncludes.Select(path => new IncludeWithPrefix(includePrefix, path)));
                }
                return(includes);
            }
Exemplo n.º 9
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;
                        }
                    }
                }
            }
Exemplo n.º 10
0
        protected void GetLinkerExecutableInfo(Project.Configuration conf, out string linkerPathOverride, out string linkerExeOverride, out string librarianExeOverride)
        {
            linkerPathOverride   = null;
            linkerExeOverride    = null;
            librarianExeOverride = null;

            var platformToolset = Options.GetObject <Options.Vc.General.PlatformToolset>(conf);
            var useLldLink      = Options.GetObject <Options.Vc.LLVM.UseLldLink>(conf);

            if (useLldLink == Options.Vc.LLVM.UseLldLink.Enable ||
                (useLldLink == Options.Vc.LLVM.UseLldLink.Default && platformToolset.IsLLVMToolchain()))
            {
                linkerPathOverride   = platformToolset == Options.Vc.General.PlatformToolset.ClangCL ? ClangForWindows.GetWindowsClangExecutablePath(conf.Target.GetFragment <DevEnv>()) : ClangForWindows.GetWindowsClangExecutablePath();
                linkerExeOverride    = "lld-link.exe";
                librarianExeOverride = "llvm-lib.exe";
            }
        }