diff --git a/build.psm1 b/build.psm1 index c8f7534342..96092ce9d3 100644 --- a/build.psm1 +++ b/build.psm1 @@ -114,14 +114,14 @@ function Start-PSBuild { $precheck = precheck 'dotnet' "Build dependency 'dotnet' not found in PATH. Run Start-PSBootstrap. Also see: https://dotnet.github.io/getting-started/" if ($FullCLR) { # cmake is needed to build powershell.exe - $precheck = $precheck -and (precheck 'cmake' 'cmake not found. You can install it from https://chocolatey.org/packages/cmake.portable') + $precheck = $precheck -and (precheck 'cmake' 'cmake not found. Run Start-PSBootstrap. You can also install it from https://chocolatey.org/packages/cmake.portable') Use-MSBuild #mc.exe is Message Compiler for native resources $mcexe = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\" -Recurse -Filter 'mc.exe' | ? {$_.FullName -match 'x64'} | select -First 1 | % {$_.FullName} if (-not $mcexe) { - throw 'mc.exe not found. Install Microsoft Windows 10 SDK from https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk' + throw 'mc.exe not found. Run Start-PSBootstrap or install Microsoft Windows 10 SDK from https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk' } $vcVarsPath = (Get-Item(Join-Path -Path "$env:VS140COMNTOOLS" -ChildPath '../../vc')).FullName @@ -590,14 +590,16 @@ function Start-PSBootstrap { Invoke-WebRequest -Uri $obtainUrl/$installScript -OutFile $installScript & ./$installScript -c $Channel -v $Version - # Install chocolatey $machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE') + $newMachineEnvironmentPath = $machinePath + + # Install chocolatey $chocolateyPath = "$env:AllUsersProfile\chocolatey\bin" if(Get-Command "choco" -ErrorAction SilentlyContinue) { log "Chocolatey is already installed. Skipping installation." } - else + else { log "Chocolatey not present. Installing chocolatey." Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) @@ -606,14 +608,43 @@ function Start-PSBootstrap { { log "Adding $chocolateyPath to Path environment variable" $env:Path += ";$chocolateyPath" - $machinePath += ";$chocolateyPath" - [Environment]::SetEnvironmentVariable('Path', $machinePath, 'MACHINE') + $newMachineEnvironmentPath += ";$chocolateyPath" } else { log "$chocolateyPath already present in Path environment variable" } } + + # Install cmake + $cmakePath = "${env:ProgramFiles(x86)}\CMake\bin" + if(Get-Command "cmake" -ErrorAction SilentlyContinue) + { + log "Cmake is already installed. Skipping installation." + } + else + { + log "Cmake not present. Installing cmake." + choco install cmake.portable -y --version 3.6.0 + + if (-not ($machinePath.ToLower().Contains($cmakePath.ToLower()))) + { + log "Adding $cmakePath to Path environment variable" + $env:Path += ";$cmakePath" + $newMachineEnvironmentPath = "$cmakePath;$newMachineEnvironmentPath" + } + else + { + log "$cmakePath already present in Path environment variable" + } + } + + # Update machine environment path + if ($newMachineEnvironmentPath -ne $machinePath) + { + [Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE') + } + } elseif ($IsWindows) { Write-Warning "Start-PSBootstrap cannot be run in Core PowerShell on Windows (need Invoke-WebRequest!)" }