Add version.hpp generation. Will trigger pre-build.

This commit is contained in:
/dev/urandom 2015-12-31 03:59:33 +01:00
parent 3fd7c1c66e
commit e6d38e68fb
No known key found for this signature in database
GPG Key ID: 41322B973E0F295E
2 changed files with 40 additions and 0 deletions

View File

@ -5,6 +5,38 @@ newoption {
value = "PATH" value = "PATH"
} }
newaction {
trigger = "generate-buildinfo",
description = "Sets up build information file like version.h.",
onWorkspace = function(wks)
-- get revision number via git
local proc = assert(io.popen("git rev-list --count HEAD", "r"))
local revNumber = assert(proc:read('*a')):gsub("%s+", "")
proc:close()
-- get old version number from version.hpp if any
local oldRevNumber = -1
local oldVersionHeader = io.open(wks.location .. "/version.hpp", "r")
if oldVersionHeader ~=nil then
local oldVersionHeaderContent = assert(oldVersionHeader:read('*a'))
oldRevNumber = string.match(oldVersionHeaderContent, "#define REVISION (%d+)")
end
-- generate version.hpp with a revision number if not equal
if oldRevNumber ~= revNumber then
print ("Update " .. oldRevNumber .. " -> " .. revNumber)
local versionHeader = assert(io.open(wks.location .. "/version.hpp", "w"))
versionHeader:write("/*\n")
versionHeader:write(" * Automatically generated by premake5.\n")
versionHeader:write(" * Do not touch, you fucking moron!\n")
versionHeader:write(" */\n")
versionHeader:write("\n")
versionHeader:write("#define REVISION " .. revNumber .. "\n")
versionHeader:close()
end
end
}
solution "iw4x" solution "iw4x"
location ("./build") location ("./build")
configurations { "Normal" } configurations { "Normal" }
@ -13,6 +45,7 @@ solution "iw4x"
kind "SharedLib" kind "SharedLib"
language "C++" language "C++"
files { "./src/**.hpp", "./src/**.cpp" } files { "./src/**.hpp", "./src/**.cpp" }
includedirs { "%{prj.location}" }
toolset "msc" -- only support Microsoft's compiler toolset "msc" -- only support Microsoft's compiler
configuration "Normal" configuration "Normal"
@ -25,6 +58,11 @@ solution "iw4x"
["Docs/*"] = {"**.txt","**.md"} ["Docs/*"] = {"**.txt","**.md"}
} }
prebuildcommands {
"cd %{_MAIN_SCRIPT_DIR}",
"premake5 generate-buildinfo"
}
if _OPTIONS["copy-to"] then if _OPTIONS["copy-to"] then
saneCopyToPath = string.gsub(_OPTIONS["copy-to"] .. "\\", "\\\\", "\\") saneCopyToPath = string.gsub(_OPTIONS["copy-to"] .. "\\", "\\\\", "\\")
postbuildcommands { postbuildcommands {

View File

@ -19,6 +19,8 @@
#include <algorithm> #include <algorithm>
#include <regex> #include <regex>
#include <version.hpp>
#include "Utils\Utils.hpp" #include "Utils\Utils.hpp"
#include "Utils\WebIO.hpp" #include "Utils\WebIO.hpp"
#include "Utils\Hooking.hpp" #include "Utils\Hooking.hpp"