2017-01-20 11:02:25 -05:00
|
|
|
gitVersioningCommand = "git describe --tags --dirty --always"
|
2019-10-02 05:30:01 -04:00
|
|
|
gitCurrentBranchCommand = "git symbolic-ref -q --short HEAD"
|
2017-01-20 11:02:25 -05:00
|
|
|
|
|
|
|
-- Quote the given string input as a C string
|
|
|
|
function cstrquote(value)
|
2022-04-07 05:41:20 -04:00
|
|
|
if value == nil then
|
|
|
|
return "\"\""
|
|
|
|
end
|
2017-01-20 11:02:25 -05:00
|
|
|
result = value:gsub("\\", "\\\\")
|
|
|
|
result = result:gsub("\"", "\\\"")
|
|
|
|
result = result:gsub("\n", "\\n")
|
|
|
|
result = result:gsub("\t", "\\t")
|
|
|
|
result = result:gsub("\r", "\\r")
|
|
|
|
result = result:gsub("\a", "\\a")
|
|
|
|
result = result:gsub("\b", "\\b")
|
|
|
|
result = "\"" .. result .. "\""
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Converts tags in "vX.X.X" format to an array of numbers {X,X,X}.
|
|
|
|
-- In the case where the format does not work fall back to old {4,2,REVISION}.
|
|
|
|
function vertonumarr(value, vernumber)
|
|
|
|
vernum = {}
|
|
|
|
for num in string.gmatch(value, "%d+") do
|
|
|
|
table.insert(vernum, tonumber(num))
|
|
|
|
end
|
|
|
|
if #vernum < 3 then
|
|
|
|
return {4,2,tonumber(vernumber)}
|
|
|
|
end
|
|
|
|
return vernum
|
|
|
|
end
|
|
|
|
|
2022-04-07 05:41:20 -04:00
|
|
|
dependencies = {
|
|
|
|
basePath = "./deps"
|
|
|
|
}
|
|
|
|
|
|
|
|
function dependencies.load()
|
|
|
|
dir = path.join(dependencies.basePath, "premake/*.lua")
|
|
|
|
deps = os.matchfiles(dir)
|
|
|
|
|
|
|
|
for i, dep in pairs(deps) do
|
|
|
|
dep = dep:gsub(".lua", "")
|
|
|
|
require(dep)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function dependencies.imports()
|
|
|
|
for i, proj in pairs(dependencies) do
|
|
|
|
if type(i) == 'number' then
|
|
|
|
proj.import()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function dependencies.projects()
|
|
|
|
for i, proj in pairs(dependencies) do
|
|
|
|
if type(i) == 'number' then
|
|
|
|
proj.project()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-20 11:02:25 -05:00
|
|
|
newoption {
|
|
|
|
trigger = "copy-to",
|
|
|
|
description = "Optional, copy the DLL to a custom folder after build, define the path here if wanted.",
|
|
|
|
value = "PATH"
|
|
|
|
}
|
|
|
|
|
|
|
|
newoption {
|
|
|
|
trigger = "copy-pdb",
|
|
|
|
description = "Copy debug information for binaries as well to the path given via --copy-to."
|
|
|
|
}
|
|
|
|
|
|
|
|
newoption {
|
|
|
|
trigger = "force-unit-tests",
|
|
|
|
description = "Always compile unit tests."
|
|
|
|
}
|
|
|
|
|
|
|
|
newoption {
|
|
|
|
trigger = "force-exception-handler",
|
|
|
|
description = "Install custom unhandled exception handler even for Debug builds."
|
|
|
|
}
|
|
|
|
|
|
|
|
newoption {
|
2022-05-31 09:56:54 -04:00
|
|
|
trigger = "disable-binary-check",
|
|
|
|
description = "Do not perform integrity checks on the exe."
|
2017-01-20 11:02:25 -05:00
|
|
|
}
|
|
|
|
|
2021-07-16 10:36:16 -04:00
|
|
|
newoption {
|
2021-07-16 13:08:50 -04:00
|
|
|
trigger = "iw4x-zones",
|
|
|
|
description = "Zonebuilder generates iw4x zones that cannot be loaded without IW4x specific patches."
|
2021-07-16 10:36:16 -04:00
|
|
|
}
|
|
|
|
|
2017-01-20 11:02:25 -05:00
|
|
|
newaction {
|
|
|
|
trigger = "version",
|
|
|
|
description = "Returns the version string for the current commit of the source code.",
|
|
|
|
onWorkspace = function(wks)
|
|
|
|
-- get current version via git
|
|
|
|
local proc = assert(io.popen(gitVersioningCommand, "r"))
|
|
|
|
local gitDescribeOutput = assert(proc:read('*a')):gsub("%s+", "")
|
|
|
|
proc:close()
|
2019-10-02 05:30:01 -04:00
|
|
|
local version = gitDescribeOutput
|
|
|
|
|
|
|
|
proc = assert(io.popen(gitCurrentBranchCommand, "r"))
|
|
|
|
local gitCurrentBranchOutput = assert(proc:read('*a')):gsub("%s+", "")
|
|
|
|
local gitCurrentBranchSuccess = proc:close()
|
|
|
|
if gitCurrentBranchSuccess then
|
|
|
|
-- We got a branch name, check if it is a feature branch
|
|
|
|
if gitCurrentBranchOutput ~= "develop" and gitCurrentBranchOutput ~= "master" then
|
|
|
|
version = version .. "-" .. gitCurrentBranchOutput
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print(version)
|
2017-01-20 11:02:25 -05:00
|
|
|
os.exit(0)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
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+", "")
|
|
|
|
|
|
|
|
-- get current version via git
|
|
|
|
local proc = assert(io.popen(gitVersioningCommand, "r"))
|
|
|
|
local gitDescribeOutput = assert(proc:read('*a')):gsub("%s+", "")
|
|
|
|
proc:close()
|
|
|
|
|
|
|
|
-- get whether this is a clean revision (no uncommitted changes)
|
|
|
|
proc = assert(io.popen("git status --porcelain", "r"))
|
|
|
|
local revDirty = (assert(proc:read('*a')) ~= "")
|
|
|
|
if revDirty then revDirty = 1 else revDirty = 0 end
|
|
|
|
proc:close()
|
|
|
|
|
|
|
|
-- get current tag name
|
|
|
|
proc = assert(io.popen("git describe --tags --abbrev=0"))
|
|
|
|
local tagName = assert(proc:read('*l'))
|
|
|
|
|
|
|
|
-- get old version number from version.hpp if any
|
|
|
|
local oldVersion = "(none)"
|
|
|
|
local oldVersionHeader = io.open(wks.location .. "/src/version.h", "r")
|
|
|
|
if oldVersionHeader ~= nil then
|
|
|
|
local oldVersionHeaderContent = assert(oldVersionHeader:read('*l'))
|
|
|
|
while oldVersionHeaderContent do
|
|
|
|
m = string.match(oldVersionHeaderContent, "#define GIT_DESCRIBE (.+)%s*$")
|
|
|
|
if m ~= nil then
|
|
|
|
oldVersion = m
|
|
|
|
end
|
|
|
|
|
|
|
|
oldVersionHeaderContent = oldVersionHeader:read('*l')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- generate version.hpp with a revision number if not equal
|
|
|
|
gitDescribeOutputQuoted = cstrquote(gitDescribeOutput)
|
|
|
|
if oldVersion ~= gitDescribeOutputQuoted then
|
|
|
|
print ("Update " .. oldVersion .. " -> " .. gitDescribeOutputQuoted)
|
|
|
|
local versionHeader = assert(io.open(wks.location .. "/src/version.h", "w"))
|
|
|
|
versionHeader:write("/*\n")
|
|
|
|
versionHeader:write(" * Automatically generated by premake5.\n")
|
2022-04-15 12:17:20 -04:00
|
|
|
versionHeader:write(" * Do not touch!\n")
|
2017-01-20 11:02:25 -05:00
|
|
|
versionHeader:write(" */\n")
|
|
|
|
versionHeader:write("\n")
|
|
|
|
versionHeader:write("#define GIT_DESCRIBE " .. gitDescribeOutputQuoted .. "\n")
|
|
|
|
versionHeader:write("#define GIT_DIRTY " .. revDirty .. "\n")
|
|
|
|
versionHeader:write("#define GIT_TAG " .. cstrquote(tagName) .. "\n")
|
|
|
|
versionHeader:write("\n")
|
|
|
|
versionHeader:write("// Legacy definitions (needed for update check)\n")
|
|
|
|
versionHeader:write("#define REVISION " .. revNumber .. "\n")
|
|
|
|
versionHeader:write("\n")
|
|
|
|
versionHeader:write("// Version transformed for RC files\n")
|
|
|
|
versionHeader:write("#define VERSION_RC " .. table.concat(vertonumarr(tagName, revNumber), ",") .. "\n")
|
|
|
|
versionHeader:write("\n")
|
|
|
|
versionHeader:write("// Alias definitions\n")
|
|
|
|
versionHeader:write("#define VERSION GIT_DESCRIBE\n")
|
|
|
|
versionHeader:write("#define SHORTVERSION " .. cstrquote(table.concat(vertonumarr(tagName, revNumber), ".")) .. "\n")
|
|
|
|
versionHeader:close()
|
|
|
|
local versionHeader = assert(io.open(wks.location .. "/src/version.hpp", "w"))
|
|
|
|
versionHeader:write("/*\n")
|
|
|
|
versionHeader:write(" * Automatically generated by premake5.\n")
|
2022-04-15 12:17:20 -04:00
|
|
|
versionHeader:write(" * Do not touch!\n")
|
2017-01-20 11:02:25 -05:00
|
|
|
versionHeader:write(" *\n")
|
|
|
|
versionHeader:write(" * This file exists for reasons of complying with our coding standards.\n")
|
|
|
|
versionHeader:write(" *\n")
|
|
|
|
versionHeader:write(" * The Resource Compiler will ignore any content from C++ header files if they're not from STDInclude.hpp.\n")
|
|
|
|
versionHeader:write(" * That's the reason why we now place all version info in version.h instead.\n")
|
|
|
|
versionHeader:write(" */\n")
|
|
|
|
versionHeader:write("\n")
|
|
|
|
versionHeader:write("#include \".\\version.h\"\n")
|
|
|
|
versionHeader:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2022-04-07 05:41:20 -04:00
|
|
|
dependencies.load()
|
2017-01-20 11:02:25 -05:00
|
|
|
|
|
|
|
workspace "iw4x"
|
2019-12-25 13:59:30 -05:00
|
|
|
startproject "iw4x"
|
2017-01-20 11:02:25 -05:00
|
|
|
location "./build"
|
|
|
|
objdir "%{wks.location}/obj"
|
2022-04-07 05:54:28 -04:00
|
|
|
targetdir "%{wks.location}/bin/%{cfg.platform}/%{cfg.buildcfg}"
|
2022-01-26 07:27:52 -05:00
|
|
|
|
2022-04-07 05:41:20 -04:00
|
|
|
configurations {"Debug", "Release"}
|
2022-01-26 07:27:52 -05:00
|
|
|
|
|
|
|
language "C++"
|
2022-05-31 12:38:09 -04:00
|
|
|
cppdialect "C++20"
|
2022-01-26 07:27:52 -05:00
|
|
|
|
2017-06-23 15:47:38 -04:00
|
|
|
architecture "x86"
|
2022-04-07 05:41:20 -04:00
|
|
|
platforms "Win32"
|
2022-01-26 07:27:52 -05:00
|
|
|
|
|
|
|
systemversion "latest"
|
|
|
|
symbols "On"
|
2018-11-29 06:05:46 -05:00
|
|
|
staticruntime "On"
|
2022-01-26 07:27:52 -05:00
|
|
|
editandcontinue "Off"
|
|
|
|
warnings "Extra"
|
|
|
|
characterset "ASCII"
|
|
|
|
|
2022-04-07 05:41:20 -04:00
|
|
|
flags {"NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks"}
|
2022-01-26 07:27:52 -05:00
|
|
|
|
2022-04-07 05:41:20 -04:00
|
|
|
filter "platforms:Win*"
|
2022-01-26 07:27:52 -05:00
|
|
|
defines {"_WINDOWS", "WIN32"}
|
|
|
|
filter {}
|
2017-01-20 11:02:25 -05:00
|
|
|
|
2022-01-25 15:08:34 -05:00
|
|
|
filter "configurations:Release"
|
2022-04-07 05:41:20 -04:00
|
|
|
optimize "Size"
|
|
|
|
buildoptions {"/GL"}
|
|
|
|
linkoptions {"/IGNORE:4702", "/LTCG"}
|
|
|
|
defines {"NDEBUG"}
|
|
|
|
flags {"FatalCompileWarnings", "FatalLinkWarnings"}
|
2017-01-20 11:02:25 -05:00
|
|
|
|
2018-11-16 16:29:14 -05:00
|
|
|
if not _OPTIONS["force-unit-tests"] then
|
|
|
|
rtti ("Off")
|
|
|
|
end
|
2022-01-26 07:27:52 -05:00
|
|
|
filter {}
|
2018-11-16 16:29:14 -05:00
|
|
|
|
2022-01-25 15:08:34 -05:00
|
|
|
filter "configurations:Debug"
|
2017-01-20 11:02:25 -05:00
|
|
|
optimize "Debug"
|
2022-04-07 05:41:20 -04:00
|
|
|
defines {"DEBUG", "_DEBUG"}
|
2022-01-26 07:27:52 -05:00
|
|
|
filter {}
|
2017-01-20 11:02:25 -05:00
|
|
|
|
|
|
|
project "iw4x"
|
|
|
|
kind "SharedLib"
|
|
|
|
language "C++"
|
|
|
|
files {
|
|
|
|
"./src/**.rc",
|
|
|
|
"./src/**.hpp",
|
|
|
|
"./src/**.cpp",
|
|
|
|
}
|
|
|
|
includedirs {
|
|
|
|
"%{prj.location}/src",
|
2017-01-27 04:17:33 -05:00
|
|
|
"./src",
|
2018-07-17 08:30:29 -04:00
|
|
|
"./lib/include",
|
|
|
|
}
|
2017-01-20 11:02:25 -05:00
|
|
|
resincludedirs {
|
|
|
|
"$(ProjectDir)src" -- fix for VS IDE
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Debug flags
|
|
|
|
if _OPTIONS["force-unit-tests"] then
|
2022-04-07 05:41:20 -04:00
|
|
|
defines {"FORCE_UNIT_TESTS"}
|
2017-01-20 11:02:25 -05:00
|
|
|
end
|
|
|
|
if _OPTIONS["force-exception-handler"] then
|
2022-04-07 05:41:20 -04:00
|
|
|
defines {"FORCE_EXCEPTION_HANDLER"}
|
2017-01-20 11:02:25 -05:00
|
|
|
end
|
2022-05-31 09:56:54 -04:00
|
|
|
if _OPTIONS["disable-binary-check"] then
|
|
|
|
defines {"DISABLE_BINARY_CHECK"}
|
|
|
|
end
|
2021-07-16 13:08:50 -04:00
|
|
|
if _OPTIONS["iw4x-zones"] then
|
2022-04-07 05:41:20 -04:00
|
|
|
defines {"GENERATE_IW4X_SPECIFIC_ZONES"}
|
2021-07-16 10:36:16 -04:00
|
|
|
end
|
2017-01-20 11:02:25 -05:00
|
|
|
|
|
|
|
-- Pre-compiled header
|
|
|
|
pchheader "STDInclude.hpp" -- must be exactly same as used in #include directives
|
|
|
|
pchsource "src/STDInclude.cpp" -- real path
|
|
|
|
|
2022-04-07 05:41:20 -04:00
|
|
|
dependencies.imports()
|
2017-01-20 11:02:25 -05:00
|
|
|
|
|
|
|
-- Pre-build
|
|
|
|
prebuildcommands
|
|
|
|
{
|
2017-01-27 08:44:36 -05:00
|
|
|
"pushd %{_MAIN_SCRIPT_DIR}",
|
2017-01-20 11:02:25 -05:00
|
|
|
"tools\\premake5 generate-buildinfo",
|
2017-01-27 08:44:36 -05:00
|
|
|
"popd",
|
2017-01-20 11:02:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
-- Post-build
|
|
|
|
if _OPTIONS["copy-to"] then
|
|
|
|
saneCopyToPath = string.gsub(_OPTIONS["copy-to"] .. "\\", "\\\\", "\\")
|
|
|
|
postbuildcommands {
|
|
|
|
"if not exist \"" .. saneCopyToPath .. "\" mkdir \"" .. saneCopyToPath .. "\"",
|
|
|
|
}
|
|
|
|
|
|
|
|
if _OPTIONS["copy-pdb"] then
|
|
|
|
postbuildcommands {
|
|
|
|
"copy /y \"$(TargetDir)*.pdb\" \"" .. saneCopyToPath .. "\"",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- This has to be the last one, as otherwise VisualStudio will succeed building even if copying fails
|
|
|
|
postbuildcommands {
|
|
|
|
"copy /y \"$(TargetDir)*.dll\" \"" .. saneCopyToPath .. "\"",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-04-07 05:41:20 -04:00
|
|
|
|
|
|
|
group "External Dependencies"
|
|
|
|
dependencies.projects()
|
2017-01-20 11:02:25 -05:00
|
|
|
|
|
|
|
rule "ProtobufCompiler"
|
|
|
|
display "Protobuf compiler"
|
|
|
|
location "./build"
|
|
|
|
fileExtension ".proto"
|
|
|
|
buildmessage "Compiling %(Identity) with protoc..."
|
|
|
|
buildcommands {
|
|
|
|
'@echo off',
|
|
|
|
'path "$(SolutionDir)\\..\\tools"',
|
|
|
|
'if not exist "$(ProjectDir)\\src\\proto" mkdir "$(ProjectDir)\\src\\proto"',
|
|
|
|
'protoc --error_format=msvs -I=%(RelativeDir) --cpp_out=src\\proto %(Identity)',
|
|
|
|
}
|
|
|
|
buildoutputs {
|
|
|
|
'$(ProjectDir)\\src\\proto\\%(Filename).pb.cc',
|
|
|
|
'$(ProjectDir)\\src\\proto\\%(Filename).pb.h',
|
|
|
|
}
|