-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpremake5.lua
583 lines (484 loc) · 18.4 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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
-- Workspace -----------------------------------------------------------------------------------------------------------
workspace "magnolia"
architecture "x86_64"
language "c++"
cppdialect "c++20"
toolset "clang"
configurations {"debug", "profile", "release"}
location "build"
staticruntime "on"
-- Output directories
targetdir ("build/%{cfg.system}/%{prj.name}")
objdir ("build/%{cfg.system}/obj/%{cfg.buildcfg}/%{prj.name}")
libdir = ""
if os.host() == "linux" then
libdir = "build/linux/lib"
elseif os.host() == "windows" then
libdir = "build/windows/lib"
end
lib_includes =
{
"libs",
"libs/sdl/include",
"libs/fmt/include",
"libs/vulkan/include",
"libs/vma/include",
"libs/assimp/include",
"libs/imgui",
"libs/imguizmo",
"libs/implot",
"libs/glm",
"libs/stb",
"libs/spirv_reflect",
"libs/json/single_include",
"libs/meshoptimizer/src",
"libs/bullet/src",
-- @TODO: this is necessary because 'config.h' is generated by the cmake
"build/linux/assimp/include"
}
lib_links =
{
"fmt", "imgui", "imguizmo", "implot", "assimp", "meshoptimizer",
"BulletDynamics", "BulletInverseDynamics", "BulletCollision",
"Bullet3Common", "Bullet3Dynamics", "Bullet3Collision", "Bullet3Geometry",
"BulletLinearMath"
}
-- @NOTE: don't use LTO on debug, it might interfere with ClangBuildAnalyzer
build_flags =
{
"LinkTimeOptimization"
}
defines
{
"VULKAN_HPP_NAMESPACE=vk"
}
linkoptions
{
-- Change your preferred linker here (or comment this line to use the system default)
"-fuse-ld=mold -Wl,-v",
-- For some reason, premake is having trouble finding assimp
"-Wl,-R" .. libdir
}
-- @TODO: consistent build folders/output
-- @TODO: fix windows build
-- Engine --------------------------------------------------------------------------------------------------------------
project "magnolia"
targetname ("%{prj.name}_%{cfg.buildcfg}")
kind "sharedlib"
pchheader "%{prj.name}/src/pch.hpp"
pchsource "%{prj.name}/src/pch.cpp"
files
{
"%{prj.name}/src/**.hpp",
"%{prj.name}/src/**.cpp",
"libs/spirv_reflect/spirv_reflect.h",
"libs/spirv_reflect/spirv_reflect.cpp",
"libs/json/single_include/nlohmann/json.hpp"
}
includedirs
{
"%{prj.name}/src",
lib_includes
}
defines
{
"VULKAN_HPP_DISPATCH_LOADER_DYNAMIC"
}
links
{
lib_links
}
libdirs
{
libdir
}
filter "system:linux"
pic "on"
links
{
"vulkan", "sdl"
}
filter "system:windows"
systemversion "latest"
defines
{
"_CRT_SECURE_NO_WARNINGS"
}
links
{
"vulkan-1",
"SDL2",
"SDL2main",
}
-- entrypoint("mainCRTStartup")
filter "configurations:debug"
buildoptions { "-Wall", "-Wextra", "-ftime-trace" }
defines { "MAG_DEBUG", "MAG_ASSERTIONS_ENABLED", "MAG_PROFILE_ENABLED" }
symbols "on" -- '-g'
optimize "off" -- '-O0'
runtime "debug"
filter "configurations:profile"
defines { "NDEBUG", "MAG_PROFILE", "MAG_PROFILE_ENABLED" }
flags { build_flags }
symbols "off"
optimize "on" -- '-O2'
runtime "release"
filter "configurations:release"
defines { "NDEBUG", "MAG_RELEASE", "MAG_PROFILE_ENABLED" }
flags { build_flags }
symbols "off"
optimize "full" -- '-O3'
runtime "release"
-- Client Application --------------------------------------------------------------------------------------------------
project "sprout_editor"
targetname ("%{prj.name}_%{cfg.buildcfg}")
kind "consoleapp"
files
{
"%{prj.name}/src/**.hpp",
"%{prj.name}/src/**.cpp"
}
includedirs
{
"%{prj.name}/src",
"magnolia/src",
lib_includes
}
libdirs
{
libdir
}
links
{
"magnolia", lib_links
}
filter "system:linux"
pic "on"
links
{
"vulkan", "sdl"
}
filter "system:windows"
systemversion "latest"
defines
{
"_CRT_SECURE_NO_WARNINGS"
}
links
{
"vulkan-1",
"SDL2",
"SDL2main",
}
-- entrypoint("mainCRTStartup")
filter "configurations:debug"
buildoptions { "-Wall", "-Wextra", "-ftime-trace" }
defines { "MAG_DEBUG", "MAG_ASSERTIONS_ENABLED", "MAG_PROFILE_ENABLED" }
symbols "on" -- '-g'
optimize "off" -- '-O0'
runtime "debug"
filter "configurations:profile"
defines { "NDEBUG", "MAG_PROFILE", "MAG_PROFILE_ENABLED" }
flags { build_flags }
symbols "off"
optimize "on" -- '-O2'
runtime "release"
filter "configurations:release"
defines { "NDEBUG", "MAG_RELEASE", "MAG_PROFILE_ENABLED" }
flags { build_flags }
symbols "off"
optimize "full" -- '-O3'
runtime "release"
-- Scripting -----------------------------------------------------------------------------------------------------------
local script_dir = "sprout_editor/assets/scripts/"
local script_files = os.matchfiles(script_dir .. "*.cpp")
common_settings = function()
targetname ("%{prj.name}_%{cfg.buildcfg}")
kind "sharedlib"
targetdir ("build/%{cfg.system}/scripts")
objdir ("build/%{cfg.system}/obj/%{cfg.buildcfg}/scripts/%{prj.name}")
includedirs
{
"magnolia/src",
lib_includes -- @TODO: remove when fmt gets removed from the headers
}
libdirs
{
libdir -- @TODO: remove when fmt gets removed from the headers
}
links
{
"magnolia",
"fmt" -- @TODO: remove when fmt gets removed from the headers
}
filter "system:linux"
pic "on"
filter "system:windows"
systemversion "latest"
defines
{
"_CRT_SECURE_NO_WARNINGS"
}
-- entrypoint("mainCRTStartup")
filter "configurations:debug"
buildoptions { "-Wall", "-Wextra", "-ftime-trace" }
defines { "MAG_DEBUG", "MAG_ASSERTIONS_ENABLED", "MAG_PROFILE_ENABLED" }
symbols "on" -- '-g'
optimize "off" -- '-O0'
runtime "debug"
filter "configurations:profile"
defines { "NDEBUG", "MAG_PROFILE", "MAG_PROFILE_ENABLED" }
flags { build_flags }
symbols "off"
optimize "on" -- '-O2'
runtime "release"
filter "configurations:release"
defines { "NDEBUG", "MAG_RELEASE", "MAG_PROFILE_ENABLED" }
flags { build_flags }
symbols "off"
optimize "full" -- '-O3'
runtime "release"
end
-- @TODO: this is a bit of a hack to compile each script .cpp file in its own .dll. We create a project for each file.
for _, file in ipairs(script_files) do
local script_name = path.getbasename(file)
project(script_name)
targetname (script_name)
files { file }
common_settings()
end
-- Libs ----------------------------------------------------------------------------------------------------------------
-- Skip compilation if already compiled
function exists(filePath)
local file = io.open(filePath, "r")
if file then
file:close()
return true
else
return false
end
end
-- Execute a shell command
function execute_command(command)
local file = io.popen(command)
local output = file:read("*a")
file:close()
return output
end
-- Get number of cores (linux only)
function number_of_cores()
result = tonumber(execute_command("nproc"))
print(string.format("(Premake) Number of cores: %d", result))
return result
end
-- vulkan --------------------------------------------------------------------------------------------------------------
project "vulkan"
kind "none"
if os.host() == "windows" then
if exists("build/windows/magnolia/vulkan-1.dll") then
os.execute("echo Skipping vulkan copy commands...")
else
os.execute("mkdir build\\windows\\magnolia 2>NUL")
os.execute("cp ext/windows/vulkan-1.dll build/windows/magnolia/vulkan-1.dll")
end
elseif os.host() == "linux" then
if exists(libdir .. "/libvulkan.so") and
exists(libdir .. "/libvulkan.so.1") and
exists(libdir .. "/libvulkan.so.1.3.268") then
os.execute("echo Skipping vulkan copy commands...")
else
os.execute("mkdir -p " .. libdir)
os.execute("mkdir -p build/linux/magnolia")
os.execute("cp ext/linux/libvulkan.so " .. libdir .. "/libvulkan.so")
os.execute("cp ext/linux/libvulkan.so.1 " .. libdir .. "/libvulkan.so.1")
os.execute("cp ext/linux/libvulkan.so.1.3.268 " .. libdir .. "/libvulkan.so.1.3.268")
end
end
-- fmt -----------------------------------------------------------------------------------------------------------------
project "fmt"
kind "none"
targetextension ".a"
targetprefix "lib"
if os.host() == "windows" then
if exists("build/windows/lib/libfmt.a") then
os.execute("echo Skipping fmt compilation...")
else
os.execute("mkdir build\\windows\\fmt 2>NUL")
os.execute("cd build\\windows\\fmt && cmake -G \"MinGW Makefiles\" ../../../libs/fmt -B . && make -j" .. os.getenv("NUMBER_OF_PROCESSORS"))
os.execute("mkdir build\\windows\\lib 2>NUL")
os.execute("copy build\\windows\\fmt\\libfmt.a build\\windows\\lib\\libfmt.a")
end
elseif os.host() == "linux" then
if exists(libdir .. "/libfmt.a") then
os.execute("echo Skipping fmt compilation...")
else
os.execute("mkdir -p build/linux/fmt")
os.execute("cd build/linux/fmt && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -S ../../../libs/fmt -B . && make -j" .. number_of_cores())
os.execute("cp build/linux/fmt/libfmt.a " .. libdir .. "/libfmt.a")
end
end
-- sdl -----------------------------------------------------------------------------------------------------------------
project "sdl"
kind "none"
if os.host() == "windows" then
if exists("build/windows/lib/libSDL2.a") and exists("build/windows/lib/libSDL2main.a") and exists("build/windows/lib/libSDL2.dll.a") and exists("build/windows/magnolia/SDL2.dll") then
os.execute("echo Skipping SDL2 compilation...")
else
os.execute("mkdir build\\windows\\magnolia 2>NUL")
os.execute("mkdir build\\windows\\sdl 2>NUL")
os.execute("cd build\\windows\\sdl && cmake -G \"MinGW Makefiles\" -S ../../../libs/sdl -B . && make -j" .. os.getenv("NUMBER_OF_PROCESSORS"))
os.execute("mkdir build\\windows\\lib 2>NUL")
os.execute("copy build\\windows\\sdl\\libSDL2.a build\\windows\\lib\\libSDL2.a")
os.execute("copy build\\windows\\sdl\\libSDL2main.a build\\windows\\lib\\libSDL2main.a")
os.execute("copy build\\windows\\sdl\\libSDL2.dll.a build\\windows\\lib\\libSDL2.dll.a")
os.execute("copy build\\windows\\sdl\\SDL2.dll build\\windows\\magnolia\\SDL2.dll")
end
elseif os.host() == "linux" then
if exists(libdir .. "/libsdl.a") and exists(libdir .. "/libSDL2main.a") then
os.execute("echo Skipping SDL2 compilation...")
else
os.execute("mkdir -p build/linux/sdl")
os.execute("cd build/linux/sdl && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -S ../../../libs/sdl -B . && make -j" .. number_of_cores())
os.execute("cp build/linux/sdl/libSDL2.a " .. libdir .. "/libsdl.a")
os.execute("cp build/linux/sdl/libSDL2main.a " .. libdir .. "/libSDL2main.a")
end
end
-- imgui ---------------------------------------------------------------------------------------------------------------
project "imgui"
kind "staticlib"
language "c++"
cppdialect "c++20"
targetdir (libdir)
objdir ("build/%{cfg.system}/%{prj.name}/%{cfg.buildcfg}")
includedirs { ".", "libs/imgui", "libs/sdl/include", "libs/vulkan/include"}
if os.host() == "windows" then
os.execute("mkdir build\\windows\\imgui 2>NUL")
end
files
{
"libs/imgui/imgui.h",
"libs/imgui/imconfig.h",
"libs/imgui/imgui_internal.h",
"libs/imgui/imstb_rectpack.h",
"libs/imgui/imstb_textedit.h",
"libs/imgui/imstb_truetype.h",
"libs/imgui/misc/cpp/imgui_stdlib.h",
"libs/imgui/misc/cpp/imgui_stdlib.cpp",
"libs/imgui/imgui.cpp",
"libs/imgui/imgui_draw.cpp",
"libs/imgui/imgui_tables.cpp",
"libs/imgui/imgui_widgets.cpp",
"libs/imgui/imgui_demo.cpp",
"libs/imgui/backends/imgui_impl_sdl2.h",
"libs/imgui/backends/imgui_impl_vulkan.h",
"libs/imgui/backends/imgui_impl_sdl2.cpp",
"libs/imgui/backends/imgui_impl_vulkan.cpp"
}
filter "system:linux"
pic "on"
systemversion "latest"
staticruntime "on"
-- imguizmo ------------------------------------------------------------------------------------------------------------
project "imguizmo"
kind "staticlib"
language "c++"
cppdialect "c++20"
targetdir (libdir)
objdir ("build/%{cfg.system}/%{prj.name}/%{cfg.buildcfg}")
includedirs { ".", "libs/imguizmo", "libs/imgui" }
if os.host() == "windows" then
os.execute("mkdir build\\windows\\imguizmo 2>NUL")
end
files
{
"libs/imguizmo/ImGuizmo.h",
"libs/imguizmo/ImGuizmo.cpp"
}
filter "system:linux"
pic "on"
systemversion "latest"
staticruntime "on"
-- assimp --------------------------------------------------------------------------------------------------------------
project "assimp"
kind "none"
if os.host() == "windows" then
os.execute("echo @TODO WINDOWS ASSIMP")
elseif os.host() == "linux" then
if exists(libdir .. "/libassimp.so") and
exists(libdir .. "/libassimp.so.5") and
exists(libdir .. "/libassimp.so.5.4.3") then
os.execute("echo Skipping assimp compilation...")
else
os.execute("mkdir -p build/linux/assimp")
os.execute("cd build/linux/assimp && cmake -S ../../../libs/assimp -B . && make -j" .. number_of_cores())
os.execute("cp build/linux/assimp/bin/libassimp.so " .. libdir .. "/libassimp.so")
os.execute("cp build/linux/assimp/bin/libassimp.so.5 " .. libdir .. "/libassimp.so.5")
os.execute("cp build/linux/assimp/bin/libassimp.so.5.4.3 " .. libdir .. "/libassimp.so.5.4.3")
end
end
-- meshoptimizer -------------------------------------------------------------------------------------------------------
project "meshoptimizer"
kind "none"
if os.host() == "windows" then
os.execute("echo @TODO WINDOWS MESHOPTIMIZER")
elseif os.host() == "linux" then
if exists(libdir .. "/libmeshoptimizer.a") then
os.execute("echo Skipping meshoptimizer compilation...")
else
os.execute("mkdir -p build/linux/meshoptimizer")
os.execute("cd build/linux/meshoptimizer && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -S ../../../libs/meshoptimizer -B . && make -j" .. number_of_cores())
os.execute("cp build/linux/meshoptimizer/libmeshoptimizer.a " .. libdir .. "/libmeshoptimizer.a")
end
end
-- bullet --------------------------------------------------------------------------------------------------------------
project "bullet"
kind "none"
-- @TODO: this cmake also compiles the examples. We want to compile only the static libs.
if os.host() == "windows" then
os.execute("echo @TODO WINDOWS BULLET")
elseif os.host() == "linux" then
if exists(libdir .. "/libBulletDynamics.a") and
exists(libdir .. "/libBulletInverseDynamics.a") and
exists(libdir .. "/libBulletCollision.a") and
exists(libdir .. "/libBullet3Common.a") and
exists(libdir .. "/libBullet3Dynamics.a") and
exists(libdir .. "/libBullet3Collision.a") and
exists(libdir .. "/libBullet3Geometry.a") and
exists(libdir .. "/libBulletLinearMath.a") then
os.execute("echo Skipping bullet compilation...")
else
os.execute("mkdir -p build/linux/bullet")
os.execute("cd build/linux/bullet && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -S ../../../libs/bullet -B . && make -j" .. number_of_cores())
os.execute("cp build/linux/bullet/src/BulletDynamics/libBulletDynamics.a " .. libdir .. "/libBulletDynamics.a")
os.execute("cp build/linux/bullet/src/BulletInverseDynamics/libBulletInverseDynamics.a " .. libdir .. "/libBulletInverseDynamics.a")
os.execute("cp build/linux/bullet/src/BulletCollision/libBulletCollision.a " .. libdir .. "/libBulletCollision.a")
os.execute("cp build/linux/bullet/src/Bullet3Common/libBullet3Common.a " .. libdir .. "/libBullet3Common.a")
os.execute("cp build/linux/bullet/src/Bullet3Dynamics/libBullet3Dynamics.a " .. libdir .. "/libBullet3Dynamics.a")
os.execute("cp build/linux/bullet/src/Bullet3Collision/libBullet3Collision.a " .. libdir .. "/libBullet3Collision.a")
os.execute("cp build/linux/bullet/src/Bullet3Geometry/libBullet3Geometry.a " .. libdir .. "/libBullet3Geometry.a")
os.execute("cp build/linux/bullet/src/LinearMath/libLinearMath.a " .. libdir .. "/libBulletLinearMath.a")
end
end
-- implot --------------------------------------------------------------------------------------------------------------
project "implot"
kind "staticlib"
language "c++"
cppdialect "c++20"
targetdir (libdir)
objdir ("build/%{cfg.system}/%{prj.name}/%{cfg.buildcfg}")
includedirs { ".", "libs/implot", "libs/imgui" }
if os.host() == "windows" then
os.execute("mkdir build\\windows\\implot 2>NUL")
end
files
{
"libs/implot/implot.h",
"libs/implot/implot_internal.h",
"libs/implot/implot.cpp",
"libs/implot/implot_items.cpp",
"libs/implot/implot_demo.cpp"
}
filter "system:linux"
pic "on"
systemversion "latest"
staticruntime "on"