-
-
Notifications
You must be signed in to change notification settings - Fork 154
/
meson.build
433 lines (381 loc) · 12.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
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
project(
'pygame_ce',
['c', 'cython'], # Project type. We need a C compiler and cython
version: run_command(
[find_program('python3', 'python'), 'buildconfig/get_version.py'],
check: true,
).stdout().strip(),
default_options: [
# the warning level is set in code below, gives more flexibility there
'warning_level=0',
],
)
defines = run_command(
[find_program('python3', 'python'), 'buildconfig/get_version.py', '--macros'],
check: true,
).stdout().strip().split()
foreach define : defines
add_global_arguments(define, language: 'c')
endforeach
pg = 'pygame' # python base package name
if host_machine.system() == 'windows'
plat = 'win'
elif host_machine.system() == 'darwin'
plat = 'mac'
elif host_machine.system() == 'linux'
plat = 'linux'
elif host_machine.system() == 'android'
plat = 'android'
error(
'The meson buildconfig of pygame-ce does not support android for now.',
'However it may be added in the future',
)
elif host_machine.system() == 'emscripten'
plat = 'emscripten'
error(
'The meson buildconfig of pygame-ce does not support emscripten for now. ',
'However it may be added in the future',
)
else
# here it one of: cygwin, dragonfly, freebsd, gnu, haiku, netbsd, openbsd, sunos
plat = 'unix'
warning(
'pygame-ce does not actively support building on your platform:',
host_machine.system(),
)
endif
cc = meson.get_compiler('c')
fs = import('fs')
py = import('python').find_installation(pure: false)
py_dep = py.dependency()
is_pypy = py.get_variable('implementation_lower', '') == 'pypy'
if not cc.has_header('Python.h', dependencies: py_dep)
error(
'Cannot use `Python.h`. Perhaps you need to install python-dev|python-devel',
)
endif
if get_option('coverage')
if cc.has_argument('--coverage')
add_global_arguments('--coverage', language: 'c')
else
error('Requested coverage but compiler doesn\'t seem to support it')
endif
if cc.has_link_argument('--coverage')
add_global_link_arguments('--coverage', language: 'c')
else
error('Requested coverage but compiler doesn\'t seem to support it')
endif
endif
pg_dir = py.get_install_dir() / pg
sdl_api = get_option('sdl_api')
sdl = 'SDL@0@'.format(sdl_api)
sdl_mixer = '@0@_mixer'.format(sdl)
sdl_ttf = '@0@_ttf'.format(sdl)
sdl_image = '@0@_image'.format(sdl)
if sdl_api == 3
add_global_arguments('-DPG_SDL3=1', '-DSDL_ENABLE_OLD_NAMES=1', language: 'c')
endif
pg_inc_dirs = []
pg_lib_dirs = []
if plat == 'win' and host_machine.cpu_family().startswith('x86')
# yes, this is a bit ugly and hardcoded but it is what it is
# TODO (middle-term goal) - Should migrate away from this
# consider meson wraps? Hopefully can also get the same build path as below
arch_suffix = 'x' + host_machine.cpu_family().substring(-2)
base_dir = meson.current_source_dir()
prebuilt_dir = base_dir / 'prebuilt-' + arch_suffix
# download prebuilts (uses legacy builconfig code)
if not fs.is_dir(prebuilt_dir)
run_command(
[
find_program('python3', 'python'),
'buildconfig/download_win_prebuilt.py',
],
check: true,
)
endif
sdl_ver = (sdl_api == 3) ? '3.1.6' : '2.30.9'
sdl_image_ver = '2.8.2'
sdl_mixer_ver = '2.8.0'
sdl_ttf_ver = '2.22.0'
dlls = []
# SDL
sdl_dir = prebuilt_dir / '@0@-@1@'.format(sdl, sdl_ver)
sdl_lib_dir = sdl_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_dir / 'include', base_dir)
pg_lib_dirs += sdl_lib_dir
dlls += sdl_lib_dir / '@[email protected]'.format(sdl)
# SDL_image
if get_option('image').enabled()
sdl_image_dir = prebuilt_dir / '@0@-@1@'.format(sdl_image, sdl_image_ver)
sdl_image_lib_dir = sdl_image_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_image_dir / 'include', base_dir)
pg_lib_dirs += sdl_image_lib_dir
dlls += [
sdl_image_lib_dir / '@[email protected]'.format(sdl_image),
sdl_image_lib_dir / 'optional' / 'libjpeg-62.dll',
sdl_image_lib_dir / 'optional' / 'libpng16-16.dll',
sdl_image_lib_dir / 'optional' / 'libtiff-5.dll',
sdl_image_lib_dir / 'optional' / 'libwebp-7.dll',
sdl_image_lib_dir / 'optional' / 'libwebpdemux-2.dll',
]
endif
# SDL_mixer
if get_option('mixer').enabled()
sdl_mixer_dir = prebuilt_dir / '@0@-@1@'.format(sdl_mixer, sdl_mixer_ver)
sdl_mixer_lib_dir = sdl_mixer_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_mixer_dir / 'include', base_dir)
pg_lib_dirs += sdl_mixer_lib_dir
dlls += [
sdl_mixer_lib_dir / '@[email protected]'.format(sdl_mixer),
sdl_mixer_lib_dir / 'optional' / 'libogg-0.dll',
sdl_mixer_lib_dir / 'optional' / 'libopus-0.dll',
sdl_mixer_lib_dir / 'optional' / 'libopusfile-0.dll',
sdl_mixer_lib_dir / 'optional' / 'libwavpack-1.dll',
sdl_mixer_lib_dir / 'optional' / 'libxmp.dll',
]
endif
# SDL_ttf
if get_option('font').enabled()
sdl_ttf_dir = prebuilt_dir / '@0@-@1@'.format(sdl_ttf, sdl_ttf_ver)
sdl_ttf_lib_dir = sdl_ttf_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_ttf_dir / 'include', base_dir)
pg_lib_dirs += sdl_ttf_lib_dir
dlls += sdl_ttf_lib_dir / '@[email protected]'.format(sdl_ttf)
endif
# freetype, portmidi and porttime
if get_option('freetype').enabled() and get_option('midi').enabled()
common_lib_dir = prebuilt_dir / 'lib'
pg_inc_dirs += fs.relative_to(prebuilt_dir / 'include', base_dir)
pg_lib_dirs += common_lib_dir
dlls += [common_lib_dir / 'freetype.dll', common_lib_dir / 'portmidi.dll']
endif
# clean unneeded file that causes build issues
unneeded_file = common_lib_dir / 'libportmidi.dll.a'
if fs.exists(unneeded_file)
run_command(
[
find_program('python3', 'python'),
'-c',
'import os; os.remove("@0@")'.format(unneeded_file),
],
check: true,
)
endif
run_command(
[
find_program('python3', 'python'),
base_dir / 'buildconfig' / '_meson_win_dll.py',
dlls,
],
check: true,
)
foreach lib : dlls
if not fs.exists(lib)
error(f'''
File "@lib@" does not exist.
Please try to delete "prebuilt_downloads/", "prebuilt-x64/" and "prebuilt-x86/" directories, and retry the installation.
''')
endif
endforeach
# put dlls in root of install
install_data(dlls, install_dir: pg_dir, install_tag: 'pg-tag')
else
bases = ['/usr/local', '/usr', '/opt/homebrew', '/opt/local']
foreach inc_dir : bases
foreach sub_inc : [
'',
'/@0@'.format(sdl),
'/freetype2',
]
full_inc = inc_dir / 'include' + sub_inc
if fs.exists(full_inc)
pg_inc_dirs += full_inc
endif
endforeach
endforeach
foreach lib_dir : bases
foreach sub_lib : ['lib', 'lib64']
full_lib = lib_dir / sub_lib
if fs.exists(full_lib)
pg_lib_dirs += full_lib
endif
endforeach
endforeach
endif
# TODO: add version constraints?
sdl_dep = dependency(sdl, required: false)
if not sdl_dep.found()
sdl_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library(sdl, dirs: pg_lib_dirs),
)
endif
# optional
sdl_image_dep = dependency(sdl_image, required: false)
if not sdl_image_dep.found()
sdl_image_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library(
sdl_image,
dirs: pg_lib_dirs,
required: get_option('image'),
),
)
endif
sdl_mixer_dep = dependency(sdl_mixer, required: false)
if not sdl_mixer_dep.found()
sdl_mixer_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library(
sdl_mixer,
dirs: pg_lib_dirs,
required: get_option('mixer'),
),
)
endif
sdl_ttf_dep = dependency(sdl_ttf, required: false)
if not sdl_ttf_dep.found()
sdl_ttf_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library(
sdl_ttf,
dirs: pg_lib_dirs,
required: get_option('font'),
),
)
endif
freetype_dep = dependency('freetype2', required: false)
if not freetype_dep.found()
freetype_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library(
'freetype',
dirs: pg_lib_dirs,
required: get_option('freetype'),
),
)
endif
portmidi_dep = dependency('portmidi', required: false)
if not portmidi_dep.found()
portmidi_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library(
'portmidi',
dirs: pg_lib_dirs,
required: get_option('midi'),
),
)
endif
portmidi_deps = [portmidi_dep]
if portmidi_dep.found()
# porttime can be a separate library, or be inbuilt in portmidi.
# So if it is available as a separate library, include it as a dependency
porttime_dep = dependency('porttime', required: false)
if not porttime_dep.found()
porttime_dep = cc.find_library(
'porttime',
dirs: pg_lib_dirs,
required: false,
)
endif
if porttime_dep.found()
portmidi_deps += porttime_dep
endif
endif
pg_base_deps = [sdl_dep, py_dep]
summary(
{
sdl: sdl_dep.found(),
sdl_image: sdl_image_dep.found(),
sdl_mixer: sdl_mixer_dep.found(),
sdl_ttf: sdl_ttf_dep.found(),
'freetype2': freetype_dep.found(),
'portmidi': portmidi_dep.found(),
'porttime': portmidi_dep.found() ? porttime_dep.found() : false,
},
section: 'Dependencies',
)
simd_avx2 = false
simd_avx2_flags = []
if host_machine.cpu_family().startswith('x86')
flag = (cc.get_argument_syntax() == 'msvc') ? '/arch:AVX2' : '-mavx2'
if cc.has_argument(flag)
simd_avx2_flags += flag
simd_avx2 = true
endif
endif
simd_sse2_neon = false
simd_sse2_neon_flags = []
if host_machine.cpu_family() == 'arm'
# first check if compiler supports the flag, and use it then. Needed only
# on 32-bit armv7.
flag = '-mfpu=neon'
if cc.has_argument(flag) and host_machine.cpu() == 'armv7l'
simd_sse2_neon_flags += [flag, '-march=armv7-a']
simd_sse2_neon = true
endif
elif host_machine.cpu_family() == 'aarch64'
# no explicit flag needed in this case
simd_sse2_neon = true
endif
if simd_sse2_neon
add_global_arguments('-DPG_ENABLE_ARM_NEON=1', language: 'c')
endif
summary(
{
'AVX2': simd_avx2,
'NEON': simd_sse2_neon,
},
section: 'SIMD',
)
# stores werror
warnings_error = []
# module specific warnings (TODO remove these by fixing code)
warnings_temp_freetype = []
warnings_temp_mask = []
if cc.get_argument_syntax() == 'msvc'
# base warnings on msvc
add_global_arguments(['/W3', '/wd4142', '/wd4996'], language: 'c')
warnings_temp_mask += ['/wd6385', '/wd6386']
if get_option('error_on_warns') and not is_pypy
warnings_error += '/WX'
endif
# TODO: msvc analyzer?
else
# base warnings on gcc/clang
add_global_arguments(['-Wall', '-Wno-error=unknown-pragmas'], language: 'c')
# check for exact gcc (flags not needed on clang)
if cc.get_id() == 'gcc'
warnings_temp_freetype += [
'-Wno-error=unused-but-set-variable',
'-Wno-error=array-bounds',
]
warnings_temp_mask += '-Wno-error=array-bounds'
endif
if cc.sizeof('long') != 8
warnings_temp_mask += '-Wno-error=shift-count-overflow'
endif
if get_option('error_on_warns') and not is_pypy
warnings_error += '-Werror'
endif
endif
subdir('src_c')
subdir('src_py')
if not get_option('stripped')
# run make_docs and make docs
if not fs.is_dir('docs/generated')
make_docs = files('buildconfig/make_docs.py')
res = run_command(
[find_program('python3', 'python'), make_docs],
check: false,
)
message(res.stdout().strip())
message(res.stderr().strip())
endif
subdir('docs')
subdir('test')
subdir('buildconfig/stubs')
install_subdir('examples', install_dir: pg_dir, install_tag: 'pg-tag')
# TODO: install headers? not really important though
endif