-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmake.lua
More file actions
433 lines (402 loc) · 16.6 KB
/
xmake.lua
File metadata and controls
433 lines (402 loc) · 16.6 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
-- This xmake.lua build file is designed as a replacement of
-- Makefile or CMakeLists.txt of standard hashlink releases.
add_rules("mode.debug", "mode.release")
-- Windows: Override default /MT following official project settings.
if is_plat("windows") then
set_runtimes("MD")
end
-- ===================================================================
-- Common dependendies
--
-- These dependencies are downloaded and built with hashlink. Our goal
-- is to make sure our built binaries can be copied and dropped to any
-- machines. Thus, our build don't use any OS provided dependencies.
--
-- We apply different strategies on different Operating systems:
--
-- Linux -
-- We maintain all dependencies ourselves, as static libraries.
-- This is to make sure we eliminate any possible version
-- mismatching issue in libstdc++.so and libgcc_s.so. We also fixed some
-- issues as below:
--
-- 1. libsndio: Official build has only static library. We provide our
-- own xmake package.
-- 2. openal-soft: Hashlink has a trick https://github.com/HaxeFoundation/hashlink/issues/636
-- that requires shared link. I have applied a private fix.
-- EDITED 2023-12-19: By defining our own openal-soft-allinone
-- package, the dependency to libsndio is removed.
-- 3. OpenGL - We depend on libglvnd to dispatch real calls to system.
-- The graphics system can't be included.
--
-- [TBD] On macOS, we use minimal set of system Frameworks.
--
-- [TBD] On Windows, we maintain all dependencies ourselves, as static
-- libraries. This is because many dependencies are not installed by
-- default on Windows.
--
-- ===================================================================
add_repositories("local-repo deps")
add_requires("mikktspace 2020.03.26", { system = false })
add_requires("libvorbis 1.3.7", { system = false })
add_requires("libpng v1.6.40", { system = false })
add_requires("minimp3 2021.05.29", { system = false })
add_requires("libjpeg-turbo 2.1.4", { system = false })
add_requires("libuv v1.46.0", { system = false })
add_requires("mbedtls 2.28.3", { system = false })
add_requires("sqlite3 3.43.0+200", { system = false })
add_requires("openal-soft-alsa 1.23.1", { alias = "openal", system = false, configs = { shared = true } })
add_requires("libsdl 2.28.5", { system = false, configs = { shared = false, sdlmain = false } })
add_requireconfs("openal-soft-alsa.**", { system = false, configs = { shared = false } })
add_requireconfs("libvorbis.**", { system = false, configs = { shared = false } })
add_requireconfs("libpng.**", { system = false, configs = { shared = false } })
-- ===================================================================
-- OS-specific dependencies
--
-- The following dependencies are expected to be provided by Opearting
-- systems, as they directly rely on infrastructure provided by
-- Operating System.
-- ===================================================================
if is_plat("linux") then
add_requires("libglvnd 1.3.4", { system = false })
elseif is_plat("macosx") then
add_frameworks("CoreFoundation", "Security", "OpenGL")
elseif is_plat("windows") then
-- No special requirements for now.
end
--
-- NOTE for Arch/Manjaro
--
-- To build the project in Arch/Manjaro system, please add a
-- self-pointing symbolic link fir path /usr/include/X11:
--
-- ln -s /usr/include/X11 /usr/include/X11/X11.
--
-- This is to fix a bug in SDL2's cmake/sdlcheck.cmake. It hardcodes a
-- set of search path to find Xext.h. However it does not hardcodes
-- /usr/include, which is where Arch/Manjaro saves Xext.h.
--
-- NOTE for macos
-- Appears we need to make sure system installs glibtoolize binary via
-- ``brew install libtool``, in order to build libuv under macOS.
--
-- ===================================================================
-- Utility functions to define compile options.
-- ===================================================================
function binary_link_flags(target)
if target:is_plat("linux") or target:is_plat("macosx") then
target:add("ldflags", "-lm")
if target:is_plat("linux") then
target:add(ldflags, "-ldl")
target:add("rpathdirs", "$ORIGIN")
target:add("ldflags", "-Wl,--no-undefined")
target:add("ldflags", "-static-libgcc")
target:add("ldflags", "-static-libstdc++")
end
end
end
function libhl_link_flags(target)
if target:is_plat("linux") or target:is_plat("macosx") then
target:add("shflags", "-lm")
if target:is_plat("linux") then
target:add("rpathdirs", "$ORIGIN")
target:add("shflags", "-Wl,--export-dynamic")
target:add("shflags", "-Wl,--no-undefined")
target:add("shflags", "-static-libgcc")
target:add("shflags", "-static-libstdc++")
end
if target:is_plat("macosx") then
target:add("shflags", "-Wl,-export_dynamic")
end
end
if target:is_plat("windows") then
target:add("shflags", "/MANIFEST")
target:add("shflags", "/manifest:embed")
target:add("shflags", "/SUBSYSTEM:WINDOWS")
target:add("shflags", "/TLBID:1")
target:add("shflags", "/DYNAMICBASE:NO")
target:add("shflags", "/NXCOMPAT:NO")
end
end
function module_link_flags(target)
if target:is_plat("linux") or target:is_plat("macosx") then
target:add("shflags", "-lm")
if target:is_plat("linux") then
target:add("rpathdirs", "$ORIGIN")
target:add("shflags", "-Wl,--export-dynamic")
target:add("shflags", "-Wl,--no-undefined")
target:add("shflags", "-static-libgcc")
target:add("shflags", "-static-libstdc++")
end
if target:is_plat("macosx") then
target:add("shflags", "-Wl,-export_dynamic")
end
end
if target:is_plat("windows") then
target:add("shflags", "/MANIFEST")
target:add("shflags", "/manifest:embed")
target:add("shflags", "/SUBSYSTEM:WINDOWS")
target:add("shflags", "/TLBID:1")
target:add("shflags", "/DYNAMICBASE")
target:add("shflags", "/NXCOMPAT")
end
end
function compile_flags(target)
if target:is_plat("linux") or target:is_plat("macosx") then
-- Build location specific
target:add("cflags", "-Ihashlink/src")
target:add("defines", "openal_soft")
-- Build location independent settings
target:add("cflags", "-Wall")
target:add("cflags", "-O3")
target:add("cflags", "-msse2")
target:add("cflags", "-mfpmath=sse")
target:add("cflags", "-std=c11")
target:add("cxflags", "-fpic")
if target:is_plat("linux") then
target:add("cxflags", "-pthread")
target:add("cxflags", "-fno-omit-frame-pointer")
target:add("cxflags", "-ftls-model=global-dynamic")
end
if target:is_plat("macosx") then
end
end
if target:is_plat("windows") then
target:add("defines", "_WINDOWS")
target:add("defines", "_WINDLL")
target:add("defines", "_USRDLL")
target:add("defines", "UNICODE")
target:add("defines", "_UNICODE")
-- for glext.h
target:add("includedirs", "hashlink/include/gl")
target:add("cxflags", "/W3")
target:add("cxflags", "/diagnostics:column")
target:add("cxflags", "/Gm-")
target:add("cxflags", "/EHsc")
target:add("cxflags", "/fp:precise")
target:add("cxflags", "/Zc:wchar_t")
target:add("cxflags", "/Zc:forScope")
target:add("cxflags", "/Zc:inline")
target:add("cxflags", "/external:W3")
target:add("cxflags", "/GS")
target:add("cxflags", "/Gd")
end
end
-- It's a utility function to combine multiple actions on same xmake hook.
function chain_actions(...)
local all_args = { ... }
return function(target)
for i, fun in ipairs(all_args) do
fun(target)
end
end
end
-- ===================================================================
-- Project build settings
-- ===================================================================
target("libhl")
set_kind("shared")
if is_plat("windows") then
-- Avoid naming conflict when building hl.lib: Both hl.exe and
-- hl.dll will have same export library name.
set_basename("libhl")
else
set_basename("hl")
end
add_defines("LIBHL_EXPORTS")
add_includedirs("hashlink/src", "hashlink/include/pcre")
add_files("hashlink/src/std/array.c",
"hashlink/src/std/buffer.c",
"hashlink/src/std/bytes.c",
"hashlink/src/std/cast.c",
"hashlink/src/std/date.c",
"hashlink/src/std/error.c",
"hashlink/src/std/debug.c",
"hashlink/src/std/file.c",
"hashlink/src/std/fun.c",
"hashlink/src/std/maps.c",
"hashlink/src/std/math.c",
"hashlink/src/std/obj.c",
"hashlink/src/std/random.c",
"hashlink/src/std/regexp.c",
"hashlink/src/std/socket.c",
"hashlink/src/std/string.c",
"hashlink/src/std/sys.c",
"hashlink/src/std/track.c",
"hashlink/src/std/types.c",
"hashlink/src/std/ucs2.c",
"hashlink/src/std/thread.c",
"hashlink/src/std/process.c")
-- pcre2 can't be easily configured via xmake package because it
-- requires a config.h file with a lot of configurations.
add_defines("HAVE_CONFIG_H", "PCRE2_CODE_UNIT_WIDTH=16")
add_files("hashlink/include/pcre/pcre2_auto_possess.c",
"hashlink/include/pcre/pcre2_chartables.c",
"hashlink/include/pcre/pcre2_compile.c",
"hashlink/include/pcre/pcre2_config.c",
"hashlink/include/pcre/pcre2_context.c",
"hashlink/include/pcre/pcre2_convert.c",
"hashlink/include/pcre/pcre2_dfa_match.c",
"hashlink/include/pcre/pcre2_error.c",
"hashlink/include/pcre/pcre2_extuni.c",
"hashlink/include/pcre/pcre2_find_bracket.c",
"hashlink/include/pcre/pcre2_jit_compile.c",
"hashlink/include/pcre/pcre2_maketables.c",
"hashlink/include/pcre/pcre2_match_data.c",
"hashlink/include/pcre/pcre2_match.c",
"hashlink/include/pcre/pcre2_newline.c",
"hashlink/include/pcre/pcre2_ord2utf.c",
"hashlink/include/pcre/pcre2_pattern_info.c",
"hashlink/include/pcre/pcre2_script_run.c",
"hashlink/include/pcre/pcre2_serialize.c",
"hashlink/include/pcre/pcre2_string_utils.c",
"hashlink/include/pcre/pcre2_study.c",
"hashlink/include/pcre/pcre2_substitute.c",
"hashlink/include/pcre/pcre2_substring.c",
"hashlink/include/pcre/pcre2_tables.c",
"hashlink/include/pcre/pcre2_ucd.c",
"hashlink/include/pcre/pcre2_valid_utf.c",
"hashlink/include/pcre/pcre2_xclass.c")
add_files("hashlink/src/gc.c")
if is_plat("macosx") then
add_includedirs("hashlink/include")
add_files("hashlink/include/mdbg/mdbg.c",
"hashlink/include/mdbg/mach_excServer.c",
"hashlink/include/mdbg/mach_excUser.c")
end
if is_plat("windows") then
add_links("user32", "ws2_32")
end
on_load(chain_actions(compile_flags, libhl_link_flags))
-----------------------------------------------------------------
-- Main executable
-----------------------------------------------------------------
-- Used by hl target to copy executable and include files. Note that due
-- to some restriction of xmake (2.8.5), we can't use chain_actions
-- because os.cp becomes unavailable when passing from chain_actions()
-- to next level.
function copy_include_and_executable(target)
local hl_install = path.join(target:installdir(), "include", "hl.h")
print("[after install] copy hashlink/src/hl.h to " .. hl_install)
os.cp("hashlink/src/hl.h", hl_install)
local hlc_install = path.join(target:installdir(), "include", "hlc.h")
print("[after install] copy hashlink/src/hlc.h to " .. hlc_install)
os.cp("hashlink/src/hlc.h", hlc_install)
local main_install = path.join(target:installdir(), "include", "hlc_main.c")
print("[after install] copy hashlink/src/hlc_main.c to " .. main_install)
os.cp("hashlink/src/hlc_main.c", main_install)
local bin_from = path.join(target:installdir(), "bin", target:filename())
local bin_install = path.join(target:installdir(), "lib", target:filename())
print("[after install] copy " .. target:filename() .. " to " .. bin_install)
os.cp(bin_from, bin_install)
end
target("hl")
set_kind("binary")
add_includedirs("hashlink/src")
add_files("hashlink/src/code.c",
"hashlink/src/jit.c",
"hashlink/src/main.c",
"hashlink/src/module.c",
"hashlink/src/debugger.c",
"hashlink/src/profile.c")
add_deps("libhl")
if is_plat("windows") then
add_links("user32")
end
on_load(chain_actions(compile_flags, binary_link_flags))
after_install(copy_include_and_executable)
-----------------------------------------------------------------
-- Below are Hashlink's built-in modules. Note that they also needs
-- haxelib install commands to get Haxe interface, in order to access
-- them.
-----------------------------------------------------------------
target("fmt")
set_kind("shared")
set_prefixname("")
set_extension(".hdll")
add_includedirs("hashlink/src")
add_files("hashlink/libs/fmt/*.c")
add_deps("libhl")
add_packages("mikktspace", "minimp3", "libvorbis", "libpng", "libjpeg-turbo")
on_load(chain_actions(compile_flags, module_link_flags))
target("ui")
set_kind("shared")
set_prefixname("")
set_extension(".hdll")
add_includedirs("hashlink/src")
add_files("hashlink/libs/ui/ui_stub.c")
add_deps("libhl")
on_load(chain_actions(compile_flags, module_link_flags))
target("uv")
set_kind("shared")
set_prefixname("")
set_extension(".hdll")
add_includedirs("hashlink/src")
add_files("hashlink/libs/uv/*.c")
add_packages("libuv")
add_deps("libhl")
on_load(chain_actions(compile_flags, module_link_flags))
target("sqlite")
set_kind("shared")
set_prefixname("")
set_extension(".hdll")
add_includedirs("hashlink/src")
add_files("hashlink/libs/sqlite/*.c")
add_packages("sqlite3")
add_deps("libhl")
on_load(chain_actions(compile_flags, module_link_flags))
target("ssl")
-- Building SSL on mbedtls on Windows is disabled due to a lack of
-- correct approach to configure threading model.
-- MbedTLS2.x supports only pthread threading, on Windows it
-- requires we provide our own mbedtls_threading_mutex_t data
-- structure and enabled MBEDTLS_THREADING_ALT macro. However, the
-- macro must be defined in the config.h of mbedtls package. That
-- means, the current xmake can't correctly configure Windows.
--
-- I need to think of a correct approach to solve it. Before I have
-- a solution, let's disable "ssl" module for now.
if is_plat("windows") then
set_enabled(false)
add_links("crypt32")
end
set_kind("shared")
set_prefixname("")
set_extension(".hdll")
add_includedirs("hashlink/src")
add_files("hashlink/libs/ssl/ssl.c")
add_packages("mbedtls")
add_deps("libhl")
on_load(chain_actions(compile_flags, module_link_flags))
target("openal")
set_kind("shared")
set_prefixname("")
set_extension(".hdll")
add_includedirs("hashlink/src")
add_files("hashlink/libs/openal/openal.c")
add_deps("libhl")
add_packages("openal")
on_load(chain_actions(compile_flags, module_link_flags))
target("sdl")
set_kind("shared")
set_prefixname("")
set_extension(".hdll")
add_includedirs("hashlink/src")
if os.isdir("hashlink/ci_fix") then
-- Ci_fix folder contains only replaceable headers for CI use.
-- Please do not include $ProjectRoot/ci_fix directly. In Linux
-- it may cause xmake stuck. The copy of ci_fix here is done by
-- CI.
add_includedirs("hashlink/ci_fix")
end
add_files("hashlink/libs/sdl/sdl.c",
"hashlink/libs/sdl/gl.c")
add_deps("libhl")
add_packages("libsdl")
if is_plat("linux") then
add_packages("libglvnd")
elseif is_plat("windows") then
add_defines("SDL_EXPORTS")
add_links("opengl32", "winmm", "user32")
end
on_load(chain_actions(compile_flags, module_link_flags))