1
0
mirror of https://github.com/XLabsProject/iw3x-port.git synced 2023-08-02 15:02:11 +02:00
iw3x-port/premake5.lua
2022-09-26 00:32:03 +02:00

156 lines
4.2 KiB
Lua

-- Option to allow copying the DLL file to a custom folder after build
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 = "no-new-structure",
description = "Do not use new virtual path structure (separating headers and source files)."
}
newaction {
trigger = "version",
description = "Returns the version string for the current commit of the source code.",
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()
print(revNumber)
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+", "")
proc:close()
-- get old version number from version.hpp if any
local oldRevNumber = "(none)"
local oldVersionHeader = io.open(wks.location .. "/src/version.hpp", "r")
if oldVersionHeader ~=nil then
local oldVersionHeaderContent = assert(oldVersionHeader:read('*a'))
oldRevNumber = string.match(oldVersionHeaderContent, "#define REVISION (%d+)")
if oldRevNumber == nil then
-- old version.hpp format?
oldRevNumber = "(none)"
end
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 .. "/src/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
}
workspace "iw3-exp"
location "./build"
objdir "%{wks.location}/obj"
targetdir "%{wks.location}/bin/%{cfg.buildcfg}"
buildlog "%{wks.location}/obj/%{cfg.architecture}/%{cfg.buildcfg}/%{prj.name}/%{prj.name}.log"
configurations { "Debug", "Release" }
architecture "x32"
platforms "x86"
buildoptions "/std:c++latest"
systemversion "latest"
defines { "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS" }
configuration "windows"
defines { "_WINDOWS", "WIN32" }
staticruntime "On"
if symbols ~= nil then
symbols "On"
else
flags { "Symbols" }
end
configuration "Release"
defines { "NDEBUG" }
flags { "MultiProcessorCompile", "LinkTimeOptimization", "No64BitChecks" }
optimize "Full"
configuration "Debug"
defines { "DEBUG", "_DEBUG" }
flags { "MultiProcessorCompile", "No64BitChecks" }
optimize "Debug"
project "iw3x"
kind "SharedLib"
language "C++"
cppdialect "C++20"
files {
"./src/**.rc",
"./src/**.hpp",
"./src/**.cpp",
}
includedirs {
"%{prj.location}/src",
"./src",
"./deps/rapidjson/include"
}
resincludedirs {
"$(ProjectDir)src" -- fix for VS IDE
}
-- Pre-compiled header
pchheader "STDInclude.hpp" -- must be exactly same as used in #include directives
pchsource "src/STDInclude.cpp" -- real path
buildoptions { "/Zm100 -Zm100" }
-- Virtual paths
if not _OPTIONS["no-new-structure"] then
vpaths {
["Headers/*"] = { "./src/**.hpp" },
["Sources/*"] = { "./src/**.cpp" },
["Resource/*"] = { "./src/**.rc" },
}
end
vpaths {
["Docs/*"] = { "**.txt","**.md" },
}
-- Pre-build
prebuildcommands {
"cd %{_MAIN_SCRIPT_DIR}",
"tools\\premake5 generate-buildinfo"
}
-- Post-build
if _OPTIONS["copy-to"] then
saneCopyToPath = string.gsub(_OPTIONS["copy-to"] .. "\\", "\\\\", "\\")
postbuildcommands {
"copy /y \"$(TargetDir)*.dll\" \"" .. saneCopyToPath .. "\""
}
end
-- Specific configurations
flags { "UndefinedIdentifiers" }
warnings "Extra"
configuration "Release"
flags { "FatalCompileWarnings" }
configuration {}