forked from taisei-project/taisei
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
384 lines (319 loc) · 11.7 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
project('taisei', 'c',
license : 'MIT',
version : 'v1.3.1',
meson_version : '>=0.45.0',
default_options : [
'c_std=c11',
'default_library=static',
'libzip:enable_crypto=false',
'libzip:enable_bzip2=false',
'sdl2:use_haptic=disabled',
'sdl2:use_power=disabled',
'sdl2:use_render=disabled',
'sdl2:use_sensor=disabled',
# You may want to change these for a debug build dir
'buildtype=release',
'strip=true',
'b_lto=true',
'b_ndebug=if-release',
]
)
minimum_recommended_meson_version = '0.48.0'
if meson.version().version_compare('<@0@'.format(minimum_recommended_meson_version))
warning('Old Meson version detected. Try upgrading to at least @0@ if the build fails.'.format(minimum_recommended_meson_version))
endif
is_debug_build = get_option('debug')
is_developer_build = (get_option('developer') == 'auto' ? is_debug_build : get_option('developer') == 'true')
cc = meson.get_compiler('c')
python3 = import('python3').find_python()
macos_app_bundle = get_option('macos_bundle') and host_machine.system() == 'darwin'
subdir('scripts')
config = configuration_data()
taisei_c_args = [
'-Wall',
'-Wpedantic',
'-Werror=assume',
'-Werror=implicit-function-declaration',
'-Werror=incompatible-pointer-types',
#
# Keep the rest sorted
#
'-Wabsolute-value',
'-Wcast-align',
'-Wcast-align=strict',
'-Wcast-function-type',
'-Wclobbered',
'-Wduplicated-branches',
'-Wduplicated-cond',
'-Wfloat-overflow-conversion',
'-Wfloat-zero-conversion',
'-Wfor-loop-analysis',
'-Wformat-pedantic',
'-Wformat-security',
'-Wgcc-compat',
'-Wgnu',
'-Wignored-qualifiers',
'-Wimplicit-fallthrough',
'-Winit-self',
'-Wlogical-op',
'-Wmissing-prototypes',
'-Wno-long-long',
'-Wno-missing-braces',
'-Wno-typedef-redefinition',
'-Wnull-dereference',
'-Wparentheses',
'-Wshadow=compatible-local',
'-Wsometimes-uninitialized',
'-Wstrict-prototypes',
'-Wtype-limits',
'-Wunneeded-internal-declaration',
'-Wunreachable-code',
'-Wunreachable-code-loop-increment',
'-fexcess-precision=standard',
'-fmerge-all-constants',
'-fno-math-errno',
'-fno-signaling-nans',
'-fno-trapping-math',
]
if get_option('b_pch') and meson.version().version_compare('<0.50.0')
# Workaround for Meson bug: https://github.com/mesonbuild/meson/issues/4905
taisei_c_args += ['-fpch-deps']
endif
taisei_c_args = cc.get_supported_arguments(taisei_c_args)
foreach arglist : [
['-msse', '-mfpmath=sse'],
]
if cc.has_multi_arguments(arglist)
taisei_c_args += arglist
endif
endforeach
sm_check = run_command(check_submodules_command)
if sm_check.stdout() != ''
foreach line : sm_check.stdout().strip().split('\n')
warning(line)
endforeach
endif
if sm_check.stderr() != ''
warning('Submodule check completed with errors:\n@0@'.format(sm_check.stderr()))
endif
static = get_option('static') or ['emscripten', 'nx'].contains(host_machine.system())
dep_freetype = dependency('freetype2', required : true, static : static, fallback : ['freetype', 'freetype_dep'])
dep_opusfile = dependency('opusfile', required : false, static : static, fallback : ['opusfile', 'opusfile_dep'])
dep_png = dependency('libpng', version : '>=1.5', required : true, static : static, fallback : ['libpng', 'png_dep'])
dep_sdl2 = dependency('sdl2', version : '>=2.0.6', required : true, static : static, fallback : ['sdl2', 'sdl2_dep'])
dep_sdl2_mixer = dependency('SDL2_mixer', version : '>=2.0.4', required : false, static : static, fallback : ['sdl2_mixer', 'sdl2_mixer_dep'])
dep_webp = dependency('libwebp', version : '>=0.5', required : false, static : static, fallback : ['libwebp', 'webp_dep'])
dep_webpdecoder = dependency('libwebpdecoder', version : '>=0.5', required : false, static : static, fallback : ['libwebp', 'webpdecoder_dep'])
dep_zip = dependency('libzip', version : '>=1.2', required : false, static : static, fallback : ['libzip', 'libzip_dep'])
dep_zlib = dependency('zlib', required : true, static : static, fallback : ['zlib', 'zlib_dep'])
dep_crypto = dependency('libcrypto', required : false, static : static)
dep_m = cc.find_library('m', required : false)
dep_cglm = subproject('cglm').get_variable('cglm_dep')
dep_glad = subproject('glad').get_variable('glad_dep')
taisei_deps = [
dep_cglm,
dep_freetype,
dep_m,
dep_png,
dep_sdl2,
dep_zlib,
# don't add glad here
]
if dep_webpdecoder.found()
taisei_deps += dep_webpdecoder
elif dep_webp.found()
warning('libwebpdecoder not found, will link against libwebp instead')
taisei_deps += dep_webp
else
error('libwebpdecoder or libwebp is required, neither found')
endif
if host_machine.system() == 'windows'
taisei_deps += cc.find_library('shlwapi')
endif
if host_machine.system() == 'emscripten'
package_data = false
enable_zip = false
else
package_data = get_option('package_data')
enable_zip = get_option('enable_zip')
package_data = (package_data == 'auto' ? enable_zip : package_data == 'true')
endif
if enable_zip
assert(dep_zip.found(), 'ZIP support enabled but libzip not found')
taisei_deps += dep_zip
endif
if package_data and not enable_zip
error('ZIP support must be enabled for data packaging to work')
endif
config.set('TAISEI_BUILDCONF_USE_ZIP', taisei_deps.contains(dep_zip))
have_posix = cc.has_header_symbol('unistd.h', '_POSIX_VERSION')
have_vla = not cc.has_header_symbol('stdlib.h', '__STDC_NO_VLA__')
have_complex = not cc.has_header_symbol('stdlib.h', '__STDC_NO_COMPLEX__')
have_timespec = cc.has_header_symbol('time.h', 'timespec_get')
assert(have_vla and have_complex, 'Your C implementation needs to support complex numbers and variable-length arrays.')
config.set('TAISEI_BUILDCONF_HAVE_TIMESPEC', have_timespec)
config.set('TAISEI_BUILDCONF_HAVE_INT128', cc.sizeof('__int128') == 16)
config.set('TAISEI_BUILDCONF_HAVE_LONG_DOUBLE', cc.sizeof('long double') > 8)
config.set('TAISEI_BUILDCONF_HAVE_POSIX', have_posix)
config.set('TAISEI_BUILDCONF_HAVE_MAX_ALIGN_T', cc.compiles('#include <stddef.h>\nmax_align_t i;', name : 'max_align_t test'))
prefer_relpath_systems = [
'windows',
]
force_relpath_systems = [
'emscripten',
'nx'
]
if macos_app_bundle
bundle_dir = 'Taisei.app'
datadir = join_paths(bundle_dir, 'Contents', 'Resources')
bindir = join_paths(bundle_dir, 'Contents', 'MacOS')
config.set('TAISEI_BUILDCONF_RELATIVE_DATA_PATH', true)
# arguments must be strings...
meson.add_install_script(
python3.path(),
join_paths(meson.source_root(), 'scripts', 'macos-install-dylibs.py'),
':'.join(meson.get_cross_property('macos_lib_path', [])),
':'.join(meson.get_cross_property('macos_tool_path', [])),
meson.get_cross_property('macos_tool_prefix', ''),
)
else
datadir = get_option('datadir')
if force_relpath_systems.contains(host_machine.system())
config.set('TAISEI_BUILDCONF_RELATIVE_DATA_PATH', true)
elif get_option('install_relative') == 'auto'
config.set('TAISEI_BUILDCONF_RELATIVE_DATA_PATH', prefer_relpath_systems.contains(host_machine.system()))
else
config.set('TAISEI_BUILDCONF_RELATIVE_DATA_PATH', get_option('install_relative') == 'true')
endif
if config.get('TAISEI_BUILDCONF_RELATIVE_DATA_PATH')
bindir = '.'
else
bindir = get_option('bindir')
endif
endif
if get_option('install_freedesktop') == 'auto'
install_xdg = not config.get('TAISEI_BUILDCONF_RELATIVE_DATA_PATH')
else
install_xdg = get_option('install_freedesktop') == 'true'
endif
if config.get('TAISEI_BUILDCONF_RELATIVE_DATA_PATH')
data_path = 'data'
doc_path = '.' # Meson bug https://github.com/mesonbuild/meson/issues/4295
xdg_path = 'freedesktop.org'
# This is relative to SDL_GetBasePath()
config.set_quoted('TAISEI_BUILDCONF_DATA_PATH', data_path)
if macos_app_bundle
# Actual installation path
data_path = join_paths(datadir, data_path)
# I don't know why would you do that, but more power to you
xdg_path = join_paths(datadir, xdg_path)
endif
else
data_path = join_paths(datadir, 'taisei')
config.set_quoted('TAISEI_BUILDCONF_DATA_PATH', join_paths(get_option('prefix'), data_path))
doc_path = join_paths(datadir, 'doc', 'taisei')
xdg_path = datadir
endif
config.set('TAISEI_BUILDCONF_DEBUG', is_debug_build)
config.set('TAISEI_BUILDCONF_DEVELOPER', is_developer_build)
config.set('TAISEI_BUILDCONF_LOG_FATAL_MSGBOX', (
host_machine.system() == 'windows' or
host_machine.system() == 'darwin' or
not is_developer_build
))
config.set('TAISEI_BUILDCONF_DEBUG_OPENGL', get_option('debug_opengl'))
install_docs = get_option('docs') and not ['emscripten', 'nx'].contains(host_machine.system())
if host_machine.system() == 'windows'
if install_docs
custom_target('COPYING.txt',
command : [eolconv_command, host_eol_style, '@INPUT@', '@OUTPUT@'],
input : 'COPYING',
output : 'COPYING.txt',
install : true,
install_dir : doc_path
)
endif
if angle_enabled
install_data(
get_option('angle_libgles'),
get_option('angle_libegl'),
install_dir : join_paths(bindir, 'ANGLE'),
)
endif
else
if install_docs
install_data('COPYING', install_dir : doc_path)
endif
if angle_enabled
error('install_angle is only available for Windows targets at the moment')
endif
endif
systype = (have_posix ? 'POSIX (@0@)' : '@0@').format(host_machine.system())
systype = '@0@, @1@, @2@'.format(systype, host_machine.cpu_family(), host_machine.cpu())
if meson.is_cross_build()
systype = '@0@ (cross-compiling)'.format(systype)
endif
version_deps = []
bindist_deps = []
subdir('misc')
subdir('emscripten')
subdir('switch')
subdir('external')
subdir('resources')
subdir('doc')
subdir('xdg')
subdir('atlas')
subdir('src')
if macos_app_bundle
dmg_target = run_target('dmg',
command : dmg_command,
depends : bindist_deps,
)
endif
if host_machine.system() == 'windows'
nsis_target = run_target('nsis',
command : nsis_command,
depends : bindist_deps,
)
endif
zip_target = run_target('zip',
command: zip_command,
depends : bindist_deps,
)
summary = '''
Summary:
Taisei version: @0@
System type: @1@
Build type: @2@
Developer mode: @15@
Audio backends: @3@ (default: @4@)
Renderers: @5@ (default: @6@)
Shader translation: @7@
ZIP support: @8@
Package data: @9@
Relative install paths: @10@
Prefix: @11@
Executables: @12@
Data: @13@
Documentation: @14@
'''.format(
taisei_version_string,
systype,
get_option('buildtype'),
', '.join(enabled_audio_backends),
get_option('a_default'),
', '.join(enabled_renderers),
default_renderer,
get_option('shader_transpiler'),
enable_zip,
package_data,
config.get('TAISEI_BUILDCONF_RELATIVE_DATA_PATH'),
get_option('prefix'),
# the $ is intentional
join_paths('$prefix', bindir),
join_paths('$prefix', data_path),
join_paths('$prefix', doc_path),
is_developer_build
)
message(summary)
run_command(postconf_command)