-
Notifications
You must be signed in to change notification settings - Fork 172
/
premake5.lua
377 lines (333 loc) · 11.1 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
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
---@diagnostic disable: undefined-global, undefined-field
if _ACTION ~= "build" and _ACTION ~= "clean" and _ACTION ~= "publish" then
os.execute("git pull")
os.execute("git submodule init")
os.execute("git submodule update")
end
local LUA_BUILD_AS_SHARED = true
workspace "Server"
configurations { "Debug", "Release" }
flags{"NoPCH","RelativeLinks"}
cppdialect "C++17"
location "./"
architecture "x64"
if not LUA_BUILD_AS_SHARED then
staticruntime "on"
end
filter "configurations:Debug"
defines { "DEBUG" }
symbols "On"
filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"
symbols "On"
filter {"system:windows"}
characterset "MBCS"
systemversion "latest"
warnings "Extra"
cdialect "C11"
buildoptions{"/experimental:c11atomics"}
filter { "system:linux" }
warnings "High"
filter { "system:macosx" }
warnings "High"
project "lua"
location "build/projects/%{prj.name}"
objdir "build/obj/%{prj.name}/%{cfg.buildcfg}"
targetdir "build/bin/%{cfg.buildcfg}"
if LUA_BUILD_AS_SHARED then
kind "SharedLib"
postbuildcommands{"{COPY} %{cfg.buildtarget.abspath} %{wks.location}"}
else
kind "StaticLib"
end
language "C"
includedirs {"./third/lua"}
files {"./third/lua/onelua.c"}
defines {"MAKE_LIB"}
filter { "system:windows" }
disablewarnings { "4244","4324","4702","4310", "4701"}
if LUA_BUILD_AS_SHARED then
defines {"LUA_BUILD_AS_DLL"}
end
filter { "system:linux" }
defines {"LUA_USE_LINUX"}
filter { "system:macosx" }
defines {"LUA_USE_MACOSX"}
project "mimalloc"
location "build/projects/%{prj.name}"
objdir "build/obj/%{prj.name}/%{cfg.buildcfg}"
targetdir "build/bin/%{cfg.buildcfg}"
kind "StaticLib"
language "C"
includedirs {"./third/mimalloc/include"}
files {"./third/mimalloc/src/static.c"}
project "moon"
location "build/projects/%{prj.name}"
objdir "build/obj/%{prj.name}/%{cfg.buildcfg}"
targetdir "build/bin/%{cfg.buildcfg}"
kind "ConsoleApp"
language "C++"
includedirs {
"./src",
"./src/moon",
"./src/moon/core",
"./third",
"./third/lua",
"./third/mimalloc/include"
}
files {
"./src/moon/**.h",
"./src/moon/**.hpp",
"./src/moon/**.cpp"
}
links{
"lua",
"lualib",
"crypt",
"pb",
"sharetable",
"mongo",
"mimalloc",
"lfmt"
}
defines {
"ASIO_STANDALONE" ,
"ASIO_NO_DEPRECATED",
"MOON_ENABLE_MIMALLOC"
}
filter { "system:windows" }
defines {"_WIN32_WINNT=0x0601"}
linkoptions { '/STACK:"8388608"' }
filter {"system:linux"}
links{"dl","pthread","stdc++fs"}
linkoptions {
"-static-libstdc++ -static-libgcc",
"-Wl,--as-needed,-rpath=./"
}
filter {"system:macosx"}
links{"dl","pthread"}
linkoptions {
"-Wl,-rpath,./",
"-undefined dynamic_lookup"
}
filter "configurations:Debug"
targetsuffix "-d"
filter{"configurations:*"}
postbuildcommands{"{COPY} %{cfg.buildtarget.abspath} %{wks.location}"}
--- Adds a Lua module to the build configuration.
---
--- This function configures a Lua module located in the specified directory
--- and assigns it the given name. Additional platform-specific options can
--- be provided to customize the build process for different operating systems.
---
--- @param dir string The path to the module's source files, relative to the current directory.
--- @param name string The name of the Lua module.
--- @param options? table Additional options for the module configuration.
--- The options table can contain the following keys:
--- - all: function() end - A function to be executed for all platforms.
--- - windows: function() end - A function to be executed only on Windows.
--- - linux: function() end - A function to be executed only on Linux.
--- - macosx: function() end - A function to be executed only on macOS.
local function add_lua_module(dir, name, options )
project(name)
location("build/projects/%{prj.name}")
objdir "build/obj/%{prj.name}/%{cfg.buildcfg}"
targetdir "build/bin/%{cfg.buildcfg}"
language "C"
kind "StaticLib"
includedirs {"./src", "./third","./third/lua"}
files { dir.."/**.h",dir.."/**.hpp", dir.."/**.c",dir.."/**.cpp"}
defines{"SOL_ALL_SAFETIES_ON"}
if not options then
options = {}
end
if type(options.all)=="function" then
options.all()
end
filter { "system:windows" }
if type(options.windows)=="function" then
options.windows()
end
filter {"system:linux"}
if type(options.linux)=="function" then
options.linux()
end
filter {"system:macosx"}
if type(options.macosx)=="function" then
options.macosx()
end
end
----------------------Lua C/C++ Modules------------------------
add_lua_module(
"./third/sharetable",
"sharetable"
)
add_lua_module(
"./third/lcrypt",
"crypt",
{
windows = function ()
disablewarnings { "4244","4267","4456", "4459"}
end
}
)
add_lua_module(
"./third/pb",
"pb"
)--protobuf
add_lua_module(
"./third/lfmt",
"lfmt"
)
add_lua_module(
"./third/lmongo",
"mongo",
{
windows = function ()
disablewarnings { "4267","4457","4456", "4459", "4996", "4244", "4310"}
end
}
)
add_lua_module(
"./src/lualib-src",
"lualib",
{
all = function()
language "C++"
includedirs {"./src/moon", "./src/moon/core", "./third/mimalloc/include"}
defines {
"ASIO_STANDALONE" ,
"ASIO_NO_DEPRECATED",
"MOON_ENABLE_MIMALLOC"
}
---json
defines{ "YYJSON_DISABLE_WRITER" }
files { "./third/yyjson/**.h", "./third/yyjson/**.c"}
---kcp
files { "./third/kcp/**.h", "./third/kcp/**.c"}
---navmesh begin
includedirs {
"./third/recastnavigation/Detour/Include",
"./third/recastnavigation/DetourCrowd/Include",
"./third/recastnavigation/DetourTileCache/Include",
"./third/recastnavigation/Recast/Include"
}
files {
"./third/recastnavigation/Detour/**.h",
"./third/recastnavigation/Detour/**.cpp",
"./third/recastnavigation/DetourCrowd/**.h",
"./third/recastnavigation/DetourCrowd/**.cpp",
"./third/recastnavigation/DetourTileCache/**.h",
"./third/recastnavigation/DetourTileCache/**.cpp",
"./third/recastnavigation/Recast/**.h",
"./third/recastnavigation/Recast/**.cpp",
"./third/fastlz/**.h",
"./third/fastlz/**.c"
}
---navmesh end
end,
windows = function ()
defines {"_WIN32_WINNT=0x0601"}
end
}
)
local function string_trim(input, chars)
chars = chars or " \t\n\r"
local pattern = "^[" .. chars .. "]+"
input = string.gsub(input, pattern, "")
pattern = "[" .. chars .. "]+$"
return string.gsub(input, pattern, "")
end
local function cleanup()
os.remove("moon")
os.remove("moon.*")
os.remove("lua.*")
os.remove("liblua.*")
os.rmdir("build/obj")
os.rmdir("build/bin")
os.rmdir(".vs")
end
-- if _ACTION == "clean" then
-- cleanup()
-- end
newaction {
trigger = "clean",
description = "Cleanup",
execute = function ()
cleanup()
end
}
newaction {
trigger = "build",
description = "Build",
execute = function ()
local host = os.host()
local switch = {
windows = function ()
os.execute("premake5.exe vs2022")
local command = os.getenv("ProgramFiles(x86)")..[[\Microsoft Visual Studio\Installer\vswhere.exe]]
command = string.format('"%s" %s', string_trim(command), " -latest -products * -requires Microsoft.Component.MSBuild -property installationPath")
local handle = assert(io.popen(command))
command = handle:read("*a")
handle:close()
os.execute(string.format('"%s%s" -maxcpucount:4 Server.sln /t:build /p:Configuration=Release ', string_trim(command), [[\MSBuild\Current\Bin\MSBuild.exe]]))
end,
linux = function ()
os.execute("premake5 gmake2")
os.execute("make -j4 config=release")
os.execute([[
#!/bin/bash
if objdump --section-headers "moon" | grep -q ".debug_info"; then
objcopy --only-keep-debug moon moon.debug
objcopy --only-keep-debug liblua.so liblua.so.debug
strip moon
strip liblua.so
objcopy --add-gnu-debuglink=moon.debug moon
objcopy --add-gnu-debuglink=liblua.so.debug liblua.so
fi
]])
end,
macosx = function ()
os.execute("premake5 gmake2 --cc=clang")
os.execute("make -j4 config=release")
end,
}
-- cleanup()
switch[host]()
end
}
newaction {
trigger = "publish",
description = "Publish",
execute = function ()
local host = os.host()
local switch = {
windows = function ()
os.execute("if exist moon-windows.zip del /f moon-windows.zip")
os.execute("if not exist clib mkdir clib")
os.execute("echo Compressing files into moon-windows.zip...")
os.execute("powershell Compress-Archive -Path moon.exe, lua.dll, lualib, service, clib, README.md -DestinationPath moon-windows.zip ")
os.execute("echo Checking if moon-windows.zip was created...")
os.execute("if exist moon-windows.zip (echo moon-windows.zip created successfully.) else (echo Failed to create moon-windows.zip.)")
end,
linux = function ()
os.execute([[
#!/bin/bash
rm -f moon-linux.zip
mkdir -p clib
zip -r moon-linux.zip moon liblua.so lualib service clib/*.so moon.debug liblua.so.debug README.md
]])
end,
macosx = function ()
os.execute([[
#!/bin/bash
rm -f moon-macosx.zip
mkdir -p clib
zip -r moon-macosx.zip moon liblua.dylib lualib service clib/*.dylib README.md
]])
end,
}
switch[host]()
end
}