From 5fb931bc24751b2515106ae4c97106f45f2fb9ef Mon Sep 17 00:00:00 2001 From: Steve MacLean Date: Thu, 6 Dec 2018 17:14:26 -0500 Subject: [PATCH] Update probe-win.ps1 from corefx Commit migrated from https://github.com/dotnet/core-setup/commit/c2324ddd3ae30ca5c8ef5927052c34ee033fac23 --- src/installer/corehost/Windows/probe-win.ps1 | 31 +++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/installer/corehost/Windows/probe-win.ps1 b/src/installer/corehost/Windows/probe-win.ps1 index d1ae1fd..353db37 100644 --- a/src/installer/corehost/Windows/probe-win.ps1 +++ b/src/installer/corehost/Windows/probe-win.ps1 @@ -6,19 +6,25 @@ function GetCMakeVersions $items = @() $items += @(Get-ChildItem hklm:\SOFTWARE\Wow6432Node\Kitware -ErrorAction SilentlyContinue) $items += @(Get-ChildItem hklm:\SOFTWARE\Kitware -ErrorAction SilentlyContinue) - return $items | Where-Object { $_.PSChildName.StartsWith("CMake ") } + return $items | where { $_.PSChildName.StartsWith("CMake") } } function GetCMakeInfo($regKey) { - # This no longer works for versions 3.5+ try { $version = [System.Version] $regKey.PSChildName.Split(' ')[1] } catch { return $null } - $cmakeDir = (Get-ItemProperty $regKey.PSPath).'(default)' + $itemProperty = Get-ItemProperty $regKey.PSPath; + if (Get-Member -inputobject $itemProperty -name "InstallDir" -Membertype Properties) { + $cmakeDir = $itemProperty.InstallDir + } + else { + # For CMake prior to version 3.5 + $cmakeDir = $itemProperty.'(default)' + } $cmakePath = [System.IO.Path]::Combine($cmakeDir, "bin\cmake.exe") if (![System.IO.File]::Exists($cmakePath)) { return $null @@ -29,26 +35,37 @@ function GetCMakeInfo($regKey) function LocateCMake { $errorMsg = "CMake is a pre-requisite to build this repository but it was not found on the path. Please install CMake from http://www.cmake.org/download/ and ensure it is on your path." - $inPathPath = (get-command cmake.exe -ErrorAction SilentlyContinue).Path + $inPathPath = (get-command cmake.exe -ErrorAction SilentlyContinue) if ($inPathPath -ne $null) { - return $inPathPath + # Resolve the first version of CMake if multiple commands are found + if ($inPathPath.Length -gt 1) { + return $inPathPath[0].Path + } + return $inPathPath.Path } # Check the default installation directory $inDefaultDir = [System.IO.Path]::Combine(${Env:ProgramFiles(x86)}, "CMake\bin\cmake.exe") if ([System.IO.File]::Exists($inDefaultDir)) { return $inDefaultDir } + # If we're running in an x86 process, and a 64-bit CMake is installed, but is not on the PATH, we also + # won't see its installation information in the registry (below). Check the default installation directory + # in the 64-bit Program Files location. + $inDefaultDir = [System.IO.Path]::Combine(${Env:ProgramW6432}, "CMake\bin\cmake.exe") + if ([System.IO.File]::Exists($inDefaultDir)) { + return $inDefaultDir + } # Let us hope that CMake keep using their current version scheme $validVersions = @() foreach ($regKey in GetCMakeVersions) { $info = GetCMakeInfo($regKey) - if ($info -ne $null) { + if ($info -ne $null) { $validVersions += @($info) } } $newestCMakePath = ($validVersions | Sort-Object -property @{Expression={$_.version}; Ascending=$false} | - Select-Object -first 1).path + select -first 1).path if ($newestCMakePath -eq $null) { Throw $errorMsg } -- 2.7.4