Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 26e0f52

Browse files
committed
Improve CMake detection on Windows when not in PATH
Equivalent to dotnet/coreclr#16328 In CMake v10.2, the key `hklm:\SOFTWARE\Kitware` returns: ```powershell Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Kitware Name Property ---- -------- CMake InstallDir : C:\Program Files\CMake\ ``` with no space after `CMake` and property name `InstallDir`, instead of `'(default)'`. Fix #28799
1 parent f5d3161 commit 26e0f52

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Native/Windows/probe-win.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@ function GetCMakeVersions
66
$items = @()
77
$items += @(Get-ChildItem hklm:\SOFTWARE\Wow6432Node\Kitware -ErrorAction SilentlyContinue)
88
$items += @(Get-ChildItem hklm:\SOFTWARE\Kitware -ErrorAction SilentlyContinue)
9-
return $items | where { $_.PSChildName.StartsWith("CMake ") }
9+
return $items | where { $_.PSChildName.StartsWith("CMake") }
1010
}
1111

1212
function GetCMakeInfo($regKey)
1313
{
14-
# This no longer works for versions 3.5+
1514
try {
1615
$version = [System.Version] $regKey.PSChildName.Split(' ')[1]
1716
}
1817
catch {
1918
return $null
2019
}
21-
$cmakeDir = (Get-ItemProperty $regKey.PSPath).'(default)'
20+
$itemProperty = Get-ItemProperty $regKey.PSPath;
21+
if (Get-Member -inputobject $itemProperty -name "InstallDir" -Membertype Properties) {
22+
$cmakeDir = $itemProperty.InstallDir
23+
}
24+
else {
25+
# For CMake prior to version 3.5
26+
$cmakeDir = $itemProperty.'(default)'
27+
}
2228
$cmakePath = [System.IO.Path]::Combine($cmakeDir, "bin\cmake.exe")
2329
if (![System.IO.File]::Exists($cmakePath)) {
2430
return $null

0 commit comments

Comments
 (0)