public override void GenerateGameProperties(UnrealTargetConfiguration Configuration, StringBuilder VCProjectFileContent, TargetType TargetType, DirectoryReference RootDirectory, FileReference TargetFilePath) { string MinVersion = string.Empty; string MaxTestedVersion = string.Empty; ConfigHierarchy EngineIni = ConfigCache.ReadHierarchy(ConfigHierarchyType.Engine, RootDirectory, UnrealTargetPlatform.HoloLens); if (EngineIni != null) { EngineIni.GetString("/Script/HoloLensPlatformEditor.HoloLensTargetSettings", "MinimumPlatformVersion", out MinVersion); EngineIni.GetString("/Script/HoloLensPlatformEditor.HoloLensTargetSettings", "MaximumPlatformVersionTested", out MaxTestedVersion); } if (!string.IsNullOrEmpty(MinVersion)) { VCProjectFileContent.Append(" <WindowsTargetPlatformMinVersion>"+ MinVersion + "</WindowsTargetPlatformMinVersion>" + ProjectFileGenerator.NewLine); } if (!string.IsNullOrEmpty(MaxTestedVersion)) { VCProjectFileContent.Append(" <WindowsTargetPlatformVersion>"+ MaxTestedVersion + "</WindowsTargetPlatformVersion>" + ProjectFileGenerator.NewLine); } WindowsCompiler Compiler = WindowsPlatform.GetDefaultCompiler(TargetFilePath); DirectoryReference PlatformWinMDLocation = HoloLens.GetCppCXMetadataLocation(Compiler, "Latest"); if (PlatformWinMDLocation == null || !FileReference.Exists(FileReference.Combine(PlatformWinMDLocation, "platform.winmd"))) { throw new BuildException("Unable to find platform.winmd for {0} toolchain; '{1}' is an invalid version", WindowsPlatform.GetCompilerName(Compiler), "Latest"); } string FoundationWinMDPath = HoloLens.GetLatestMetadataPathForApiContract("Windows.Foundation.FoundationContract", Compiler); string UniversalWinMDPath = HoloLens.GetLatestMetadataPathForApiContract("Windows.Foundation.UniversalApiContract", Compiler); VCProjectFileContent.Append(" <AdditionalOptions>/ZW /ZW:nostdlib</AdditionalOptions>"+ ProjectFileGenerator.NewLine); VCProjectFileContent.Append(" <NMakePreprocessorDefinitions>$(NMakePreprocessorDefinitions);PLATFORM_HOLOLENS=1;HOLOLENS=1;</NMakePreprocessorDefinitions>"+ ProjectFileGenerator.NewLine); if (PlatformWinMDLocation != null) { VCProjectFileContent.Append(" <NMakeAssemblySearchPath>$(NMakeAssemblySearchPath);"+ PlatformWinMDLocation + "</NMakeAssemblySearchPath>" + ProjectFileGenerator.NewLine); } VCProjectFileContent.Append(" <NMakeForcedUsingAssemblies>$(NMakeForcedUsingAssemblies);"+ FoundationWinMDPath + ";" + UniversalWinMDPath + ";platform.winmd</NMakeForcedUsingAssemblies>" + ProjectFileGenerator.NewLine); }
/// <summary> /// Creates an environment with the given settings /// </summary> /// <param name="Compiler">The compiler version to use</param> /// <param name="Platform">The platform to target</param> /// <param name="CompilerVersion">The specific toolchain version to use</param> /// <param name="WindowsSdkVersion">Version of the Windows SDK to use</param> /// <returns>New environment object with paths for the given settings</returns> public static VCEnvironment Create(WindowsCompiler Compiler, CppPlatform Platform, string CompilerVersion, string WindowsSdkVersion) { // Get the actual toolchain directory VersionNumber SelectedToolChainVersion; DirectoryReference SelectedToolChainDir; if (!WindowsPlatform.TryGetVCToolChainDir(Compiler, CompilerVersion, out SelectedToolChainVersion, out SelectedToolChainDir)) { throw new BuildException("{0}{1} must be installed in order to build this target.", WindowsPlatform.GetCompilerName(Compiler), String.IsNullOrEmpty(CompilerVersion)? "" : String.Format(" ({0})", CompilerVersion)); } // Get the actual Windows SDK directory VersionNumber SelectedWindowsSdkVersion; DirectoryReference SelectedWindowsSdkDir; if (!WindowsPlatform.TryGetWindowsSdkDir(WindowsSdkVersion, out SelectedWindowsSdkVersion, out SelectedWindowsSdkDir)) { throw new BuildException("Windows SDK{1} must be installed in order to build this target.", String.IsNullOrEmpty(WindowsSdkVersion)? "" : String.Format(" ({0})", WindowsSdkVersion)); } return(new VCEnvironment(Compiler, Platform, SelectedToolChainDir, SelectedToolChainVersion, SelectedWindowsSdkDir, SelectedWindowsSdkVersion)); }
/// <summary> /// Sets up the standard compile environment for the toolchain /// </summary> private void SetupEnvironment() { // Add the standard Visual C++ include paths IncludePaths.Add(DirectoryReference.Combine(ToolChainDir, "INCLUDE")); // Add the standard Visual C++ library paths if (Compiler >= WindowsCompiler.VisualStudio2017) { if (Platform == CppPlatform.Win32) { LibraryPaths.Add(DirectoryReference.Combine(ToolChainDir, "lib", "x86")); } else { LibraryPaths.Add(DirectoryReference.Combine(ToolChainDir, "lib", "x64")); } } else { if (Platform == CppPlatform.Win32) { LibraryPaths.Add(DirectoryReference.Combine(ToolChainDir, "LIB")); } else { LibraryPaths.Add(DirectoryReference.Combine(ToolChainDir, "LIB", "amd64")); } } // If we're on Visual Studio 2015 and using pre-Windows 10 SDK, we need to find a Windows 10 SDK and add the UCRT include paths if (Compiler >= WindowsCompiler.VisualStudio2015 && WindowsSdkVersion < new VersionNumber(10)) { KeyValuePair <VersionNumber, DirectoryReference> Pair = WindowsPlatform.FindUniversalCrtDirs().OrderByDescending(x => x.Key).FirstOrDefault(); if (Pair.Key == null || Pair.Key < new VersionNumber(10)) { throw new BuildException("{0} requires the Universal CRT to be installed.", WindowsPlatform.GetCompilerName(Compiler)); } DirectoryReference IncludeRootDir = DirectoryReference.Combine(Pair.Value, "include", Pair.Key.ToString()); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "ucrt")); DirectoryReference LibraryRootDir = DirectoryReference.Combine(Pair.Value, "lib", Pair.Key.ToString()); if (Platform == CppPlatform.Win64) { LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "ucrt", "x64")); } else { LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "ucrt", "x86")); } } // Add the NETFXSDK include path. We need this for SwarmInterface. DirectoryReference NetFxSdkDir; if (WindowsPlatform.TryGetNetFxSdkInstallDir(out NetFxSdkDir)) { IncludePaths.Add(DirectoryReference.Combine(NetFxSdkDir, "include", "um")); if (Platform == CppPlatform.Win32) { LibraryPaths.Add(DirectoryReference.Combine(NetFxSdkDir, "lib", "um", "x86")); } else { LibraryPaths.Add(DirectoryReference.Combine(NetFxSdkDir, "lib", "um", "x64")); } } // Add the Windows SDK paths if (WindowsSdkVersion >= new VersionNumber(10)) { DirectoryReference IncludeRootDir = DirectoryReference.Combine(WindowsSdkDir, "include", WindowsSdkVersion.ToString()); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "ucrt")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "shared")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "um")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "winrt")); DirectoryReference LibraryRootDir = DirectoryReference.Combine(WindowsSdkDir, "lib", WindowsSdkVersion.ToString()); if (Platform == CppPlatform.Win64) { LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "ucrt", "x64")); LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "um", "x64")); } else { LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "ucrt", "x86")); LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "um", "x86")); } } else { DirectoryReference IncludeRootDir = DirectoryReference.Combine(WindowsSdkDir, "include"); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "shared")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "um")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "winrt")); DirectoryReference LibraryRootDir = DirectoryReference.Combine(WindowsSdkDir, "lib", "winv6.3"); if (Platform == CppPlatform.Win64) { LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "um", "x64")); } else { LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "um", "x86")); } } }
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)); }
/// <summary> /// Creates an environment with the given settings /// </summary> /// <param name="Compiler">The compiler version to use</param> /// <param name="Platform">The platform to target</param> /// <param name="CompilerVersion">The specific toolchain version to use</param> /// <param name="WindowsSdkVersion">Version of the Windows SDK to use</param> /// <returns>New environment object with paths for the given settings</returns> public static VCEnvironment Create(WindowsCompiler Compiler, UnrealTargetPlatform Platform, string CompilerVersion, string WindowsSdkVersion) { // Get the compiler version info VersionNumber SelectedCompilerVersion; DirectoryReference SelectedCompilerDir; if (!WindowsPlatform.TryGetToolChainDir(Compiler, CompilerVersion, out SelectedCompilerVersion, out SelectedCompilerDir)) { throw new BuildException("{0}{1} must be installed in order to build this target.", WindowsPlatform.GetCompilerName(Compiler), String.IsNullOrEmpty(CompilerVersion)? "" : String.Format(" ({0})", CompilerVersion)); } // Get the toolchain info WindowsCompiler ToolChain; VersionNumber SelectedToolChainVersion; DirectoryReference SelectedToolChainDir; if (Compiler == WindowsCompiler.Clang || Compiler == WindowsCompiler.Intel) { ToolChain = WindowsCompiler.VisualStudio2017; if (!WindowsPlatform.TryGetToolChainDir(ToolChain, null, out SelectedToolChainVersion, out SelectedToolChainDir)) { throw new BuildException("{0}{1} must be installed in order to build this target.", WindowsPlatform.GetCompilerName(Compiler), String.IsNullOrEmpty(CompilerVersion)? "" : String.Format(" ({0})", CompilerVersion)); } } else { ToolChain = Compiler; SelectedToolChainVersion = SelectedCompilerVersion; SelectedToolChainDir = SelectedCompilerDir; } // Get the actual Windows SDK directory VersionNumber SelectedWindowsSdkVersion; DirectoryReference SelectedWindowsSdkDir; if (!WindowsPlatform.TryGetWindowsSdkDir(WindowsSdkVersion, out SelectedWindowsSdkVersion, out SelectedWindowsSdkDir)) { throw new BuildException("Windows SDK{0} must be installed in order to build this target.", String.IsNullOrEmpty(WindowsSdkVersion) ? "" : String.Format(" ({0})", WindowsSdkVersion)); } return(new VCEnvironment(Platform, Compiler, SelectedCompilerDir, SelectedCompilerVersion, ToolChain, SelectedToolChainDir, SelectedToolChainVersion, SelectedWindowsSdkDir, SelectedWindowsSdkVersion)); }
/// <summary> /// Sets up the standard compile environment for the toolchain /// </summary> private void SetupEnvironment(UnrealTargetPlatform Platform) { // Add the standard Visual C++ include paths IncludePaths.Add(DirectoryReference.Combine(ToolChainDir, "INCLUDE")); string ArchFolder = WindowsExports.GetArchitectureSubpath(Architecture); // Add the standard Visual C++ library paths if (ToolChain >= WindowsCompiler.VisualStudio2017) { if (Platform == UnrealTargetPlatform.HoloLens) { LibraryPaths.Add(DirectoryReference.Combine(ToolChainDir, "lib", ArchFolder, "store")); } else { LibraryPaths.Add(DirectoryReference.Combine(ToolChainDir, "lib", ArchFolder)); } } else { DirectoryReference LibsPath = DirectoryReference.Combine(ToolChainDir, "LIB"); if (Platform == UnrealTargetPlatform.HoloLens) { LibsPath = DirectoryReference.Combine(LibsPath, "store"); } if (Architecture == WindowsArchitecture.x64) { LibsPath = DirectoryReference.Combine(LibsPath, "amd64"); } else if (Architecture == WindowsArchitecture.ARM32) { LibsPath = DirectoryReference.Combine(LibsPath, "arm"); } LibraryPaths.Add(LibsPath); } // If we're on Visual Studio 2015 and using pre-Windows 10 SDK, we need to find a Windows 10 SDK and add the UCRT include paths if (ToolChain >= WindowsCompiler.VisualStudio2015_DEPRECATED && WindowsSdkVersion < new VersionNumber(10)) { KeyValuePair <VersionNumber, DirectoryReference> Pair = WindowsPlatform.FindUniversalCrtDirs().OrderByDescending(x => x.Key).FirstOrDefault(); if (Pair.Key == null || Pair.Key < new VersionNumber(10)) { throw new BuildException("{0} requires the Universal CRT to be installed.", WindowsPlatform.GetCompilerName(ToolChain)); } DirectoryReference IncludeRootDir = DirectoryReference.Combine(Pair.Value, "include", Pair.Key.ToString()); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "ucrt")); DirectoryReference LibraryRootDir = DirectoryReference.Combine(Pair.Value, "lib", Pair.Key.ToString()); LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "ucrt", ArchFolder)); } // Add the NETFXSDK include path. We need this for SwarmInterface. DirectoryReference NetFxSdkDir; if (WindowsPlatform.TryGetNetFxSdkInstallDir(out NetFxSdkDir)) { IncludePaths.Add(DirectoryReference.Combine(NetFxSdkDir, "include", "um")); LibraryPaths.Add(DirectoryReference.Combine(NetFxSdkDir, "lib", "um", ArchFolder)); } else { throw new BuildException("Could not find NetFxSDK install dir; this will prevent SwarmInterface from installing. Install a version of .NET Framework SDK at 4.6.0 or higher."); } // Add the Windows SDK paths if (WindowsSdkVersion >= new VersionNumber(10)) { DirectoryReference IncludeRootDir = DirectoryReference.Combine(WindowsSdkDir, "include", WindowsSdkVersion.ToString()); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "ucrt")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "shared")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "um")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "winrt")); DirectoryReference LibraryRootDir = DirectoryReference.Combine(WindowsSdkDir, "lib", WindowsSdkVersion.ToString()); LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "ucrt", ArchFolder)); LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "um", ArchFolder)); } else { DirectoryReference IncludeRootDir = DirectoryReference.Combine(WindowsSdkDir, "include"); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "shared")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "um")); IncludePaths.Add(DirectoryReference.Combine(IncludeRootDir, "winrt")); DirectoryReference LibraryRootDir = DirectoryReference.Combine(WindowsSdkDir, "lib", "winv6.3"); LibraryPaths.Add(DirectoryReference.Combine(LibraryRootDir, "um", ArchFolder)); } }