-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmake.lua
More file actions
477 lines (426 loc) · 14.8 KB
/
xmake.lua
File metadata and controls
477 lines (426 loc) · 14.8 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
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
set_project("fan")
set_languages("cxx26")
if is_plat("wasm") then
add_cxxflags("-pthread", "-DFAN_WASM", {force = true})
add_ldflags("-s USE_GLFW=3", "-s ASYNCIFY=1", "-pthread", "-s PTHREAD_POOL_SIZE=4", {force = true})
else
option("compiler") set_default("clang") option_end()
if get_config("compiler") == "gcc" then
set_toolchains("gcc")
else
set_toolchains("clang")
end
end
rule("mode.mode_none")
rule_end()
add_rules("mode.mode_none", "mode.debug", "mode.release")
rule("mode.asan")
on_load(function (target)
target:set("optimize", "none")
target:set("symbols", "debug")
target:add("cxxflags", "-fsanitize=address", "-fno-omit-frame-pointer")
target:add("ldflags", "-fsanitize=address")
target:add("defines", "_DEBUG=3")
end)
rule_end()
if is_mode("asan") then
add_rules("mode.asan")
end
set_defaultmode("mode_none")
if is_mode("mode_none") then
add_defines("_DEBUG=3")
end
if is_mode("release") then
set_optimize("fastest")
add_cxflags("-O3", {force = true})
add_ldflags("-s", {force = true})
add_defines("NDEBUG")
add_defines("_DEBUG=0")
elseif is_mode("debug") then
set_optimize("none")
set_symbols("debug")
add_cxflags("-g", "-gdwarf-4", "-fno-inline", "-fno-inline-functions", {force = true})
add_defines("_DEBUG=3")
end
option("FAN_2D") set_default(true) option_end()
option("FAN_GUI") set_default(false) option_end()
option("FAN_PHYSICS_2D") set_default(true) option_end()
option("FAN_JSON") set_default(true) option_end()
option("FAN_3D") set_default(false) option_end()
option("FAN_OPENGL") set_default(true) option_end()
option("FAN_VULKAN") set_default(false) option_end()
option("FAN_FMT") set_default(false) option_end()
option("FAN_WAYLAND_SCREEN") set_default(false) option_end()
option("FAN_NETWORK") set_default(false) option_end()
option("FAN_AUDIO") set_default(false) option_end()
option("FAN_USE_STD_MODULE")
set_default(false)
set_showmenu(true)
add_defines("FAN_USE_STD_MODULE")
option_end()
if has_config("FAN_USE_STD_MODULE") then
set_policy("build.c++.modules.std", true)
end
option("main") set_default("examples/engine_demos/engine_demo.cpp") option_end()
if has_config("FAN_OPENGL") then add_defines("FAN_OPENGL") end
if has_config("FAN_2D") then add_defines("FAN_2D") end
if has_config("FAN_GUI") then add_defines("FAN_GUI") end
if has_config("FAN_JSON") then add_defines("FAN_JSON") end
if has_config("FAN_3D") then add_defines("fan_3D") end
if has_config("FAN_PHYSICS_2D") then add_defines("FAN_PHYSICS_2D") end
if has_config("FAN_VULKAN") then add_defines("FAN_VULKAN") end
if has_config("FAN_NETWORK") then add_defines("FAN_NETWORK") end
if has_config("FAN_FMT") then add_defines("FAN_FMT") end
if has_config("FAN_AUDIO") then add_defines("FAN_AUDIO") end
add_includedirs(".", {public = true})
local llvm_sdk = "/usr/lib/llvm"
if type(get_config) == "function" then
local cfgsdk = get_config("sdk")
if cfgsdk and cfgsdk ~= "" then llvm_sdk = cfgsdk end
end
local is_gcc = get_config("compiler") == "gcc"
if not is_gcc and not is_plat("wasm") then
add_cxxflags("-stdlib=libstdc++", {force = true})
end
set_policy("build.c++.modules.std", true)
set_policy("build.c++.modules.reuse", true)
add_cxxflags("-pthread", {force = true})
local common_flags = {
"-Wall", "-Wextra",
"-Wno-unused-variable",
"-Wno-unused-parameter",
"-Wno-unused-function",
"-Wno-invalid-offsetof",
"-Wno-missing-field-initializers",
"-Wno-sign-compare",
"-Wno-unused-but-set-parameter",
"-Wno-unused-value",
"-Wno-padded",
"-fsized-deallocation",
}
local clang_only_flags = {
"-ferror-limit=20",
"-Wno-include-angled-in-module-purview",
"-fmacro-backtrace-limit=0",
"-Wno-shift-op-parentheses",
"-Wno-int-to-void-pointer-cast",
"-Wno-bitwise-op-parentheses",
}
local gcc_only_flags = {
"-fmax-errors=20",
}
add_cxxflags(table.unpack(common_flags), {force = true})
if is_gcc then
add_cxxflags(table.unpack(gcc_only_flags), {force = true})
add_cxxflags("-fmodules-ts", "-fno-module-lazy", {force = true})
else
add_cxxflags(table.unpack(clang_only_flags), {force = true})
end
if has_config("FAN_GUI") then
add_defines(
"IMGUI_IMPL_OPENGL_LOADER_CUSTOM",
"IMGUI_DEFINE_MATH_OPERATORS",
"IMGUI_DISABLE_SSE",
"IMGUI_ENABLE_FREETYPE",
"IMGUI_ENABLE_FREETYPE_LUNASVG",
"STBI_NO_SIMD"
)
end
local module_files = {
"fan/reflection.ixx",
"fan/types/types.ixx", "fan/types/color.ixx", "fan/types/vector.ixx",
"fan/types/quaternion.ixx", "fan/types/matrix.ixx", "fan/types/fstring.ixx",
"fan/types/compile_time_string.ixx", "fan/memory/memory.ixx", "fan/math/math.ixx",
"fan/time.ixx", "fan/mpl.ixx", "fan/utility.ixx", "fan/formatter.ixx",
"fan/print_error.ixx", "fan/print.ixx", "fan/random.ixx", "fan/log_dispatcher.ixx",
"fan/process.ixx", "fan/io/io_types.ixx", "fan/io/directory.ixx", "fan/io/file.ixx",
"fan/physics/collision/rectangle.ixx", "fan/physics/collision/triangle.ixx",
"fan/physics/collision/circle.ixx", "fan/physics/physics_types.ixx",
"fan/graphics/common_types.ixx", "fan/graphics/camera.ixx", "fan/graphics/image_load.ixx",
"fan/graphics/webp.ixx", "fan/graphics/stb.ixx", "fan/graphics/common_context.ixx",
"fan/graphics/opengl/gl_core.ixx", "fan/graphics/opengl/uniform_block.ixx",
"fan/texture_pack/tp0.ixx", "fan/graphics/2D/shapes_types.ixx",
"fan/graphics/2D/culling.ixx", "fan/graphics/2D/shapes.ixx",
"fan/graphics/audio_subsystem.ixx", "fan/graphics/physics_subsystem.ixx",
"fan/graphics/input_subsystem.ixx", "fan/graphics/loco.ixx", "fan/graphics/graphics.ixx",
"fan/graphics/file_dialog.ixx", "fan/graphics/2D/algorithm/raycast_grid.ixx",
"fan/pathfind.ixx", "fan/spatial.ixx", "fan/ecs.ixx", "fan/window/window.ixx",
"fan/window/input_common.ixx", "fan/window/input.ixx", "fan/window/input_action.ixx",
"fan/audio/audio.ixx", "fan/event/event_types.ixx", "fan/event/event.ixx",
"fan/noise.ixx", "fan/graphics/gameplay/gameplay_types.ixx",
"fan/graphics/gameplay/gameplay.ixx", "fan/crypto.ixx", "fan/graphics/gui/console.ixx",
"fan/graphics/stb_raw.ixx", "fan/graphics/webp_raw.ixx", "fan/event/uv_raw.ixx",
"fan/graphics/gui/tilemap_editor/loader.ixx", "fan/graphics/gui/tilemap_editor/renderer0.ixx"
}
if has_config("FAN_WAYLAND_SCREEN") then table.insert(module_files, "fan/video/screen_codec.ixx") end
if has_config("FAN_JSON") then table.insert(module_files, "fan/types/json.ixx") end
if has_config("FAN_FMT") then table.insert(module_files, "fan/fmt.ixx") end
if has_config("FAN_GUI") then
table.insert(module_files, "fan/graphics/gui/gui_base.ixx")
table.insert(module_files, "fan/graphics/gui/gui_input.ixx")
table.insert(module_files, "fan/graphics/gameplay/items.ixx")
table.insert(module_files, "fan/graphics/gui/gameplay/equipment.ixx")
table.insert(module_files, "fan/graphics/gui/gameplay/hotbar.ixx")
table.insert(module_files, "fan/graphics/gui/gameplay/inventory.ixx")
table.insert(module_files, "fan/graphics/gui/gameplay/inventory_hotbar.ixx")
table.insert(module_files, "fan/graphics/gui/gameplay/drag_drop.ixx")
table.insert(module_files, "fan/graphics/gui/gameplay/slot_renderer.ixx")
table.insert(module_files, "fan/graphics/gui/text_logger.ixx")
table.insert(module_files, "fan/graphics/gui/gui_types.ixx")
table.insert(module_files, "fan/graphics/gui/gui.ixx")
table.insert(module_files, "fan/graphics/gui/settings_menu.ixx")
table.insert(module_files, "fan/graphics/gui/keybinds_menu.ixx")
end
if has_config("FAN_NETWORK") then
table.insert(module_files, "fan/network/network.ixx")
table.insert(module_files, "fan/graphics/graphics_network.ixx")
end
if has_config("FAN_PHYSICS_2D") then
table.insert(module_files, "fan/physics/b2_integration.ixx")
table.insert(module_files, "fan/physics/physics_common_context.ixx")
table.insert(module_files, "fan/graphics/physics_shapes.ixx")
end
if has_config("FAN_3D") then
table.insert(module_files, "fan/graphics/opengl/3D/objects/fms.ixx")
table.insert(module_files, "fan/graphics/opengl/3D/objects/model.ixx")
end
table.insert(module_files, "fan/fan.ixx")
function find_impl_files(module_list)
local impl_files = {}
for _, module_path in ipairs(module_list) do
local dir = path.directory(module_path)
local name = path.basename(module_path)
local impl_path = path.join(dir, name .. "_impl.cpp")
if os.isfile(impl_path) then
table.insert(impl_files, impl_path)
end
end
return impl_files
end
local impl_files = find_impl_files(module_files)
if os.isfile("fan/graphics/2D/algorithm/AStar.cpp") then
table.insert(impl_files, "fan/graphics/2D/algorithm/AStar.cpp")
end
if has_config("FAN_GUI") then
target("imgui")
set_kind("static")
add_rules("c++.unity_build", {batchsize = 16})
if not is_gcc and not is_plat("wasm") then
add_cxxflags("-stdlib=libstdc++", {force = true})
add_ldflags("-stdlib=libstdc++", "-lstdc++", {force = true})
end
add_includedirs(
"fan/imgui",
"fan/imgui/misc/freetype",
"third_party/fan/include",
"third_party/fan/include/freetype2"
)
on_load(function (target)
if target:is_plat("linux") then
import("lib.detect.find_tool")
local pkg_config = find_tool("pkg-config")
if pkg_config then
local result = os.iorunv("pkg-config", {"--cflags-only-I", "glib-2.0"})
if result then
for _, path in ipairs(result:split("%s+")) do
if path:startswith("-I") then
target:add("includedirs", path:sub(3))
end
end
end
end
end
end)
add_files(
"fan/imgui/imgui.cpp",
"fan/imgui/imgui_draw.cpp",
"fan/imgui/imgui_widgets.cpp",
"fan/imgui/imgui_tables.cpp",
"fan/imgui/imgui_impl_glfw.cpp",
"fan/imgui/implot_items.cpp",
"fan/imgui/implot.cpp",
"fan/imgui/text_editor.cpp",
"fan/imgui/misc/freetype/imgui_freetype.cpp",
"fan/imgui/ImGuizmo.cpp"
)
add_files("fan/imgui/imgui_impl_opengl3.cpp", {unity_ignored = true})
if has_config("FAN_VULKAN") then
add_files("fan/imgui/imgui_impl_vulkan.cpp")
end
if has_config("FAN_3D") and has_config("FAN_GUI") then
add_files("fan/imgui/ImGuizmo.cpp")
end
add_linkdirs("third_party/fan/lib")
add_links("freetype", "lunasvg")
target_end()
end
if not is_plat("wasm") then
target("nfd")
set_kind("static")
add_rules("c++.unity_build", {batchsize = 8})
if is_plat("linux") then
add_files(
"fan/nativefiledialog/nfd_common.c",
"fan/nativefiledialog/nfd_gtk.c"
)
elseif is_plat("windows") then
add_files(
"fan/nativefiledialog/nfd_common.c",
"fan/nativefiledialog/nfd_win.cpp"
)
end
on_load(function (target)
if target:is_plat("linux") then
import("lib.detect.find_tool")
local pkg_config = find_tool("pkg-config")
if pkg_config then
local cflags = os.iorunv("pkg-config", {"--cflags-only-I", "gtk+-3.0"})
if cflags then
for _, path in ipairs(cflags:split("%s+")) do
if path:startswith("-I") then
target:add("includedirs", path:sub(3))
end
end
end
local libs = os.iorunv("pkg-config", {"--libs", "gtk+-3.0"})
if libs then
for _, lib in ipairs(libs:split("%s+")) do
if lib:startswith("-l") then
target:add("links", lib:sub(3))
end
end
end
end
end
end)
target_end()
end
target("a.exe")
set_kind("binary")
add_rules("c++.build.modules")
if is_plat("wasm") then
set_extension(".html")
add_ldflags("--preload-file shaders -s MAX_WEBGL_VERSION=2", "-s MIN_WEBGL_VERSION=2", {force = true})
add_linkdirs("third_party/fan/lib/wasm")
add_links("uv_wasm", "webp_wasm")
end
if has_config("FAN_GUI") then
add_deps("imgui")
end
if not is_plat("wasm") then
add_deps("nfd")
end
for _, file in ipairs(module_files) do
if file == "fan/reflection.ixx" then
add_files(file, {cxxflags = "-freflection"})
else
add_files(file)
end
end
for _, impl in ipairs(impl_files) do
add_files(impl)
end
if not is_plat("wasm") then
add_files("third_party/fan/glad.c")
end
local main_file = get_config("main")
set_policy("check.auto_ignore_flags", false)
add_files("main.cpp", { cxxflags = "-freflection" })
add_includedirs(".", "third_party/fan/include", {public = true})
add_linkdirs("third_party/fan/lib")
if is_plat("linux") then
add_links(
"webp", "glfw", "X11", "opus", "pulse-simple",
"uv", "GL", "ssl", "crypto", "png", "z", "curl"
)
if has_config("FAN_FMT") then add_links("fmt") end
if has_config("FAN_GUI") then add_links("freetype", "lunasvg") end
if has_config("FAN_PHYSICS_2D") then
add_ldflags("-Wl,--whole-archive", "third_party/fan/lib/libbox2d.a", "-Wl,--no-whole-archive", {force = true})
end
if has_config("FAN_3D") then add_links("assimp") end
if has_config("FAN_VULKAN") then
add_packages("vulkansdk")
add_links("shaderc_shared")
end
if has_config("FAN_WAYLAND_SCREEN") then
add_links("wayland-client", "pipewire-0.3", "dbus-1")
add_links("avcodec", "avutil", "swscale")
end
elseif is_plat("windows") then
add_links("opengl32")
add_linkdirs("lib/GLFW", "lib/GLEW", "lib/libuv", "lib/libwebp", "lib/opus", "lib/openssl")
add_links(
"glfw3_mt", "glew32s", "uv_a", "libwebp",
"opus", "libssl", "libcrypto"
)
if has_config("FAN_GUI") then
add_linkdirs("lib/freetype", "lib/lunasvg")
add_links("freetype", "lunasvg")
end
if has_config("FAN_PHYSICS_2D") then
add_linkdirs("lib/box2d")
add_links("box2d")
end
if has_config("FAN_3D") then
add_linkdirs("C:/Program Files/Assimp/lib/x64")
add_links("assimp-vc143-mt")
end
if has_config("FAN_VULKAN") then
add_packages("vulkansdk")
add_links("shaderc_shared")
end
if has_config("FAN_WAYLAND_SCREEN") then
add_linkdirs("lib/libx264", "lib/openh264")
add_links(
"DXGI", "D3D11", "libx264",
"welsdcore", "welsecore", "WelsDecPlus",
"WelsEncPlus", "WelsVP"
)
end
end
on_load(function (target)
if target:is_plat("linux") then
import("lib.detect.find_tool")
if has_config("FAN_GUI") then
local pkg_config = find_tool("pkg-config")
if pkg_config then
local libs = os.iorunv("pkg-config", {"--libs", "gtk+-3.0"})
if libs then
for _, lib in ipairs(libs:split("%s+")) do
if lib:startswith("-l") then
target:add("links", lib:sub(3))
end
end
end
end
end
if find_tool("mold") then
target:add("ldflags", "-fuse-ld=mold", {force = true})
elseif find_tool("gold") then
target:add("ldflags", "-fuse-ld=gold", {force = true})
end
end
end)
target_end()
local marker = "fan_modules_info_printed.flag"
after_load(function (target)
if target:name() ~= "fan_modules" then
return
end
if os.isfile(marker) then
return
end
io.writefile(marker, "1")
print("Module files: " .. #module_files)
print("Implementation files: " .. #impl_files)
if #impl_files > 0 then
print("Found implementations:")
for i = 1, math.min(5, #impl_files) do
print(" - " .. impl_files[i])
end
if #impl_files > 5 then
print(" ... and " .. (#impl_files - 5) .. " more")
end
end
end)