chore: write header with git version

This commit is contained in:
Jan 2024-01-23 21:53:01 +01:00
parent 50d4282b54
commit 7919683748
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
2 changed files with 44 additions and 0 deletions

View File

@ -3,6 +3,7 @@ include "tools/scripts/including.lua"
include "tools/scripts/linking.lua"
include "tools/scripts/options.lua"
include "tools/scripts/platform.lua"
include "tools/scripts/version.lua"
-- ==================
-- Workspace
@ -63,6 +64,13 @@ workspace "OpenAssetTools"
"__STDC_WANT_LIB_EXT1__=1",
"_CRT_SECURE_NO_WARNINGS"
}
-- Write the current version to a header
-- This is better than adding it as macro here since changing a global macro would cause a full rebuild
WriteVersionHeader()
includedirs {
GetVersionHeaderFolder()
}
filter "options:debug-structureddatadef"
defines { "STRUCTUREDDATADEF_DEBUG" }

36
tools/scripts/version.lua Normal file
View File

@ -0,0 +1,36 @@
local BuildSubFolderFolder = "premake"
local HeaderFileName = "GitVersion.h"
function GetGitVersion()
result, errorCode = os.outputof("git describe --tags")
if errorCode == 0 then
return result
end
return "Unknown"
end
function GetVersionHeaderFolder()
return path.join(BuildFolder(), BuildSubFolderFolder)
end
function WriteVersionHeader()
local folder = GetVersionHeaderFolder()
local file = path.join(folder, HeaderFileName)
local content = string.format([[
#pragma once
#define GIT_VERSION "%s"
]], GetGitVersion())
if os.isdir(folder) ~= True then
os.mkdir(folder)
end
local ok, err = os.writefile_ifnotequal(content, file)
if ok == -1 then
error("Could not create version file: " .. err)
end
end