// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Diagnostics; using System.Linq; using EpicGames.Core; namespace UnrealBuildTool { //////////////////////////////////////////////////////////////////////////////// // If you are looking for version numbers, see Engine/Config/Windows/Windows_SDK.json //////////////////////////////////////////////////////////////////////////////// partial class MicrosoftPlatformSDK : UEBuildPlatformSDK { private static MicrosoftPlatformSDK SDK => GetSDKForPlatformOrMakeTemp("Win64")!; /// /// The default compiler version to be used, if installed. /// static VersionNumberRange[] PreferredClangVersions = SDK.GetVersionNumberRangeArrayFromConfig("PreferredClangVersions"); /// /// The minimum supported Clang compiler /// static VersionNumber MinimumClangVersion => SDK.GetRequiredVersionNumberFromConfig("MinimumClangVersion"); /// /// Ranges of tested compiler toolchains to be used, in order of preference. If multiple toolchains in a range are present, the latest version will be preferred. /// Note that the numbers here correspond to the installation *folders* rather than precise executable versions. /// /// static VersionNumberRange[] PreferredVisualCppVersions => SDK.GetVersionNumberRangeArrayFromConfig("PreferredVisualCppVersions"); /// /// Minimum Clang version required for MSVC toolchain versions /// static Tuple[] MinimumRequiredClangVersion => SDK.GetVersionNumberRangeArrayFromConfig("MinimumRequiredClangVersion"). Select(x => new Tuple(x.Min, x.Max)).ToArray(); /// /// Tested compiler toolchains that should not be allowed. /// static VersionNumberRange[] BannedVisualCppVersions => SDK.GetVersionNumberRangeArrayFromConfig("BannedVisualCppVersions"); /// /// The minimum supported MSVC compiler /// static VersionNumber MinimumVisualCppVersion => SDK.GetRequiredVersionNumberFromConfig("MinimumVisualCppVersion"); /// /// The default compiler version to be used, if installed. /// https://www.intel.com/content/www/us/en/developer/articles/tool/oneapi-standalone-components.html#dpcpp-cpp /// static VersionNumberRange[] PreferredIntelOneApiVersions => SDK.GetVersionNumberRangeArrayFromConfig("PreferredIntelOneApiVersions"); /// /// The minimum supported Intel compiler /// static VersionNumber MinimumIntelOneApiVersion => SDK.GetRequiredVersionNumberFromConfig("MinimumIntelOneApiVersion"); /// /// If a toolchain version is a preferred version /// /// The toolchain type /// The version number /// If the version is preferred public static bool IsPreferredVersion(WindowsCompiler toolchain, VersionNumber version) { if (toolchain.IsMSVC()) { return PreferredVisualCppVersions.Any(x => x.Contains(version)); } else if (toolchain.IsIntel()) { return PreferredIntelOneApiVersions.Any(x => x.Contains(version)); } else if (toolchain.IsClang()) { return PreferredClangVersions.Any(x => x.Contains(version)); } return false; } /// /// Get the latest preferred toolchain version /// /// The toolchain type /// The version number public static VersionNumber GetLatestPreferredVersion(WindowsCompiler toolchain) { if (toolchain.IsMSVC()) { return PreferredVisualCppVersions.Select(x => x.Min).Max()!; } else if (toolchain.IsIntel()) { return PreferredIntelOneApiVersions.Select(x => x.Min).Max()!; } else if (toolchain.IsClang()) { return PreferredClangVersions.Select(x => x.Min).Max()!; } return new VersionNumber(0); } /// /// The minimum supported Clang version for a given MSVC toolchain /// /// /// public static VersionNumber GetMinimumClangVersionForVcVersion(VersionNumber vcVersion) { return MinimumRequiredClangVersion.FirstOrDefault(x => vcVersion >= x.Item1)?.Item2 ?? MinimumClangVersion; } /// /// The base Clang version for a given Intel toolchain /// /// /// public static VersionNumber GetClangVersionForIntelCompiler(FileReference intelCompilerPath) { FileReference ldLLdPath = FileReference.Combine(intelCompilerPath.Directory, "compiler", "ld.lld.exe"); if (FileReference.Exists(ldLLdPath)) { FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(ldLLdPath.FullName); VersionNumber version = new VersionNumber(versionInfo.FileMajorPart, versionInfo.FileMinorPart, versionInfo.FileBuildPart); return version; } return MinimumClangVersion; } /// /// Whether toolchain errors should be ignored. Enable to ignore banned toolchains when generating projects, /// as components such as the recommended toolchain can be installed by opening the generated solution via the .vsconfig file. /// If enabled the error will be downgraded to a warning. /// public static bool IgnoreToolchainErrors { get; set; } = false; } }