Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

build(cmake): ship build.bat as a per-machine build.example.bat template

Olcay Seygan20bfabcf3004
diff --git a/.gitignore b/.gitignore
index f63140713..5fb8020fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,6 @@ build/
# Python bytecode from Tools/
__pycache__/
*.pyc
+
+# Local copy of build.example.bat, tweaked per machine
+build.bat
diff --git a/build.bat b/build.example.bat
similarity index 59%
rename from build.bat
rename to build.example.bat
index d2d78a54b..0190a873a 100644
--- a/build.bat
+++ b/build.example.bat
@@ -8,10 +8,36 @@ rem build.bat Debug build another config (Release|RelWithDebInfo|Deb
rem build.bat Release test build, then run ctest
rem build.bat Release generals build a single target
rem build.bat clean delete build\ and reconfigure from scratch
+rem
+rem This is the committed template. Copy it to build.bat (git-ignored) and edit
+rem the MACHINE SETTINGS block below to match this PC:
+rem
+rem copy build.example.bat build.bat
+
+rem ------------------------------ MACHINE SETTINGS -----------------------------
+rem Leave a value empty to let the script work it out on its own.
+
+rem Full path to cmake.exe. Empty = PATH first, then the copy shipped with VS2022.
+set "CMAKE="
+
+rem Visual Studio editions to probe for that shipped cmake, in order.
+set "VS_EDITIONS=Community Professional Enterprise BuildTools"
+
+rem CMake generator. Win32 x86 only -- x64 is rejected by the CMakeLists on purpose.
+set "GENERATOR=Visual Studio 17 2022"
+set "PLATFORM=Win32"
+
+rem Config used when the command line does not name one.
+set "DEFAULT_CONFIG=Release"
+
+rem Build tree. Empty = <repo>\build. Point it at a fast local disk if this
+rem checkout lives on a network share or a slow drive.
+set "BUILD="
+rem --------------------------- END MACHINE SETTINGS ----------------------------
set "ROOT=%~dp0"
set "SRC=%ROOT%GeneralsMD\Code"
-set "BUILD=%ROOT%build"
+if not defined BUILD set "BUILD=%ROOT%build"
set "CONFIG=%~1"
set "ARG2=%~2"
@@ -21,17 +47,20 @@ if /i "%CONFIG%"=="clean" (
set "CONFIG=%ARG2%"
set "ARG2="
)
-if "%CONFIG%"=="" set "CONFIG=Release"
+if "%CONFIG%"=="" set "CONFIG=%DEFAULT_CONFIG%"
set "RUNTESTS="
set "TARGET="
if /i "%ARG2%"=="test" (set "RUNTESTS=1") else (if not "%ARG2%"=="" set "TARGET=%ARG2%")
-rem --- locate cmake: PATH first, then the copy shipped with VS2022 ---
-set "CMAKE="
+rem --- locate cmake: MACHINE SETTINGS, then PATH, then the copy shipped with VS2022 ---
+if defined CMAKE if not exist "%CMAKE%" (
+ echo [build] ERROR: CMAKE is set to "%CMAKE%" in the MACHINE SETTINGS block, but that file does not exist.
+ exit /b 1
+)
for /f "delims=" %%C in ('where cmake 2^>nul') do if not defined CMAKE set "CMAKE=%%C"
if not defined CMAKE (
- for %%E in (Community Professional Enterprise BuildTools) do (
+ for %%E in (%VS_EDITIONS%) do (
set "TRY=C:\Program Files\Microsoft Visual Studio\2022\%%E\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
if not defined CMAKE if exist "!TRY!" set "CMAKE=!TRY!"
)
@@ -46,7 +75,7 @@ echo [build] config: %CONFIG%
rem --- configure (only when the cache is missing) ---
if not exist "%BUILD%\CMakeCache.txt" (
echo [build] configuring %SRC% -^> %BUILD%
- "%CMAKE%" -S "%SRC%" -B "%BUILD%" -G "Visual Studio 17 2022" -A Win32
+ "%CMAKE%" -S "%SRC%" -B "%BUILD%" -G "%GENERATOR%" -A %PLATFORM%
if !errorlevel! neq 0 (
echo [build] ERROR: configure failed.
exit /b 1