build_win32.bat

C++ software renderer

build_win32.bat

1.97 KB
echo off
setlocal enabledelayedexpansion

set ROOT=%~dp0
set SRC_FILES=%ROOT%src\*.cpp
set STB_FILES=%ROOT%external\stb
set SDL_FILES=%ROOT%external\SDL\include


:: =====================
:: ==== Parse flags ====
:: =====================
for %%A in (%*) do (
    if /I "%%~A"=="-r" set "BUILD=Release"
)


:: =====================
:: === MSVC Nonsense ===
:: =====================
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath`) do (
    set "VS_PATH=%%i"
)
if defined VS_PATH (
    call "%VS_PATH%\VC\Auxiliary\Build\vcvarsall.bat" x64
) else (
    echo ERROR: Visual Studio installation not found.
    exit /b 1
)


:: ===================
:: === Directories ===
:: ===================
if not exist build mkdir build
if not exist external mkdir external


:: ====================
:: === Dependencies ===
:: ====================

:: https://github.com/libsdl-org/SDL/releases/download/release-2.32.10/SDL2-devel-2.32.10-VC.zip
if not exist external\SDL (
    echo ERROR: %ROOT%external\SDL\ missing.
    exit /b 1
)

:: =========================
:: === Compilation Flags ===
:: =========================

:: /permissive- not really needed with "/std:c++20?"
:: /arch:AVX2 /arch:AVX512
:: /fp:fast /
:: comp: /GL, link: /LTCG
if "%BUILD%"=="Release" (
    set CFLAGS=/std:c++20 /O2 /Oi /GR- /EHsc /permissive- /Fe:renderer.exe
    set LFLAGS=/SUBSYSTEM:WINDOWS
) else (
    set CFLAGS=/std:c++20 /W4 /permissive- /Od /ZI /EHsc /Fe:renderer.exe
    set LFLAGS=/SUBSYSTEM:CONSOLE /DEBUG
)


:: ===================
:: === Compilation ===
:: ===================
pushd build
cl /D_CRT_SECURE_NO_WARNINGS ^
  %CFLAGS% ^
  /I %STB_FILES% ^
  /I %SDL_FILES% %SRC_FILES% ^
  /link %LFLAGS% ^
  shell32.lib ^
  %ROOT%external\SDL\lib\x64\SDL2main.lib ^
  %ROOT%external\SDL\lib\x64\SDL2.lib
popd


:: ========================
:: === Post compilation ===
:: ========================
copy /Y %ROOT%external\SDL\lib\x64\SDL2.dll build\ >nul