-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[macOS] Refactor Platform and Compiler settings for Apple Platforms
This commit introduces two new global settings classes. ApplePlatformSettings and ClangForAppleSettings. The goal is to make the compiler path and SDK path more configurable and able to be overriden from nuget packages that contain a custom compiler and sdk. This introduces a breaking change in the form of deprecating Options.Xcode.SDKRoot this has been split up per platform, meaning that if you want to change the SDK root you need to now set ApplePlatform.Settings.MacOSSDKPath ApplePlatform.Settings.IPhoneOSSDKPath etc. This also introduces the ClangForApple.Settings.IsAppleClang which can be used to check if the current compiler is the apple version of clang or a custom one.
- Loading branch information
1 parent
25d80ec
commit a8b8910
Showing
9 changed files
with
212 additions
and
72 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/ApplePlatformSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright (c) Ubisoft. All Rights Reserved. | ||
// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information. | ||
|
||
using System.IO; | ||
|
||
namespace Sharpmake | ||
{ | ||
public static class ApplePlatform | ||
{ | ||
public static class Settings | ||
{ | ||
private static string s_xcodeDevPath; | ||
public static string XCodeDeveloperPath | ||
{ | ||
get | ||
{ | ||
if (s_xcodeDevPath == null && Util.GetExecutingPlatform() != Platform.mac) | ||
throw new Error("ApplePlatform.Settings.XCodeDeveloperPath must be defined when not running on macOS"); | ||
|
||
return s_xcodeDevPath ?? (s_xcodeDevPath = "/Applications/Xcode.app/Contents/Developer"); | ||
} | ||
|
||
set | ||
{ | ||
s_xcodeDevPath = Util.PathMakeStandard(value); | ||
} | ||
} | ||
|
||
private static string s_macOSSDKPath; | ||
public static string MacOSSDKPath | ||
{ | ||
get | ||
{ | ||
return s_macOSSDKPath ?? (s_macOSSDKPath = $"{XCodeDeveloperPath}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"); | ||
} | ||
|
||
set | ||
{ | ||
s_macOSSDKPath = Util.PathMakeStandard(value); | ||
} | ||
} | ||
|
||
private static string s_iphoneOSSDKPath; | ||
public static string IPhoneOSSDkPath | ||
{ | ||
get | ||
{ | ||
return s_iphoneOSSDKPath ?? (s_iphoneOSSDKPath = $"{XCodeDeveloperPath}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"); | ||
} | ||
|
||
set | ||
{ | ||
s_iphoneOSSDKPath = Util.PathMakeStandard(value); | ||
} | ||
} | ||
|
||
|
||
private static string s_macCatalystSDKPath; | ||
public static string MacCatalystSDKPath | ||
{ | ||
get | ||
{ | ||
return s_macCatalystSDKPath ?? (s_macCatalystSDKPath = $"{XCodeDeveloperPath}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"); | ||
} | ||
|
||
set | ||
{ | ||
s_macCatalystSDKPath = Util.PathMakeStandard(value); | ||
} | ||
} | ||
|
||
private static string s_tvOSSDKPath; | ||
public static string TVOSSDKPath | ||
{ | ||
get | ||
{ | ||
return s_tvOSSDKPath ?? (s_tvOSSDKPath = $"{XCodeDeveloperPath}/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk"); | ||
} | ||
|
||
set | ||
{ | ||
s_tvOSSDKPath = Util.PathMakeStandard(value); | ||
} | ||
} | ||
|
||
private static string s_watchOSSDKPath; | ||
public static string WatchOSSDKPath | ||
{ | ||
get | ||
{ | ||
return s_watchOSSDKPath ?? (s_watchOSSDKPath = $"{XCodeDeveloperPath}/Platforms/watchOS.platform/Developer/SDKs/watchOS.sdk"); | ||
} | ||
|
||
set | ||
{ | ||
s_watchOSSDKPath = Util.PathMakeStandard(value); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/ClangForAppleSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) Ubisoft. All Rights Reserved. | ||
// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information. | ||
|
||
using System.IO; | ||
|
||
namespace Sharpmake | ||
{ | ||
public static class ClangForApple | ||
{ | ||
public static string GetClangExecutablePath() | ||
{ | ||
return Path.Combine(Settings.LLVMInstallDir, "bin"); | ||
} | ||
|
||
public static string GetClangIncludePath() | ||
{ | ||
return Path.Combine(Settings.LLVMInstallDir, "lib", "clang", Settings.ClangVersion, "include"); | ||
} | ||
|
||
public static string GetClangLibraryPath() | ||
{ | ||
return Path.Combine(Settings.LLVMInstallDir, "lib", "clang", Settings.ClangVersion, "lib", "darwin"); | ||
} | ||
|
||
public static class Settings | ||
{ | ||
private static bool s_isAppleClang = true; | ||
public static bool IsAppleClang | ||
{ | ||
get | ||
{ | ||
if (Util.GetExecutingPlatform() == Platform.win64) | ||
return false; | ||
return s_isAppleClang; | ||
} | ||
set | ||
{ | ||
if (value && Util.GetExecutingPlatform() == Platform.win64) | ||
throw new Error("Apple clang doesn't work on Windows"); | ||
s_isAppleClang = value; | ||
} | ||
} | ||
|
||
private static string s_llvmInstallDir; | ||
public static string LLVMInstallDir | ||
{ | ||
get | ||
{ | ||
if (!string.IsNullOrEmpty(s_llvmInstallDir)) | ||
return s_llvmInstallDir; | ||
|
||
if (Util.GetExecutingPlatform() == Platform.win64) | ||
return ClangForWindows.Settings.LLVMInstallDir; | ||
|
||
return $"{ApplePlatform.Settings.XCodeDeveloperPath}/Toolchains/XcodeDefault.xctoolchain/usr"; | ||
} | ||
|
||
set | ||
{ | ||
s_llvmInstallDir = Util.PathMakeStandard(value); | ||
} | ||
} | ||
|
||
private static string s_clangVersion; | ||
public static string ClangVersion | ||
{ | ||
get | ||
{ | ||
if (s_clangVersion == null) | ||
{ | ||
if (Util.DirectoryExists(LLVMInstallDir)) | ||
s_clangVersion = Util.GetClangVersionFromLLVMInstallDir(LLVMInstallDir); | ||
else | ||
throw new Error($"ClangForApple.Settings.LLVMInstallDir is pointing to {LLVMInstallDir}, which doesn't exists."); | ||
} | ||
return s_clangVersion; | ||
} | ||
|
||
set | ||
{ | ||
s_clangVersion = value; | ||
if (!Util.DirectoryExists(Path.Combine(LLVMInstallDir, "lib", "clang", s_clangVersion))) | ||
throw new Error($"Cannot find required files for Clang {s_clangVersion} in {LLVMInstallDir}"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.