From 99f04142611b389db64bb1ad519ecc6375bb9206 Mon Sep 17 00:00:00 2001 From: jacob Date: Sat, 6 Apr 2024 20:22:37 -0500 Subject: [PATCH] cleaner & order independent build.bat arg usage --- build.bat | 136 +++++++++++++++++++++--------------------------------- 1 file changed, 52 insertions(+), 84 deletions(-) diff --git a/build.bat b/build.bat index 69c58019..25f0d37a 100644 --- a/build.bat +++ b/build.bat @@ -1,93 +1,38 @@ @echo off setlocal -:: Description of build options: -:: -:: - Configuration -:: 1. debug: The target is intended to run in a debugger -:: 2. debug_asan: The target is intended to run in a debugger with address sanitization enabled -:: 3. profiling: The target is compiled with optimizations, debug info, and profiler timing info -:: 4. release: The target is compiled with optimizations and no debug info -:: -:: - Platform -:: 1. developer: The target will include all developer tooling -:: 2. user: The target will not include any developer tooling +:: Description of command line arguments (disabled by default): +:: "debug" The target is intended to run in a debugger with debug info and optimizations disabled +:: "developer" The target will include all developer tooling +:: "profiling" The target will be compiled with profiling markup +:: "asan" The target will compile with address sanitizer enabled -echo --------------- -where /q cmake || ( - echo ERROR: "cmake" not found - please install it and add the executable to your path +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: Verify environment +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +if "%Platform%" neq "x64" ( + echo ERROR: Platform is not "x64" - please run this from the MSVC x64 native tools command prompt. exit /b 1 ) where /q clang.exe || ( - echo ERROR: "clang.exe" not found - please run this from the MSVC x64 native tools command prompt. + echo ERROR: "clang.exe" not found. exit /b 1 ) -clang -v -echo --------------- where /q lld-link || ( - echo ERROR: "lld-link.exe" not found - please run this from the MSVC x64 native tools command prompt. + echo ERROR: "lld-link.exe" not found. exit /b 1 ) -echo lld-link version -lld-link --version -echo --------------- where /q ninja.exe || ( - echo ERROR: "ninja.exe" not found - please run this from the MSVC x64 native tools command prompt. + echo ERROR: "ninja.exe" not found. exit /b 1 ) -echo ninja version -ninja --version -echo --------------- -:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -:: Configuration -:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - -set config_default=-DRTC=0 -DASAN=0 -DCRTLIB=0 -DDEBINFO=0 -DDEVELOPER=0 -DPROFILING=0 -DUNOPTIMIZED=0 - -:: Arg1 -> compiler options mappings -set config1_debug=-DRTC=1 -DCRTLIB=1 -DDEBINFO=1 -DUNOPTIMIZED=1 -set config1_debug_asan=%config1_debug% -DASAN=1 -set config1_profiling=-DPROFILING=1 -DCRTLIB=1 -DDEBINFO=1 -set config1_release= - -:: Arg2 -> compiler options mappings -set config2_developer=-DDEVELOPER=1 -set config2_user= - -:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -:: Check args -:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - -set argerror=false - -:: Check arg 1 -set arg_config=%1% -if /I "%arg_config%" neq "debug" ( - if /I "%arg_config%" neq "debug_asan" ( - if /I "%arg_config%" neq "profiling" ( - if /I "%arg_config%" neq "release" ( - echo ERROR: must specify either 'debug', 'debug_asan', 'profiling', or 'release' as first argument - set argerror=true - ) - ) - ) -) - -:: Check arg 2 -set arg_platform=%2% -if /I "%arg_platform%" neq "developer" ( - if /I "%arg_platform%" neq "user" ( - echo ERROR: must specify either 'developer' or 'user' as second argument - set argerror=true - ) -) - -:: Exit if error -if %argerror% neq false ( +where /q cmake || ( + echo ERROR: "cmake.exe" not found. exit /b 1 ) @@ -95,15 +40,41 @@ if %argerror% neq false ( :: Choose configuration from args :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -set opt_config1= -if "%arg_config%" equ "debug" set opt_config1=%config1_debug% -if "%arg_config%" equ "debug_asan" set opt_config1=%config1_debug_asan% -if "%arg_config%" equ "profiling" set opt_config1=%config1_profiling% -if "%arg_config%" equ "release" set opt_config1=%config1_release% +:: Must explicitly pass disabled CMake options or else missing options are +:: assumed to be equal to the value from the last build +set cmake_options_zero=-DRTC=0 -DASAN=0 -DCRTLIB=0 -DDEBINFO=0 -DDEVELOPER=0 -DPROFILING=0 -DUNOPTIMIZED=0 -set opt_config2= -if "%arg_platform%" equ "developer" set opt_config2=%config2_developer% -if "%arg_platform%" equ "user" set opt_config2=%config2_user% +set cmake_options_enabled= + +echo ======================================== + +for %%a in (%*) do set "%%a=1" + +if "%debug%" == "1" ( + echo [Debug build] + set cmake_options_enabled=%cmake_options_enabled% -DRTC=1 -DCRTLIB=1 -DDEBINFO=1 -DUNOPTIMIZED=1 +) else ( + echo [Release build] +) + +if "%developer%" == "1" ( + echo [Developer build] + set cmake_options_enabled=%cmake_options_enabled% -DDEVELOPER=1 +) else ( + echo [User build] +) + +if "%profiling%" == "1" ( + echo [Profiling enabled] + set cmake_options_enabled=%cmake_options_enabled% -DPROFILING=1 -DCRTLIB=1 -DDEBINFO=1 +) + +if "%asan%" == "1" ( + echo [Address sanitizer enabled] + set cmake_options_enabled=%cmake_options_enabled% -DASAN=1 -DCRTLIB=1 -DDEBINFO=1 +) + +echo ======================================== :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Build @@ -111,10 +82,7 @@ if "%arg_platform%" equ "user" set opt_config2=%config2_user% if not exist "build" mkdir build -echo Calling cmake with options: %opt_config1% %opt_config2% - -:: https://stackoverflow.com/a/46593308 -cmake -H. -G Ninja -B build %config_default% %opt_config1% %opt_config2%^ +cmake -H. -G Ninja -B build %cmake_options_zero% %cmake_options_enabled%^ -DCMAKE_C_COMPILER:PATH="clang.exe"^ -DCMAKE_CXX_COMPILER:PATH="clang.exe"^ -DCMAKE_C_COMPILER_ID="Clang"^ @@ -125,6 +93,6 @@ cmake -H. -G Ninja -B build %config_default% %opt_config1% %opt_config2%^ if NOT %errorlevel% == 0 exit /b 1 cmake --build build -@REM cmake --build build -v +:: cmake --build build -v exit /b %errorlevel%