forked from The-Powder-Toy/The-Powder-Toy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
508 lines (486 loc) · 14 KB
/
meson.build
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
project('the-powder-toy', [ 'c', 'cpp' ], version: 'the.cake.is.a.lie', default_options: [
'cpp_std=c++17',
'build.cpp_std=c++17', # used when cross-compiling
])
to_array = generator(
executable('toarray', sources: 'data/ToArray.cpp', native: true),
output: [ '@PLAINNAME@.cpp', '@PLAINNAME@.h' ],
arguments: [ '@OUTPUT0@', '@OUTPUT1@', '@INPUT@', '@EXTRA_ARGS@' ]
)
c_compiler = meson.get_compiler('c')
copt_x86 = false
copt_64bit = false
copt_msvc = false
if c_compiler.get_id() in [ 'msvc' ]
copt_compiler = 'msvc'
copt_msvc = true
elif c_compiler.get_id() in [ 'gcc', 'clang' ]
copt_compiler = 'gcc'
else
warning('unsupported compiler: ' + c_compiler.get_id() + '; you are on your own')
copt_compiler = 'gcc'
endif
if host_machine.cpu_family() in [ 'x86_64' ]
copt_architecture = 'x86_64'
copt_x86 = true
copt_64bit = true
elif host_machine.cpu_family() in [ 'x86' ]
copt_architecture = 'i686'
copt_x86 = true
elif host_machine.cpu_family() in [ 'aarch64' ]
copt_architecture = 'arm64'
copt_64bit = true
elif host_machine.cpu_family() in [ 'arm' ]
copt_architecture = 'arm'
else
warning('unsupported architecture: ' + host_machine.cpu_family() + '; you are on your own')
copt_architecture = 'i686'
endif
if host_machine.system() in [ 'linux', 'freebsd' ]
copt_platform = 'lin'
elif host_machine.system() in [ 'windows' ]
copt_platform = 'win'
elif host_machine.system() in [ 'darwin' ]
copt_platform = 'mac'
elif host_machine.system() in [ 'android' ]
copt_platform = 'and'
else
warning('unsupported platform: ' + host_machine.system() + '; you are on your own')
copt_platform = 'lin'
endif
uopt_static = get_option('static')
use_tpt_libs = 'no'
if uopt_static == 'system'
if copt_platform == 'win'
error('no way to find static system libraries on windows')
endif
elif uopt_static == 'prebuilt'
use_tpt_libs = 'static'
elif copt_platform == 'win'
use_tpt_libs = 'dynamic'
elif copt_platform == 'and'
use_tpt_libs = 'static'
endif
conf_data = configuration_data()
conf_data.set('CURL_STATICLIB', false)
conf_data.set('ZLIB_WINAPI', false)
if get_option('ogli') or get_option('oglr')
error('OpenGL features are currently unavailable')
endif
tpt_libs_vtag = get_option('tpt_libs_vtag')
if tpt_libs_vtag == ''
tpt_libs_vtag = 'v20220414193335'
endif
if use_tpt_libs != 'no'
nope = false
if copt_architecture == 'i686' and not copt_msvc
nope = true
endif
if copt_architecture == 'x86_64' and (copt_platform == 'lin' or copt_platform == 'mac') and copt_compiler != 'gcc'
nope = true
endif
if copt_architecture == 'arm64' and copt_platform != 'mac'
nope = true
endif
if copt_platform == 'and'
nope = false
endif
quad_compiler = copt_compiler
if copt_platform == 'win' and copt_compiler == 'gcc'
quad_compiler = 'mingw'
if get_option('b_lto')
error('mingw does not like static + lto, you will have to disable this error if you want to proceed')
endif
endif
if nope
error('no prebuilt @0@-@1@-@2@-@3@ libraries are currently provided'.format(copt_architecture, copt_platform, quad_compiler, use_tpt_libs))
endif
tpt_libs = subproject('tpt-libs-prebuilt-@0@-@1@-@2@-@3@-@4@'.format(copt_architecture, copt_platform, quad_compiler, use_tpt_libs, tpt_libs_vtag))
endif
uopt_native = get_option('native')
uopt_x86_sse = get_option('x86_sse')
if uopt_x86_sse == 'auto'
uopt_x86_sse_level = 20
elif uopt_x86_sse == 'sse3'
uopt_x86_sse_level = 30
elif uopt_x86_sse == 'sse2'
uopt_x86_sse_level = 20
elif uopt_x86_sse == 'sse'
uopt_x86_sse_level = 10
elif uopt_x86_sse == 'none'
uopt_x86_sse_level = 0
endif
if not copt_x86 or uopt_native
uopt_x86_sse_level = 0
endif
uopt_lua = get_option('lua')
if copt_platform == 'and' and uopt_lua == 'luajit'
message('LuaJIT is not supported on Android')
uopt_lua = 'lua5.2'
endif
if uopt_lua == 'luajit'
lua_opt_dep = [ use_tpt_libs != 'no' ? tpt_libs.get_variable('luajit_dep') : dependency('luajit', static: uopt_static == 'system') ]
elif uopt_lua == 'lua5.2'
lua_opt_dep = [ use_tpt_libs != 'no' ? tpt_libs.get_variable('lua52_dep') : dependency('lua5.2', static: uopt_static == 'system') ]
elif uopt_lua == 'lua5.1'
lua_opt_dep = [ use_tpt_libs != 'no' ? tpt_libs.get_variable('lua51_dep') : dependency('lua5.1', static: uopt_static == 'system') ]
else
lua_opt_dep = []
endif
uopt_http = get_option('http')
if uopt_http and copt_platform != 'and'
curl_opt_dep = [ use_tpt_libs != 'no' ? tpt_libs.get_variable('libcurl_dep') : dependency('libcurl', static: uopt_static == 'system') ]
else
curl_opt_dep = []
endif
uopt_fftw = get_option('gravfft')
if uopt_fftw
fftw_opt_dep = [ use_tpt_libs != 'no' ? tpt_libs.get_variable('fftw_dep') : dependency('fftw3f', static: uopt_static == 'system') ]
else
fftw_opt_dep = []
endif
threads_dep = dependency('threads')
zlib_dep = use_tpt_libs != 'no' ? tpt_libs.get_variable('zlib_dep') : dependency('zlib', static: uopt_static == 'system')
sdl2_dep = use_tpt_libs != 'no' ? tpt_libs.get_variable('sdl2_dep') : dependency('sdl2', static: uopt_static == 'system')
sdl2main_dep = use_tpt_libs != 'no' ? tpt_libs.get_variable('sdl2main_dep') : []
project_link_args = []
project_c_args = []
project_cpp_args = []
if copt_msvc
if uopt_x86_sse_level >= 30
message('SSE3 configured to be enabled but unavailable in msvc')
uopt_x86_sse_level = 20
endif
if uopt_native
message('local machine optimization configured to be enabled but unavailable in msvc')
uopt_native = false
endif
args_msvc = [
'/GS',
'-D_SCL_SECURE_NO_WARNINGS',
'-DUNICODE',
'-D_UNICODE',
]
if copt_64bit
message('SSE explicitly configured but unavailable in msvc targeting 64-bit machines')
else
if uopt_x86_sse_level >= 20
args_msvc += [ '/arch:SSE2' ]
elif uopt_x86_sse_level >= 10
args_msvc += [ '/arch:SSE' ]
endif
endif
if get_option('debug')
project_link_args += [
'/NODEFAULTLIB:MSVCRT',
]
else
args_msvc += [
'/Oy-',
'/fp:fast',
]
project_link_args += [
'/OPT:REF',
'/OPT:ICF',
]
endif
project_c_args += args_msvc
project_cpp_args += args_msvc
else
args_ccomp = [ '-Wno-unused-result' ]
if copt_platform == 'mac'
if uopt_x86_sse_level >= 0
message('SSE level explicitly configured but unavailable on macosx')
uopt_x86_sse_level = 0
endif
if uopt_native
message('local machine optimization configured to be enabled but unavailable on macosx')
uopt_native = false
endif
else
if uopt_x86_sse_level >= 30
args_ccomp += [ '-msse3' ]
endif
if uopt_x86_sse_level >= 20
args_ccomp += [ '-msse2' ]
endif
if uopt_x86_sse_level >= 10
args_ccomp += [ '-msse' ]
endif
if uopt_native
args_ccomp += [ '-march=native' ]
endif
endif
if copt_platform == 'win'
args_ccomp += [
'-DUNICODE',
'-D_UNICODE',
]
if uopt_static != 'none' and copt_platform != 'and'
project_link_args += [ '-static', '-static-libgcc', '-static-libstdc++' ]
endif
endif
if not get_option('debug')
args_ccomp += [
'-ftree-vectorize',
'-funsafe-math-optimizations',
'-ffast-math',
'-fomit-frame-pointer',
]
endif
if copt_platform == 'mac' and uopt_static == 'prebuilt'
args_ccomp += [ '-mmacosx-version-min=10.9' ]
project_link_args += [ '-mmacosx-version-min=10.9' ]
endif
if copt_platform == 'and'
if not copt_64bit
args_ccomp += [ '-U_FILE_OFFSET_BITS' ]
endif
project_link_args += [ '-static-libstdc++' ]
else
if not get_option('b_pie') and get_option('workaround_gcc_no_pie') # nice one, meson
if copt_architecture != 'arm64' # no position independent executable for arm64
if c_compiler.get_id() in [ 'clang' ]
project_link_args += [ '-Wl,-no_pie' ]
else
project_link_args += [ '-no-pie' ]
endif
endif
endif
endif
project_c_args += args_ccomp
project_cpp_args += args_ccomp + [ '-Wno-invalid-offsetof' ]
endif
if copt_platform == 'win'
other_dep = tpt_libs.get_variable('other_dep')
args_ccomp_win = [ '-D_WIN32_WINNT=0x0501' ]
project_c_args += args_ccomp_win
project_cpp_args += args_ccomp_win
windows_mod = import('windows')
if uopt_static != 'none'
conf_data.set('CURL_STATICLIB', true)
if copt_architecture == 'x86_64'
conf_data.set('ZLIB_WINAPI', true)
endif
else
foreach input_and_output : tpt_libs.get_variable('config_dlls')
configure_file(input: input_and_output[0], output: input_and_output[1], copy: true)
endforeach
endif
elif copt_platform == 'lin'
if uopt_static != 'none'
project_link_args += [ '-static-libgcc', '-static-libstdc++' ]
endif
endif
if copt_platform == 'mac' and uopt_lua == 'luajit' and copt_architecture != 'arm64'
project_link_args += [
'-pagezero_size', '10000',
'-image_base', '100000000',
]
endif
project_inc = include_directories([ 'src', 'data', 'resources' ])
if copt_platform == 'win'
copt_identplatform = copt_64bit ? 'WIN64' : 'WIN32'
elif copt_platform == 'lin'
copt_identplatform = copt_64bit ? 'LIN64' : 'LIN32'
elif copt_platform == 'mac'
copt_identplatform = copt_architecture == 'arm64' ? 'MACOSARM' : 'MACOSX'
else
copt_identplatform = 'UNKNOWN'
endif
conf_data.set('LIN', copt_platform == 'lin')
conf_data.set('AND', copt_platform == 'and')
conf_data.set('WIN', copt_platform == 'win')
conf_data.set('MACOSX', copt_platform == 'mac')
conf_data.set('X86', copt_x86)
conf_data.set('X86_SSE3', uopt_x86_sse_level >= 30)
conf_data.set('X86_SSE2', uopt_x86_sse_level >= 20)
conf_data.set('X86_SSE', uopt_x86_sse_level >= 10)
conf_data.set('NATIVE', uopt_native)
conf_data.set('_64BIT', copt_64bit)
conf_data.set('OGLI', get_option('ogli'))
conf_data.set('OGLR', get_option('oglr'))
conf_data.set('PIX32OGL', get_option('ogli'))
conf_data.set('BETA', get_option('beta'))
conf_data.set('NO_INSTALL_CHECK', not get_option('install_check'))
conf_data.set('IGNORE_UPDATES', get_option('ignore_updates'))
conf_data.set('MOD_ID', get_option('mod_id'))
conf_data.set('DEBUG', get_option('debug'))
conf_data.set('SNAPSHOT', get_option('snapshot'))
conf_data.set('SNAPSHOT_ID', get_option('snapshot_id'))
conf_data.set('SERVER', '"' + get_option('server') + '"')
conf_data.set('STATICSERVER', '"' + get_option('static_server') + '"')
conf_data.set('IDENT_PLATFORM', '"' + copt_identplatform + '"')
conf_data.set('IDENT', '"@0@-@1@-@2@"'.format(copt_architecture, copt_platform, copt_compiler).to_upper())
if get_option('update_server') != ''
conf_data.set('UPDATESERVER', '"' + get_option('update_server') + '"')
else
conf_data.set('UPDATESERVER', false)
endif
resources_files = []
subdir('src')
subdir('data')
subdir('resources')
if get_option('build_powder')
powder_deps = [
threads_dep,
zlib_dep,
sdl2_dep,
sdl2main_dep,
lua_opt_dep,
curl_opt_dep,
fftw_opt_dep,
]
if copt_platform == 'win'
powder_deps += other_dep
endif
if copt_platform == 'and'
subdir('android')
powder_sha = shared_library(
'powder',
sources: powder_files,
include_directories: [ project_inc, powder_inc ],
c_args: project_c_args,
cpp_args: project_cpp_args,
link_args: project_link_args,
dependencies: powder_deps,
)
python3 = find_program('python3')
android_platform_jar = meson.get_external_property('android_platform_jar')
java_runtime_jar = meson.get_external_property('java_runtime_jar')
android_keystore = get_option('android_keystore')
sdl_jar = tpt_libs.get_variable('sdl_jar')
powder_jar = custom_target(
'powder-jar',
output: 'powder.jar',
command: [
python3,
files('android/powder-jar.py'),
find_program('javac'),
find_program('jar'),
meson.current_source_dir(),
meson.current_build_dir(),
'@PRIVATE_DIR@',
'@OUTPUT@',
android_platform_jar,
java_runtime_jar,
sdl_jar,
get_option('debug') ? 'debug' : 'release',
powder_jar_sources,
],
)
unaligned_apk = custom_target(
'build-apk',
output: 'powder.unaligned.apk',
input: powder_sha,
command: [
python3,
files('android/build-apk.py'),
find_program('d8'),
find_program('aapt'),
find_program('aapt2'),
meson.current_source_dir(),
meson.current_build_dir(),
'@PRIVATE_DIR@',
'@OUTPUT@',
'@INPUT@',
android_platform_jar,
sdl_jar,
powder_jar,
copt_architecture,
get_option('debug') ? 'debug' : 'release',
android_manifest_xml,
android_resources,
],
)
unsigned_apk = custom_target(
'align-apk',
output: 'powder.unsigned.apk',
input: unaligned_apk,
command: [
python3,
files('android/align-apk.py'),
find_program('zipalign'),
meson.current_build_dir(),
'@OUTPUT@',
'@INPUT@',
],
)
signed_apk = custom_target(
'sign-apk',
output: 'powder.apk',
input: unsigned_apk,
command: [
python3,
files('android/sign-apk.py'),
find_program('apksigner'),
meson.current_build_dir(),
'@OUTPUT@',
'@INPUT@',
android_keystore,
get_option('android_keyalias'),
],
)
adb = find_program('adb', required: false)
if adb.found()
install_apk = custom_target(
'install-apk',
input: signed_apk,
output: 'install-apk',
command: [ python3, files('android/install-apk.py'), adb, meson.current_build_dir(), '@OUTPUT@', '@INPUT@' ],
)
custom_target(
'run-apk',
input: [ signed_apk, install_apk ],
output: 'run-apk',
command: [ python3, files('android/run-apk.py'), adb, meson.current_build_dir(), '@OUTPUT@', '@INPUT0@' ],
)
endif
else
executable(
'powder',
sources: powder_files,
include_directories: [ project_inc, powder_inc ],
c_args: project_c_args,
cpp_args: project_cpp_args,
gui_app: not get_option('debug'),
link_args: project_link_args,
dependencies: powder_deps,
)
endif
endif
if get_option('build_render')
render_deps = [
threads_dep,
zlib_dep,
]
executable(
'render',
sources: render_files,
include_directories: [ project_inc, render_inc ],
c_args: project_c_args,
cpp_args: project_cpp_args,
link_args: project_link_args,
dependencies: render_deps,
)
endif
if get_option('build_font')
font_deps = [
threads_dep,
zlib_dep,
sdl2_dep,
sdl2main_dep,
]
if copt_platform == 'win'
font_deps += other_dep
endif
executable(
'font',
sources: font_files,
include_directories: [ project_inc, font_inc ],
c_args: project_c_args,
cpp_args: project_cpp_args,
link_args: project_link_args,
dependencies: font_deps,
)
endif