This repository has been archived by the owner on May 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
premake4.lua
390 lines (291 loc) · 9.29 KB
/
premake4.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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
--[[----------------------------------------------------------------------------
premake4.lua -- Copyright (c) 2013 Noel Cower. All rights reserved.
See COPYING under the project root for the source code license. If this file
is not present, refer to <https://raw.github.com/nilium/snow/master/COPYING>.
------------------------------------------------------------------------------]]
-- Set up snow table
snow = {}
--[[----------------------------------------------------------------------------
join_arrays
Joins zero or more arrays into a single array. Discards original keys in
input tables.
------------------------------------------------------------------------------]]
function snow.join_arrays(...)
local result = {}
local inputs = {...}
for ik,iv in pairs(inputs) do
for jk,jv in pairs(iv) do
result[#result + 1] = jv
end
end
return result
end
function snow.tostring(e)
if e == nil then
return ""
elseif type(e) == "function" then
return snow.tostring(e())
elseif type(e) == "number" then
return tostring(e)
elseif type(e) == "boolean" then
if e then
return "1"
else
return "0"
end
else
return tostring(e)
end
end
--[[----------------------------------------------------------------------------
formatrb_string
Returns arguments combined for format.rb
------------------------------------------------------------------------------]]
function snow.formatrb_string(t)
local result = ""
for k,v in pairs(t) do
result = result .. " '" .. snow.tostring(k) .. "=" .. snow.tostring(v) .. "'"
end
return result
end
function snow.install(source_path, install_path, verbose)
if verbose then
print("Installing '" .. source_path .."' to '" .. install_path .. "'")
end
local done, errmsg = os.copyfile(source_path, install_path)
if not done then
print("os.copyfile: " .. errms)
print("Unable to copy " .. source_path, " unable to continue installation")
return false
end
return true
end
function snow.correct_dirsep(str)
if os.is("windows") then
return string.gsub(str, "/", "\\")
else
return string.gsub(str, "\\", "/")
end
end
function snow.dirname(str)
local last = string.findlast(str, "/", true)
if last ~= nil then
return string.sub(str, 0, last)
end
return str
end
function snow.mkdir_p(path)
local dirsep = "/"
if os.is("windows") then
dirsep = "\\"
end
local components = string.explode(path, "/")
local last_dir = 0
do -- Make sure nothing along the way is a file
local dir_build = ""
for i, v in ipairs(components) do
if v ~= "" then
dir_build = dir_build .. dirsep .. v
if os.isdir(dir_build) == true then
last_dir = i
elseif os.isfile(dir_build) then
return false -- Cannot create dir if file of the same name exists already
end
end
end -- for in components
end -- do check path
do
local dir_build = ""
for i, v in ipairs(components) do
if #v > 0 then
dir_build = dir_build .. dirsep .. v
if i > last_dir then
local done, errmsg = os.mkdir(dir_build)
if not done then
print("Unable to create directory: " .. dir_build)
return false
end -- if not done
end -- if i > last_dir
end
end -- for in components
end -- do build directory
return true
end -- mkdir_p
-- Main build configuration
solution "snow"
configurations { "debug", "release" }
newoption {
trigger = "with-server",
description = "Enables the server code in the engine build."
}
if os.is("macosx") then
newoption {
trigger = "gcc",
description = "Specifies use of GCC on OS X"
}
end
--[[ snow_c_libs project ------------------------------------------]] do
project "snow_c_libs"
kind "StaticLib"
targetdir "lib"
language "C"
files { "ext/snow-ext/sqlite3.c", "ext/snow-ext/stb_image.c" }
buildoptions { "-arch x86_64" }
end
--[[ snow_objcxx_libs project ------------------------------------------]] do
project "snow_objcxx_libs"
kind "StaticLib"
targetdir "lib"
language "C++"
files( os.matchfiles("src/**.mm") )
flags { "FloatStrict", "NoRTTI" }
defines { "SNOW_EXCLUDE_EXT_LIBRARIES" }
buildoptions { "-arch x86_64" }
buildoptions { "-include src/snow.objc.hh" }
buildoptions { "-std=c++11" }
configuration { "macosx" }
buildoptions { "-stdlib=libc++" }
links { "c++" }
configuration { "macosx", "release" }
buildoptions { "-O3" }
configuration "release"
defines { "NDEBUG" }
configuration "debug"
defines { "DEBUG" }
flags { "Symbols" }
end
--[[ snowhash project ---------------------------------------------]] do
project "snowhash"
language "C++"
kind "ConsoleApp"
files { "snowhash.cc" }
defines { "SNOW_EXCLUDE_EXT_LIBRARIES" }
-- Link snow-common
linkoptions { '`pkg-config --libs snow-common`' }
buildoptions { '`pkg-config --cflags snow-common`' }
buildoptions { "-std=c++11" }
configuration { "macosx" }
buildoptions { "-stdlib=libc++" }
links { "c++" }
configuration { "macosx", "release" }
buildoptions { "-O3" }
configuration "release"
defines { "NDEBUG" }
configuration "debug"
defines { "DEBUG" }
flags { "Symbols" }
end
--[[ snowhost project ---------------------------------------------]] do
project "snowhost"
language "C++"
kind "ConsoleApp"
files { "host.cc" }
links { "snow_c_libs" }
includedirs { "ext" }
-- Link snow-common
linkoptions { '`pkg-config --libs snow-common`' }
buildoptions { '`pkg-config --cflags snow-common`' }
links { "zmq" }
buildoptions { "-std=c++11" }
configuration { "macosx" }
buildoptions { "-stdlib=libc++" }
links { "c++" }
configuration { "macosx", "release" }
buildoptions { "-O3" }
configuration "release"
defines { "NDEBUG" }
configuration "debug"
defines { "DEBUG" }
flags { "Symbols" }
end
--[[ snow project -------------------------------------------------]] do
project "snow"
targetdir "bin"
kind "WindowedApp"
-- Option defaults
local g_exclude_suffixes = {}
buildoptions { "-include '" .. path.getabsolute('src') .. "/snow.cxx.hh'"}
-- Compiler flags
local g_version = "0.0.1"
language "C++"
flags { "FloatStrict", "NoRTTI" }
objdir "obj"
-- Libraries
includedirs { "ext" }
links { "zmq" }
links { "physfs", "snow_c_libs", "snow_objcxx_libs" }
linkoptions { '`fltk-config --ldflags`' }
buildoptions { '`fltk-config --cxxflags`' }
-- Add sources/include directories
local cxx_files = snow.join_arrays(os.matchfiles("src/**.cc"), os.matchfiles("src/**.cxx"), os.matchfiles("src/**.cpp"))
files(cxx_files)
excludes "src/snow.cc" -- pch only
configuration "not with-server"
excludes { "src/server/*" }
configuration { "macosx", "release" }
buildoptions { "-O3" }
configuration "release"
defines { "NDEBUG" }
configuration "debug"
defines { "DEBUG" }
flags { "Symbols" }
local g_build_config_opts = {
USE_EXCEPTIONS = true,
USE_SERVER = false
}
if _OPTIONS["with-server"] ~= nil then
g_build_config_opts.USE_SERVER = not not _OPTIONS["with-server"]
end
-- OS X specific options
configuration "macosx"
links { "Cocoa.framework" }
links { "OpenGL.framework" }
links { "IOKit.framework" }
buildoptions { "-arch x86_64" }
linkoptions { "-ObjC++", "-headerpad_max_install_names", "-arch x86_64" }
configuration {}
buildoptions { "-std=c++11" }
configuration { "macosx" }
buildoptions { "-stdlib=libc++" }
links { "c++" }
local target_path_osx = "bin/snow.app/Contents/MacOS/snow"
local change_libs_osx = {
["libphysfs.1.dylib"] = "@executable_path/../Frameworks/libphysfs.dylib",
["/usr/local/lib/libzmq.3.dylib"] = "@executable_path/../Frameworks/libzmq.dylib",
["/usr/local/lib/libenet.2.dylib"] = "@executable_path/../Frameworks/libenet.dylib"
}
do
local changes_string = ''
for from,to in pairs(change_libs_osx) do
changes_string = changes_string .. " -change '" .. from .. "' '" .. to .. "'"
end
if #changes_string > 0 then
changes_string = changes_string .. " '" .. target_path_osx .. "'"
postbuildcommands { "install_name_tool" .. changes_string }
end
end
-- files { "src/main.mm" }
-- excludes { "src/main.cc" }
-- pkg-config packages
configuration {}
g_dynamic_libs = { "libzmq" }
g_static_libs = { "snow-common", "libenet", "glfw3" }
if #g_static_libs > 0 then
linkoptions { "`pkg-config --libs " .. table.concat(g_static_libs, " ") .. "`"}
end
if #g_dynamic_libs > 0 then
linkoptions { "`pkg-config --libs " .. table.concat(g_dynamic_libs, " ") .. "`"}
end
if (#g_dynamic_libs + #g_static_libs) > 0 then
local combined_libs = table.concat(snow.join_arrays(g_dynamic_libs, g_static_libs), " ")
buildoptions { "`pkg-config --cflags " .. combined_libs .. "`"}
end
-- Generate build-config/pkg-config
if _ACTION and _ACTION ~= "install" then
-- Generate build-config.hh
local config_src = "'src/build-config.hh.in'"
local config_dst = "'src/build-config.hh'"
print("Generating 'src/build-config.hh'...")
os.execute("./format.rb " .. config_src .. " " .. config_dst .. snow.formatrb_string(g_build_config_opts))
end
end