/** Gets the path to the resource compiler's rc.exe for the specified platform. */ string GetResourceCompilerToolPath(CPPTargetPlatform Platform) { // 64 bit -- we can use the 32 bit version to target 64 bit on 32 bit OS. if (Platform == CPPTargetPlatform.Win64 || Platform == CPPTargetPlatform.UWP) { if (WindowsPlatform.Compiler == WindowsCompiler.VisualStudio2015 && WindowsPlatform.bUseWindowsSDK10) { return(Path.Combine(WindowsSDKExtensionDir, "bin/x64/rc.exe")); } else { return(Path.Combine(WindowsSDKDir, "bin/x64/rc.exe")); } } // @todo UWP: Verify that Windows XP will compile using VS 2015 (it should be supported) if (!WindowsPlatform.IsWindowsXPSupported()) // Windows XP requires use to force Windows SDK 7.1 even on the newer compiler, so we need the old path RC.exe { if (WindowsPlatform.Compiler == WindowsCompiler.VisualStudio2015 && WindowsPlatform.bUseWindowsSDK10) { return(Path.Combine(WindowsSDKExtensionDir, "bin/x86/rc.exe")); } else { return(Path.Combine(WindowsSDKDir, "bin/x86/rc.exe")); } } return(Path.Combine(WindowsSDKDir, "bin/rc.exe")); }
/// <returns>The path to Windows SDK directory for the specified version.</returns> private static string FindWindowsSDKInstallationFolder(CPPTargetPlatform InPlatform) { // When targeting Windows XP on Visual Studio 2012+, we need to point at the older Windows SDK 7.1A that comes // installed with Visual Studio 2012 Update 1. (http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx) string Version; if (WindowsPlatform.IsWindowsXPSupported()) { Version = "v7.1A"; } else { switch (WindowsPlatform.Compiler) { case WindowsCompiler.VisualStudio2015: if (WindowsPlatform.bUseWindowsSDK10) { Version = "v10.0"; } else { Version = "v8.1"; } break; case WindowsCompiler.VisualStudio2013: Version = "v8.1"; break; case WindowsCompiler.VisualStudio2012: Version = "v8.0"; break; default: throw new BuildException("Unexpected compiler setting when trying to determine Windows SDK folder"); } } // Based on VCVarsQueryRegistry string FinalResult = null; foreach (string IndividualVersion in Version.Split('|')) { var Result = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows\" + IndividualVersion, "InstallationFolder", null) ?? Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\" + IndividualVersion, "InstallationFolder", null) ?? Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\" + IndividualVersion, "InstallationFolder", null); if (Result != null) { FinalResult = (string)Result; break; } } if (FinalResult == null) { throw new BuildException("Windows SDK {0} must be installed in order to build this target.", Version); } return(FinalResult); }
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%")); } }
/** Gets the path to the resource compiler's rc.exe for the specified platform. */ static string GetResourceCompilerToolPath(CPPTargetPlatform Platform, string WindowsSDKDir) { // 64 bit -- we can use the 32 bit version to target 64 bit on 32 bit OS. if (Platform == CPPTargetPlatform.Win64) { return(Path.Combine(WindowsSDKDir, "bin/x64/rc.exe")); } if (!WindowsPlatform.IsWindowsXPSupported()) // Windows XP requires use to force Windows SDK 7.1 even on the newer compiler, so we need the old path RC.exe { return(Path.Combine(WindowsSDKDir, "bin/x86/rc.exe")); } return(Path.Combine(WindowsSDKDir, "bin/rc.exe")); }
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%")); } }