Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal
- if "%~1"=="" (
- echo No arguments provided. Use:
- echo build.bat --release --run : To build and run in release mode
- echo build.bat --debug --run : To build and run in debug mode
- echo build.bat --release : To only build in release mode
- echo build.bat --debug : To only build in debug mode
- pause
- exit /b 1
- )
- if "%~1"=="--release" (
- if "%~2"=="--run" (
- echo Setting up MSVC environment...
- call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
- if errorlevel 1 (
- echo Failed to set up MSVC environment. Exiting...
- pause
- exit /b 1
- )
- )
- )
- if "%~1"=="--debug" (
- if "%~2"=="--run" (
- echo Setting up MSVC environment...
- call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
- if errorlevel 1 (
- echo Failed to set up MSVC environment. Exiting...
- pause
- exit /b 1
- )
- )
- )
- set INCLUDE_PATH=.\vendor\glad\include\glad;.\vendor\glfw\include\GLFW
- set LIBRARY_PATH=.\vendor\glfw\lib
- set COMPILER="C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\cl.exe"
- set BUILD_DIR=.\build
- set SRC_DIR=.\src
- if not exist "%BUILD_DIR%" (
- echo Creating build directory...
- mkdir "%BUILD_DIR%"
- )
- echo Checking for glfw3.dll at "%CD%\vendor\glfw\lib\glfw3.dll"
- if not exist "%CD%\vendor\glfw\lib\glfw3.dll" (
- echo glfw3.dll not found at expected path. Exiting...
- pause
- exit /b 1
- )
- echo Copying glfw3.dll to build directory...
- copy /y ".\vendor\glfw\lib\glfw3.dll" "%BUILD_DIR%\glfw3.dll"
- if "%~1"=="--release" (
- echo Building in RELEASE mode...
- echo %COMPILER% /EHsc /O2 /std:c++17 ^
- /I"%INCLUDE_PATH%" ^
- /link /LIBPATH:"%LIBRARY_PATH%" ^
- /out:"%BUILD_DIR%\test.exe" ^
- "%SRC_DIR%\main.cpp" ^
- "%SRC_DIR%\glad.c" ^
- glfw3.lib gdi32.lib
- %COMPILER% /EHsc /O2 /std:c++17 ^
- /I"%INCLUDE_PATH%" ^
- /link /LIBPATH:"%LIBRARY_PATH%" ^
- /out:"%BUILD_DIR%\test.exe" ^
- "%SRC_DIR%\main.cpp" ^
- "%SRC_DIR%\glad.c" ^
- glfw3.lib gdi32.lib
- if not exist "%BUILD_DIR%\test.exe" (
- echo Compilation failed. Exiting...
- pause
- exit /b 1
- )
- echo Release build completed successfully.
- )
- if "%~1"=="--debug" (
- echo Building in DEBUG mode...
- echo %COMPILER% /EHsc /Zi /Od /std:c++17 ^
- /I"%INCLUDE_PATH%" ^
- /link /LIBPATH:"%LIBRARY_PATH%" ^
- /out:"%BUILD_DIR%\test.exe" ^
- "%SRC_DIR%\main.cpp" ^
- "%SRC_DIR%\glad.c" ^
- glfw3.lib gdi32.lib
- %COMPILER% /EHsc /Zi /Od /std:c++17 ^
- /I"%INCLUDE_PATH%" ^
- /link /LIBPATH:"%LIBRARY_PATH%" ^
- /out:"%BUILD_DIR%\test.exe" ^
- "%SRC_DIR%\main.cpp" ^
- "%SRC_DIR%\glad.c" ^
- glfw3.lib gdi32.lib
- if not exist "%BUILD_DIR%\test.exe" (
- echo Compilation failed. Exiting...
- pause
- exit /b 1
- )
- echo Debug build completed successfully.
- )
- if "%~2"=="--run" (
- echo Running test.exe...
- start "" "%BUILD_DIR%\test.exe"
- )
- exit /b 0
- echo Invalid argument: %~1
- echo Use:
- echo build.bat --release --run : To build and run in release mode
- echo build.bat --debug --run : To build and run in debug mode
- echo build.bat --release : To only build in release mode
- echo build.bat --debug : To only build in debug mode
- pause
- exit /b 1
- endlocal
Add Comment
Please, Sign In to add comment