-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmeson.build
More file actions
1990 lines (1875 loc) · 68.9 KB
/
Copy pathmeson.build
File metadata and controls
1990 lines (1875 loc) · 68.9 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
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(
'openQ4',
['c', 'cpp'],
version: '0.11.0',
meson_version: '>=1.6.0',
default_options: ['c_std=c11', 'cpp_std=c++20', 'b_vscrt=static_from_buildtype'],
)
host_system = host_machine.system()
host_cpu_family = host_machine.cpu_family()
if not ['windows', 'linux', 'darwin'].contains(host_system)
error('Unsupported host system for openQ4 Meson build: ' + host_system)
endif
binary_arch = host_cpu_family
if host_cpu_family == 'x86_64'
binary_arch = 'x64'
elif host_cpu_family == 'x86'
binary_arch = 'x86'
elif host_cpu_family == 'aarch64'
binary_arch = 'arm64'
endif
game_sp_binary_name = 'game-sp_' + binary_arch
game_mp_binary_name = 'game-mp_' + binary_arch
game_module_filename_suffix = '.so'
if host_system == 'windows'
game_module_filename_suffix = '.dll'
elif host_system == 'darwin'
game_module_filename_suffix = '.dylib'
endif
engine_client_binary_name = meson.project_name() + '-client_' + binary_arch
engine_ded_binary_name = meson.project_name() + '-ded_' + binary_arch
if host_cpu_family != 'x86_64' and not (host_system == 'linux' and host_cpu_family == 'aarch64')
warning(
'openQ4 currently targets x64 as the active compatibility baseline. '
+ 'Non-x64 builds are considered experimental during platform bring-up.'
)
endif
platform_backend_requested = get_option('platform_backend')
platform_backend = platform_backend_requested
macos_graphics_bridge = get_option('macos_graphics_bridge')
macos_openal_provider = get_option('macos_openal_provider')
if host_system == 'windows' and platform_backend_requested == 'native'
error('platform_backend=native is only valid on non-Windows hosts.')
endif
if host_system != 'darwin' and macos_graphics_bridge != 'opengl'
error('macos_graphics_bridge=' + macos_graphics_bridge + ' is only valid on macOS hosts.')
endif
if host_system != 'darwin' and macos_openal_provider != 'apple_framework'
error('macos_openal_provider=' + macos_openal_provider + ' is only valid on macOS hosts.')
endif
if host_system == 'linux'
if platform_backend_requested == 'legacy_win32'
error('platform_backend=legacy_win32 is only valid on Windows hosts.')
endif
elif host_system == 'darwin'
if platform_backend_requested == 'legacy_win32'
error('platform_backend=legacy_win32 is only valid on Windows hosts.')
endif
if macos_graphics_bridge == 'metal' and platform_backend_requested != 'sdl3'
error('macos_graphics_bridge=metal requires platform_backend=sdl3 so the bridge stays on the shared SDL3 path instead of the native Cocoa backend.')
endif
if platform_backend_requested == 'native'
warning(
'platform_backend=native on macOS is comparison-only diagnostic infrastructure. '
+ 'Release packages use platform_backend=sdl3; do not treat the native Cocoa/OpenGL backend as supported release coverage.'
)
endif
elif host_system != 'windows'
error('Unsupported host system for platform backend selection: ' + host_system)
endif
use_sdl3_backend = platform_backend == 'sdl3'
use_macos_metal_bridge = host_system == 'darwin' and macos_graphics_bridge == 'metal'
if host_system == 'windows' and not use_sdl3_backend
warning(
'legacy_win32 backend is transitional. '
+ 'Use -Dplatform_backend=sdl3 for portability-focused development.'
)
endif
if host_system == 'windows'
# Windows commonly enables a non-functional Microsoft Store python3.exe
# application alias. Prefer the real python.exe launcher there.
py = find_program('python', 'python3', native: true, required: true)
else
py = find_program('python3', 'python', native: true, required: true)
endif
fs_mod = import('fs')
if host_system == 'darwin'
add_languages('objc', 'objcpp', required: true)
macos_deployment_target = '11.0'
add_project_arguments(
'-mmacosx-version-min=' + macos_deployment_target,
language: ['c', 'cpp', 'objc', 'objcpp'],
)
add_project_link_arguments(
'-mmacosx-version-min=' + macos_deployment_target,
language: ['c', 'cpp', 'objc', 'objcpp'],
)
endif
version_track = get_option('version_track').strip()
version_iteration = get_option('version_iteration').strip()
version_base_override = get_option('version_base_override').strip()
openal_root_override = get_option('openal_root_override').strip()
generated_version_header_path = meson.current_build_dir() / 'openq4_version_generated.h'
version_metadata_command = [
py,
meson.project_source_root() / 'tools' / 'build' / 'openq4_version.py',
'--source-root',
meson.project_source_root(),
'--track',
version_track,
]
# Release builds pin the exact version. Everything else lets the helper resolve
# it: project(version:) above is only a floor, raised to the newest published v*
# tag when git history is available, so an unpinned build never advertises a
# version that was never released.
if version_base_override != ''
version_metadata_command += ['--base-version', version_base_override]
endif
if version_iteration != ''
version_metadata_command += ['--iteration', version_iteration]
endif
version_metadata_result = run_command(
version_metadata_command + ['--header-out', generated_version_header_path],
check: true,
)
# Git metadata changes whenever HEAD or the worktree changes, without changing
# meson.build. Re-run the lightweight generator for every build invocation;
# write_if_changed keeps downstream recompilation limited to real version
# changes. The configure-time invocation above ensures the header also exists
# before a backend performs its first dependency scan.
generated_version_header = custom_target(
'openq4_version_generated',
output: 'openq4_version_generated.h',
command: version_metadata_command + ['--header-out', '@OUTPUT@'],
depend_files: files('tools/build/openq4_version.py'),
build_always_stale: true,
build_by_default: true,
install: false,
)
openq4_version_base = meson.project_version()
openq4_version_short = meson.project_version()
openq4_version_full = meson.project_version()
openq4_version_tag = meson.project_version()
openq4_version_date = ''
openq4_product_version = meson.project_name() + ' ' + meson.project_version()
openq4_product_version_full = openq4_product_version
openq4_version_resource_dotted = meson.project_version() + '.0'
openq4_git_sha = ''
openq4_git_dirty = '0'
openq4_commit_count = '0'
root_include_dir = include_directories('.')
foreach version_line : version_metadata_result.stdout().strip().split('\n')
if version_line == ''
continue
endif
version_pair = version_line.split('=')
if version_pair.length() != 2
continue
endif
version_key = version_pair[0]
version_value = version_pair[1]
if version_key == 'base_version'
openq4_version_base = version_value
elif version_key == 'version_short'
openq4_version_short = version_value
elif version_key == 'version'
openq4_version_full = version_value
elif version_key == 'version_tag'
openq4_version_tag = version_value
elif version_key == 'version_date'
openq4_version_date = version_value
elif version_key == 'product_version'
openq4_product_version = version_value
elif version_key == 'product_version_full'
openq4_product_version_full = version_value
elif version_key == 'resource_dotted'
openq4_version_resource_dotted = version_value
elif version_key == 'git_sha'
openq4_git_sha = version_value
elif version_key == 'git_dirty'
openq4_git_dirty = version_value
elif version_key == 'commit_count'
openq4_commit_count = version_value
endif
endforeach
build_engine = get_option('build_engine')
build_games = get_option('build_games')
build_game_sp = get_option('build_game_sp')
build_game_mp = get_option('build_game_mp')
needs_game_headers = build_engine or build_games
install_root_dir = meson.project_source_root() / '.install'
install_game_dir = install_root_dir / 'baseoq4'
game_libs_repo_root = ''
game_libs_source_root = ''
game_libs_repo_summary = 'not required'
game_stage_root = ''
game_stage_game_root = ''
game_stage_mpgame_root = ''
game_stage_game_include_rel = '.tmp/gamelibs_stage/src/game'
game_stage_mpgame_include_rel = '.tmp/gamelibs_stage/src/mpgame'
bse_source_root = meson.project_source_root() / 'src' / 'bse'
game_sp_module_defs_file = ''
game_mp_module_defs_file = ''
if not build_engine and not build_games
error('At least one build target must be enabled. Use -Dbuild_engine=true and/or -Dbuild_games=true.')
endif
if get_option('build_native_tests')
openq4_core_safety_test = executable(
'openq4-core-safety-test',
files(
'tools/tests/native/CoreSafetyTest.cpp',
'src/idlib/CryptoHash.cpp',
'src/framework/async/Rcon2Protocol.cpp',
),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-core-safety',
openq4_core_safety_test,
timeout: 30,
)
openq4_level_load_cache_format_test = executable(
'openq4-level-load-cache-format-test',
files(
'tools/tests/native/LevelLoadCacheFormatTest.cpp',
'src/framework/LevelLoadCacheFormat.cpp',
),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-level-load-cache-format',
openq4_level_load_cache_format_test,
timeout: 30,
)
openq4_level_load_pipeline_test = executable(
'openq4-level-load-pipeline-test',
files(
'tools/tests/native/LevelLoadPipelineTest.cpp',
'src/framework/LevelLoadPipeline.cpp',
'src/framework/ParallelJobSystem.cpp',
),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-level-load-pipeline',
openq4_level_load_pipeline_test,
timeout: 30,
)
openq4_job_system_test = executable(
'openq4-job-system-test',
files(
'tools/tests/native/ParallelJobSystemTest.cpp',
'src/framework/ParallelJobSystem.cpp',
),
include_directories: root_include_dir,
dependencies: dependency('threads', required: true),
install: false,
)
test(
'openq4-job-system',
openq4_job_system_test,
timeout: 30,
)
openq4_gpu_frame_timing_test = executable(
'openq4-gpu-frame-timing-test',
files('tools/tests/native/GpuFrameTimingTest.cpp'),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-gpu-frame-timing',
openq4_gpu_frame_timing_test,
timeout: 30,
)
openq4_temporal_presentation_core_test = executable(
'openq4-temporal-presentation-core-test',
files('tools/tests/native/TemporalPresentationCoreTest.cpp'),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-temporal-presentation-core',
openq4_temporal_presentation_core_test,
timeout: 30,
)
openq4_temporal_history_core_test = executable(
'openq4-temporal-history-core-test',
files('tools/tests/native/TemporalHistoryCoreTest.cpp'),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-temporal-history-core',
openq4_temporal_history_core_test,
timeout: 30,
)
openq4_renderer_contracts_test = executable(
'openq4-renderer-contracts-test',
files(
'tools/tests/native/RendererContractsTest.cpp',
'src/renderer/RendererContracts.cpp',
),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-renderer-contracts',
openq4_renderer_contracts_test,
timeout: 30,
)
openq4_advanced_lighting_core_test = executable(
'openq4-advanced-lighting-core-test',
files('tools/tests/native/AdvancedLightingCoreTest.cpp'),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-advanced-lighting-core',
openq4_advanced_lighting_core_test,
timeout: 30,
)
openq4_advanced_screen_space_core_test = executable(
'openq4-advanced-screen-space-core-test',
files('tools/tests/native/AdvancedScreenSpaceCoreTest.cpp'),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-advanced-screen-space-core',
openq4_advanced_screen_space_core_test,
timeout: 30,
)
openq4_specular_probe_atlas_packing_test = executable(
'openq4-specular-probe-atlas-packing-test',
files('tools/tests/native/ModernSpecularProbeAtlasPackingTest.cpp'),
include_directories: root_include_dir,
install: false,
)
test(
'openq4-specular-probe-atlas-packing',
openq4_specular_probe_atlas_packing_test,
timeout: 30,
)
endif
openq4_pak_files = []
openq4_paks_generated_header = []
if build_engine or build_games
openq4_pak_script_files = files(
'tools/build/openq4_pak.py',
)
openq4_pak_manifest_script_files = files(
'tools/build/write_pak_manifest.py',
)
openq4_pak0_source_manifest = custom_target(
'openq4_pak0_source_manifest',
output: 'pak0.sources',
command: [
py,
meson.project_source_root() / 'tools' / 'build' / 'write_pak_manifest.py',
meson.project_source_root(),
'pak0.pk4',
'content/baseoq4/pak0',
'@OUTPUT@',
],
depend_files: openq4_pak_script_files + openq4_pak_manifest_script_files,
build_always_stale: true,
build_by_default: true,
)
openq4_pak1_source_manifest = custom_target(
'openq4_pak1_source_manifest',
output: 'pak1.sources',
command: [
py,
meson.project_source_root() / 'tools' / 'build' / 'write_pak_manifest.py',
meson.project_source_root(),
'pak1.pk4',
'content/baseoq4/pak1',
'@OUTPUT@',
],
depend_files: openq4_pak_script_files + openq4_pak_manifest_script_files,
build_always_stale: true,
build_by_default: true,
)
openq4_pak0_output = custom_target(
'openq4_pak0',
input: openq4_pak0_source_manifest,
output: 'pak0.pk4',
command: [
py,
meson.project_source_root() / 'tools' / 'build' / 'build_openq4_pack.py',
'--pak-name',
'pak0.pk4',
'--source-dir',
meson.project_source_root() / 'content' / 'baseoq4' / 'pak0',
'--manifest',
'@INPUT@',
'--out',
'@OUTPUT@',
'--stage-out',
meson.current_build_dir() / 'baseoq4' / 'pak0.pk4',
],
depend_files: openq4_pak_script_files + files(
'tools/build/build_openq4_pack.py',
),
build_by_default: true,
install: true,
install_dir: install_game_dir,
)
openq4_pak1_output = custom_target(
'openq4_pak1',
input: openq4_pak1_source_manifest,
output: 'pak1.pk4',
command: [
py,
meson.project_source_root() / 'tools' / 'build' / 'build_openq4_pack.py',
'--pak-name',
'pak1.pk4',
'--source-dir',
meson.project_source_root() / 'content' / 'baseoq4' / 'pak1',
'--manifest',
'@INPUT@',
'--out',
'@OUTPUT@',
'--stage-out',
meson.current_build_dir() / 'baseoq4' / 'pak1.pk4',
],
depend_files: openq4_pak_script_files + files(
'tools/build/build_openq4_pack.py',
),
build_by_default: true,
install: true,
install_dir: install_game_dir,
)
openq4_paks_header_output = custom_target(
'openq4_paks_generated_header',
input: [openq4_pak0_output, openq4_pak1_output],
output: 'openq4_paks_generated.h',
command: [
py,
meson.project_source_root() / 'tools' / 'build' / 'generate_pak_header.py',
'--pak0',
'@INPUT0@',
'--pak1',
'@INPUT1@',
'--header-out',
'@OUTPUT@',
],
depend_files: openq4_pak_script_files + files(
'tools/build/generate_pak_header.py',
),
build_by_default: true,
install: false,
)
openq4_pak_files = [openq4_pak0_output, openq4_pak1_output]
openq4_paks_generated_header = [openq4_paks_header_output]
endif
if needs_game_headers
game_libs_repo_discovery = run_command(
py,
'-c',
'import os, pathlib, sys; root = pathlib.Path(sys.argv[1]); raw = os.environ.get("OPENQ4_GAMELIBS_REPO", "").strip(); repo = pathlib.Path(raw) if raw else (root / ".." / "openQ4-game"); print(repo.resolve().as_posix())',
meson.project_source_root(),
check: true,
)
game_libs_repo_root = game_libs_repo_discovery.stdout().strip()
if game_libs_repo_root == ''
error('Failed to resolve the openQ4-game repository path. Set OPENQ4_GAMELIBS_REPO or place it at ../openQ4-game.')
endif
game_libs_source_root = game_libs_repo_root / 'src'
if not fs_mod.is_dir(game_libs_source_root / 'game')
error('openQ4-game source directory not found: ' + game_libs_source_root / 'game')
endif
if not fs_mod.is_dir(game_libs_source_root / 'mpgame')
error('openQ4-game multiplayer source directory not found: ' + game_libs_source_root / 'mpgame')
endif
game_stage_result = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'stage_gamelibs.py',
meson.project_source_root(),
game_libs_repo_root,
meson.project_source_root() / '.tmp' / 'gamelibs_stage',
check: true,
)
game_stage_root = game_stage_result.stdout().strip()
if game_stage_root == ''
error('Failed to stage game sources from openQ4-game.')
endif
game_stage_game_root = game_stage_root / 'src' / 'game'
if not fs_mod.is_dir(game_stage_game_root)
error('Staged game source directory not found: ' + game_stage_game_root)
endif
game_stage_mpgame_root = game_stage_root / 'src' / 'mpgame'
if not fs_mod.is_dir(game_stage_mpgame_root)
error('Staged multiplayer game source directory not found: ' + game_stage_mpgame_root)
endif
game_stage_manifest = game_stage_root / 'openq4_gamelibs_stage_manifest.json'
if not fs_mod.is_file(game_stage_manifest)
error('Staged openQ4-game source manifest not found: ' + game_stage_manifest)
endif
game_sp_module_defs_file = game_stage_game_root / 'Game.def'
game_mp_module_defs_file = game_stage_mpgame_root / 'mpgame.def'
if host_system == 'windows' and not fs_mod.is_file(game_sp_module_defs_file)
error('Staged Game.def not found: ' + game_sp_module_defs_file)
endif
if host_system == 'windows' and not fs_mod.is_file(game_mp_module_defs_file)
error('Staged mpgame.def not found: ' + game_mp_module_defs_file)
endif
game_libs_repo_summary = game_libs_repo_root
endif
if build_engine and not fs_mod.is_dir(bse_source_root)
error('Integrated BSE source directory not found: ' + bse_source_root)
endif
cc = meson.get_compiler('c')
cpp = meson.get_compiler('cpp')
linux_x11_dep = disabler()
linux_xext_dep = disabler()
linux_xxf86vm_dep = disabler()
linux_gl_dep = disabler()
linux_x11_helpers_enabled = false
linux_x11_option = get_option('linux_x11')
if build_engine and host_system == 'linux'
if linux_x11_option.disabled()
linux_gl_dep = cc.find_library('OpenGL', required: true)
else
linux_gl_dep = cc.find_library('OpenGL', required: false)
if not linux_gl_dep.found()
linux_gl_dep = cc.find_library('GL', required: true)
endif
endif
if use_sdl3_backend
if not linux_x11_option.disabled()
linux_x11_dep = dependency('x11', required: linux_x11_option)
linux_xext_dep = dependency('xext', required: linux_x11_option)
linux_x11_helpers_enabled = linux_x11_dep.found() and linux_xext_dep.found()
endif
else
if linux_x11_option.disabled()
error('linux_x11=disabled requires the SDL3 platform backend.')
endif
linux_x11_dep = dependency('x11', required: true)
linux_xext_dep = dependency('xext', required: true)
linux_xxf86vm_dep = dependency('xxf86vm', required: true)
linux_x11_helpers_enabled = true
endif
endif
# Phase B8 F3: on SDL3 Windows/Linux the client executable sheds the
# statically linked renderer and always loads the renderer-gl module
# ('gl' resolves to the module there). macOS and the legacy backends keep
# the static renderer; the dedicated targets keep it everywhere until the
# server front-end story changes.
renderer_module_only_client = build_engine and get_option('build_renderer_gl') and use_sdl3_backend and (host_system == 'windows' or host_system == 'linux')
# Phase B7: the Windows SDL3 ded keeps the renderer front-end but links no GL
windows_gl_free_ded = build_engine and host_system == 'windows' and use_sdl3_backend
engine_source_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'meson_sources.py',
'--host-system',
host_system,
'--platform-backend',
platform_backend,
'--linux-x11-helpers',
linux_x11_helpers_enabled ? 'true' : 'false',
'--include-game',
'false',
'--renderer',
renderer_module_only_client ? 'module' : 'static',
check: true,
)
engine_source_paths = engine_source_discovery.stdout().strip().split('\n')
if engine_source_paths.length() == 0
error('tools/build/meson_sources.py returned no engine source files.')
endif
dedicated_engine_source_paths = engine_source_paths
if windows_gl_free_ded
# the Windows ded target keeps the static renderer (minus the GL link);
# discover its own list
dedicated_static_source_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'meson_sources.py',
'--host-system',
host_system,
'--platform-backend',
platform_backend,
'--linux-x11-helpers',
'false',
'--include-game',
'false',
'--renderer',
'static',
'--target-kind',
'dedicated',
check: true,
)
dedicated_engine_source_paths = dedicated_static_source_discovery.stdout().strip().split('\n')
if dedicated_engine_source_paths.length() == 0
error('tools/build/meson_sources.py returned no Windows dedicated source files.')
endif
endif
if host_system == 'linux'
dedicated_engine_source_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'meson_sources.py',
'--host-system',
host_system,
'--platform-backend',
platform_backend,
'--linux-x11-helpers',
'false',
'--include-game',
'false',
'--target-kind',
'dedicated',
check: true,
)
dedicated_engine_source_paths = dedicated_engine_source_discovery.stdout().strip().split('\n')
if dedicated_engine_source_paths.length() == 0
error('tools/build/meson_sources.py returned no Linux dedicated-server source files.')
endif
endif
imagetools_source_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'meson_sources.py',
'--emit',
'imagetools',
check: true,
)
imagetools_source_paths = imagetools_source_discovery.stdout().strip().split('\n')
if imagetools_source_paths.length() == 0
error('tools/build/meson_sources.py returned no imagetools source files.')
endif
openq4_imagetools_sources = files(imagetools_source_paths)
render_geo_source_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'meson_sources.py',
'--emit',
'render_geo',
check: true,
)
render_geo_source_paths = render_geo_source_discovery.stdout().strip().split('\n')
if render_geo_source_paths.length() == 0
error('tools/build/meson_sources.py returned no render_geo source files.')
endif
openq4_render_geo_sources = files(render_geo_source_paths)
renderer_gl_source_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'meson_sources.py',
'--emit',
'renderer_gl',
check: true,
)
renderer_gl_source_paths = renderer_gl_source_discovery.stdout().strip().split('\n')
if renderer_gl_source_paths.length() == 0
error('tools/build/meson_sources.py returned no renderer_gl source files.')
endif
openq4_renderer_gl_sources = files(renderer_gl_source_paths)
openq4_engine_sources = files(engine_source_paths)
if build_engine
openq4_engine_sources += [openq4_paks_generated_header, generated_version_header]
endif
game_sp_sources = []
game_mp_sources = []
game_sources = []
bse_sources = []
game_idlib_sources = []
if build_games
game_sp_source_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'list_sources.py',
game_stage_root,
'src/game',
'src/game/Callbacks.cpp',
'src/game/gamesys/Callbacks.cpp',
check: true,
)
game_sp_source_paths = game_sp_source_discovery.stdout().strip().split('\n')
if game_sp_source_paths.length() == 0
error('tools/build/list_sources.py returned no single-player game source files.')
endif
game_sp_absolute_paths = []
foreach rel_path : game_sp_source_paths
game_sp_absolute_paths += [game_stage_root / rel_path]
endforeach
game_sp_sources = files(game_sp_absolute_paths)
game_mp_source_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'list_sources.py',
game_stage_root,
'src/mpgame',
'src/mpgame/Callbacks.cpp',
'src/mpgame/gamesys/Callbacks.cpp',
check: true,
)
game_mp_source_paths = game_mp_source_discovery.stdout().strip().split('\n')
if game_mp_source_paths.length() == 0
error('tools/build/list_sources.py returned no multiplayer game source files.')
endif
game_mp_absolute_paths = []
foreach rel_path : game_mp_source_paths
game_mp_absolute_paths += [game_stage_root / rel_path]
endforeach
game_mp_sources = files(game_mp_absolute_paths)
game_sources = game_sp_sources + game_mp_sources
savegame_compat_header = custom_target(
'openq4_savegame_compat_generated',
output: 'openq4_savegame_compat_generated.h',
command: [
py,
meson.project_source_root() / 'tools' / 'build' / 'generate_savegame_compat_header.py',
'--project-root',
meson.project_source_root(),
'--game-stage-root',
game_stage_root,
'--header-out',
'@OUTPUT@',
],
depend_files: files(engine_source_paths) + game_sources + files(dedicated_engine_source_paths) + files(
'tools/build/generate_savegame_compat_header.py',
),
install: false,
)
game_sp_sources += [savegame_compat_header, generated_version_header]
game_mp_sources += [savegame_compat_header, generated_version_header]
if build_engine
# Session preflights the exact GameLibs source stamp before tearing down
# the active map, so the engine target must see the same generated header.
openq4_engine_sources += [savegame_compat_header]
endif
endif
if build_engine
bse_source_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'list_sources.py',
meson.project_source_root(),
'src/bse',
check: true,
)
bse_source_paths = bse_source_discovery.stdout().strip().split('\n')
if bse_source_paths.length() == 0
error('tools/build/list_sources.py returned no BSE source files.')
endif
bse_sources = files(bse_source_paths)
endif
if build_engine or build_games
game_idlib_discovery = run_command(
py,
meson.project_source_root() / 'tools' / 'build' / 'list_sources.py',
meson.project_source_root(),
'src/idlib',
'src/idlib/math/Simd_AltiVec.cpp',
check: true,
)
game_idlib_paths = game_idlib_discovery.stdout().strip().split('\n')
if game_idlib_paths.length() == 0
error('tools/build/list_sources.py returned no game idlib source files.')
endif
game_idlib_sources = files(game_idlib_paths)
endif
resource_compiler = find_program('rc', 'windres', required: false)
openq4_version_resources = []
if host_system == 'windows' and resource_compiler.found()
windows_mod = import('windows')
openq4_version_resources = windows_mod.compile_resources(
'src/sys/win32/rc/openQ4Version.rc',
include_directories: [root_include_dir],
)
openq4_engine_sources += openq4_version_resources
endif
is_msvc = cc.get_id() == 'msvc' and cpp.get_id() == 'msvc'
msvc_2026_min = '19.46.0'
if is_msvc
if cpp.version().version_compare('<' + msvc_2026_min)
msvc_2026_msg = 'MSVC 19.46+ (Visual Studio 2026 toolset baseline) is recommended. Detected: ' + cpp.version() + '.'
if get_option('enforce_msvc_2026')
error(msvc_2026_msg)
else
warning(msvc_2026_msg + ' Configure with -Denforce_msvc_2026=true to enforce this baseline.')
endif
endif
elif get_option('enforce_msvc_2026')
warning('enforce_msvc_2026 is only meaningful when using the MSVC toolchain.')
endif
fallback_opt = ['default_library=static']
glew_default_options = fallback_opt
sdl3_default_options = fallback_opt
if host_system == 'linux' and use_sdl3_backend
glew_default_options += ['openq4_sdl3_loader=true']
if linux_x11_option.disabled()
sdl3_default_options += ['x11=disabled']
elif linux_x11_option.enabled()
sdl3_default_options += ['x11=enabled']
else
sdl3_default_options += ['x11=auto']
endif
endif
glew_dep = disabler()
glew_dedicated_dep = disabler()
stb_vorbis_dep = disabler()
openal_dep = disabler()
sdl3_dep = disabler()
macos_graphics_bridge_dep = disabler()
deps = []
if build_engine
if host_system == 'linux' and use_sdl3_backend
glew_sp = subproject('glew', default_options: glew_default_options)
glew_dep = glew_sp.get_variable('glew_dep')
glew_dedicated_dep = glew_sp.get_variable('glew_dedicated_dep')
else
glew_dep = dependency(
'glew',
required: true,
fallback: ['glew', 'glew_dep'],
default_options: glew_default_options,
)
if host_system == 'linux' or host_system == 'windows' or host_system == 'darwin'
# darwin needs it for the MoltenVK-backed Vulkan renderer module, which
# links no GL but shares front-end translation units that reference it
glew_dedicated_sp = subproject('glew', default_options: glew_default_options)
glew_dedicated_dep = glew_dedicated_sp.get_variable('glew_dedicated_dep')
endif
endif
stb_vorbis_dep = dependency(
'stb_vorbis',
required: true,
fallback: ['stb_vorbis', 'stb_vorbis_dep'],
default_options: fallback_opt,
)
if host_system == 'darwin'
if macos_openal_provider == 'apple_framework'
openal_dep = dependency('appleframeworks', modules: ['OpenAL'], required: true)
else
# The release provider specifically means an OpenAL Soft-style package.
# Meson's generic OpenAL lookup may otherwise fall back to Apple's
# framework when pkg-config cannot see the pinned dependency, while the
# compile defines below still select AL/... headers. Fail during
# configure instead of combining framework libraries with incompatible
# OpenAL Soft headers (GitHub issues #94 and #122).
openal_dep = dependency('openal', required: true, method: 'pkg-config')
endif
else
if host_system == 'windows' and openal_root_override != ''
openal_override_root = openal_root_override
openal_override_include_dir = openal_override_root / 'include'
if cc.get_argument_syntax() == 'msvc'
openal_override_include_args = ['/I', openal_override_include_dir]
else
openal_override_include_args = ['-I', openal_override_include_dir]
endif
openal_override_lib = cc.find_library(
'OpenAL32',
dirs: [openal_override_root / 'lib'],
required: true,
)
openal_dep = declare_dependency(
compile_args: openal_override_include_args,
dependencies: [openal_override_lib],
)
else
openal_dep = dependency(
'openal',
required: true,
fallback: ['openal-soft-prebuilt', 'openal_dep'],
default_options: fallback_opt,
)
endif
endif
if use_sdl3_backend
if host_system == 'linux' and not linux_x11_option.auto()
# A system SDL's compiled video-driver set cannot be changed by a Meson
# feature option. Explicit linux_x11 modes therefore select the bundled
# SDL so enabled/disabled is a real build contract rather than a hint
# that silently depends on the distribution's SDL configuration.
sdl3_subproject = subproject('sdl3', default_options: sdl3_default_options)
sdl3_dep = sdl3_subproject.get_variable('sdl3_dep')
else
sdl3_dep = dependency(
'sdl3',
version: '>=3.4.4',
required: true,
fallback: ['sdl3', 'sdl3_dep'],
default_options: sdl3_default_options,
)
endif
endif
deps = [glew_dep, openal_dep, stb_vorbis_dep]
if host_system == 'windows'
windows_shell_dep = cc.find_library('shell32', required: true)
windows_ole_dep = cc.find_library('ole32', required: true)
deps += [
cc.find_library('opengl32', required: true),
cc.find_library('Dbghelp', required: true),
cc.find_library('bcrypt', required: true),
cc.find_library('Iphlpapi', required: true),
cc.find_library('Winmm', required: true),
cc.find_library('ws2_32', required: true),
windows_shell_dep,
windows_ole_dep,
]
if use_sdl3_backend
deps += [sdl3_dep]
else
deps += [
cc.find_library('dinput8', required: true),
cc.find_library('dxguid', required: true),
]
endif
elif host_system == 'linux'
deps += [
dependency('threads', required: true),
cc.find_library('dl', required: true),
linux_gl_dep,
]
if use_sdl3_backend
deps += [sdl3_dep]
if linux_x11_helpers_enabled
deps += [linux_x11_dep, linux_xext_dep]
endif
else
deps += [linux_x11_dep, linux_xext_dep, linux_xxf86vm_dep]
endif
elif host_system == 'darwin'
if use_macos_metal_bridge
macos_graphics_bridge_dep = dependency(
'appleframeworks',
modules: ['Metal', 'QuartzCore'],
required: true,
)
endif
macos_framework_modules = ['Cocoa', 'OpenGL', 'ApplicationServices']
if not use_sdl3_backend
macos_framework_modules += ['Carbon']
endif
deps += [
dependency('threads', required: true),
dependency(