-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathmeson.build
More file actions
471 lines (436 loc) · 17 KB
/
Copy pathmeson.build
File metadata and controls
471 lines (436 loc) · 17 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
project(
'vkquake',
'c',
meson_version : '>= 1.3',
default_options : ['c_std=gnu11,c11', 'buildtype=release', 'strip=false', 'debug=true', 'b_ndebug=if-release', 'warning_level=1', 'werror=true'])
cc = meson.get_compiler('c')
# Always build keeping frame pointers to get better backtraces
add_project_arguments(cc.get_supported_arguments('-fno-omit-frame-pointer', '/Oy-'), language: 'c')
# Ask linker not to locate uninitialized variables into COMMON (will use .bss then) to avoid macOS link issue
add_project_arguments('-fno-common', language: 'c')
if host_machine.system() == 'windows'
foreach native : [true, false]
add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', '-D_CRT_NONSTDC_NO_DEPRECATE', '-D_WINSOCK_DEPRECATED_NO_WARNINGS', language : 'c', native : native)
endforeach
endif
if host_machine.system() != 'windows'
if cc.has_header_symbol('sched.h', 'CPU_ZERO', prefix: '#define _GNU_SOURCE')
message('Info: Task affinity support enabled.')
add_project_arguments('-D_GNU_SOURCE', language: 'c')
else
message('Warning: sched.h not found, disabling Task affinity support.')
add_project_arguments('-DTASK_AFFINITY_NOT_AVAILABLE', language: 'c')
endif
endif
shaders = [
'Shaders/alias.vert',
'Shaders/md5.vert',
'Shaders/basic.vert',
'Shaders/fte_particles.frag',
'Shaders/fte_particles_msaa.frag',
'Shaders/basic_alphatest.frag',
'Shaders/basic_notex.frag',
'Shaders/draw_pic.frag',
'Shaders/draw_pic_alphatest.frag',
'Shaders/draw_pic_xbr.frag',
'Shaders/draw_pic_xbr_alphatest.frag',
'Shaders/draw_pic_xbr.vert',
'Shaders/cs_tex_warp.comp',
'Shaders/indirect.comp',
'Shaders/indirect_clear.comp',
'Shaders/postprocess.frag',
'Shaders/scene_upscale.frag',
'Shaders/ssao_composite.frag',
'Shaders/ssao_composite_debug.frag',
'Shaders/ssao_composite_msaa_debug.frag',
'Shaders/ssao_prepare.comp',
'Shaders/ssao_prepare_msaa.comp',
'Shaders/ssao_evaluate.comp',
'Shaders/ssao_evaluate_fp16.comp',
'Shaders/ssao_mip.comp',
'Shaders/ssao_mip_fp16.comp',
'Shaders/ssao_mip_msaa.comp',
'Shaders/ssao_mip_msaa_fp16.comp',
'Shaders/ssao_filter.comp',
'Shaders/ssao_filter_fp16.comp',
'Shaders/ssao_composite_msaa.frag',
'Shaders/postprocess.vert',
'Shaders/showtris.frag',
'Shaders/showtris.vert',
'Shaders/md5_debug.vert',
'Shaders/sky_box.frag',
'Shaders/sky_cube.frag',
'Shaders/sky_cube.vert',
'Shaders/sky_layer.frag',
'Shaders/sky_layer.vert',
'Shaders/world.vert',
'Shaders/ray_debug.comp',
'Shaders/mesh_interpolate.comp',
'Shaders/skinning.comp',
]
# Prefer SDL3 over SDL2; -Duse_sdl3=enabled requires SDL3, disabled forces SDL2
use_sdl3_opt = get_option('use_sdl3')
use_sdl3 = false
if host_machine.system() == 'windows'
if use_sdl3_opt.disabled()
error('SDL2 is not supported on Windows')
endif
# use the bundled SDL3 like the other Windows builds do
sdl_dep = declare_dependency(
include_directories : include_directories('Windows/SDL3/include'),
dependencies : cc.find_library('SDL3', dirs : meson.project_source_root() / 'Windows/SDL3/lib64'))
use_sdl3 = true
else
if not use_sdl3_opt.disabled()
sdl_dep = dependency('sdl3', required : use_sdl3_opt.enabled())
use_sdl3 = sdl_dep.found()
endif
endif
if use_sdl3
add_project_arguments('-DUSE_SDL3', language: 'c')
message('Info: Using SDL3.')
else
sdl_dep = dependency('sdl2')
message('Info: Using SDL2.')
endif
glslang = find_program('glslangValidator')
spirv_opt = find_program('spirv-opt')
run_test_canonicalize_ids_spirv_opt = run_command(spirv_opt, '-h', check : false)
has_canonicalize_ids_spirv_opt = (run_test_canonicalize_ids_spirv_opt.stdout().strip().contains('--canonicalize-ids'))
bintoc = executable('bintoc', ['Shaders/bintoc.c'], native: true)
mkpak = executable('mkpak', ['Misc/vq_pak/mkpak.c'], native: true)
if (build_machine.system() == 'darwin') or get_option('buildtype').startswith('debug')
spirv_opt_args = [] # MoltenVK spirv-cross has a bug that breaks optimized shaders
else
if not has_canonicalize_ids_spirv_opt
error('spirv-opt does not support --canonicalize-ids, a newer Vulkan SDK is required')
endif
spirv_opt_args = ['-Os', '--canonicalize-ids', '--strip-debug']
endif
glslang_args = ['-V', '--quiet']
if get_option('buildtype').startswith('debug')
glslang_args += '-g'
endif
vq_pak_path = join_paths(meson.project_source_root(), 'Misc', 'vq_pak')
mkpak_toc_file = join_paths(vq_pak_path, 'vq_pak_contents.txt')
mkpak_command = [mkpak, '@OUTPUT@', vq_pak_path, mkpak_toc_file, '@DEPFILE@']
run_mkpak = custom_target('run-mkpak',
output : 'vkquake.pak',
depfile : 'vkquake.pak.d',
command: mkpak_command)
# Write the embedded pak into the build dir so Meson can track it.
bintoc_compress_command = [bintoc, '-c', '@INPUT@', 'vkquake.pak', '@OUTPUT@']
run_generate_embedded_pak = custom_target('run-embed_vkquake_pak',
output : 'embedded_pak.c',
input : run_mkpak,
command : bintoc_compress_command)
# shader sources compiled multiple times with different preprocessor defines
shader_variants = [
['Shaders/basic.frag', 'basic.frag', []],
['Shaders/basic.frag', 'basic_oit.frag', ['-DWBOIT=1']],
['Shaders/basic.frag', 'basic_mboit_moment.frag', ['-DMBOIT=1']],
['Shaders/basic.frag', 'basic_mboit_composite.frag', ['-DMBOIT=1', '-DMBOIT_COMPOSITE=1']],
['Shaders/basic.frag', 'basic_mboit_composite_msaa.frag', ['-DMBOIT=1', '-DMBOIT_COMPOSITE=1', '-DMSAA=1']],
['Shaders/world.frag', 'world.frag', []],
['Shaders/world.frag', 'world_oit.frag', ['-DWBOIT=1']],
['Shaders/world.frag', 'world_mboit_moment.frag', ['-DMBOIT=1']],
['Shaders/world.frag', 'world_mboit_composite.frag', ['-DMBOIT=1', '-DMBOIT_COMPOSITE=1']],
['Shaders/world.frag', 'world_mboit_composite_msaa.frag', ['-DMBOIT=1', '-DMBOIT_COMPOSITE=1', '-DMSAA=1']],
['Shaders/alias.frag', 'alias.frag', []],
['Shaders/alias.frag', 'alias_alphatest.frag', ['-DALIAS_ALPHA_TEST=1']],
['Shaders/alias.frag', 'alias_oit.frag', ['-DWBOIT=1']],
['Shaders/alias.frag', 'alias_alphatest_oit.frag', ['-DALIAS_ALPHA_TEST=1', '-DWBOIT=1']],
['Shaders/alias.frag', 'alias_mboit_moment.frag', ['-DMBOIT=1']],
['Shaders/alias.frag', 'alias_alphatest_mboit_moment.frag', ['-DALIAS_ALPHA_TEST=1', '-DMBOIT=1']],
['Shaders/alias.frag', 'alias_mboit_composite.frag', ['-DMBOIT=1', '-DMBOIT_COMPOSITE=1']],
['Shaders/alias.frag', 'alias_alphatest_mboit_composite.frag', ['-DALIAS_ALPHA_TEST=1', '-DMBOIT=1', '-DMBOIT_COMPOSITE=1']],
['Shaders/alias.frag', 'alias_mboit_composite_msaa.frag', ['-DMBOIT=1', '-DMBOIT_COMPOSITE=1', '-DMSAA=1']],
['Shaders/alias.frag', 'alias_alphatest_mboit_composite_msaa.frag', ['-DALIAS_ALPHA_TEST=1', '-DMBOIT=1', '-DMBOIT_COMPOSITE=1', '-DMSAA=1']],
['Shaders/alias.frag', 'md5_mboit_composite.frag', ['-DMBOIT=1', '-DMBOIT_COMPOSITE=1', '-DMBOIT_INPUT_SET=4']],
['Shaders/alias.frag', 'md5_alphatest_mboit_composite.frag', ['-DALIAS_ALPHA_TEST=1', '-DMBOIT=1', '-DMBOIT_COMPOSITE=1', '-DMBOIT_INPUT_SET=4']],
['Shaders/alias.frag', 'md5_mboit_composite_msaa.frag', ['-DMBOIT=1', '-DMBOIT_COMPOSITE=1', '-DMSAA=1', '-DMBOIT_INPUT_SET=4']],
['Shaders/alias.frag', 'md5_alphatest_mboit_composite_msaa.frag', ['-DALIAS_ALPHA_TEST=1', '-DMBOIT=1', '-DMBOIT_COMPOSITE=1', '-DMSAA=1', '-DMBOIT_INPUT_SET=4']],
['Shaders/md5.vert', 'md5_8.vert', ['-DEIGHT_WEIGHT_SKINNING']],
['Shaders/wboit_resolve.frag', 'wboit_resolve.frag', []],
['Shaders/wboit_resolve.frag', 'wboit_resolve_msaa.frag', ['-DMSAA=1']],
['Shaders/mboit_resolve.frag', 'mboit_resolve.frag', []],
['Shaders/mboit_resolve.frag', 'mboit_resolve_msaa.frag', ['-DMSAA=1']],
['Shaders/screen_effects.comp', 'screen_effects_8bit.comp', []],
['Shaders/screen_effects.comp', 'screen_effects_10bit.comp', ['-DUSE_10BIT=1']],
['Shaders/update_lightmap.comp', 'update_lightmap_8bit.comp', []],
['Shaders/update_lightmap.comp', 'update_lightmap_8bit_rt.comp', ['-DRAY_QUERIES=1']],
['Shaders/update_lightmap.comp', 'update_lightmap_10bit.comp', ['-DUSE_10BIT=1']],
['Shaders/update_lightmap.comp', 'update_lightmap_10bit_rt.comp', ['-DUSE_10BIT=1', '-DRAY_QUERIES=1']],
['Shaders/skinning.comp', 'skinning_8.comp', ['-DEIGHT_WEIGHT_SKINNING']],
]
fs = import('fs')
shader_jobs = []
foreach shader : shaders
target_env = (shader.contains('sops') or shader.contains('ssao_mip') or shader.contains('_fp16')) ? ['--target-env', 'vulkan1.1'] : []
shader_jobs += [[shader, fs.name(shader), target_env]]
endforeach
foreach variant : shader_variants
shader_jobs += [[variant[0], variant[1], variant[2]]]
endforeach
shaders_c = []
foreach job : shader_jobs
source = job[0]
name = job[1]
args = glslang_args + job[2]
if spirv_opt_args.length() > 0
spv = custom_target(name.underscorify() + '_raw_spv',
input : source,
output : name + '.raw.spv',
depfile : name + '.deps',
command : [glslang] + args + ['-o', '@OUTPUT@', '@INPUT@', '--depfile', '@DEPFILE@'])
spv = custom_target(name.underscorify() + '_spv',
input : spv,
output : name + '.spv',
command : [spirv_opt] + spirv_opt_args + ['@INPUT@', '-o', '@OUTPUT@'])
else
spv = custom_target(name.underscorify() + '_spv',
input : source,
output : name + '.spv',
depfile : name + '.deps',
command : [glslang] + args + ['-o', '@OUTPUT@', '@INPUT@', '--depfile', '@DEPFILE@'])
endif
shaders_c += custom_target(name.underscorify() + '_c',
input : spv,
output : name + '.c',
command : [bintoc, '@INPUT@', name + '_spv', '@OUTPUT@'])
endforeach
srcs = [
'Quake/bgmusic.c',
'Quake/cd_null.c',
'Quake/cfgfile.c',
'Quake/chase.c',
'Quake/cl_demo.c',
'Quake/cl_input.c',
'Quake/cl_main.c',
'Quake/cl_parse.c',
'Quake/cl_tent.c',
'Quake/cmd.c',
'Quake/common.c',
'Quake/console.c',
'Quake/crc.c',
'Quake/cvar.c',
'Quake/gl_draw.c',
'Quake/gl_fog.c',
'Quake/gl_heap.c',
'Quake/gl_mesh.c',
'Quake/gl_model.c',
'Quake/gl_refrag.c',
'Quake/gl_rlight.c',
'Quake/gl_rmain.c',
'Quake/gl_rmisc.c',
'Quake/r_passes.c',
'Quake/r_ssao.c',
'Quake/gl_screen.c',
'Quake/gl_sky.c',
'Quake/gl_texmgr.c',
'Quake/gl_vidsdl.c',
'Quake/gl_warp.c',
'Quake/host.c',
'Quake/host_cmd.c',
'Quake/image.c',
'Quake/json.c',
'Quake/in_sdl.c',
'Quake/in_sdl2.c',
'Quake/in_sdl3.c',
'Quake/keys.c',
'Quake/main_sdl.c',
'Quake/mathlib.c',
'Quake/mdfour.c',
'Quake/mem.c',
'Quake/menu.c',
'Quake/net_dgrm.c',
'Quake/net_loop.c',
'Quake/net_main.c',
'Quake/palette.c',
'Quake/pr_cmds.c',
'Quake/pr_edict.c',
'Quake/pr_exec.c',
'Quake/pr_ext.c',
'Quake/r_alias.c',
'Quake/r_brush.c',
'Quake/r_part.c',
'Quake/r_part_fte.c',
'Quake/r_sprite.c',
'Quake/r_world.c',
'Quake/sbar.c',
'Quake/snd_codec.c',
'Quake/snd_dma.c',
'Quake/snd_mem.c',
'Quake/snd_mix.c',
'Quake/snd_sdl.c',
'Quake/snd_sdl3.c',
'Quake/snd_umx.c',
'Quake/snd_wave.c',
'Quake/steam.c',
'Quake/strlcat.c',
'Quake/strlcpy.c',
'Quake/sv_main.c',
'Quake/sv_move.c',
'Quake/sv_phys.c',
'Quake/sv_user.c',
'Quake/sys_sdl.c',
'Quake/tasks.c',
'Quake/view.c',
'Quake/wad.c',
'Quake/world.c',
'Quake/hash_map.c',
run_generate_embedded_pak,
]
if host_machine.system() == 'windows'
srcs += [
'Quake/net_win.c',
'Quake/net_wins.c',
'Quake/net_wipx.c',
'Quake/pl_win.c',
'Quake/sys_sdl_win.c',
]
srcs += import('windows').compile_resources(
'Windows/vkQuake.rc',
# the \xA9 copyright escape is Windows-1252; llvm-rc refuses 8 bit
# codepoints without an explicit codepage. gcc builds use windres,
# which takes no /C option
args : cc.get_id() == 'gcc' ? [] : ['/C', '1252'],
include_directories : include_directories('Windows', 'Quake'),
depend_files : ['Windows/vkQuake.ico'])
else
srcs += [
'Quake/net_bsd.c',
'Quake/net_udp.c',
'Quake/pl_linux.c',
'Quake/sys_sdl_unix.c',
]
endif
cflags = cc.get_supported_arguments('-Wno-trigraphs', '-Wno-microsoft-enum-forward-reference') + ['-D_FILE_OFFSET_BITS=64']
if cc.get_id() == 'clang'
# the stb single header libraries define their whole API static
cflags += '-Wno-unused-function'
endif
deps = [
cc.find_library('m', required : false),
cc.find_library('dl', required : false),
dependency('threads'),
sdl_dep,
]
if host_machine.system() == 'windows'
foreach syslib : ['ws2_32', 'winmm', 'dbghelp', 'ole32', 'uuid']
deps += cc.find_library(syslib)
endforeach
import('fs').copyfile('Windows/SDL3/lib64/SDL3.dll')
endif
if build_machine.system() == 'darwin'
molten_dirs = []
if import('fs').exists('/opt/homebrew/lib/libMoltenVK.dylib')
molten_dirs += '/opt/homebrew/lib'
endif
deps += cc.find_library('MoltenVK', required : true, dirs : molten_dirs)
else
deps += dependency('vulkan', version: '>=1.4.341')
endif
if get_option('use_codec_wave').enabled()
cflags += '-DUSE_CODEC_WAVE'
endif
if host_machine.system() == 'windows'
# the bundled codec libraries, like the other Windows builds use
codec_inc = include_directories('Windows/codecs/include')
codec_lib_dir = meson.project_source_root() / 'Windows/codecs/x64'
codec_deps = {}
foreach name, option : {
'libmad' : 'use_codec_mp3',
'libmpg123' : 'use_codec_mp3',
'libFLAC' : 'use_codec_flac',
'libogg' : 'use_codec_vorbis',
'libvorbisfile' : 'use_codec_vorbis',
'libvorbis' : 'use_codec_vorbis',
'libopus' : 'use_codec_opus',
'libopusfile' : 'use_codec_opus',
}
lib = cc.find_library(name, dirs : codec_lib_dir, required : get_option(option))
codec_deps += {name : lib.found() ? declare_dependency(include_directories : codec_inc, dependencies : lib) : lib}
endforeach
foreach dll : ['libFLAC-8.dll', 'libmad-0.dll', 'libmpg123-0.dll', 'libogg-0.dll', 'libopus-0.dll', 'libopusfile-0.dll', 'libvorbis-0.dll', 'libvorbisfile-3.dll']
import('fs').copyfile('Windows/codecs/x64' / dll)
endforeach
mad_dep = codec_deps['libmad']
mpg123_dep = codec_deps['libmpg123']
flac_dep = codec_deps['libFLAC']
ogg_dep = codec_deps['libogg']
vorbisfile_dep = codec_deps['libvorbisfile']
vorbis_dep = codec_deps['libvorbis']
tremor_dep = dependency('', required : false)
opus_dep = codec_deps['libopus']
opusfile_dep = codec_deps['libopusfile']
else
if get_option('mp3_lib') == 'mad'
mad_dep = dependency('mad', required : get_option('use_codec_mp3'))
else
mpg123_dep = dependency('libmpg123', required : get_option('use_codec_mp3'))
endif
flac_dep = dependency('flac', required : get_option('use_codec_flac'))
ogg_dep = dependency('ogg', required : get_option('use_codec_vorbis'))
if get_option('vorbis_lib') == 'vorbis'
vorbisfile_dep = dependency('vorbisfile', required : get_option('use_codec_vorbis'))
vorbis_dep = dependency('vorbis', required : get_option('use_codec_vorbis'))
else
tremor_dep = dependency('vorbisidec', required : get_option('use_codec_vorbis'))
endif
opus_dep = dependency('opus', required : get_option('use_codec_opus'))
opusfile_dep = dependency('opusfile', required : get_option('use_codec_opus'))
endif
if get_option('mp3_lib') == 'mad'
if mad_dep.found()
srcs += [ 'Quake/snd_mp3.c', 'Quake/snd_mp3tag.c' ]
deps += mad_dep
cflags += '-DUSE_CODEC_MP3'
endif
else
if mpg123_dep.found()
srcs += [ 'Quake/snd_mpg123.c', 'Quake/snd_mp3tag.c' ]
deps += mpg123_dep
cflags += '-DUSE_CODEC_MP3'
endif
endif
if flac_dep.found()
srcs += 'Quake/snd_flac.c'
deps += flac_dep
cflags += '-DUSE_CODEC_FLAC'
endif
if get_option('vorbis_lib') == 'vorbis'
if ogg_dep.found() and vorbisfile_dep.found() and vorbis_dep.found()
srcs += 'Quake/snd_vorbis.c'
deps += [ ogg_dep, vorbisfile_dep, vorbis_dep ]
cflags += '-DUSE_CODEC_VORBIS'
endif
else
if ogg_dep.found() and tremor_dep.found()
srcs += 'Quake/snd_vorbis.c'
deps += [ ogg_dep, tremor_dep ]
cflags += [ '-DUSE_CODEC_VORBIS', '-DVORBIS_USE_TREMOR' ]
endif
endif
if opus_dep.found() and opusfile_dep.found()
srcs += 'Quake/snd_opus.c'
deps += [ opus_dep, opusfile_dep ]
cflags += '-DUSE_CODEC_OPUS'
endif
if get_option('buildtype').startswith('debug')
cflags += '-D_DEBUG'
endif
if get_option('do_userdirs').enabled()
cflags += '-DDO_USERDIRS=1'
endif
incdirs = [
'Quake/mimalloc',
]
executable(
'vkquake',
[srcs, shaders_c],
dependencies : deps,
include_directories : incdirs,
c_args : cflags,
c_pch : 'Quake/quakedef.h',
win_subsystem : 'windows')