Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@

Temp/*

# Auto-generated version file
CommonLib/RealSimVersion.h

CommonLib/libevent/build/*
CommonLib/libevent/out/build/*
CommonLib/yaml-cpp/build/*
Expand Down
11 changes: 0 additions & 11 deletions CommonLib/RealSimVersion.h

This file was deleted.

16 changes: 16 additions & 0 deletions CommonLib/RealSimVersion.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef REALSIM_VERSION_H
#define REALSIM_VERSION_H

// Auto-generated from git tags - DO NOT EDIT MANUALLY
// Generated at: @GENERATION_TIME@

#define REALSIM_VERSION_MAJOR @VERSION_MAJOR@
#define REALSIM_VERSION_MINOR @VERSION_MINOR@
#define REALSIM_VERSION_PATCH @VERSION_PATCH@

#define REALSIM_VERSION_NUMBER 0x@VERSION_HEX@
#define REALSIM_VERSION_STRING "@VERSION_STRING@"
#define REALSIM_GIT_COMMIT "@GIT_COMMIT@"
#define REALSIM_GIT_TAG "@GIT_TAG@"

#endif
16 changes: 16 additions & 0 deletions TrafficLayer/TrafficLayer/TrafficLayer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
<SourcePath>$(VC_SourcePath)</SourcePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -File "$(SolutionDir)..\..\scripts\generate_version.ps1"</Command>
<Message>Generating version header from git tags...</Message>
</PreBuildEvent>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
Expand All @@ -131,6 +135,10 @@
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -File "$(SolutionDir)..\..\scripts\generate_version.ps1"</Command>
<Message>Generating version header from git tags...</Message>
</PreBuildEvent>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
Expand All @@ -151,6 +159,10 @@
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -File "$(SolutionDir)..\..\scripts\generate_version.ps1"</Command>
<Message>Generating version header from git tags...</Message>
</PreBuildEvent>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
Expand All @@ -168,6 +180,10 @@
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -File "$(SolutionDir)..\..\scripts\generate_version.ps1"</Command>
<Message>Generating version header from git tags...</Message>
</PreBuildEvent>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
Expand Down
53 changes: 53 additions & 0 deletions scripts/generate_version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Auto-generate RealSimVersion.h from git tags
# This script is called by Visual Studio Pre-Build Event

$ErrorActionPreference = "Stop"

$RepoRoot = Split-Path -Parent $PSScriptRoot
$TemplateFile = Join-Path $RepoRoot "CommonLib\RealSimVersion.h.in"
$OutputFile = Join-Path $RepoRoot "CommonLib\RealSimVersion.h"

# Get git tag information
Push-Location $RepoRoot
try {
# Get latest tag (e.g., v0.7.0)
$GitTag = git describe --tags --abbrev=0

# Parse version from tag (v0.7.0 → 0, 7, 0)
if ($GitTag -match '^v?(\d+)\.(\d+)\.(\d+)') {
$Major = [int]$Matches[1]
$Minor = [int]$Matches[2]
$Patch = [int]$Matches[3]
} else {
throw "Invalid tag format: $GitTag (expected vX.Y.Z)"
}

# Get current commit hash (short)
$GitCommit = git rev-parse --short HEAD

# Build version string and hex
$VersionString = "$Major.$Minor.$Patch"
$VersionHex = "{0:X2}{1:X2}{2:X2}" -f $Major, $Minor, $Patch
$GenTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"

# Read template and replace placeholders
$Template = Get-Content $TemplateFile -Raw
$Output = $Template `
-replace '@VERSION_MAJOR@', $Major `
-replace '@VERSION_MINOR@', $Minor `
-replace '@VERSION_PATCH@', $Patch `
-replace '@VERSION_STRING@', $VersionString `
-replace '@VERSION_HEX@', $VersionHex `
-replace '@GIT_COMMIT@', $GitCommit `
-replace '@GIT_TAG@', $GitTag `
-replace '@GENERATION_TIME@', $GenTime

Set-Content -Path $OutputFile -Value $Output -NoNewline
Write-Host "Generated $OutputFile from tag: $GitTag (commit: $GitCommit)" -ForegroundColor Green

} catch {
Write-Error "Failed to generate version header: $_"
exit 1
} finally {
Pop-Location
}