// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Flax.Build.Platforms; namespace Flax.Build { partial class Configuration { /// /// Prints all SDKs found on system. Can be used to query Win10 SDK or any other platform-specific toolsets used by build tool. /// [CommandLine("printSDKs", "Prints all SDKs found on system. Can be used to query Win10 SDK or any other platform-specific toolsets used by build tool.")] public static void PrintSDKs() { Log.Info("Printing SDKs..."); Sdk.Print(); } } /// /// The base class for all SDKs. /// public abstract class Sdk { private static Dictionary _sdks; /// /// Returns true if SDK is valid. /// public bool IsValid { get; protected set; } = false; /// /// Gets the version of the SDK. /// public Version Version { get; protected set; } = new Version(); /// /// Gets the path to the SDK install location. /// public string RootPath { get; protected set; } = string.Empty; /// /// Gets the platforms list supported by this SDK. /// public abstract TargetPlatform[] Platforms { get; } /// /// Prints info about all SDKs. /// public static void Print() { Get(string.Empty); foreach (var e in _sdks) { var sdk = e.Value; if (sdk.IsValid) Log.Message(sdk.GetType().Name + ", " + sdk.Version + ", " + sdk.RootPath); else Log.Message(sdk.GetType().Name + ", missing"); } foreach (var e in WindowsPlatformBase.GetSDKs()) { Log.Message("Windows SDK " + e.Key + ", " + WindowsPlatformBase.GetSDKVersion(e.Key) + ", " + e.Value); } foreach (var e in WindowsPlatformBase.GetToolsets()) { Log.Message("Windows Toolset " + e.Key + ", " + e.Value); } } /// /// Gets the specified SDK. /// /// The SDK name. /// The SDK instance or null if not supported. public static Sdk Get(string name) { if (_sdks == null) { using (new ProfileEventScope("GetSdks")) { _sdks = new Dictionary(); var types = Builder.BuildTypes.Where(x => !x.IsAbstract && x.IsSubclassOf(typeof(Sdk))); foreach (var type in types) { object instance = null; var instanceField = type.GetField("Instance", BindingFlags.Public | BindingFlags.Static); if (instanceField != null) { instance = instanceField.GetValue(null); } else if (type.GetConstructor(Type.EmptyTypes) != null) { instance = Activator.CreateInstance(type); } if (instance != null) _sdks.Add(type.Name, (Sdk)instance); } } } _sdks.TryGetValue(name, out var result); return result; } /// /// Returns true if SDK is supported and is valid. /// /// The SDK name. /// true if the SDK is valid; otherwise, false. public static bool HasValid(string name) { return Get(name)?.IsValid ?? false; } } }