Make build.cmd lookup the install directory of cmake in the registry if it's not...
authorKasper F. Brandt <poizan@poizan.dk>
Sat, 7 Feb 2015 18:26:24 +0000 (19:26 +0100)
committerKasper F. Brandt <poizan@poizan.dk>
Thu, 12 Feb 2015 17:19:00 +0000 (18:19 +0100)
build.cmd
src/pal/tools/gen-buildsys-win.bat
src/pal/tools/probe-win.ps1 [new file with mode: 0644]

index bbcefc6..5e84112 100644 (file)
--- a/build.cmd
+++ b/build.cmd
@@ -74,16 +74,14 @@ md "%__LogsDir%"
 ::Cleanup intermediates folder
 if exist "%__IntermediatesDir%" rd /s /q "%__IntermediatesDir%"
 
-:: Check prerequisites
 :CheckPrereqs
+:: Check prerequisites
 echo Checking pre-requisites...
 echo.
-::
-:: Check presence of CMake on the path
-for %%X in (cmake.exe) do (set FOUNDCMake=%%~$PATH:X)
-if defined FOUNDCMake goto CheckVS
-echo 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.
-goto :eof
+:: Eval the output from probe-win1.ps1
+for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
+
+goto CheckVS
 
 :CheckVS
 :: Check presence of VS
index 348d006..ac51caa 100644 (file)
@@ -14,7 +14,14 @@ set basePath=%1
 set "basePath=%basePath:"=%"
 :: remove trailing slash
 if %basePath:~-1%==\ set "basePath=%basePath:~0,-1%"
-cmake "-DCMAKE_USER_MAKE_RULES_OVERRIDE=%basePath%\src\pal\tools\windows-compiler-override.txt" -G "Visual Studio 12 2013 Win64" %1
+
+if defined CMakePath goto DoGen
+
+:: Eval the output from probe-win1.ps1
+for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& .\probe-win.ps1"') do %%a
+
+:DoGen
+"%CMakePath%" "-DCMAKE_USER_MAKE_RULES_OVERRIDE=%basePath%\src\pal\tools\windows-compiler-override.txt" -G "Visual Studio 12 2013 Win64" %1
 endlocal
 GOTO :DONE
 
diff --git a/src/pal/tools/probe-win.ps1 b/src/pal/tools/probe-win.ps1
new file mode 100644 (file)
index 0000000..70030b1
--- /dev/null
@@ -0,0 +1,59 @@
+# This file probes for the prerequisites for the build system, and outputs commands for eval'ing
+# from the cmd scripts to set variables (and exit on error)
+
+function GetCMakeVersions
+{
+  $items = @()
+  $items += @(Get-ChildItem hklm:\SOFTWARE\Wow6432Node\Kitware -ErrorAction SilentlyContinue)
+  $items += @(Get-ChildItem hklm:\SOFTWARE\Kitware -ErrorAction SilentlyContinue)
+  return $items | where { $_.PSChildName.StartsWith("CMake ") }
+}
+
+function GetCMakeInfo($regKey)
+{
+  try {
+    $version = [System.Version] $regKey.PSChildName.Split(' ')[1]
+  }
+  catch {
+    return $null
+  }
+  $cmakeDir = (Get-ItemProperty $regKey.PSPath).'(default)'
+  $cmakePath = [System.IO.Path]::Combine($cmakeDir, "bin\cmake.exe")
+  if (![System.IO.File]::Exists($cmakePath)) {
+    return $null
+  }
+  return @{'version' = $version; 'path' = $cmakePath}
+}
+
+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
+  if ($inPathPath -ne $null) {
+    return $inPathPath
+  }
+  # Let us hope that CMake keep using their current version scheme
+  $validVersions = @()
+  foreach ($regKey in GetCMakeVersions) {
+    $info = GetCMakeInfo($regKey)
+    if ($info -ne $null) { 
+      $validVersions += @($info)
+    }
+  }
+  $newestCMakePath = ($validVersions |
+    Sort-Object -property @{Expression={$_.version}; Ascending=$false} |
+    select -first 1).path
+  if ($newestCMakePath -eq $null) {
+    Throw $errorMsg
+  }
+  return $newestCMakePath
+}
+
+try {
+  $cmakePath = LocateCMake
+  [System.Console]::WriteLine("set CMakePath=" + $cmakePath)
+}
+catch {
+  [System.Console]::Error.WriteLine($_.Exception.Message)
+  [System.Console]::WriteLine("exit /b 1")
+}