power_play/build.bat
2024-05-03 02:35:25 -05:00

129 lines
3.5 KiB
Batchfile

@echo off
setlocal
:: 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
:: "msvc" Compile with MSVC instead of Clang
for %%a in (%*) do set "%%a=1"
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 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
)
if "%msvc%" == "1" (
where /q cl.exe || (
echo ERROR: "cl.exe" not found.
exit /b 1
)
) else (
where /q clang.exe || (
echo ERROR: "clang.exe" not found.
exit /b 1
)
where /q lld-link || (
echo ERROR: "lld-link.exe" not found.
exit /b 1
)
)
where /q ninja.exe || (
echo ERROR: "ninja.exe" not found.
exit /b 1
)
where /q cmake || (
echo ERROR: "cmake.exe" not found.
exit /b 1
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Choose configuration from args
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 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 -DMSVC=0
set cmake_options_enabled=
echo ========================================
if "%msvc%" == "1" (
echo [Msvc]
set cmake_options_enabled=%cmake_options_enabled% -DMSVC=1
) else (
echo [Clang]
)
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
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if not exist "build" mkdir build
if "%msvc%" == "1" (
cmake -H. -G Ninja -B build %cmake_options_zero% %cmake_options_enabled%^
-DCMAKE_C_COMPILER:PATH="cl.exe"^
-DCMAKE_CXX_COMPILER:PATH="cl.exe"^
-DPLATFORM_WIN32=1
) else (
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"^
-DCMAKE_CXX_COMPILER_ID="Clang"^
-DCMAKE_SYSTEM_NAME="Generic"^
-DPLATFORM_WIN32=1
)
if NOT %errorlevel% == 0 (
echo.
echo ERROR: Configuration failed
exit /b 1
)
cmake --build build
:: cmake --build build -v
if NOT %errorlevel% == 0 (
echo.
echo ERROR: Build failed
exit /b 1
)