@@ -396,6 +396,31 @@ $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.e
396396$VSInstallRoot = & $vswhere - nologo - latest - products " *" - all - prerelease - property installationPath
397397$msbuild = " $VSInstallRoot \MSBuild\Current\Bin\$BuildArchName \MSBuild.exe"
398398
399+ function Get-CMake {
400+ try {
401+ return (Get-Command " cmake.exe" - ErrorAction Stop).Source
402+ } catch {
403+ if (Test-Path - Path " ${VSInstallRoot} \Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin" - PathType Container) {
404+ return " ${VSInstallRoot} \Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
405+ }
406+ }
407+ throw " CMake not found on Path nor in the Visual Studio Installation. Please Install CMake to continue."
408+ }
409+
410+ function Get-Ninja {
411+ try {
412+ return (Get-Command " Ninja.exe" - ErrorAction Stop).Source
413+ } catch {
414+ if (Test-Path - Path " ${VSInstallRoot} \Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja" - PathType Container) {
415+ return " ${VSInstallRoot} \Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe"
416+ }
417+ }
418+ throw " Ninja not found on Path nor in the Visual Studio Installation. Please Install Ninja to continue."
419+ }
420+
421+ $cmake = Get-CMake
422+ $ninja = Get-Ninja
423+
399424$NugetRoot = " $BinaryCache \nuget"
400425$LibraryRoot = " $ImageRoot \Library"
401426
@@ -1222,14 +1247,6 @@ function Build-CMakeProject {
12221247 }
12231248
12241249 if ($Platform.OS -eq [OS ]::Android) {
1225- $vswhere = " ${env: ProgramFiles(x86)} \Microsoft Visual Studio\Installer\vswhere.exe"
1226- $VSInstallPath = & $vswhere - nologo - latest - products * - property installationPath
1227- if (Test-Path " ${VSInstallPath} \Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin" ) {
1228- $env: Path = " ${VSInstallPath} \Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;${VSInstallPath} \Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;${env: Path} "
1229- Add-KeyValueIfNew $Defines CMAKE_MAKE_PROGRAM " ${VSInstallPath} \Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe"
1230- } else {
1231- throw " Missing CMake and Ninja in the visual studio installation that are needed to build Android"
1232- }
12331250 $androidNDKPath = Get-AndroidNDKPath
12341251 Add-KeyValueIfNew $Defines CMAKE_C_COMPILER (Join-Path - Path $androidNDKPath - ChildPath " toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe" )
12351252 Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER (Join-Path - Path $androidNDKPath - ChildPath " toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe" )
@@ -1428,6 +1445,8 @@ function Build-CMakeProject {
14281445 Add-KeyValueIfNew $Defines CMAKE_INSTALL_PREFIX $InstallTo
14291446 }
14301447
1448+ Add-KeyValueIfNew $Defines CMAKE_MAKE_PROGRAM " $ninja "
1449+
14311450 # Generate the project
14321451 $cmakeGenerateArgs = @ (" -B" , $Bin , " -S" , $Src , " -G" , $Generator )
14331452 if ($CacheScript ) {
@@ -1467,26 +1486,25 @@ function Build-CMakeProject {
14671486 } elseif ($UsePinnedCompilers.Contains (" Swift" )) {
14681487 $env: Path = " $ ( Get-PinnedToolchainRuntime ) ;${env: Path} "
14691488 }
1470-
14711489 if ($ToBatch ) {
14721490 Write-Output " "
1473- Write-Output " echo cmake.exe $cmakeGenerateArgs "
1491+ Write-Output " echo $ cmake $cmakeGenerateArgs "
14741492 } else {
1475- Write-Host " cmake.exe $cmakeGenerateArgs "
1493+ Write-Host " $ cmake $cmakeGenerateArgs "
14761494 }
1477- Invoke-Program cmake.exe @cmakeGenerateArgs
1495+ Invoke-Program $ cmake @cmakeGenerateArgs
14781496
14791497 # Build all requested targets
14801498 foreach ($Target in $BuildTargets ) {
14811499 if ($Target -eq " default" ) {
1482- Invoke-Program cmake.exe -- build $Bin
1500+ Invoke-Program $ cmake -- build $Bin
14831501 } else {
1484- Invoke-Program cmake.exe -- build $Bin -- target $Target
1502+ Invoke-Program $ cmake -- build $Bin -- target $Target
14851503 }
14861504 }
14871505
14881506 if ($BuildTargets.Length -eq 0 -and $InstallTo ) {
1489- Invoke-Program cmake.exe -- build $Bin -- target install
1507+ Invoke-Program $ cmake -- build $Bin -- target install
14901508 }
14911509 }
14921510
@@ -2270,7 +2288,7 @@ function Build-ExperimentalRuntime {
22702288 Invoke-VsDevShell $BuildPlatform
22712289
22722290 Push-Location " ${SourceCache} \swift\Runtimes"
2273- Start-Process - Wait - WindowStyle Hidden - FilePath cmake.exe - ArgumentList @ (" -P" , " Resync.cmake" )
2291+ Start-Process - Wait - WindowStyle Hidden - FilePath $ cmake - ArgumentList @ (" -P" , " Resync.cmake" )
22742292 Pop-Location
22752293 }
22762294
@@ -2681,7 +2699,7 @@ function Test-LLBuild {
26812699 # Build additional llvm executables needed by tests
26822700 Invoke-IsolatingEnvVars {
26832701 Invoke-VsDevShell $BuildPlatform
2684- Invoke-Program ninja.exe - C (Get-ProjectBinaryCache $BuildPlatform BuildTools) FileCheck not
2702+ Invoke-Program $ ninja - C (Get-ProjectBinaryCache $BuildPlatform BuildTools) FileCheck not
26852703 }
26862704
26872705 Invoke-IsolatingEnvVars {
0 commit comments