forked from dosbox-staging/dosbox-staging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
1336 lines (1191 loc) · 38.3 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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
project(
'dosbox-staging',
'c',
'cpp',
version: '0.82.0-alpha',
license: 'GPL-2.0-or-later',
meson_version: '>= 0.59.0',
default_options: [
'cpp_std=c++20',
'buildtype=release',
'b_ndebug=if-release',
'b_staticpic=false',
'b_pie=false',
'warning_level=3',
'glib:b_staticpic=true',
'glib:glib_assert=false',
'glib:glib_checks=false',
'glib:glib_debug=disabled',
'glib:libmount=disabled',
'glib:libelf=disabled',
'glib:nls=disabled',
'glib:tests=false',
'glib:warning_level=0',
'glib:xattr=false',
'gtest:warning_level=0',
'libjpeg-turbo:b_staticpic=true',
'libpng:b_staticpic=true',
'zlib-ng:c_std=c11',
],
)
# Gather internal resource dependencies
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# These are always present regardless of host, compiler, dependencies, or options.
#
data_dir = get_option('datadir')
licenses_dir = data_dir / 'licenses' / meson.project_name()
doc_dir = data_dir / 'doc' / meson.project_name()
install_man('docs/dosbox.1')
# Bundle licenses, but skip the ones that are not relevant for
# binary distribution or allow us to not distribute the license text.
install_data(
'LICENSE',
'licenses/BSD-2-Clause.txt',
'licenses/BSD-3-Clause.txt',
'licenses/GPL-2.0.txt',
'licenses/LGPL-2.1.txt',
'licenses/MIT.txt',
'licenses/Zlib.txt',
install_dir: licenses_dir,
)
install_data('AUTHORS', 'README', 'THANKS', install_dir: doc_dir)
subdir('contrib/linux')
subdir('contrib/icons')
subdir('contrib/resources')
# Gather OS family type
# ~~~~~~~~~~~~~~~~~~~~~
#
os_family_name = {
'linux': 'LINUX',
'windows': 'WIN32',
'cygwin': 'WIN32',
'darwin': 'MACOSX',
'freebsd': 'BSD',
'netbsd': 'BSD',
'openbsd': 'BSD',
'dragonfly': 'BSD',
}.get(host_machine.system(), 'UNKNOWN_OS')
# Gather compiler settings
# ~~~~~~~~~~~~~~~~~~~~~~~~
#
cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')
prefers_static_libs = (get_option('default_library') == 'static')
summary('Build type', get_option('buildtype'), section: 'Build Summary')
summary('Install prefix', get_option('prefix'), section: 'Build Summary')
# extra build flags
extra_flags = [
'-Wno-unknown-pragmas',
'-fpch-preprocess',
]
warnings = []
# Enable additional warnings
foreach flag : [
'-Walloca',
'-Wctor-dtor-privacy',
'-Wdate-time',
'-Wdisabled-optimization',
'-Wduplicated-branches',
'-Weffc++',
'-Wextra-semi',
'-Wfloat-conversion',
'-Wlogical-op',
'-Wlogical-not-parentheses',
'-Wredundant-decls',
'-Wmismatched-tags',
'-Wsizeof-pointer-div',
'-Wstack-protector',
'-Wstrict-null-sentinel',
'-Wsuggest-override',
'-Wzero-as-null-pointer-constant',
]
if cxx.has_argument(flag)
warnings += flag
endif
endforeach
# Ignore some warnings enabled by default
foreach flag : ['-Wno-format-security']
if cxx.has_argument(flag)
warnings += flag
endif
endforeach
# generate linker map file
extra_link_flags = [
'-Wl,-map,dosbox.map',
'-Wl,-Map,dosbox.map',
'-Wl,--Map,dosbox.map',
]
# If the compiler provides std::filesystem, then we consider it modern enough
# that we can trust it's extra helpful warnings to let us improve the code quality.
if cxx.has_header('filesystem')
extra_flags += ['-Wmaybe-uninitialized', '-Weffc++', '-Wextra-semi']
else
# Otherwise, it's an old compiler and we're just trying to build, and don't
# care about fixing their warnings (some generate warnings from their own STL).
warning(
'Compiler lacks the C++17 std::filesystem - try to upgrade your compiler!',
)
endif
# As of commit e73aaa57, overriding CXXFLAGS with -Os produces a binary that hangs
# when using a relase build with GCC.
#
# CXXFLAGS="-Os" meson setup --buildtype=release --native-file=.github/meson/native-gcc.ini build
#
# This is most likely a GCC bug because the optimization level should not change
# functionality. All other -O-levels work. Clang also handles this (replace
# native-gcc.ini with native-clang.ini to test it).
#
if get_option('buildtype') == 'release' and cxx.get_id() == 'gcc'
cxxflags_env = run_command('sh', '-c', 'echo "$CXXFLAGS"', check: false)
if cxxflags_env.returncode() == 0 and cxxflags_env.stdout().contains('-Os')
error(
'\n\n',
'Overriding CXXFLAGS with the size-optimization flag, "-Os", when\n',
'performing a release build with GCC produces a binary that hangs.\n',
'Use the "minsize" buildtype instead.',
)
endif
endif
is_optimized_buildtype = (
get_option('buildtype') in ['release', 'minsize', 'debugoptimized']
)
if is_optimized_buildtype
# For optimized build types, we're not anticipating
# needing debuggable floating point signals.
# These safety measures are still enabled in debug builds,
# so if an issue is reported where these happen help, then
# testing with debug builds will make use of them.
#
extra_flags += [
'-fstrict-aliasing',
'-Wstrict-aliasing',
'-fmerge-all-constants',
'-fno-math-errno',
'-fno-signed-zeros',
'-fno-trapping-math',
'-frename-registers',
'-ffunction-sections',
'-fdata-sections',
]
extra_link_flags += ['-Wl,--gc-sections']
endif
# Let sanitizer builds recover and continue
if get_option('b_sanitize') != 'none'
extra_flags += ['-fsanitize-recover=all']
endif
# Add Debug-specific flags here
if get_option('buildtype').startswith('debug')
# Use GCC's and Clang's maximum check flags except
# for macOS and Windows, where Xcode and MSYS2 both
# fails with undefined symbols.
if os_family_name not in ['MACOSX', 'WIN32']
extra_flags += [
'--enable-concept-checks',
'-D_GLIBCXX_ASSERTIONS=1',
'-D_GLIBCXX_DEBUG=1',
'-D_GLIBCXX_DEBUG_PEDANTIC=1',
'-D_GLIBCXX_SANITIZE_VECTOR=1',
'-D_LIBCPP_DEBUG=1',
'-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1',
'-D_LIBCPP_ENABLE_HARDENED_MODE=1',
]
endif
endif
if get_option('asm')
extra_flags += ['--save-temps', '/FAs']
endif
if get_option('time_trace')
extra_flags += ['-ftime-trace']
endif
# Don't flood us with hundreds of suggestions to use Microsoft-specific calls
if host_machine.system() == 'windows'
extra_flags += '-Wno-pedantic-ms-format'
endif
# Don't flood us with hundreds of suggestions to use snprintf on Apple + Clang
if host_machine.system() == 'darwin' and cxx.get_id() == 'clang'
extra_flags += '-Wno-deprecated-declarations'
endif
if prefers_static_libs
extra_flags += ['-static-libstdc++', '-static-libgcc']
if host_machine.system() != 'darwin'
extra_link_flags += ['-no-pie']
endif
else
extra_flags += [
'-shared-libstdc++',
'-shared-libgcc',
'-fPIC',
]
extra_link_flags += '-lstdc++_s'
endif
if get_option('narrowing_warnings')
extra_flags += ['-Wconversion', '-Wnarrowing']
endif
if get_option('autovec_info')
# At least O2 is needed enable auto-vectorizion
extra_flags += [
'-march=native',
'-O2',
'-Wno-system-headers',
'-Rpass-analysis=loop-vectorize',
'-fopt-info-vec-missed',
'-fopt-info-vec',
]
endif
# Tag BSD executables with the WX-needed bit
if os_family_name == 'BSD'
extra_link_flags += ['-Wl,-z,wxneeded']
endif
# SIMD assessment for optimized builds with zlib-ng
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# If the user asked for 'native' SIMD flags then we check if
# their compiler supports the native arch type. If it doesn't,
# we try to enable NEON (on Arm) and SSE2 and/or SSSE3 (on x86).
#
# Currently zlib-ng is the driving force behind these checks as
# it provides a meaningful speedup in video and frame capture.
#
# Note that these build flags needs to be defined before adding
# subpackages because the flags are used when compiling them.
simd_instruction_sets = []
zlib_ng_options = get_option('use_zlib_ng')
zlib_ng_wants_native = zlib_ng_options.contains('native')
zlib_ng_is_native = zlib_ng_wants_native and cc.has_argument('-march=native')
if is_optimized_buildtype and zlib_ng_is_native
extra_flags += '-march=native'
simd_instruction_sets += 'native'
message('Enabling native SIMD optimizations')
endif
# NEON on Aarch64
# ~~~~~~~~~~~~~~~
if target_machine.cpu_family() == 'aarch64'
# aarch64 always supports NEON:
# ref: https://developer.arm.com/documentation/den0024/a/AArch64-Floating-point-and-NEON
zlib_ng_options += 'neon'
simd_instruction_sets += 'NEON'
message('Using the ARM NEON instruction set')
endif
# NEON on Aarch32
# ~~~~~~~~~~~~~~~
if (
target_machine.cpu_family() == 'arm'
and (zlib_ng_is_native
or zlib_ng_wants_native
or 'neon' in zlib_ng_options)
)
neon_test_code = '''
#include <arm_neon.h>
int main() {
uint8x16_t a = vdupq_n_u8(0);
uint8x16_t b = vdupq_n_u8(0);
uint8x16_t result = vaddq_u8(a, b);
return 0;
}
'''
neon_cflag = '-mfpu=neon-vfpv4'
neon_test = cc.run(
neon_test_code,
args: neon_cflag,
name: 'ARM NEON instruction set test',
)
if (neon_test.compiled() and neon_test.returncode() == 0)
zlib_ng_options += 'neon'
extra_flags += neon_cflag
simd_instruction_sets += 'NEON'
message('Enabling the ARM NEON instruction set')
endif
endif
# SSE2 and SSSE3 on x86
# ~~~~~~~~~~~~~~~~~~~~~
if (
target_machine.cpu_family().startswith('x86')
and (
zlib_ng_is_native
or zlib_ng_wants_native
or 'sse2' in zlib_ng_options
or 'ssse3' in zlib_ng_options
)
)
sse2_test_code = '''
#include <emmintrin.h>
int main() {
__m128i a = _mm_setzero_si128();
__m128i b = _mm_setzero_si128();
__m128i result = _mm_add_epi32(a, b);
return 0;
}
'''
sse2_cflags = '-msse2'
sse2_test = cc.run(
sse2_test_code,
args: sse2_cflags,
name: 'SSE2 instruction set test',
)
if (sse2_test.compiled() and sse2_test.returncode() == 0)
zlib_ng_options += 'sse2'
extra_flags += sse2_cflags
simd_instruction_sets += 'SSE2'
message('Enabling the SSE2 instruction set')
endif
ssse3_test_code = '''
#include <tmmintrin.h>
int main() {
__m128i a = _mm_setzero_si128();
__m128i b = _mm_setzero_si128();
__m128i result = _mm_hadd_epi16(a, b);
return 0;
}
'''
ssse3_cflag = '-mssse3'
ssse3_test = cc.run(
ssse3_test_code,
args: ssse3_cflag,
name: 'SSSE3 instruction set test',
)
if (ssse3_test.compiled() and ssse3_test.returncode() == 0)
zlib_ng_options += 'ssse3'
extra_flags += ssse3_cflag
simd_instruction_sets += 'SSSE3'
message('Enabling the SSSE3 instruction set')
endif
endif
if simd_instruction_sets.length() == 0
simd_instruction_sets = ['none']
endif
summary(
'SIMD instruction sets',
', '.join(simd_instruction_sets),
section: 'Build Summary',
)
# Allow-list the flags against the compiler, and add them to the project
cc_supported_arguments = cc.get_supported_arguments(extra_flags)
add_project_arguments(cc_supported_arguments, language: 'c')
cxx_supported_arguments = cxx.get_supported_arguments(extra_flags)
add_project_arguments(cxx_supported_arguments, language: 'cpp')
link_supported_arguments = cxx.get_supported_link_arguments(extra_link_flags)
add_project_link_arguments(link_supported_arguments, language: 'cpp')
# Gather data to populate config.h
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# The actual config.h file will be generated after interpreting
# all the build files in all the subdirs.
#
conf_data = configuration_data()
conf_data.set('version', meson.project_version())
conf_data.set('project_name', meson.project_name())
conf_data.set_quoted(
'CUSTOM_DATADIR',
get_option('prefix') / get_option('datadir'),
)
conf_data.set10(os_family_name, true)
conf_data.set10('C_MODEM', get_option('use_sdl2_net'))
conf_data.set10('C_IPX', get_option('use_sdl2_net'))
conf_data.set10('C_SLIRP', get_option('use_slirp'))
conf_data.set10('C_NE2000', get_option('use_slirp'))
conf_data.set10('C_FLUIDSYNTH', get_option('use_fluidsynth'))
conf_data.set10('C_MT32EMU', get_option('use_mt32emu'))
conf_data.set10('C_TRACY', get_option('tracy'))
conf_data.set10('C_FPU', true)
conf_data.set10('C_FPU_X86', host_machine.cpu_family() in ['x86', 'x86_64'])
if get_option('enable_debugger') != 'none'
conf_data.set10('C_DEBUG', true)
endif
if get_option('enable_debugger') == 'heavy'
conf_data.set10('C_HEAVY_DEBUG', true)
endif
foreach osdef : ['LINUX', 'WIN32', 'MACOSX', 'BSD']
if conf_data.has(osdef)
conf_data.set10('C_DIRECTSERIAL', true)
endif
endforeach
if cc.has_function('clock_gettime', prefix: '#include <time.h>')
conf_data.set10('HAVE_CLOCK_GETTIME', true)
endif
if cc.has_function('__builtin_available')
conf_data.set10('HAVE_BUILTIN_AVAILABLE', true)
endif
if cc.has_function('__builtin___clear_cache')
conf_data.set10('HAVE_BUILTIN_CLEAR_CACHE', true)
endif
if cc.has_function('mprotect', prefix: '#include <sys/mman.h>')
conf_data.set10('HAVE_MPROTECT', true)
endif
if cc.has_function('mmap', prefix: '#include <sys/mman.h>')
conf_data.set10('HAVE_MMAP', true)
endif
if cc.has_header_symbol('sys/mman.h', 'MAP_JIT')
conf_data.set10('HAVE_MAP_JIT', true)
endif
if cc.has_function(
'pthread_jit_write_protect_np',
prefix: '#include <pthread.h>',
)
conf_data.set10('HAVE_PTHREAD_WRITE_PROTECT_NP', true)
endif
if cc.has_function(
'sys_icache_invalidate',
prefix: '#include <libkern/OSCacheControl.h>',
)
conf_data.set10('HAVE_SYS_ICACHE_INVALIDATE', true)
endif
if cxx.has_function(
'pthread_setname_np',
prefix: '#include <pthread.h>',
dependencies: dependency('threads'),
)
conf_data.set10('HAVE_PTHREAD_SETNAME_NP', true)
endif
# strnlen was originally a Linux-only function
if cc.has_function('strnlen', prefix: '#include <string.h>')
conf_data.set10('HAVE_STRNLEN', true)
endif
if cc.has_member('struct dirent', 'd_type', prefix: '#include <dirent.h>')
conf_data.set10('HAVE_STRUCT_DIRENT_D_TYPE', true)
endif
foreach header : [
'libgen.h',
'pwd.h',
'strings.h',
'sys/xattr.h',
'netinet/in.h',
]
if cc.has_header(header)
conf_data.set10('HAVE_' + header.underscorify().to_upper(), true)
endif
endforeach
# Check for the actual calls we need in socket.h, because some systems
# have socket.h but are missing some calls.
if cc.has_header('sys/socket.h')
if (
cc.has_function('getpeername', prefix: '#include <sys/socket.h>')
and cc.has_function('getsockname', prefix: '#include <sys/socket.h>')
)
conf_data.set10('HAVE_SYS_SOCKET_H', true)
endif
endif
# Header windows.h defines old min/max macros, that conflict with C++11
# std::min/std::max. Defining NOMINMAX prevents these macros from appearing.
if cxx.get_id() == 'msvc'
conf_data.set10('NOMINMAX', true)
endif
if host_machine.system() in ['windows', 'cygwin']
conf_data.set10('_USE_MATH_DEFINES', true)
endif
if host_machine.endian() == 'big'
conf_data.set10('WORDS_BIGENDIAN', true)
endif
# Get host page size
# ~~~~~~~~~~~~~~~~~~
# When detecting the page size, we use Meson's configured
# compiler to make a system call because Meson will build and run
# it via the cross compiler (if one is in use), which is
# particularly important we get the destiantion machine's page
# size as opposed to the local build machine's page size.
#
pagesize = 4096
pagesize_option = get_option('pagesize')
if pagesize_option > 0
# User has provided the page size
pagesize = pagesize_option
else
# Detect the page size using a syscall via the cross compiler
pagesize_api = os_family_name == 'WIN32' ? 'windows' : 'posix'
pagesize_src = files('contrib/pagesize' / pagesize_api + '_pagesize.c')
pagesize_cmd = cc.run(
pagesize_src,
name: 'Query host page size',
)
if pagesize_cmd.returncode() == 0
pagesize = pagesize_cmd.stdout().strip().to_int()
else
error('''Unable to detect the host's page size''')
endif
endif
conf_data.set('PAGESIZE', pagesize)
summary(
'Host page size (bytes)',
pagesize.to_string(),
section: 'Build Summary',
)
set_prio_code = '''
#include <sys/resource.h>
int main() {
return setpriority(PRIO_PROCESS, 0, PRIO_MIN + PRIO_MAX);
}
'''
if cc.compiles(set_prio_code, name: 'test for setpriority support')
conf_data.set10('HAVE_SETPRIORITY', true)
endif
# New compilers can check for this feature using __has_builtin, but this is
# broken prior to Clang 10 and GCC 10, so we prefer to have this compilation
# check for now:
builtin_expect_code = '''
void fun(bool test) {
// value of 'test' is usually going to be true
if (__builtin_expect(test, true)) {
/* likely branch */
} else {
/* unlikely branch */
}
}
'''
if cxx.compiles(builtin_expect_code, name: 'test for __builtin_expect support')
conf_data.set10('C_HAS_BUILTIN_EXPECT', true)
endif
atomic_code = '''
#include <atomic>
#include <cstdint>
int main() {
std::atomic<std::int32_t> x32 = 1;
std::atomic<std::int64_t> x64 = 1;
return static_cast<int>(x64.load() - x32.load());
}
'''
atomic_external_dep = dependency('atomic', required: false)
atomic_internal_dep = declare_dependency(link_args: '-latomic')
if cxx.links(
atomic_code,
dependencies: atomic_external_dep,
name: 'compiler supports atomic types using external library',
)
atomic_dep = atomic_external_dep
elif cxx.links(
atomic_code,
dependencies: atomic_internal_dep,
name: 'compiler supports atomic types using internal library',
)
atomic_dep = atomic_internal_dep
else
atomic_dep = dependency('atomic')
endif
# Gather external dependencies
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# system and compiler libraries
# Optional libraries
optional_dep = dependency('', required: false)
msg = 'You can disable this dependency with: -D@0@=false'
default_wrap_options = ['default_library=static', 'warning_level=0']
wraps_forced = get_option('wrap_mode') == 'forcefallback'
wraps_disabled = get_option('wrap_mode') in ['nodownload', 'nofallback']
dl_dep = cc.find_library('dl', required: false)
stdcppfs_dep = cxx.find_library('stdc++fs', required: false)
threads_dep = dependency('threads')
# 3rd party libraries
static_libs_list = get_option('try_static_libs')
wants_tests = true
# tests are disabled for release builds unless requested
if get_option('buildtype') == 'release' and get_option('unit_tests').auto()
wants_tests = false
elif get_option('unit_tests').disabled()
wants_tests = false
endif
libiir_dep = dependency(
'iir',
version: ['>= 1.9.3', '< 2'],
default_options: default_wrap_options + ['tests=' + wants_tests.to_string()],
static: ('iir' in static_libs_list or prefers_static_libs),
include_type: 'system',
)
opus_dep = dependency(
'opusfile',
version: ['>= 0.8', '< 1'],
static: ('opusfile' in static_libs_list or prefers_static_libs),
include_type: 'system',
)
if host_machine.system() == 'darwin' and not wraps_disabled
# use SDL2 wrap so we can control MACOSX_DEPLOYMENT_TARGET during the build
sdl2_dep = subproject(
'sdl2',
default_options: default_wrap_options,
).get_variable('sdl2_dep')
else
sdl2_dep = dependency(
'sdl2',
version: ['>= 2.0.5', '< 3'],
static: ('sdl2' in static_libs_list),
fallback: [],
include_type: 'system',
)
endif
# zlib
# ~~~~
zlib_provider = 'none'
zlib_ng_provider = 'none'
zlib_dep = disabler()
zlib_is_static = 'zlib' in static_libs_list or prefers_static_libs
zlib_ng_is_allowed = 'false' not in zlib_ng_options
if not zlib_ng_is_allowed
zlib_ng_provider = 'disabled'
endif
# Try using the system-provided zlib-ng library so long as the wrap isn't
# forced. Using the system-provided library is a free upgrade for all the build
# types, so we always prefer this first if the user allows it.
#
try_system_zlib_ng = (
zlib_ng_is_allowed
and not wraps_forced
and 'zlib-ng' not in get_option('force_fallback_for')
)
# The zlib-ng wrap, on the other hand, is a costly endeavour because it
# single-handedly quadruples the 'meson setup' time for the entire project (6.1s
# to 25.8s) due to the use of the much slower CMake build system, therefore we
# only expend this effort (to optimize zlib) for commensurate optimized builds.
# This nuance is also explained in meson_options.txt for packagers.
#
try_builtin_zlib_ng = (
zlib_ng_is_allowed
and (not wraps_disabled
or 'zlib-ng' in get_option('force_fallback_for'))
)
system_zlib_ng_dep = disabler()
if try_system_zlib_ng
system_zlib_ng_dep = dependency(
'zlib-ng',
required: false,
fallback: [],
static: zlib_is_static,
include_type: 'system',
)
if (system_zlib_ng_dep.found())
zlib_ng_provider = 'system library'
conf_data.set10('C_SYSTEM_ZLIB_NG', true)
try_builtin_zlib_ng = false
else
zlib_ng_provider = 'skipped (system library not found)'
endif
endif
# We only justify the extra time to setup zlib-ng (using CMake) if
# the user wants an optimized build, so check if we can skip it:
#
if try_builtin_zlib_ng and not is_optimized_buildtype
zlib_ng_provider = 'skipped (non-optimized build)'
try_builtin_zlib_ng = false
endif
# Meson needs to be new enough to setup the zlib-ng CMake project, so
# check if Meson is too old:
#
if try_builtin_zlib_ng and meson.version() < '1.3.0'
zlib_ng_provider = 'skipped (meson is < 1.3.0)'
try_builtin_zlib_ng = false
endif
# CMake needs to be available both on the host and in Meson as a module to
# setup the zlib-ng CMake project, so check if we're missing either:
#
cmake_module = disabler()
if try_builtin_zlib_ng
cmake_bin = find_program('cmake', required: false)
cmake_module = import('cmake', required: false)
if not cmake_bin.found()
zlib_ng_provider = 'skipped (CMake not found)'
try_builtin_zlib_ng = false
elif not cmake_module.found()
zlib_ng_provider = 'skipped (Meson\'s CMake module not found)'
try_builtin_zlib_ng = false
endif
endif
# If we passed all the above checks, everything is in place to use the wrap!
if try_builtin_zlib_ng
cmake_options = cmake_module.subproject_options()
zlib_ng_defines = {
'ZLIB_COMPAT': true,
'WITH_OPTIM': true,
'ZLIB_BUILD_STATIC': true,
'PIC': get_option('b_staticpic'),
'BUILD_SHARED_LIBS': false,
'WITH_GTEST': false,
'ZLIB_ENABLE_TESTS': false,
'WITH_NATIVE_INSTRUCTIONS': zlib_ng_is_native,
'WITH_SANITIZER': get_option('b_sanitize'),
'CMAKE_C_FLAGS': ' '.join(cc_supported_arguments),
}
foreach instruction_set : [
'avx2',
'avx512',
'avx512vnni',
'sse2',
'ssse3',
'sse42',
'pclmulqdq',
'vpclmulqdq',
'acle',
'neon',
'armv6',
'altivec',
'power8',
'rvv',
'crc32_vx',
'dfltcc_deflate',
'dfltcc_inflate',
]
cmake_define_key = 'WITH_' + instruction_set.to_upper()
cmake_define_value = (
zlib_ng_is_native
or zlib_ng_options.contains(instruction_set)
)
zlib_ng_defines += {cmake_define_key: cmake_define_value}
endforeach
cmake_options.add_cmake_defines(zlib_ng_defines)
zlib_ng_subproject = cmake_module.subproject(
'zlib-ng',
options: cmake_options,
)
zlib_ng_provider = 'built-in'
# We configure zlib-ng to be a drop in replacement for zlib, so we
# can directly assign the zlib_dep from the zlib-ng subproject:
#
zlib_dep = zlib_ng_subproject.get_variable('zlib_dep')
zlib_provider = 'built-in (zlib-ng)'
endif
# Otherwise use the system's zlib
if not zlib_dep.found()
zlib_dep = dependency(
'zlib',
version: ['>= 1.2.11', '< 2'],
required: true,
fallback: [],
static: zlib_is_static,
include_type: 'system',
)
zlib_provider = 'system library'
endif
summary('zlib-ng provider', zlib_ng_provider)
summary('zlib provider', zlib_provider)
# PNG
# ~~~
png_has_internal_dep = zlib_dep.type_name() == 'internal'
if png_has_internal_dep
png_dep = subproject(
'libpng',
default_options: default_wrap_options,
).get_variable('png_dep')
else
png_dep = dependency(
'libpng',
version: ['>= 1.2', '< 2'],
required: true,
fallback: [],
static: 'png' in static_libs_list or prefers_static_libs,
include_type: 'system',
)
endif
summary(
'PNG provider',
png_dep.type_name() == 'internal' ? 'built-in' : 'system library',
)
# SpeexDSP
# ~~~~~~~~
# Default to the system library
speexdsp_dep = dependency(
'speexdsp',
version: ['>= 1.2', '< 2'],
required: false,
fallback: [],
static: ('speexdsp' in static_libs_list or prefers_static_libs),
include_type: 'system',
)
# The library needs to be available and testable to be trusted
can_trust_system_speexdsp = (
speexdsp_dep.found()
and meson.can_run_host_binaries()
)
# Test the library. Trust is dropped if the test fails.
if can_trust_system_speexdsp
system_speexdsp_test = cxx.run(
files('contrib/check-speexdsp/test_speexdsp_float_api.cpp'),
dependencies: speexdsp_dep,
name: 'SpeexDSP system library has reliable floating-point API',
)
can_trust_system_speexdsp = (
system_speexdsp_test.compiled()
and system_speexdsp_test.returncode() == 0
)
if can_trust_system_speexdsp
speexdsp_summary_msg = 'system library'
endif
endif
# Use the wrap if the system doesn't have SpeexDSP, we couldn't test it, or testing failed
if not can_trust_system_speexdsp
speexdsp_dep = subproject(
'speexdsp',
default_options: default_wrap_options,
).get_variable('speexdsp_dep')
speexdsp_summary_msg = 'built-in'
endif
summary('SpeexDSP provider', speexdsp_summary_msg)
# File-descriptor manipulation routines, such as FD_ZERO, are used
# by Enet, slirp, and ManyMouse's X11 interface. Unfortunately these
# routines aren't universally available, such as on Android.
#
have_fd_zero = (
cc.has_header_symbol('sys/select.h', 'FD_ZERO')
or cc.has_header_symbol('winsock2.h', 'FD_ZERO')
)
# SDL Networking
sdl2_net_dep = optional_dep
sdl2_net_summary_msg = 'Disabled'
if get_option('use_sdl2_net')
if host_machine.system() == 'darwin' and not wraps_disabled
# use wrap so we can control MACOSX_DEPLOYMENT_TARGET during the build
sdl2_net_dep = subproject(
'sdl2_net',
default_options: default_wrap_options,
).get_variable('sdl2_net_dep')
else
sdl2_net_dep = dependency(
'SDL2_net',
version: ['>= 2.0.0', '< 3'],
static: ('sdl2_net' in static_libs_list),
fallback: [],
not_found_message: msg.format('use_sdl2_net'),
include_type: 'system',
)
endif
sdl2_net_summary_msg = sdl2_net_dep.found()
if sdl2_net_dep.found() and not have_fd_zero
sdl2_net_dep = optional_dep
sdl2_net_summary_msg = 'Disabled due to host missing file-descriptor routines'
endif
endif
summary('SDL_net 2.0 support', sdl2_net_summary_msg)
# slirp (depends on glib)
libslirp_dep = optional_dep
libslirp_summary_msg = 'Disabled'
if get_option('use_slirp')
libslirp_dep = dependency(
'slirp',
version: ['>= 4.6.1', '< 5'],
default_options: default_wrap_options,
static: ('slirp' in static_libs_list or prefers_static_libs),
not_found_message: msg.format('use_slirp'),
include_type: 'system',
)
libslirp_summary_msg = libslirp_dep.found()
if libslirp_dep.found() and not have_fd_zero
libslirp_summary_msg = 'Disabled due to host missing file-descriptor routines'
libslirp_dep = optional_dep
endif
endif
summary('slirp support', libslirp_summary_msg)
# OpenGL
opengl_dep = optional_dep
if get_option('use_opengl')
opengl_dep = dependency('gl', not_found_message: msg.format('use_opengl'))
endif
conf_data.set10('C_OPENGL', opengl_dep.found())
# FluidSynth (depends on glib)
fluid_dep = optional_dep
if get_option('use_fluidsynth')
fluid_dep = dependency(
'fluidsynth',
version: ['>= 2.2.3', '< 3'],
modules: ['FluidSynth::libfluidsynth'],
static: ('fluidsynth' in static_libs_list or prefers_static_libs),
not_found_message: msg.format('use_fluidsynth'),
default_options: [
'default_library=static',
'try-static-deps=true',
'enable-floats=true',
'openmp=disabled',
'enable-threads=false',