Guest User

build.bat

a guest
Jan 2nd, 2025
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.65 KB | Source Code | 0 0
  1. @echo off
  2. setlocal
  3.  
  4. if "%~1"=="" (
  5.     echo No arguments provided. Use:
  6.     echo   build.bat --release --run : To build and run in release mode
  7.     echo   build.bat --debug --run   : To build and run in debug mode
  8.     echo   build.bat --release      : To only build in release mode
  9.     echo   build.bat --debug        : To only build in debug mode
  10.     pause
  11.     exit /b 1
  12. )
  13.  
  14. if "%~1"=="--release" (
  15.     if "%~2"=="--run" (
  16.         echo Setting up MSVC environment...
  17.         call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
  18.         if errorlevel 1 (
  19.             echo Failed to set up MSVC environment. Exiting...
  20.             pause
  21.             exit /b 1
  22.         )
  23.     )
  24. )
  25.  
  26. if "%~1"=="--debug" (
  27.     if "%~2"=="--run" (
  28.         echo Setting up MSVC environment...
  29.         call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
  30.         if errorlevel 1 (
  31.             echo Failed to set up MSVC environment. Exiting...
  32.             pause
  33.             exit /b 1
  34.         )
  35.     )
  36. )
  37.  
  38. set INCLUDE_PATH=.\vendor\glad\include\glad;.\vendor\glfw\include\GLFW
  39. set LIBRARY_PATH=.\vendor\glfw\lib
  40. set COMPILER="C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\cl.exe"
  41. set BUILD_DIR=.\build
  42. set SRC_DIR=.\src
  43.  
  44. if not exist "%BUILD_DIR%" (
  45.     echo Creating build directory...
  46.     mkdir "%BUILD_DIR%"
  47. )
  48.  
  49. echo Checking for glfw3.dll at "%CD%\vendor\glfw\lib\glfw3.dll"
  50. if not exist "%CD%\vendor\glfw\lib\glfw3.dll" (
  51.     echo glfw3.dll not found at expected path. Exiting...
  52.     pause
  53.     exit /b 1
  54. )
  55.  
  56. echo Copying glfw3.dll to build directory...
  57. copy /y ".\vendor\glfw\lib\glfw3.dll" "%BUILD_DIR%\glfw3.dll"
  58.  
  59. if "%~1"=="--release" (
  60.     echo Building in RELEASE mode...
  61.  
  62.     echo %COMPILER% /EHsc /O2 /std:c++17 ^
  63.         /I"%INCLUDE_PATH%" ^
  64.         /link /LIBPATH:"%LIBRARY_PATH%" ^
  65.         /out:"%BUILD_DIR%\test.exe" ^
  66.         "%SRC_DIR%\main.cpp" ^
  67.         "%SRC_DIR%\glad.c" ^
  68.         glfw3.lib gdi32.lib
  69.  
  70.     %COMPILER% /EHsc /O2 /std:c++17 ^
  71.         /I"%INCLUDE_PATH%" ^
  72.         /link /LIBPATH:"%LIBRARY_PATH%" ^
  73.         /out:"%BUILD_DIR%\test.exe" ^
  74.         "%SRC_DIR%\main.cpp" ^
  75.         "%SRC_DIR%\glad.c" ^
  76.         glfw3.lib gdi32.lib
  77.  
  78.     if not exist "%BUILD_DIR%\test.exe" (
  79.         echo Compilation failed. Exiting...
  80.         pause
  81.         exit /b 1
  82.     )
  83.     echo Release build completed successfully.
  84. )
  85.  
  86. if "%~1"=="--debug" (
  87.     echo Building in DEBUG mode...
  88.  
  89.     echo %COMPILER% /EHsc /Zi /Od /std:c++17 ^
  90.         /I"%INCLUDE_PATH%" ^
  91.         /link /LIBPATH:"%LIBRARY_PATH%" ^
  92.         /out:"%BUILD_DIR%\test.exe" ^
  93.         "%SRC_DIR%\main.cpp" ^
  94.         "%SRC_DIR%\glad.c" ^
  95.         glfw3.lib gdi32.lib
  96.  
  97.     %COMPILER% /EHsc /Zi /Od /std:c++17 ^
  98.         /I"%INCLUDE_PATH%" ^
  99.         /link /LIBPATH:"%LIBRARY_PATH%" ^
  100.         /out:"%BUILD_DIR%\test.exe" ^
  101.         "%SRC_DIR%\main.cpp" ^
  102.         "%SRC_DIR%\glad.c" ^
  103.         glfw3.lib gdi32.lib
  104.  
  105.     if not exist "%BUILD_DIR%\test.exe" (
  106.         echo Compilation failed. Exiting...
  107.         pause
  108.         exit /b 1
  109.     )
  110.     echo Debug build completed successfully.
  111. )
  112.  
  113. if "%~2"=="--run" (
  114.     echo Running test.exe...
  115.     start "" "%BUILD_DIR%\test.exe"
  116. )
  117.  
  118. exit /b 0
  119.  
  120. echo Invalid argument: %~1
  121. echo Use:
  122. echo   build.bat --release --run : To build and run in release mode
  123. echo   build.bat --debug --run   : To build and run in debug mode
  124. echo   build.bat --release      : To only build in release mode
  125. echo   build.bat --debug        : To only build in debug mode
  126. pause
  127. exit /b 1
  128.  
  129. endlocal
  130.  
Add Comment
Please, Sign In to add comment