geopro/build.bat

86 lines
3.0 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
REM ============================================================
REM geopro build helper (Windows / MSVC + Ninja, CMake presets)
REM
REM Usage: build [app | all | test | run | configure]
REM app (default) build target geopro_desktop
REM all build all targets
REM test build + run unit tests via ctest
REM run build + launch geopro_desktop
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 把临时目录指向 D: 的构建目录,规避 C: 盘满导致链接器写 %TEMP% 失败(LNK1108)。
REM 仅作用于本次构建(setlocal 作用域),不污染用户 shell。注意仍建议尽快清理 C: 盘。
set "TEMP=%BUILDDIR%\tmp"
set "TMP=%BUILDDIR%\tmp"
if not exist "%TEMP%" mkdir "%TEMP%"
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
)
for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -property installationPath`) do set "VSPATH=%%i"
if not defined VSPATH ( echo [build] Visual Studio not found. & 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
echo [build] unknown command "%CMD%". Use: app ^| all ^| test ^| run ^| 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%