-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpremake5.lua
More file actions
316 lines (283 loc) · 8.48 KB
/
premake5.lua
File metadata and controls
316 lines (283 loc) · 8.48 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
------------------------------------------------------------------
-- premake 5 test solution
------------------------------------------------------------------
local solutionName = "string-id"
-- Table of windowed application projects to create. These names should have the
-- same name as the folder the project's source code is located in
local winApps =
{
}
-- Table of console application projects to create. These names should have the
-- same name as the folder the project's source code is located in
local consoleApps =
{
"sidbot", -- SID database manipulator
"sidserver", -- SID database server
"sidclient", -- SID database client
"unit-test", -- unit test
}
-- Table of projects that use Unicode. These names should have the
-- same name as the folder the project's source code is located in
local unicodeApps =
{
}
-- Table of static librari projects to create. These names should have the
-- same name as the folder the project's source code is located in.
local staticLibs =
{
"sid", -- SID core library
"siddb", -- SID database
"sidnet", -- SID network library
"cppunit",
}
-- Table of static librari projects to create. These names should have the
-- same name as the folder the project's source code is located in.
local dynamicLibs =
{
"sidvsdebug", -- SID Visual Studio autoexp addin
}
-- Table of paths to external libraries' include folder
local includeDirs =
{
"./lib/CppUnit/Include",
}
-- Table of paths to external libraries lib folder
local libDirs =
{
"./lib/CppUnit/Lib",
}
-- Table of paths to external libraries lib files
local libFiles =
{
}
-- Table of flags for different game configurations
-- possible flag values can be found at
-- http://industriousone.com/flags
local debugFlags =
{
"Symbols",
"NoMinimalRebuild",
"NoEditAndContinue",
}
local releaseFlags =
{
"Symbols",
"NoMinimalRebuild",
"NoEditAndContinue",
}
local shipFlags =
{
"Symbols",
"NoMinimalRebuild",
"NoEditAndContinue",
}
-- Table of linker options
local linkerOptions =
{
"/ignore:4075",
"/ignore:4098",
"/ignore:4099"
}
-- Table of preprocessor definitions for different game configuration
local debugDefines =
{
"_DEBUG",
"_CRT_SECURE_NO_WARNINGS"
}
local releaseDefines =
{
"_NDEBUG",
"_RELEASE",
"_CRT_SECURE_NO_WARNINGS"
}
local shipDefines =
{
"_NDEBUG",
"_SHIP",
"_CRT_SECURE_NO_WARNINGS"
}
-- paths
-- Variables for paths to files, in case project layout changes
local solutionDir = "./sln"
local projectDir = solutionDir
local objDir = "./obj"
local sourceDir = "./src"
local outDir = "./bin"
local debugDir = "./working"
-- Windows SDK
function os.winSdkVersion()
local reg_arch = iif( os.is64bit(), "\\Wow6432Node\\", "\\" )
local sdk_version = os.getWindowsRegistry( "HKLM:SOFTWARE" .. reg_arch .."Microsoft\\Microsoft SDKs\\Windows\\v10.0\\ProductVersion" )
if sdk_version ~= nil then return sdk_version end
end
-- Search through all directories and subdirectories of path and return all of them
-- t - file directory table (to be filled)
-- paht - the string name of the directory to search
function FindDirectoriesRecursive(t, path)
for dir in io.popen("dir " .. "\"" .. path .. "\"" .. " /b /ad"):lines()
do
table.insert(t, path .. "/" .. dir)
FindDirectoriesRecursive(t, path .. "/" .. dir)
end
end
-- Opens file and stores all project dependencies into a table
function ReadDependencies(fileName)
t = {}
-- check file existence
local f = io.open(fileName)
if f == nil then
return t
else
io.close(f)
end
-- add dependencies
for line in io.lines(fileName)
do
table.insert(t, line)
end
return t
end
-- This function sets up a visual studio project
local allProjectIncludeDirs = {}
function SetUpProj(projName, projType, locPath, pchFile, fileDir, outDir)
kind(projType)
language("C++")
location(locPath)
libdirs(libDirs)
objdir(objDir)
debugdir(debugDir)
linkoptions(linkerOptions)
architecture("x64")
includedirs(fileDir)
links(ReadDependencies(fileDir .. "/dependencies.txt"))
-- Windows SDK
filter({"system:windows", "action:vs*"})
systemversion(os.winSdkVersion() .. ".0")
includedirs("$(VC_IncludePath)")
includedirs("$(WindowsSDK_IncludePath)")
libdirs("$(WindowsSDK_LibraryPath_x64")
filter({})
-- recursively scan project directory
directories = {fileDir}
FindDirectoriesRecursive(directories, fileDir)
-- include library projects
for _, proj in ipairs(staticLibs) do
includedirs(sourceDir .. "/lib/" .. proj)
end
for _, proj in ipairs(dynamicLibs) do
includedirs(sourceDir .. "/dll/" .. proj)
end
-- additional includes
includedirs(includeDirs)
-- Set up filter
vpaths({[".proj"] = {"**/*.txt"}})
--vpaths({[".proj"] = {"**/*main.cpp", "**/*Main.cpp"}})
--vpaths({[".proj"] = {"**/*precompiled.h", "**/*precompiled.cpp", "**/*precompiled.c", "**/*Precompiled.h", "**/*Precompiled.cpp", "**/*Precompiled.c"}})
vpaths({[".proj"] = {"**/*.rc" }})
for _, folder in ipairs(directories)
do
vpaths({[string.sub(folder, string.len(fileDir) + 2)]
= {folder .. "/*.h" ,
folder .. "/*.hpp",
folder .. "/*.c" ,
folder .. "/*.cpp"}})
end
-- include all files following these patterns
files({fileDir .. "/**.h" ,
fileDir .. "/**.hpp",
fileDir .. "/**.c" ,
fileDir .. "/**.cpp",
fileDir .. "/**.txt"})
-- include a precompiled header the fullpath should NOT be specified
pchheader(pchFile .. ".h")
-- set the pch creator, specified by fullpath name
if projName ~= "Lua" then
pchsource(fileDir .. "/" .. pchFile .. ".cpp")
else
pchsource(fileDir .. "/" .. pchFile .. ".c")
end
-- set build options
opt = "/FI" .. pchFile .. ".h" -- force include precompiled header
buildoptions({opt}) -- apply build options to project
-- set character set
for _, name in ipairs(unicodeApps)
do
if projName == name then
flags({"Unicode"})
end
end
-- set configuration-specific stuff
-- NOTE: the target directory for applications are set to the working directory
-- because Visual Studio 2012 ignores debug working directory (a known bug)
-- set debug configuration
configuration("Debug")
optimize("Off")
targetname(projName .. "_debug")
defines(debugDefines)
flags(debugFlags)
targetdir(outDir)
-- set release configuration
configuration("Release")
optimize("Speed")
targetname(projName .. "_release")
defines(releaseDefines)
flags(releaseFlags)
targetdir(outDir)
-- set ship configuration
configuration("Ship")
optimize("Full")
targetname(projName)
defines(shipDefines)
flags(shipFlags)
targetdir(outDir)
end
-- premake5 main function
-- checking for nil lets --help action work
if _ACTION ~= nil then
-- Create Solution
workspace(solutionName)
configurations({"Debug", "Release", "Ship"})
platforms("x64")
location(solutionDir)
debugdir(workingDir)
--postbuildcommands { "\"$(TargetPath)\"" } -- actions to run after build
for _, lib in ipairs(libFiles) do
links(lib)
end
-- steps to perform on clean action
if _ACTION == "clean" then
os.rmdir(solutionDir)
return
end
-- create windowed apps, libraries, and console apps
for j = 1, 4 do
-- set default variable names
precompiledName = "precompiled"
locationPath = projectDir
if j == 1 then
appType = "WindowedApp"
for _, proj in ipairs(winApps) do
project(proj)
SetUpProj(proj, appType, locationPath, precompiledName, sourceDir .. "/app/" .. proj, outDir)
end
elseif j == 2 then
appType = "ConsoleApp"
for _, proj in ipairs(consoleApps) do
project(proj)
SetUpProj(proj, appType, locationPath, precompiledName, sourceDir .. "/app/" .. proj, outDir)
end
elseif j == 3 then
appType = "StaticLib"
for _, proj in ipairs(staticLibs) do
project(proj)
SetUpProj(proj, appType, locationPath, precompiledName, sourceDir .. "/lib/" .. proj, outDir)
end
elseif j == 4 then
appType = "SharedLib"
for _, proj in ipairs(dynamicLibs) do
project(proj)
SetUpProj(proj, appType, locationPath, precompiledName, sourceDir .. "/dll/" .. proj, outDir)
end
end -- if/else
end -- outer for loop
end -- action is nil check