Add version system

This commit is contained in:
Grayson Riffe 2023-08-30 08:05:36 -05:00
parent 4ae052ee18
commit 0f83170c43
4 changed files with 60 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.vs/ .vs/
build/ build/
version.h

48
WinChat/PreBuild.bat Normal file
View File

@ -0,0 +1,48 @@
@echo off
echo [Pre Build] Startup
::Set Version
echo [Pre Build] Setting version...
::First make sure git is in the path
where git >nul 2>&1
if %errorlevel% neq 0 goto noGit
goto yesGit
:noGit
echo [Pre Build] Error: git not found on PATH!
exit 1
::We have git on the command line, so set the version string
:yesGit
git describe HEAD > temp1
git branch --show-current > temp2
set /p commit= < temp1
set /p branch= < temp2
del temp1
del temp2
::If the current branch is stable, don't include it in the version string
if "%branch%" == "stable" goto noBranch
set version=%commit%+%branch%
goto testOutput
:noBranch
set version=%commit%
::Don't touch the version file if it's already up to date
:testOutput
set /p oldVersion= < src\version.h
if "%oldVersion%" == "#define APPVERSION "%version%"" goto sameVersion
echo #define APPVERSION "%version%"> src\version.h
goto continue
:sameVersion
echo [Pre Build] Same version
:continue
echo [Pre Build] Exit
exit

View File

@ -64,6 +64,9 @@
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
<PreBuildEvent>
<Command>PreBuild.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile> <ClCompile>
@ -82,6 +85,9 @@
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
<PreBuildEvent>
<Command>PreBuild.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\main.cpp" /> <ClCompile Include="src\main.cpp" />

View File

@ -1,7 +1,11 @@
#include <iostream> #include <iostream>
#include "version.h"
#define APPNAME "WinChat"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
std::printf("WinChat\n"); std::printf(APPNAME " " APPVERSION "\n");
std::cin.get(); std::cin.get();
return EXIT_SUCCESS; return EXIT_SUCCESS;