-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpremake5.lua
163 lines (136 loc) · 4.34 KB
/
premake5.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
-- 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
}
require("deps/iw4-open-formats")
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
}
iw4_open_formats.import()
-- 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 {}
group "External Dependencies"
iw4_open_formats.project()