/// <summary> /// Gets a list of Windows Sdk installation directories, ordered by preference /// </summary> /// <returns>String with the name</returns> public static List <KeyValuePair <string, DirectoryReference> > GetWindowsSdkDirs() { List <KeyValuePair <string, DirectoryReference> > WindowsSdkDirs = new List <KeyValuePair <string, DirectoryReference> >(); // Add the default directory first VersionNumber Version; DirectoryReference DefaultWindowsSdkDir; if (WindowsPlatform.TryGetWindowsSdkDir(null, out Version, out DefaultWindowsSdkDir)) { WindowsSdkDirs.Add(new KeyValuePair <string, DirectoryReference>(Version.ToString(), DefaultWindowsSdkDir)); } // Add all the other directories sorted in reverse order IReadOnlyDictionary <VersionNumber, DirectoryReference> WindowsSdkDirPairs = WindowsPlatform.FindWindowsSdkDirs(); foreach (KeyValuePair <VersionNumber, DirectoryReference> Pair in WindowsSdkDirPairs.OrderByDescending(x => x.Key)) { if (!WindowsSdkDirs.Any(x => x.Value == Pair.Value)) { WindowsSdkDirs.Add(new KeyValuePair <string, DirectoryReference>(Pair.Key.ToString(), Pair.Value)); } } return(WindowsSdkDirs); }
public override void GetVisualStudioPreDefaultString(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration, StringBuilder VCProjectFileContent) { // VS2017 expects WindowsTargetPlatformVersion to be set in conjunction with these other properties, otherwise the projects // will fail to load when the solution is in a HoloLens configuration. // Default to latest supported version. Game projects can override this later. // Because this property is only required for VS2017 we can safely say that's the compiler version (whether that's actually true // or not) string SDKFolder = ""; string SDKVersion = ""; DirectoryReference folder; VersionNumber version; if (WindowsPlatform.TryGetWindowsSdkDir("Latest", out version, out folder)) { SDKFolder = folder.FullName; SDKVersion = version.ToString(); } VCProjectFileContent.AppendLine(" <AppContainerApplication>true</AppContainerApplication>"); VCProjectFileContent.AppendLine(" <ApplicationType>Windows Store</ApplicationType>"); VCProjectFileContent.AppendLine(" <ApplicationTypeRevision>10.0</ApplicationTypeRevision>"); VCProjectFileContent.AppendLine(" <WindowsAppContainer>true</WindowsAppContainer>"); VCProjectFileContent.AppendLine(" <AppxPackage>true</AppxPackage>"); VCProjectFileContent.AppendLine(" <WindowsTargetPlatformVersion>{0}</WindowsTargetPlatformVersion>", SDKVersion.ToString()); }
/// <summary> /// Tries to get the directory for an installed Windows SDK /// </summary> /// <param name="DesiredVersion">Receives the desired version on success</param> /// <param name="OutSdkVersion">Version of SDK</param> /// <param name="OutSdkDir">Path to SDK root folder</param> /// <returns>String with the name</returns> public static bool TryGetWindowsSdkDir(string DesiredVersion, out Version OutSdkVersion, out DirectoryReference OutSdkDir) { VersionNumber vn; if (WindowsPlatform.TryGetWindowsSdkDir(DesiredVersion, out vn, out OutSdkDir)) { OutSdkVersion = new Version(vn.ToString()); return(true); } OutSdkVersion = new Version(); return(false); }
/// <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="Architecture">The Architecture 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, WindowsArchitecture Architecture, 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) { if (WindowsPlatform.TryGetToolChainDir(WindowsCompiler.VisualStudio2019, null, out SelectedToolChainVersion, out SelectedToolChainDir)) { ToolChain = WindowsCompiler.VisualStudio2019; } else if (WindowsPlatform.TryGetToolChainDir(WindowsCompiler.VisualStudio2017, null, out SelectedToolChainVersion, out SelectedToolChainDir)) { ToolChain = WindowsCompiler.VisualStudio2017; } else { throw new BuildException("{0} or {1} must be installed in order to build this target.", WindowsPlatform.GetCompilerName(WindowsCompiler.VisualStudio2019), WindowsPlatform.GetCompilerName(WindowsCompiler.VisualStudio2017)); } } 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, Architecture, ToolChain, SelectedToolChainDir, SelectedToolChainVersion, SelectedWindowsSdkDir, SelectedWindowsSdkVersion)); }
internal static string GetLatestMetadataPathForApiContract(string ApiContract, WindowsCompiler Compiler) { DirectoryReference SDKFolder; VersionNumber SDKVersion; if (!WindowsPlatform.TryGetWindowsSdkDir("Latest", out SDKVersion, out SDKFolder)) { return(string.Empty); } DirectoryReference ReferenceDir = DirectoryReference.Combine(SDKFolder, "References"); if (DirectoryReference.Exists(ReferenceDir)) { // Prefer a contract from a suitable SDK-versioned subdir of the references folder when available (starts with 15063 SDK) //Version WindowsSDKVersionMaxForToolchain = Compiler < WindowsCompiler.VisualStudio2017 ? HoloLens.MaximumSDKVersionForVS2015 : null; DirectoryReference SDKVersionedReferenceDir = DirectoryReference.Combine(ReferenceDir, SDKVersion.ToString()); DirectoryReference ContractDir = DirectoryReference.Combine(SDKVersionedReferenceDir, ApiContract); Version ContractLatestVersion = null; FileReference MetadataFileRef = null; if (DirectoryReference.Exists(ContractDir)) { // Note: contract versions don't line up with Windows SDK versions (they're numbered independently as 1.0.0.0, 2.0.0.0, etc.) ContractLatestVersion = FindLatestVersionDirectory(ContractDir.FullName, null); MetadataFileRef = FileReference.Combine(ContractDir, ContractLatestVersion.ToString(), ApiContract + ".winmd"); } // Retry in unversioned references dir if we failed above. if (MetadataFileRef == null || !FileReference.Exists(MetadataFileRef)) { ContractDir = DirectoryReference.Combine(ReferenceDir, ApiContract); if (DirectoryReference.Exists(ContractDir)) { ContractLatestVersion = FindLatestVersionDirectory(ContractDir.FullName, null); MetadataFileRef = FileReference.Combine(ContractDir, ContractLatestVersion.ToString(), ApiContract + ".winmd"); } } if (MetadataFileRef != null && FileReference.Exists(MetadataFileRef)) { return(MetadataFileRef.FullName); } } return(string.Empty); }
/// <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)); }
public override void ValidateTarget(TargetRules Target) { // WindowsTargetRules are reused for HoloLens, so that build modules can keep the model that reuses "windows" configs for most cases // That means overriding those settings here that need to be adjusted for HoloLens // Compiler version and pix flags must be reloaded from the HoloLens hive // Currently BP-only projects don't load build-related settings from their remote ini when building UE4Game.exe // (see TargetRules.cs, where the possibly-null project directory is passed to ConfigCache.ReadSettings). // It's important for HoloLens that we *do* use the project-specific settings when building (VS 2017 vs 2015 and // retail Windows Store are both examples). Possibly this should be done on all platforms? But in the interest // of not changing behavior on other platforms I'm limiting the scope. DirectoryReference IniDirRef = DirectoryReference.FromFile(Target.ProjectFile); if (IniDirRef == null && !string.IsNullOrEmpty(UnrealBuildTool.GetRemoteIniPath())) { IniDirRef = new DirectoryReference(UnrealBuildTool.GetRemoteIniPath()); } // Stash the current compiler choice (accounts for command line) in case ReadSettings reverts it to default WindowsCompiler CompilerBeforeReadSettings = Target.HoloLensPlatform.Compiler; ConfigCache.ReadSettings(IniDirRef, Platform, Target.HoloLensPlatform); if (Target.HoloLensPlatform.Compiler == WindowsCompiler.Default) { if (CompilerBeforeReadSettings != WindowsCompiler.Default) { // Previous setting was more specific, use that Target.HoloLensPlatform.Compiler = CompilerBeforeReadSettings; } else { Target.HoloLensPlatform.Compiler = WindowsPlatform.GetDefaultCompiler(Target.ProjectFile); } } if (!Target.bGenerateProjectFiles) { Log.TraceInformationOnce("Using {0} architecture for deploying to HoloLens device", Target.HoloLensPlatform.Architecture); } Target.WindowsPlatform.Compiler = Target.HoloLensPlatform.Compiler; Target.WindowsPlatform.Architecture = Target.HoloLensPlatform.Architecture; Target.WindowsPlatform.bPixProfilingEnabled = Target.HoloLensPlatform.bPixProfilingEnabled; Target.WindowsPlatform.bUseWindowsSDK10 = true; Target.bDeployAfterCompile = true; Target.bCompileNvCloth = false; // requires CUDA // Disable Simplygon support if compiling against the NULL RHI. if (Target.GlobalDefinitions.Contains("USE_NULL_RHI=1")) { Target.bCompileSpeedTree = false; } // Use shipping binaries to avoid dependency on nvToolsExt which fails WACK. if (Target.Configuration == UnrealTargetConfiguration.Shipping) { Target.bUseShippingPhysXLibraries = true; } // Be resilient to SDKs being uninstalled but still referenced in the INI file VersionNumber SelectedWindowsSdkVersion; DirectoryReference SelectedWindowsSdkDir; if (!WindowsPlatform.TryGetWindowsSdkDir(Target.HoloLensPlatform.Win10SDKVersionString, out SelectedWindowsSdkVersion, out SelectedWindowsSdkDir)) { Target.HoloLensPlatform.Win10SDKVersionString = "Latest"; } // Initialize the VC environment for the target, and set all the version numbers to the concrete values we chose. VCEnvironment Environment = VCEnvironment.Create(Target.WindowsPlatform.Compiler, Platform, Target.WindowsPlatform.Architecture, Target.WindowsPlatform.CompilerVersion, Target.HoloLensPlatform.Win10SDKVersionString, null); Target.WindowsPlatform.Environment = Environment; Target.WindowsPlatform.Compiler = Environment.Compiler; Target.WindowsPlatform.CompilerVersion = Environment.CompilerVersion.ToString(); Target.WindowsPlatform.WindowsSdkVersion = Environment.WindowsSdkVersion.ToString(); // Windows 10 SDK version // Auto-detect latest compatible by default (recommended), allow for explicit override if necessary // Validate that the SDK isn't too old, and that the combination of VS and SDK is supported. Target.HoloLensPlatform.Win10SDKVersion = new Version(Environment.WindowsSdkVersion.ToString()); if (!Target.bGenerateProjectFiles) { Log.TraceInformationOnce("Building using Windows SDK version {0} for HoloLens", Target.HoloLensPlatform.Win10SDKVersion); if (Target.HoloLensPlatform.Win10SDKVersion < MinimumSDKVersionRecommended) { Log.TraceWarning("Your Windows SDK version {0} is older than the minimum recommended version ({1}) for HoloLens. Consider upgrading.", Target.HoloLensPlatform.Win10SDKVersion, MinimumSDKVersionRecommended); } else if (Target.HoloLensPlatform.Win10SDKVersion > MaximumSDKVersionTested) { Log.TraceInformationOnce("Your Windows SDK version ({0}) for HoloLens is newer than the highest tested with this version of UBT ({1}). This is probably fine, but if you encounter issues consider using an earlier SDK.", Target.HoloLensPlatform.Win10SDKVersion, MaximumSDKVersionTested); } } HoloLensExports.InitWindowsSdkToolPath(Target.HoloLensPlatform.Win10SDKVersion.ToString()); }