Skip to content

Commit 479a7f8

Browse files
authored
Merge pull request #36 from sourcehold/feature/extract-cmake-finder-in-own-script
[PROJECT] Add cmake helper script
2 parents a64669b + 55cbbda commit 479a7f8

3 files changed

Lines changed: 47 additions & 30 deletions

File tree

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ Visual Studio Code with the proper extensions only needs to open the folder and
6565
Additionally, it configures format-on-save and a debug target for the UCP3.
6666

6767
If the scripts are preferred, the following triggers a build using the scripts:
68-
69-
1. Open a terminal. If the Visual Studio CMake version is used, it needs to be the CMD developer command prompt.
68+
1. Open a terminal.
7069
2. Navigate to this project folder
7170
3. Execute build.bat:
7271
```sh
@@ -77,9 +76,14 @@ If the scripts are preferred, the following triggers a build using the scripts:
7776
reccmp/run reccmp-reccmp --target STRONGHOLDCRUSADER --verbose 0x401000
7877
```
7978

79+
If CMake is installed and not in PATH, for example if installed via Visual Studio, `cmakew.bat` can be used instead. It tries to detect a CMake installation and uses it.
80+
8081
Note that any code needs to be formatted properly using the provided `clang-format`. The way to do so it up to the developer. Many IDEs support it out of the box.
8182

82-
Should any files be added to the source code in `src/core` or the ucp files in `ucp`, the cmake script [create-include-lists.cmake](create-include-lists.cmake) needs to be rerun and the changed list files need to be committed.
83+
Should any files be added to the source code in `src/core` or the ucp files in `ucp`, the cmake script [create-include-lists.cmake](create-include-lists.cmake) needs to be rerun and the changed list files need to be committed:
84+
```bat
85+
.\cmakew -P create-include-lists.cmake
86+
```
8387

8488
#### Manual configuration
8589

build.bat

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,6 @@ if "%~1"=="" (
1313
set "PRESET=%~1"
1414
set "TARGET=%~2"
1515

16-
:: --- Check for cmake ---
17-
where cmake >nul 2>nul
18-
if errorlevel 1 (
19-
echo [INFO] Auto-detecting cmake location using vswhere.
20-
if not exist "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" (
21-
echo [ERROR] 'vswhere' not found, cannot locate 'cmake'.
22-
exit /b 1
23-
)
24-
FOR /F "tokens=* USEBACKQ" %%g IN (`"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath -requires Microsoft.VisualStudio.Component.VC.CMake.Project`) do (
25-
SET "CMAKE=%%g\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin"
26-
)
27-
if not exist "!CMAKE!" (
28-
FOR /F "tokens=* USEBACKQ" %%g IN (`"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath -requires Microsoft.VisualStudio.Component.VC.CMake.Project -products Microsoft.VisualStudio.Product.BuildTools` ) do (
29-
SET "CMAKE=%%g\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin"
30-
)
31-
)
32-
if not exist "!CMAKE!" (
33-
echo [ERROR] 'cmake' is not found in PATH and not found using vswhere.
34-
exit /b 1
35-
)
36-
echo [INFO] Detected: "!CMAKE!"
37-
set "PATH=!CMAKE!;%PATH%"
38-
)
39-
4016
:: --- Kill mspdbsrv.exe if it's running ---
4117
tasklist | find /I "mspdbsrv.exe" >nul
4218
if not errorlevel 1 (
@@ -49,7 +25,7 @@ if not errorlevel 1 (
4925

5026
:: --- Run cmake configure using preset ---
5127
echo [INFO] Configuring with preset "%PRESET%"...
52-
cmake --preset "%PRESET%"
28+
call .\cmakew --preset "%PRESET%"
5329
if errorlevel 1 (
5430
echo [ERROR] CMake configure failed for preset "%PRESET%".
5531
exit /b 1
@@ -58,15 +34,15 @@ if errorlevel 1 (
5834
:: --- Run cmake build using preset ---
5935
if "%TARGET%"=="" (
6036
echo [INFO] Building preset "%PRESET%" with default target...
61-
cmake --build --preset "%PRESET%"
37+
call .\cmakew --build --preset "%PRESET%"
6238
if errorlevel 1 (
6339
echo [ERROR] CMake build failed for preset "%PRESET%".
6440
exit /b 1
6541
)
6642
echo Build completed successfully for preset "%PRESET%".
6743
) else (
6844
echo [INFO] Building preset "%PRESET%" with target "%TARGET%"...
69-
cmake --build --preset "%PRESET%" --target "%TARGET%"
45+
call .\cmakew --build --preset "%PRESET%" --target "%TARGET%"
7046
if errorlevel 1 (
7147
echo [ERROR] CMake build failed for preset "%PRESET%" target "%TARGET%".
7248
exit /b 1

cmakew.bat

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@echo off
2+
setlocal EnableDelayedExpansion
3+
4+
:: --- Check if cmake is in PATH ---
5+
where cmake >nul 2>nul
6+
if errorlevel 1 (
7+
echo [INFO] Auto-detecting cmake location using vswhere.
8+
9+
if not exist "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" (
10+
echo [ERROR] 'vswhere' not found, cannot locate 'cmake'.
11+
exit /b 1
12+
)
13+
14+
:: Try to locate CMake in latest VS installation
15+
FOR /F "tokens=* USEBACKQ" %%g IN (`"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath -requires Microsoft.VisualStudio.Component.VC.CMake.Project`) do (
16+
SET "CMAKE=%%g\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin"
17+
)
18+
19+
:: If not found, try latest Build Tools installation
20+
if not exist "!CMAKE!" (
21+
FOR /F "tokens=* USEBACKQ" %%g IN (`"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath -requires Microsoft.VisualStudio.Component.VC.CMake.Project -products Microsoft.VisualStudio.Product.BuildTools`) do (
22+
SET "CMAKE=%%g\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin"
23+
)
24+
)
25+
26+
if not exist "!CMAKE!" (
27+
echo [ERROR] 'cmake' not found in PATH and not found using vswhere.
28+
exit /b 1
29+
)
30+
31+
echo [INFO] Detected: "!CMAKE!"
32+
set "PATH=!CMAKE!;%PATH%"
33+
)
34+
35+
:: --- Proxy all arguments to actual CMake ---
36+
cmake %*
37+
exit /b %errorlevel%

0 commit comments

Comments
 (0)