@echo off REM =========================================================================== REM FCS Glass - noninteractive build driver (ASSUMPTIONS D-5, HC3). REM REM Usage: scripts\build.cmd [Release^|RelWithDebInfo^|Debug] [run] REM scripts\build.cmd clean REM REM Mirrors the demo's proven pattern: the PATH cmake/ninja on this machine are REM MinGW builds, so we deliberately ignore them and drive the Visual Studio REM toolchain through vcvars64.bat with an explicit generator and arch. REM Never prompts, never uses -Confirm (the HC3 rule the C# version needed). REM =========================================================================== setlocal EnableDelayedExpansion set "ROOT=%~dp0.." set "CFG=%~1" if "%CFG%"=="" set "CFG=RelWithDebInfo" if /I "%CFG%"=="clean" goto :clean set "DO_RUN=%~2" if /I "%DO_RUN%"=="run" (set "DO_RUN=1") else (set "DO_RUN=0") REM --- locate MSVC via vswhere ------------------------------------------------ set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" if not exist "%VSWHERE%" ( echo [build] FATAL: vswhere.exe not found. Install Visual Studio 2022 Build Tools. exit /b 1 ) for /f "usebackq tokens=*" %%I in (`"%VSWHERE%" -latest -products * ^ -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^ -property installationPath`) do set "VSPATH=%%I" if not defined VSPATH ( echo [build] FATAL: no Visual Studio installation with the C++ x64 tools. exit /b 1 ) echo [build] MSVC root: !VSPATH! set "VCVARS=!VSPATH!\VC\Auxiliary\Build\vcvars64.bat" if not exist "!VCVARS!" ( echo [build] FATAL: vcvars64.bat not found under "!VSPATH!". exit /b 1 ) REM --- prefer the VS-bundled cmake, else fall back to PATH -------------------- set "VSCMAKE=!VSPATH!\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" if exist "!VSCMAKE!" (set "CMAKE=!VSCMAKE!") else (set "CMAKE=cmake") if exist "%ROOT%\build" rmdir /S /Q "%ROOT%\build" call "!VCVARS!" >nul if errorlevel 1 ( echo [build] FATAL: vcvars64.bat failed. exit /b 1 ) echo [build] configuring (%CFG%)... "%CMAKE%" -S "%ROOT%" -B "%ROOT%\build" ^ -G "Visual Studio 17 2022" -A x64 ^ -DCMAKE_BUILD_TYPE=%CFG% if errorlevel 1 ( echo [build] FATAL: configure failed. exit /b 1 ) echo [build] compiling... "%CMAKE%" --build "%ROOT%\build" --config %CFG% --parallel if errorlevel 1 ( echo [build] FATAL: compile failed. exit /b 1 ) echo. echo [build] artifacts: if exist "%ROOT%\build\bin\fcs_glass.exe" (echo bin\fcs_glass.exe) if exist "%ROOT%\build\bin\fcs_selftest.exe" (echo bin\fcs_selftest.exe) REM BUG-27: the Visual Studio generator appends the configuration directory REM (build\bin\RelWithDebInfo\), while a Ninja generator does not (build\bin\). REM Checking only the flat path reported "no artifacts" for a build that had in REM fact succeeded - which is how a green build looked like a failed one. if exist "%ROOT%\build\bin\%CFG%\fcs_glass.exe" (echo bin\%CFG%\fcs_glass.exe) if exist "%ROOT%\build\bin\%CFG%\fcs_selftest.exe" (echo bin\%CFG%\fcs_selftest.exe) echo. if "%DO_RUN%"=="1" ( REM BUG-27: the parentheses around M0a MUST be escaped. Inside a parenthesized REM if-block an unescaped ')' closes the block, so cmd died with REM "... was unexpected at this time." and the script exited 1 on EVERY run, REM whether or not 'run' was passed - the whole block is parsed before the REM condition is evaluated. echo [build] launching fcs_selftest ^(M0a probe^)... "%ROOT%\build\bin\%CFG%\fcs_selftest.exe" exit /b %errorlevel% ) exit /b 0 :clean if exist "%ROOT%\build" rmdir /S /Q "%ROOT%\build" echo [build] removed build\ exit /b 0