diff --git a/premake5.lua b/premake5.lua index 19af224f..7733f1fb 100644 --- a/premake5.lua +++ b/premake5.lua @@ -5,6 +5,38 @@ newoption { 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" location ("./build") configurations { "Normal" } @@ -13,6 +45,7 @@ solution "iw4x" kind "SharedLib" language "C++" files { "./src/**.hpp", "./src/**.cpp" } + includedirs { "%{prj.location}" } toolset "msc" -- only support Microsoft's compiler configuration "Normal" @@ -25,6 +58,11 @@ solution "iw4x" ["Docs/*"] = {"**.txt","**.md"} } + prebuildcommands { + "cd %{_MAIN_SCRIPT_DIR}", + "premake5 generate-buildinfo" + } + if _OPTIONS["copy-to"] then saneCopyToPath = string.gsub(_OPTIONS["copy-to"] .. "\\", "\\\\", "\\") postbuildcommands { diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index b789173f..fe492110 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -19,6 +19,8 @@ #include #include +#include + #include "Utils\Utils.hpp" #include "Utils\WebIO.hpp" #include "Utils\Hooking.hpp"