public static bool IsVisualStudioInstalled() { string BaseVSToolPath = WindowsPlatform.GetVSComnToolsPath(); if (string.IsNullOrEmpty(BaseVSToolPath) == false) { return(true); } return(false); }
private VCEnvironment(CPPTargetPlatform InPlatform) { Platform = InPlatform; // If Visual Studio is not installed, the Windows SDK path will be used, which also happens to be the same // directory. (It installs the toolchain into the folder where Visual Studio would have installed it to). BaseVSToolPath = WindowsPlatform.GetVSComnToolsPath(); if (string.IsNullOrEmpty(BaseVSToolPath)) { throw new BuildException("Visual Studio 2012, 2013 or 2015 must be installed in order to build this target."); } WindowsSDKDir = FindWindowsSDKInstallationFolder(Platform); WindowsSDKExtensionDir = FindWindowsSDKExtensionInstallationFolder(); NetFxSDKExtensionDir = FindNetFxSDKExtensionInstallationFolder(); WindowsSDKExtensionHeaderLibVersion = FindWindowsSDKExtensionLatestVersion(WindowsSDKExtensionDir); PlatformVSToolPath = GetPlatformVSToolPath(Platform, BaseVSToolPath); CompilerPath = GetCompilerToolPath(PlatformVSToolPath); CLExeVersion = FindCLExeVersion(CompilerPath); LinkerPath = GetLinkerToolPath(PlatformVSToolPath); LibraryLinkerPath = GetLibraryLinkerToolPath(PlatformVSToolPath); ResourceCompilerPath = GetResourceCompilerToolPath(Platform); // We ensure an extra trailing slash because of a user getting an odd error where the paths seemed to get concatenated wrongly: // // C:\Programme\Microsoft Visual Studio 12.0\Common7\Tools../../VC/bin/x86_amd64/vcvarsx86_amd64.bat // // https://answers.unrealengine.com/questions/233640/unable-to-create-project-files-for-48-preview-3.html // bool bUse64BitCompiler = Platform == CPPTargetPlatform.Win64 || Platform == CPPTargetPlatform.UWP; string BaseToolPathWithTrailingSlash = BaseVSToolPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar; string VCVarsBatchFile = Path.Combine(BaseToolPathWithTrailingSlash, bUse64BitCompiler ? @"..\..\VC\bin\x86_amd64\vcvarsx86_amd64.bat" : "vsvars32.bat"); if (Platform == CPPTargetPlatform.UWP && UWPPlatform.bBuildForStore) { Utils.SetEnvironmentVariablesFromBatchFile(VCVarsBatchFile, "store"); } else { Utils.SetEnvironmentVariablesFromBatchFile(VCVarsBatchFile); } // When targeting Windows XP on Visual Studio 2012+, we need to override the Windows SDK include and lib path set // by the batch file environment (http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx) if (WindowsPlatform.IsWindowsXPSupported()) { // Lib and bin folders have a x64 subfolder for 64 bit development. var ConfigSuffix = (Platform == CPPTargetPlatform.Win64) ? "\\x64" : ""; Environment.SetEnvironmentVariable("PATH", Utils.ResolveEnvironmentVariable(WindowsSDKDir + "bin" + ConfigSuffix + ";%PATH%")); Environment.SetEnvironmentVariable("LIB", Utils.ResolveEnvironmentVariable(WindowsSDKDir + "lib" + ConfigSuffix + ";%LIB%")); Environment.SetEnvironmentVariable("INCLUDE", Utils.ResolveEnvironmentVariable(WindowsSDKDir + "include;%INCLUDE%")); } }
/** Accesses the bin directory for the VC toolchain for the specified platform. */ static string GetVCToolPath(CPPTargetPlatform Platform, CPPTargetConfiguration Configuration, string ToolName) { // Initialize environment variables required for spawned tools. InitializeEnvironmentVariables(Platform); // Out variable that is going to contain fully qualified path to executable upon return. string VCToolPath = ""; // is target 64-bit? bool bIsTarget64Bit = true; // We need to differentiate between 32 and 64 bit toolchain on Windows. { // rc.exe resides in the Windows SDK folder. if (ToolName.ToUpperInvariant() == "RC") { // 64 bit -- we can use the 32 bit version to target 64 bit on 32 bit OS. if (bIsTarget64Bit) { VCToolPath = Path.Combine(WindowsSDKDir, "bin/x64/rc.exe"); } // 32 bit else { VCToolPath = Path.Combine(WindowsSDKDir, "bin/x86/rc.exe"); } } // cl.exe and link.exe are found in the toolchain specific folders (32 vs. 64 bit). We do however use the 64 bit linker if available // even when targeting 32 bit as it's noticeably faster. else { // Grab path to Visual Studio binaries from the system environment string BaseVSToolPath = WindowsPlatform.GetVSComnToolsPath(WindowsCompiler.VisualStudio2012); if (string.IsNullOrEmpty(BaseVSToolPath)) { throw new BuildException("Visual Studio 2012 must be installed in order to build this target."); } if (Platform == CPPTargetPlatform.WinRT_ARM) { VCToolPath = Path.Combine(BaseVSToolPath, "../../VC/bin/x86_arm/" + ToolName + ".exe"); } else { VCToolPath = Path.Combine(BaseVSToolPath, "../../VC/bin/amd64/" + ToolName + ".exe"); } } } return(VCToolPath); }
private VCEnvironment(CPPTargetPlatform InPlatform) { Platform = InPlatform; // If Visual Studio is not installed, the Windows SDK path will be used, which also happens to be the same // directory. (It installs the toolchain into the folder where Visual Studio would have installed it to). BaseVSToolPath = WindowsPlatform.GetVSComnToolsPath(); if (string.IsNullOrEmpty(BaseVSToolPath)) { throw new BuildException("Visual Studio 2012, 2013 or 2015 must be installed in order to build this target."); } WindowsSDKDir = FindWindowsSDKInstallationFolder(Platform); WindowsSDKExtensionDir = FindWindowsSDKExtensionInstallationFolder(); NetFxSDKExtensionDir = FindNetFxSDKExtensionInstallationFolder(); WindowsSDKExtensionHeaderLibVersion = FindWindowsSDKExtensionLatestVersion(WindowsSDKExtensionDir); PlatformVSToolPath = GetPlatformVSToolPath(Platform, BaseVSToolPath); CompilerPath = GetCompilerToolPath(PlatformVSToolPath); CLExeVersion = FindCLExeVersion(CompilerPath); LinkerPath = GetLinkerToolPath(PlatformVSToolPath); LibraryLinkerPath = GetLibraryLinkerToolPath(PlatformVSToolPath); ResourceCompilerPath = GetResourceCompilerToolPath(Platform); var VCVarsBatchFile = Path.Combine(BaseVSToolPath, (Platform == CPPTargetPlatform.Win64 || Platform == CPPTargetPlatform.UWP) ? "../../VC/bin/x86_amd64/vcvarsx86_amd64.bat" : "vsvars32.bat"); if (Platform == CPPTargetPlatform.UWP && UWPPlatform.bBuildForStore) { Utils.SetEnvironmentVariablesFromBatchFile(VCVarsBatchFile, "store"); } else { Utils.SetEnvironmentVariablesFromBatchFile(VCVarsBatchFile); } // When targeting Windows XP on Visual Studio 2012+, we need to override the Windows SDK include and lib path set // by the batch file environment (http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx) if (WindowsPlatform.IsWindowsXPSupported()) { // Lib and bin folders have a x64 subfolder for 64 bit development. var ConfigSuffix = (Platform == CPPTargetPlatform.Win64) ? "\\x64" : ""; Environment.SetEnvironmentVariable("PATH", Utils.ResolveEnvironmentVariable(WindowsSDKDir + "bin" + ConfigSuffix + ";%PATH%")); Environment.SetEnvironmentVariable("LIB", Utils.ResolveEnvironmentVariable(WindowsSDKDir + "lib" + ConfigSuffix + ";%LIB%")); Environment.SetEnvironmentVariable("INCLUDE", Utils.ResolveEnvironmentVariable(WindowsSDKDir + "include;%INCLUDE%")); } }
/** * Initializes environment variables required by toolchain. Different for 32 and 64 bit. */ static void InitializeEnvironmentVariables(CPPTargetPlatform Platform) { if (!bAreEnvironmentVariablesAlreadyInitialized) { string VCVarsBatchFile = ""; // Grab path to Visual Studio binaries from the system environment string BaseVSToolPath = WindowsPlatform.GetVSComnToolsPath(WindowsCompiler.VisualStudio2012); if (string.IsNullOrEmpty(BaseVSToolPath)) { BaseVSToolPath = "C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/Tools/"; if (Directory.Exists("C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/Tools/") == false) { throw new BuildException("Visual Studio 2012 must be installed in order to build this target."); } } // 64 bit tool chain. if (Platform == CPPTargetPlatform.WinRT_ARM) { VCVarsBatchFile = Path.Combine(BaseVSToolPath, "../../VC/bin/x86_arm/vcvarsx86_arm.bat"); } else { VCVarsBatchFile = Path.Combine(BaseVSToolPath, "../../VC/bin/x86_amd64/vcvarsx86_amd64.bat"); } // @todo: This is failing when building the Win32 target through NMake!!!! Utils.SetEnvironmentVariablesFromBatchFile(VCVarsBatchFile); if (WinRTPlatform.ShouldCompileWinRT() == true) { string EnvVarName = Utils.ResolveEnvironmentVariable(WindowsSDKDir + "Windows Metadata" + ";%LIBPATH%"); Environment.SetEnvironmentVariable("LIBPATH", EnvVarName); } bAreEnvironmentVariablesAlreadyInitialized = true; } }
private VCEnvironment(CPPTargetPlatform InPlatform, bool bSupportWindowsXP) { Platform = InPlatform; // If Visual Studio is not installed, the Windows SDK path will be used, which also happens to be the same // directory. (It installs the toolchain into the folder where Visual Studio would have installed it to). BaseVSToolPath = WindowsPlatform.GetVSComnToolsPath(); if (string.IsNullOrEmpty(BaseVSToolPath)) { throw new BuildException("Visual Studio 2015 must be installed in order to build this target."); } WindowsSDKDir = FindWindowsSDKInstallationFolder(Platform, bSupportWindowsXP); WindowsSDKLibVersion = FindWindowsSDKLibVersion(WindowsSDKDir); WindowsSDKExtensionDir = FindWindowsSDKExtensionInstallationFolder(); NetFxSDKExtensionDir = FindNetFxSDKExtensionInstallationFolder(); VisualCppDir = FindVisualCppInstallationFolder(WindowsPlatform.Compiler); WindowsSDKExtensionHeaderLibVersion = FindWindowsSDKExtensionLatestVersion(WindowsSDKExtensionDir); UniversalCRTDir = FindUniversalCRTInstallationFolder(); UniversalCRTVersion = FindUniversalCRTVersion(UniversalCRTDir); VSToolPath32Bit = GetVSToolPath32Bit(BaseVSToolPath); VSToolPath64Bit = GetVSToolPath64Bit(BaseVSToolPath); // Compile using 64 bit tools for 64 bit targets, and 32 for 32. string CompilerVSToolPath = (Platform == CPPTargetPlatform.Win64 || Platform == CPPTargetPlatform.UWP) ? VSToolPath64Bit : VSToolPath32Bit; // 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) string LinkerVSToolPath = VSToolPath64Bit; CompilerPath = GetCompilerToolPath(CompilerVSToolPath); CLExeVersion = FindCLExeVersion(CompilerPath); LinkerPath = GetLinkerToolPath(LinkerVSToolPath); LibraryLinkerPath = GetLibraryLinkerToolPath(LinkerVSToolPath); ResourceCompilerPath = 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, VSToolPath32Bit, true) == 0)) { PathEnvironmentVariable = VSToolPath32Bit + ";" + PathEnvironmentVariable; Environment.SetEnvironmentVariable("PATH", PathEnvironmentVariable); } // Setup the INCLUDE environment variable List <string> IncludePaths = GetVisualCppIncludePaths(VisualCppDir, UniversalCRTDir, UniversalCRTVersion, NetFxSDKExtensionDir, WindowsSDKDir, WindowsSDKLibVersion); if (InitialIncludePaths != null) { IncludePaths.Add(InitialIncludePaths); } Environment.SetEnvironmentVariable("INCLUDE", String.Join(";", IncludePaths)); // Setup the LIB environment variable List <string> LibraryPaths = GetVisualCppLibraryPaths(VisualCppDir, UniversalCRTDir, UniversalCRTVersion, NetFxSDKExtensionDir, WindowsSDKDir, WindowsSDKLibVersion, Platform); if (InitialLibraryPaths != null) { LibraryPaths.Add(InitialLibraryPaths); } Environment.SetEnvironmentVariable("LIB", String.Join(";", LibraryPaths)); }