Last active
December 4, 2020 12:50
-
-
Save fun4jimmy/a975f418faf170c7d029f8604d5cffc0 to your computer and use it in GitHub Desktop.
A batch file used to locate the CMake executable, first checking the path then trying to find the installed location.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal | |
:: check for cmake on the path | |
SET CMAKE_EXE=cmake.exe | |
where /Q "%CMAKE_EXE%" | |
if errorlevel 1 ( | |
call :find_installed_cmake | |
if errorlevel 1 ( | |
echo Unable to locate cmake.exe, are you sure it is installed? | |
exit /b 1 | |
) | |
) | |
echo %CMAKE_EXE% | |
goto :eof | |
:find_installed_cmake | |
set REGISTRY_PATH="HKEY_LOCAL_MACHINE\Software\Kitware\CMake" | |
set REGISTRY_VARIABLE="InstallDir" | |
:: a successful output from reg.exe will be of the form | |
:: | |
:: HKEY_LOCAL_MACHINE\Software\Kitware\CMake | |
:: InstallDir REG_SZ C:\Program Files\CMake\ | |
:: | |
:: We redirect stderr to nul to suppress any error messages so we can provide our own. | |
for /F "skip=2 tokens=2,*" %%A IN ('reg.exe query %REGISTRY_PATH% /v %REGISTRY_VARIABLE% 2^>nul') DO set "CMAKE_INSTALL_DIR=%%B" | |
if "%CMAKE_INSTALL_DIR%" == "" ( | |
exit /b 1 | |
) | |
set CMAKE_EXE=%CMAKE_INSTALL_DIR%bin\cmake.exe | |
exit /b 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment