@echo off setlocal enabledelayedexpansion set "SCRIPT_DIR=%~dp0" :: %~dp0 always ends with \ which breaks cmake quoting ("path\" escapes the quote) set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%" set "BUILD_DIR=%SCRIPT_DIR%\build" :: -- Compiler detection (with vswhere fallback for MSVC) -------------------- set "HAS_COMPILER=0" where g++ >nul 2>&1 && set "HAS_COMPILER=1" where clang++ >nul 2>&1 && set "HAS_COMPILER=1" where cl >nul 2>&1 && set "HAS_COMPILER=1" if "%HAS_COMPILER%"=="1" goto :compiler_ok set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" if not exist "%VSWHERE%" goto :compiler_ok for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -property installationPath`) do ( set "VS_PATH=%%i" ) if not defined VS_PATH goto :compiler_ok set "VCVARS=!VS_PATH!\VC\Auxiliary\Build\vcvarsall.bat" if not exist "!VCVARS!" goto :compiler_ok echo Setting up MSVC environment... call "!VCVARS!" x64 >nul 2>&1 :compiler_ok :: -- Build and test --------------------------------------------------------- if "%1"=="--clean" ( if exist "%BUILD_DIR%" ( echo Cleaning build directory... rmdir /s /q "%BUILD_DIR%" ) ) if not exist "%BUILD_DIR%\CMakeCache.txt" ( echo Configuring test build. First run will fetch Google Test... cmake -S "%SCRIPT_DIR%" -B "%BUILD_DIR%" -DCMAKE_BUILD_TYPE=Debug if errorlevel 1 ( echo FAIL: cmake configure failed. echo cmake and a C++ compiler are required for host-side tests. echo Run 'anvil doctor' to see install instructions. exit /b 1 ) ) echo Building tests... cmake --build "%BUILD_DIR%" --parallel if errorlevel 1 ( echo FAIL: build failed exit /b 1 ) echo. echo Running tests... echo. ctest --test-dir "%BUILD_DIR%" --output-on-failure if errorlevel 1 ( echo. echo FAIL: Some tests failed. exit /b 1 ) echo. echo PASS: All tests passed.