23 public const string LatestVersion =
"4.1.2";
24 internal static string GetArchiveName(
string version = LatestVersion)
25 => (plat: EnvironmentInfo.Platform, arch: RuntimeInformation.OSArchitecture)
switch
27 (PlatformFamily.Windows, Architecture.X64) => $
"cmake-{version}-windows-x86_64.zip",
28 (PlatformFamily.Windows, Architecture.X86) => $
"cmake-{version}-windows-i386.zip",
29 (PlatformFamily.Windows, Architecture.Arm64) => $
"cmake-{version}-windows-arm64.zip",
30 (PlatformFamily.Linux, Architecture.X64) => $
"cmake-{version}-linux-x86_64.tar.gz",
31 (PlatformFamily.Linux, Architecture.Arm64) => $
"cmake-{version}-linux-aarch64.tar.gz",
32 (PlatformFamily.OSX, _) => $
"cmake-{version}-macos-universal.tar.gz",
33 var other =>
throw new Exception($
"Trying to use CMake on an unsupported platform: {other.plat} {other.arch}")
36 public static AbsolutePath GetLocalCMakeBin(
string version = LatestVersion)
38 var archiveName = GetArchiveName(version);
39 var subfolderName = archiveName
41 .Replace(
".tar.gz",
"");
43 var localPath = NukeBuild.TemporaryDirectory /
"cmake";
44 return EnvironmentInfo.Platform == PlatformFamily.OSX
45 ? localPath / subfolderName
46 : localPath / subfolderName /
"bin";
54 var archiveName = GetArchiveName(version);
55 var subfolderName = archiveName
57 .Replace(
".tar.gz",
"");
59 var localPath = NukeBuild.TemporaryDirectory /
"cmake";
60 if (!(localPath / subfolderName).DirectoryExists())
62 var downloadPath = localPath / archiveName;
63 Log.Information(
"Downloading CMake {0}", archiveName);
64 HttpTasks.HttpDownloadFile(
65 $
"https://github.com/Kitware/CMake/releases/download/v{LatestVersion}/{archiveName}",
69 Log.Information(
"Extracting CMake {0}", subfolderName);
70 if (archiveName.EndsWithOrdinalIgnoreCase(
".zip"))
72 downloadPath.UnZipTo(localPath);
74 else if (archiveName.EndsWithOrdinalIgnoreCase(
".tar.gz"))
76 downloadPath.UnTarGZipTo(localPath);
79 var programPath = EnvironmentInfo.Platform
switch
81 PlatformFamily.Windows => localPath / subfolderName /
"bin" /
"cmake.exe",
82 PlatformFamily.Linux => localPath / subfolderName /
"bin" /
"cmake",
83 PlatformFamily.OSX => localPath / subfolderName /
"CMake.app",
84 var other =>
throw new Exception($
"Trying to use CMake on an unsupported platform: {other}")
86 return ToolResolver.GetTool(programPath);
89 public static ValueOrError<Tool> EnsureCMake =>
TryGetCMake();
94 public static Tool
CMake => EnsureCMake.Get();