1echo off
2setlocal enabledelayedexpansion
3
4set ROOT=%~dp0
5::set SRC_FILES=src\renderer.cpp
6set SRC_FILES=%ROOT%src\*.cpp
7
8
9:: =====================
10:: ==== Parse flags ====
11:: =====================
12for %%A in (%*) do (
13 if /I "%%~A"=="-r" set "BUILD=Release"
14)
15
16
17:: =====================
18:: === MSVC Nonsense ===
19:: =====================
20for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath`) do (
21 set "VS_PATH=%%i"
22)
23if defined VS_PATH (
24 call "%VS_PATH%\VC\Auxiliary\Build\vcvarsall.bat" x64
25) else (
26 echo ERROR: Visual Studio installation not found.
27 exit /b 1
28)
29
30
31:: ===================
32:: === Directories ===
33:: ===================
34if not exist build mkdir build
35if not exist external mkdir external
36
37
38:: ====================
39:: === Dependencies ===
40:: ====================
41
42:: https://github.com/libsdl-org/SDL/releases/download/release-2.32.10/SDL2-devel-2.32.10-VC.zip
43if not exist external\SDL (
44 echo ERROR: %ROOT%external\SDL\ missing.
45 exit /b 1
46)
47
48:: =========================
49:: === Compilation Flags ===
50:: =========================
51
52:: /permissive- not really needed with "/std:c++20?"
53:: /arch:AVX2 /arch:AVX512
54:: /fp:fast /
55:: comp: /GL, link: /LTCG
56if "%BUILD%"=="Release" (
57 set CFLAGS=/std:c++20 /O2 /Oi /GR- /EHsc /permissive- /Fe:renderer.exe
58 set LFLAGS=/SUBSYSTEM:WINDOWS
59) else (
60 set CFLAGS=/std:c++20 /W4 /permissive- /Od /ZI /EHsc /Fe:renderer.exe
61 set LFLAGS=/SUBSYSTEM:CONSOLE /DEBUG
62)
63
64
65:: ===================
66:: === Compilation ===
67:: ===================
68pushd build
69cl %CFLAGS% ^
70 /I %ROOT%external\SDL\include %SRC_FILES% ^
71 /link %LFLAGS% ^
72 shell32.lib ^
73 %ROOT%external\SDL\lib\x64\SDL2main.lib ^
74 %ROOT%external\SDL\lib\x64\SDL2.lib
75popd
76
77
78:: ========================
79:: === Post compilation ===
80:: ========================
81copy /Y %ROOT%external\SDL\lib\x64\SDL2.dll build\ >nul