-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxmake.lua
More file actions
230 lines (183 loc) · 6.78 KB
/
Copy pathxmake.lua
File metadata and controls
230 lines (183 loc) · 6.78 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
-- official package from a pull request
includes("packages/s/soloud/xmake.lua")
includes("packages/w/wren/xmake.lua")
-- fix from official package because in wasm pthread option is force set to 0
includes("packages/l/libsdl3/xmake.lua")
-- official package from my repo with custom settings
includes("packages/h/haclog/xmake.lua")
add_rules("mode.debug", "mode.release")
if is_plat("windows") then
local msvcRuntime = is_mode("debug") and "MTd" or "MT"
set_runtimes(msvcRuntime)
end
local asset_pipeline_python = is_host("windows") and "python" or "python3"
option("tracy")
set_default(false)
set_showmenu(true)
set_description("Enable Tracy profiler instrumentation")
option_end()
option("embed_assets")
set_default(is_plat("wasm"))
set_showmenu(true)
set_description("Generate embedded assets before building game (auto-enabled for wasm)")
option_end()
if is_arch("x64") then
add_defines("GRNGAME_X64")
end
if has_config("tracy") then
add_requires("tracy")
end
local suffix = ""
if has_config("embed_assets") then
suffix = "embedded"
end
if is_plat("wasm") then
add_requireconfs("**", {
configs = {
cflags = {"-pthread", "-matomics", "-mbulk-memory"},
cxxflags = {"-pthread", "-matomics", "-mbulk-memory"},
ldflags = {"-pthread"}
}
})
end
-- render + input
add_requires("libsdl3", {version = "3.4.0"}, {configs = {shared = false}})
add_requires("libsdl3_image", {version = "3.2.0"}, {configs = {shared = false}})
add_requires("libsdl3_ttf", {version = "3.2.2"}, {configs = {shared = false, freetype = false}, system = false})
-- maths
add_requires("klib", {version = "2024.06.03"}, {configs = {shared = false}})
add_requires("cglm", {version = "v0.9.6"}, {configs = {shared = false}})
-- song
add_requires("soloud pr402", {configs = {shared = false, cxflags = is_arch("arm64") and "-DDR_MP3_NO_SIMD" or nil }})
-- folder
add_requires("tinydir", {version = "1.2.6"}, {configs = {shared = false}})
if not is_plat("wasm") then
add_requires("efsw", {version = "1.6.2"},{configs = {shared = false}, system = false})
end
-- scripting
add_requires("wren Map-api", {version = "Map-api"}, {configs = {shared = false}})
-- simd
add_requires("highway", {version = "1.3.0"}, {configs = {shared = false}})
-- files
add_requires("sqlite3", {version = "3-3.53.0+0"}, {configs = {shared = false}, system = false})
add_requires("cjson",{configs = {shared = false}})
--logs
if not is_plat("wasm") then
add_requires("haclog", {version = "color_fix"}, {configs = {shared = false}})
end
set_warnings("all", "extra")
target("GrnGame")
add_defines("WITH_SDL3_STATIC")
set_languages("c23", "cxx20")
set_kind("static")
add_files("grngame/**.c", "grngame/**.cpp")
remove_files("grngame/assets/embedded_main.c")
add_headerfiles("grngame/**.h")
add_includedirs(".", {public = true})
-- packages
add_packages("libsdl3",
"libsdl3_image", "libsdl3_ttf",
"klib", "cglm", "soloud", "tinydir",
"wren", "freetype", "sqlite3", "highway", "Libimagequant", "cjson","haclog",
{public = true}
)
if not is_plat("wasm") then
add_packages( "efsw","haclog", {public = true})
end
if has_config("tracy") then
add_packages("tracy", {public = true})
end
-- platform defines
if is_plat("linux") then
add_defines("GRNGAME_LINUX", "_GNU_SOURCE", {public = true})
add_cxxflags("-frtti", "-fexceptions")
elseif is_plat("windows") then
add_defines("GRNGAME_WINDOWS", {public = true})
elseif is_plat("macosx") then
add_defines("GRNGAME_MACOS", {public = true})
end
-- mode defines
if is_mode("debug") then
add_defines("GRNGAME_DEBUG", {public = true})
elseif is_mode("release") then
add_defines("GRNGAME_RELEASE", {public = true})
if not is_plat("macosx") then
set_policy("build.optimization.lto", true)
end
end
if has_config("embed_assets") then
add_defines("GRNGAME_EMBED_ASSETS", {public = true})
end
add_defines("CGLM_USE_ANONYMOUS_STRUCT=1", {public = true})
if has_config("tracy") then
add_defines("TRACY_ENABLE", {public = true})
end
if not (has_config("embed_assets") or is_plat("wasm")) then
add_defines("GRNGAME_HOT_RELOAD_ENABLE")
end
if is_plat("wasm") then
add_defines("GRNGAME_WASM", {public = true})
add_ldflags(
"--shell-file", "grngame/web/shell.html",
"-sFORCE_FILESYSTEM=1",
"-sASYNCIFY",
"-sALLOW_MEMORY_GROWTH=0",
"-sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency",
"-pthread",
{public = true, force = true}
)
end
local plat = get_config("plat") or os.host()
local arch = get_config("arch") or os.arch()
local mode = get_config("mode") or "release"
if not is_plat("wasm") then
target("Embedded-" .. plat .. "-" .. arch .. "-" .. mode)
set_languages("c17", "cxx17")
set_kind("binary")
set_targetdir(path.join("$(builddir)", "Embedded"))
add_files("grngame/assets/embedded_main.c")
add_headerfiles("grngame/**.h")
add_deps("GrnGame")
target("EmbeddedBenchmark-" .. plat .. "-" .. arch .. "-" .. mode)
set_languages("c17", "cxx17")
set_kind("binary")
set_targetdir(path.join("$(builddir)", "EmbeddedBenchmark"))
add_files("benchmark/embedded/main.c")
add_headerfiles("grngame/**.h")
add_deps("GrnGame")
end
target("Runtime-" .. plat .. "-" .. arch .. "-" .. mode .. suffix)
set_languages("c17", "cxx17")
set_kind("binary")
set_targetdir(path.join("$(builddir)", "Runtime"))
add_files("runtime/main.c")
add_deps("GrnGame")
if not is_plat("wasm") then
add_deps("Embedded-" .. plat .. "-" .. arch .. "-" .. mode)
end
local test_target = "tests/json"
target(test_target)
set_kind("phony")
on_run(function (target)
import("lib.detect.find_tool")
local python = find_tool("python") or find_tool("python3")
assert(python, "Python not found!")
local target_name = target:name()
os.execv(python.program, {
"scripts/asset_pipeline.py",
target_name,
path.join("build", target_name)
})
local plat = get_config("plat")
local arch = get_config("arch")
local mode = get_config("mode") or "release"
local suffix = ""
local ext = is_host("windows") and ".exe" or ""
local runtime_path = path.join(
"build",
"tests",
"json",
"Runtime-" .. plat .. "-" .. arch .. "-" .. mode .. suffix .. ext
)
os.execv(runtime_path)
end)