// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. using System; using System.IO; using Flax.Build.Projects; namespace Flax.Build.Platforms { /// /// The build platform for all Mac systems. /// /// public sealed class MacPlatform : UnixPlatform { /// public override TargetPlatform Target => TargetPlatform.Mac; /// public override bool HasRequiredSDKsInstalled { get; } /// public override bool HasSharedLibrarySupport => true; /// public override string SharedLibraryFileExtension => ".dylib"; /// public override string ProgramDatabaseFileExtension => ".dSYM"; /// public override string SharedLibraryFilePrefix => string.Empty; /// public override ProjectFormat DefaultProjectFormat => ProjectFormat.XCode; /// /// XCode Developer path returned by xcode-select. /// public string XCodePath; /// /// Initializes a new instance of the class. /// public MacPlatform() { if (Platform.BuildTargetPlatform != TargetPlatform.Mac) return; try { // Check if XCode is installed XCodePath = Utilities.ReadProcessOutput("xcode-select", "--print-path"); if (string.IsNullOrEmpty(XCodePath) || !Directory.Exists(XCodePath)) throw new Exception(XCodePath); Log.Verbose(string.Format("Found XCode at {0}", XCodePath)); HasRequiredSDKsInstalled = true; } catch { Log.Warning("Missing XCode. Cannot build for Mac platform."); } } /// protected override Toolchain CreateToolchain(TargetArchitecture architecture) { return new MacToolchain(this, architecture); } /// public override bool CanBuildPlatform(TargetPlatform platform) { switch (platform) { case TargetPlatform.Mac: return HasRequiredSDKsInstalled; default: return false; } } public static void FixInstallNameId(string dylibPath) { Utilities.Run("install_name_tool", string.Format(" -id \"@rpath/{0}\" \"{1}\"", Path.GetFileName(dylibPath), dylibPath), null, null, Utilities.RunOptions.ThrowExceptionOnError); } } }