geopro/build.bat

94 lines
3.7 KiB
Batchfile

@echo off
REM ============================================================
REM geopro build helper (Windows / MSVC + Ninja, CMake presets)
REM
REM Usage: build [app | all | test | run | rebuild | configure]
REM app (default) build target geopro_desktop (incremental)
REM all build all targets (incremental)
REM test build + run unit tests via ctest
REM run incremental build + launch geopro_desktop
REM rebuild FORCE clean rebuild (--clean-first) + launch - use when
REM incremental seems stale / changes not showing up
REM configure force re-run CMake configure (after CMakeLists changes)
REM
REM Requires: Visual Studio 2022/2026 (Desktop C++ workload, ships
REM CMake + Ninja) and the VCPKG_ROOT environment variable.
REM Note: cmake/ninja/cl are NOT on PATH on this machine; this script
REM locates VS via vswhere and activates the MSVC env itself.
REM ============================================================
setlocal
set "ROOT=%~dp0"
set "BUILDDIR=%ROOT%build\release"
set "PRESET=msvc-release"
REM --- locate Visual Studio (vswhere lives at a fixed path) ---
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist "%VSWHERE%" (
echo [build] vswhere not found. Open "x64 Native Tools Command Prompt for VS" and build manually.
exit /b 1
)
REM -all -prerelease for VS2026 preview (note: -latest yields empty on this preview, and
REM -products * would pull in the bundled BuildTools whose vcpkg/env breaks our preset);
REM -requires ensures the C++ toolset is present. Multiple installs -> last one wins.
for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -all -prerelease -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSPATH=%%i"
if not defined VSPATH ( echo [build] Visual Studio with C++ toolset not found. Install the VS Desktop C++ workload. & exit /b 1 )
set "VCVARS=%VSPATH%\VC\Auxiliary\Build\vcvars64.bat"
set "CMAKE=%VSPATH%\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
set "CTEST=%VSPATH%\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\ctest.exe"
if not exist "%VCVARS%" ( echo [build] vcvars64.bat not found: "%VCVARS%" & exit /b 1 )
if not exist "%CMAKE%" ( echo [build] cmake not found: "%CMAKE%" & exit /b 1 )
REM --- activate MSVC environment (cl / link / include / lib) ---
call "%VCVARS%" >nul
set "CMD=%~1"
if "%CMD%"=="" set "CMD=app"
if /i "%CMD%"=="configure" goto :configure
if /i "%CMD%"=="app" goto :app
if /i "%CMD%"=="all" goto :all
if /i "%CMD%"=="test" goto :test
if /i "%CMD%"=="run" goto :run
if /i "%CMD%"=="rebuild" goto :rebuild
echo [build] unknown command "%CMD%". Use: app ^| all ^| test ^| run ^| rebuild ^| configure
exit /b 1
:ensure
if not exist "%BUILDDIR%\CMakeCache.txt" "%CMAKE%" --preset %PRESET%
exit /b 0
:configure
"%CMAKE%" --preset %PRESET%
exit /b %errorlevel%
:app
call :ensure
"%CMAKE%" --build "%BUILDDIR%" --target geopro_desktop
exit /b %errorlevel%
:all
call :ensure
"%CMAKE%" --build "%BUILDDIR%"
exit /b %errorlevel%
:test
call :ensure
"%CMAKE%" --build "%BUILDDIR%" --target geopro_tests || exit /b 1
"%CTEST%" --test-dir "%BUILDDIR%" --output-on-failure
exit /b %errorlevel%
:run
call :ensure
"%CMAKE%" --build "%BUILDDIR%" --target geopro_desktop || exit /b 1
"%BUILDDIR%\src\app\geopro_desktop.exe"
exit /b %errorlevel%
:rebuild
REM Force full clean rebuild (--clean-first) then launch; avoids flaky ninja incremental.
REM If geopro_desktop is already running, link fails (LNK1104, exe locked) - close it first.
call :ensure
"%CMAKE%" --build "%BUILDDIR%" --target geopro_desktop --clean-first || exit /b 1
"%BUILDDIR%\src\app\geopro_desktop.exe"
exit /b %errorlevel%