Exemple #1
0
        private VCEnvironment(CPPTargetPlatform InPlatform, WindowsCompiler InCompiler, bool bSupportWindowsXP)
        {
            Platform = InPlatform;
            Compiler = InCompiler;

            // Get the Visual Studio install directory
            WindowsPlatform.TryGetVSInstallDir(Compiler, out VSInstallDir);

            // Get the Visual C++ compiler install directory.
            if (!WindowsPlatform.TryGetVCInstallDir(Compiler, out VCInstallDir))
            {
                throw new BuildException(WindowsPlatform.GetCompilerName(Compiler) + " must be installed in order to build this target.");
            }

            // Figure out the default toolchain directory. VS15 separates this out into separate directories, with platforms as subdirectories under that.
            DirectoryReference VCToolChainDir = null;

            if (Compiler == WindowsCompiler.VisualStudio2017)
            {
                string Version = File.ReadAllText(FileReference.Combine(VCInstallDir, "Auxiliary", "Build", "Microsoft.VCToolsVersion.default.txt").FullName).Trim();
                VCToolChainDir = DirectoryReference.Combine(VCInstallDir, "Tools", "MSVC", Version);
            }

            WindowsSDKDir          = FindWindowsSDKInstallationFolder(Platform, Compiler, bSupportWindowsXP);
            WindowsSDKLibVersion   = FindWindowsSDKLibVersion(WindowsSDKDir, bSupportWindowsXP);
            WindowsSDKExtensionDir = bSupportWindowsXP ? "" : FindWindowsSDKExtensionInstallationFolder(Compiler);
            NetFxSDKExtensionDir   = bSupportWindowsXP ? "" : FindNetFxSDKExtensionInstallationFolder(Compiler);
            WindowsSDKExtensionHeaderLibVersion = bSupportWindowsXP ? new Version(0, 0, 0, 0) : FindWindowsSDKExtensionLatestVersion(WindowsSDKExtensionDir);
            UniversalCRTDir     = bSupportWindowsXP ? "" : FindUniversalCRTInstallationFolder(Compiler);
            UniversalCRTVersion = bSupportWindowsXP ? "0.0.0.0" : FindUniversalCRTVersion(UniversalCRTDir);

            VCToolPath32 = GetVCToolPath32(Compiler, VCInstallDir, VCToolChainDir);
            VCToolPath64 = GetVCToolPath64(Compiler, VCInstallDir, VCToolChainDir);

            // Compile using 64 bit tools for 64 bit targets, and 32 for 32.
            DirectoryReference CompilerDir = (Platform == CPPTargetPlatform.Win64) ? VCToolPath64 : VCToolPath32;

            // Regardless of the target, if we're linking on a 64 bit machine, we want to use the 64 bit linker (it's faster than the 32 bit linker and can handle large linking jobs)
            DirectoryReference LinkerDir = VCToolPath64;

            CompilerPath         = GetCompilerToolPath(InPlatform, CompilerDir);
            CLExeVersion         = FindCLExeVersion(CompilerPath.FullName);
            LinkerPath           = GetLinkerToolPath(InPlatform, LinkerDir);
            LibraryManagerPath   = GetLibraryLinkerToolPath(InPlatform, LinkerDir);
            ResourceCompilerPath = new FileReference(GetResourceCompilerToolPath(Platform, bSupportWindowsXP));

            // Make sure the base 32-bit VS tool path is in the PATH, regardless of which configuration we're using. The toolchain may need to reference support DLLs from this directory (eg. mspdb120.dll).
            string PathEnvironmentVariable = Environment.GetEnvironmentVariable("PATH") ?? "";

            if (!PathEnvironmentVariable.Split(';').Any(x => String.Compare(x, VCToolPath32.FullName, true) == 0))
            {
                PathEnvironmentVariable = VCToolPath32.FullName + ";" + PathEnvironmentVariable;
                Environment.SetEnvironmentVariable("PATH", PathEnvironmentVariable);
            }

            // Setup the INCLUDE environment variable
            List <string> IncludePaths = GetVisualCppIncludePaths(Compiler, VCInstallDir, VCToolChainDir, UniversalCRTDir, UniversalCRTVersion, NetFxSDKExtensionDir, WindowsSDKDir, WindowsSDKLibVersion, bSupportWindowsXP);

            if (InitialIncludePaths != null)
            {
                IncludePaths.Add(InitialIncludePaths);
            }
            Environment.SetEnvironmentVariable("INCLUDE", String.Join(";", IncludePaths));

            // Setup the LIB environment variable
            List <string> LibraryPaths = GetVisualCppLibraryPaths(Compiler, VCInstallDir, VCToolChainDir, UniversalCRTDir, UniversalCRTVersion, NetFxSDKExtensionDir, WindowsSDKDir, WindowsSDKLibVersion, Platform, bSupportWindowsXP);

            if (InitialLibraryPaths != null)
            {
                LibraryPaths.Add(InitialLibraryPaths);
            }
            Environment.SetEnvironmentVariable("LIB", String.Join(";", LibraryPaths));
        }