Created
October 25, 2023 10:16
-
-
Save pietromoro/40d962d93d5c99b0c365fa1a4b49e6dd to your computer and use it in GitHub Desktop.
Simple build script for a c/cpp msvc project without going deep in msvisual studio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal EnableDelayedExpansion | |
| REM TODO: Make this better this one, detect vcvarsall for 2019/2022 versions and run accordingly | |
| if not defined DevEnvDir ( | |
| call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" | |
| ) | |
| set BUILD_DIR=build | |
| set SOURCE_DIR=src | |
| set PROJECT_NAME=MyProject | |
| rmdir /S /Q %BUILD_DIR% | |
| mkdir %BUILD_DIR% | |
| set INCLUDES=/I ..\lib\ /I ..\src\ | |
| set FLAGS=/MD /utf-8 /Od /Zo /Zi /FC %INCLUDES% | |
| pushd %SOURCE_DIR% | |
| set FILENAMES= | |
| echo Compiling the following sources: | |
| for /R %%f in (*.c) do ( | |
| echo %%f | |
| if "%%~xf"==".c" set FILENAMES=!FILENAMES! "%%f" | |
| ) | |
| popd | |
| pushd %BUILD_DIR% | |
| echo[ | |
| echo Compiling libraries... | |
| cl /nologo /c %FLAGS% /Tp ..\lib\mysrc.cpp | |
| if %errorlevel% neq 0 (goto fail) | |
| echo[ | |
| echo Compiling source code... | |
| cl /nologo /c %FLAGS% /Tc %FILENAMES% | |
| if %errorlevel% neq 0 (goto fail) | |
| echo Compiling resources... | |
| rc /nologo /fo "%PROJECT_NAME%.res" "..\res\%PROJECT_NAME%.rc" | |
| if %errorlevel% neq 0 (goto fail) | |
| echo Linking... | |
| link /nologo *.obj %PROJECT_NAME%.res /SUBSYSTEM:WINDOWS /OUT:"%PROJECT_NAME%.exe" | |
| if %errorlevel% neq 0 (goto fail) | |
| echo Manifesting... | |
| mt /nologo -manifest "..\res\%PROJECT_NAME%.manifest" -outputresource:"%PROJECT_NAME%.exe" | |
| if %errorlevel% neq 0 (goto fail) | |
| :success | |
| popd | |
| echo[ | |
| echo Compiled successfully! | |
| exit /b 0 | |
| :fail | |
| popd | |
| echo[ | |
| echo Compilation failed... | |
| exit /b 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment