-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeson.build
More file actions
590 lines (527 loc) · 17 KB
/
meson.build
File metadata and controls
590 lines (527 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
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
project('vkrt', ['c', 'cpp'],
version: '1.0',
default_options: [
'c_std=c11',
'cpp_std=c++17',
'warning_level=3',
],
)
sys = host_machine.system()
is_linux = sys == 'linux'
is_windows = sys == 'windows'
is_darwin = sys == 'darwin'
if not is_linux and not is_windows and not is_darwin
error('Unsupported host system: ' + sys)
endif
cc = meson.get_compiler('c')
cpp = meson.get_compiler('cpp')
cmake = import('cmake')
fs = import('fs')
python = find_program('python3')
embed_data = find_program(meson.project_source_root() / 'scripts' / 'embed_data.py')
llvm_program_dirs = []
if is_darwin
llvm_program_dirs += [
'/opt/homebrew/opt/llvm/bin',
'/usr/local/opt/llvm/bin',
'/opt/homebrew/bin',
'/usr/local/bin',
]
else
llvm_program_dirs += [
'/usr/local/opt/llvm/bin',
'/opt/homebrew/opt/llvm/bin',
'/usr/local/bin',
'/opt/homebrew/bin',
]
endif
clang_tidy = find_program(
'clang-tidy',
dirs: llvm_program_dirs,
required: true,
)
run_clang_tidy = find_program(
'run-clang-tidy',
'run-clang-tidy.py',
dirs: llvm_program_dirs,
required: true,
)
buildtype = get_option('buildtype')
profiling_enabled = get_option('profiling')
linux_window_backend = get_option('linux_window_backend')
c_args = []
cpp_args = []
app_link_args = []
cc_is_msvc = cc.get_argument_syntax() == 'msvc'
cpp_is_msvc = cpp.get_argument_syntax() == 'msvc'
is_debug_build = buildtype == 'debug' or buildtype == 'debugoptimized'
c_define_prefix = cc_is_msvc ? '/D' : '-D'
cpp_define_prefix = cpp_is_msvc ? '/D' : '-D'
if is_linux
c_args += [
c_define_prefix + '_GNU_SOURCE',
c_define_prefix + '_POSIX_C_SOURCE=200112L',
]
cpp_args += [
cpp_define_prefix + '_GNU_SOURCE',
cpp_define_prefix + '_POSIX_C_SOURCE=200112L',
]
endif
if is_windows
c_args += [c_define_prefix + '_CRT_SECURE_NO_WARNINGS']
cpp_args += [cpp_define_prefix + '_CRT_SECURE_NO_WARNINGS']
endif
c_args += [c_define_prefix + 'VKRT_VERSION="' + get_option('vkrt_version') + '"']
c_args += [c_define_prefix + 'GLFW_INCLUDE_NONE']
cpp_args += [cpp_define_prefix + 'GLFW_INCLUDE_NONE']
validation_enabled = is_debug_build and not profiling_enabled
debug_utils_enabled = validation_enabled or profiling_enabled
trace_enabled = is_debug_build
if trace_enabled
c_args += [c_define_prefix + 'VKRT_TRACE_ENABLED=1']
else
c_args += [c_define_prefix + 'VKRT_TRACE_ENABLED=0']
endif
c_args += [c_define_prefix + 'VKRT_PROFILING_ENABLED=' + (profiling_enabled ? '1' : '0')]
c_args += [c_define_prefix + 'VKRT_VALIDATION_ENABLED=' + (validation_enabled ? '1' : '0')]
c_args += [c_define_prefix + 'VKRT_DEBUG_UTILS_ENABLED=' + (debug_utils_enabled ? '1' : '0')]
cpp_args += [cpp_define_prefix + 'VKRT_PROFILING_ENABLED=' + (profiling_enabled ? '1' : '0')]
cpp_args += [cpp_define_prefix + 'VKRT_VALIDATION_ENABLED=' + (validation_enabled ? '1' : '0')]
cpp_args += [cpp_define_prefix + 'VKRT_DEBUG_UTILS_ENABLED=' + (debug_utils_enabled ? '1' : '0')]
if profiling_enabled
if cc_is_msvc
c_args += ['/Zi', '/Oy-']
else
c_args += ['-g', '-fno-omit-frame-pointer']
endif
if cpp_is_msvc
cpp_args += ['/Zi', '/Oy-']
else
cpp_args += ['-g', '-fno-omit-frame-pointer']
endif
if cc_is_msvc or cpp_is_msvc
app_link_args += ['/DEBUG']
else
app_link_args += ['-g']
endif
endif
slang_compile_args = ['-O3']
if profiling_enabled
slang_compile_args += ['-g']
endif
slangc = find_program('slangc', required: true)
project_includes = include_directories(
'assets/fonts',
'src/shared',
)
external_includes = include_directories(
'external/glfw3/include',
'external/imgui/include',
'external/cglm/include',
'external/cgltf/include',
'external/cjson',
'external/nfd/src/include',
'external/tinyexr',
is_system: true,
)
core_includes = include_directories(
'src/core/api',
'src/core/runtime',
'src/core/render',
'src/core/scene',
'src/core/utility',
)
app_local_includes = include_directories(
'src/app',
'src/app/session',
'src/app/mesh',
'src/app/render',
'src/app/scene',
'src/app/editor',
)
app_core_includes = include_directories(
'src/core/api',
'src/core/utility',
)
app_includes = [
project_includes,
app_local_includes,
app_core_includes,
external_includes,
]
core_build_includes = [
project_includes,
core_includes,
external_includes,
]
core_internal_includes = include_directories(
'src/core/internal',
)
vulkan_dep = dependency('vulkan', required: true)
windows_system_deps = []
darwin_system_deps = []
if is_windows
windows_system_deps += cc.find_library('dwmapi', required: true)
endif
if is_darwin
darwin_system_deps += dependency(
'appleframeworks',
modules: [
'Cocoa',
'CoreFoundation',
'IOKit',
'QuartzCore',
],
)
endif
linux_glfw_backend = 'auto'
linux_x11_probe_deps = []
linux_wayland_probe_deps = []
linux_wayland_scanner = disabler()
linux_has_x11 = false
linux_has_wayland = false
if is_linux
linux_x11_probe_deps = [
dependency('x11', required: false, method: 'pkg-config'),
dependency('xrandr', required: false, method: 'pkg-config'),
dependency('xinerama', required: false, method: 'pkg-config'),
dependency('xcursor', required: false, method: 'pkg-config'),
dependency('xi', required: false, method: 'pkg-config'),
dependency('xext', required: false, method: 'pkg-config'),
]
linux_wayland_probe_deps = [
dependency('wayland-client', required: false, method: 'pkg-config'),
dependency('wayland-cursor', required: false, method: 'pkg-config'),
dependency('wayland-egl', required: false, method: 'pkg-config'),
dependency('xkbcommon', required: false, method: 'pkg-config'),
]
linux_wayland_scanner = find_program('wayland-scanner', required: false, native: true)
linux_has_x11 = true
foreach dep : linux_x11_probe_deps
linux_has_x11 = linux_has_x11 and dep.found()
endforeach
linux_has_wayland = linux_wayland_scanner.found()
foreach dep : linux_wayland_probe_deps
linux_has_wayland = linux_has_wayland and dep.found()
endforeach
if linux_window_backend == 'auto'
if linux_has_x11 and linux_has_wayland
linux_glfw_backend = 'both'
elif linux_has_wayland
linux_glfw_backend = 'wayland'
elif linux_has_x11
linux_glfw_backend = 'x11'
else
error('No supported Linux GLFW backend was detected. Install X11 development files, or Wayland development files plus wayland-scanner, or set -Dlinux_window_backend explicitly.')
endif
else
linux_glfw_backend = linux_window_backend
endif
if linux_glfw_backend == 'x11'
if not linux_has_x11
error('linux_window_backend=x11 requires x11, xrandr, xinerama, xcursor, xi, and xext development files.')
endif
elif linux_glfw_backend == 'wayland'
if not linux_has_wayland
error('linux_window_backend=wayland requires wayland-client, wayland-cursor, wayland-egl, xkbcommon, and wayland-scanner.')
endif
elif linux_glfw_backend == 'both'
if not linux_has_x11 or not linux_has_wayland
error('linux_window_backend=both requires both the X11 and Wayland development stacks, plus wayland-scanner.')
endif
else
error('Invalid linux_window_backend option: ' + linux_glfw_backend)
endif
elif linux_window_backend != 'auto'
message('Ignoring linux_window_backend=' + linux_window_backend + ' on ' + sys)
endif
glfw_build_win32 = is_windows
glfw_build_cocoa = is_darwin
glfw_build_x11 = is_linux and (linux_glfw_backend == 'x11' or linux_glfw_backend == 'both')
glfw_build_wayland = is_linux and (linux_glfw_backend == 'wayland' or linux_glfw_backend == 'both')
glfw_msvc_runtime = ''
if cc_is_msvc or cpp_is_msvc
vscrt = get_option('b_vscrt')
if vscrt == 'from_buildtype'
glfw_msvc_runtime = buildtype == 'debug' ? 'MultiThreadedDebugDLL' : 'MultiThreadedDLL'
elif vscrt == 'static_from_buildtype'
glfw_msvc_runtime = buildtype == 'debug' ? 'MultiThreadedDebug' : 'MultiThreaded'
elif vscrt == 'md'
glfw_msvc_runtime = 'MultiThreadedDLL'
elif vscrt == 'mdd'
glfw_msvc_runtime = 'MultiThreadedDebugDLL'
elif vscrt == 'mt'
glfw_msvc_runtime = 'MultiThreaded'
elif vscrt == 'mtd'
glfw_msvc_runtime = 'MultiThreadedDebug'
endif
endif
threads_dep = dependency('threads')
rt_dep = dependency('rt', required: false)
glfw_dep = dependency('glfw3', required: false, method: 'pkg-config')
if not glfw_dep.found()
glfw_options = cmake.subproject_options()
glfw_options.set_override_option('warning_level', '0')
glfw_options.add_cmake_defines({
'BUILD_SHARED_LIBS': 'OFF',
'GLFW_BUILD_DOCS': 'OFF',
'GLFW_BUILD_EXAMPLES': 'OFF',
'GLFW_BUILD_TESTS': 'OFF',
'GLFW_INSTALL': 'OFF',
'GLFW_BUILD_WIN32': glfw_build_win32 ? 'ON' : 'OFF',
'GLFW_BUILD_COCOA': glfw_build_cocoa ? 'ON' : 'OFF',
'GLFW_BUILD_X11': glfw_build_x11 ? 'ON' : 'OFF',
'GLFW_BUILD_WAYLAND': glfw_build_wayland ? 'ON' : 'OFF',
'GLFW_ENABLE_WARNINGS': 'OFF',
'CMAKE_SUPPRESS_DEVELOPER_WARNINGS': 'TRUE',
})
if glfw_msvc_runtime != ''
glfw_options.add_cmake_defines({
'CMAKE_MSVC_RUNTIME_LIBRARY': glfw_msvc_runtime,
})
endif
glfw_project = cmake.subproject('glfw', options: glfw_options)
glfw_dep = glfw_project.dependency('glfw')
endif
zlib_dep = dependency('zlib', required: false)
zlib_compile_dep = disabler()
if not zlib_dep.found()
zlib_project = subproject('zlib', default_options: ['default_library=static'])
zlib_dep = zlib_project.get_variable('zlib_dep')
endif
zlib_compile_dep = zlib_dep.partial_dependency(
compile_args: true,
includes: true,
)
spng_from_system = false
spng_dep = dependency('spng', required: false, method: 'pkg-config')
if not spng_dep.found()
spng_dep = dependency('libspng', required: false, method: 'pkg-config')
endif
spng_from_system = spng_dep.found()
if not spng_dep.found()
spng_project = subproject(
'spng',
default_options: [
'default_library=static',
'static_zlib=false',
'build_examples=false',
'warning_level=0',
]
)
spng_dep = spng_project.get_variable('spng_dep')
endif
turbojpeg_dep = dependency('libturbojpeg', required: false, method: 'pkg-config')
if not turbojpeg_dep.found()
turbojpeg_project = subproject(
'libjpeg-turbo',
default_options: [
'default_library=static',
'tests=disabled',
'warning_level=0',
] + (is_linux ? ['c_args=-D_DEFAULT_SOURCE -include strings.h'] : [])
)
turbojpeg_dep = turbojpeg_project.get_variable('turbojpeg_dep')
endif
oidn_runtime_files = []
oidn_subproject_name = ''
oidn_cpu = host_machine.cpu_family()
if is_windows and oidn_cpu == 'x86_64'
oidn_subproject_name = 'oidn_windows_x86_64'
elif is_linux and oidn_cpu == 'x86_64'
oidn_subproject_name = 'oidn_linux_x86_64'
elif is_darwin and oidn_cpu == 'aarch64'
oidn_subproject_name = 'oidn_macos_arm64'
elif is_darwin and oidn_cpu == 'x86_64'
oidn_subproject_name = 'oidn_macos_x86_64'
else
error('OIDN is required but no packaged build is available for ' + sys + ' ' + oidn_cpu)
endif
oidn_project = subproject(oidn_subproject_name, required: true)
oidn_dep = oidn_project.get_variable('oidn_dep')
oidn_runtime_files = oidn_project.get_variable('oidn_runtime_files')
oidn_version = oidn_project.get_variable('oidn_version')
c_args += [c_define_prefix + 'VKRT_GLFW_VERSION="' + glfw_dep.version() + '"']
c_args += [c_define_prefix + 'VKRT_SPNG_VERSION="' + spng_dep.version() + '"']
c_args += [c_define_prefix + 'VKRT_TURBOJPEG_VERSION="' + turbojpeg_dep.version() + '"']
c_args += [c_define_prefix + 'VKRT_OIDN_VERSION="' + oidn_version + '"']
core_cpp_args = cpp_args
if is_windows and cpp_is_msvc
core_cpp_args += ['/wd4245', '/wd4702']
endif
core_dependencies = [
vulkan_dep,
glfw_dep,
threads_dep,
rt_dep,
spng_dep,
turbojpeg_dep,
spng_from_system ? zlib_dep : zlib_compile_dep,
windows_system_deps,
darwin_system_deps,
]
core_dependencies += [oidn_dep]
app_dependencies = [
vulkan_dep,
glfw_dep,
threads_dep,
rt_dep,
windows_system_deps,
darwin_system_deps,
]
imgui_dependencies = [
vulkan_dep,
glfw_dep,
]
dcimgui = static_library('dcimgui',
include_directories: [external_includes],
dependencies: imgui_dependencies,
cpp_args: cpp_args,
sources: files(
'external/imgui/src/dcimgui.cpp',
'external/imgui/src/dcimgui_impl_glfw.cpp',
'external/imgui/src/dcimgui_impl_vulkan.cpp',
'external/imgui/src/dcimgui_internal.cpp',
'external/imgui/src/imgui.cpp',
'external/imgui/src/imgui_demo.cpp',
'external/imgui/src/imgui_draw.cpp',
'external/imgui/src/imgui_impl_glfw.cpp',
'external/imgui/src/imgui_impl_vulkan.cpp',
'external/imgui/src/imgui_tables.cpp',
'external/imgui/src/imgui_widgets.cpp',
),
override_options: ['warning_level=0'],
)
cjson = static_library('cjson',
include_directories: include_directories('external/cjson'),
sources: files('external/cjson/cJSON.c'),
override_options: ['warning_level=0'],
)
subdir('src')
file_dialogs_opt = get_option('file_dialogs')
file_dialogs_enabled = false
file_dialogs_backend = 'disabled'
app_dialog_source = files('src/app/editor/dialogs_stub.c')
app_link_with = [vkrt, dcimgui, cjson]
if not file_dialogs_opt.disabled()
nfd_source = []
nfd_deps = []
nfd_cpp_args = []
if is_windows
nfd_source = files('external/nfd/src/nfd_win.cpp')
file_dialogs_enabled = true
file_dialogs_backend = 'win32'
elif is_linux
nfd_backend = get_option('nfd_backend')
dbus_dep = dependency('dbus-1', required: false, method: 'pkg-config')
gtk3_dep = dependency('gtk+-3.0', required: false, method: 'pkg-config')
if nfd_backend == 'portal'
if not dbus_dep.found()
if file_dialogs_opt.enabled()
error('file_dialogs enabled with nfd_backend=portal requires dbus-1 development files')
endif
else
nfd_source = files('external/nfd/src/nfd_portal.cpp')
nfd_deps += dbus_dep
nfd_cpp_args += ['-DNFD_PORTAL']
file_dialogs_enabled = true
file_dialogs_backend = 'portal'
endif
elif nfd_backend == 'gtk'
if not gtk3_dep.found()
if file_dialogs_opt.enabled()
error('file_dialogs enabled with nfd_backend=gtk requires gtk+-3.0 development files')
endif
else
nfd_source = files('external/nfd/src/nfd_gtk.cpp')
nfd_deps += gtk3_dep
file_dialogs_enabled = true
file_dialogs_backend = 'gtk'
endif
elif nfd_backend == 'auto'
if dbus_dep.found()
nfd_source = files('external/nfd/src/nfd_portal.cpp')
nfd_deps += dbus_dep
nfd_cpp_args += ['-DNFD_PORTAL']
file_dialogs_enabled = true
file_dialogs_backend = 'portal'
message('NFD backend: portal (dbus-1)')
elif gtk3_dep.found()
nfd_source = files('external/nfd/src/nfd_gtk.cpp')
nfd_deps += gtk3_dep
file_dialogs_enabled = true
file_dialogs_backend = 'gtk'
message('NFD backend: gtk (gtk+-3.0)')
elif file_dialogs_opt.enabled()
error('file_dialogs enabled but no Linux NFD backend was found. Install dbus-1 or gtk+-3.0 development files.')
endif
else
error('Invalid nfd_backend option: ' + nfd_backend)
endif
elif file_dialogs_opt.enabled()
error('file_dialogs is currently only supported by this Meson build on Windows and Linux.')
endif
if file_dialogs_enabled
nfd = static_library('nfd',
include_directories: include_directories('external/nfd/src/include'),
sources: nfd_source,
dependencies: nfd_deps,
cpp_args: nfd_cpp_args,
override_options: ['warning_level=0'],
)
app_dialog_source = files('src/app/editor/dialogs.c')
app_link_with += [nfd]
else
message('Native file dialogs disabled for this build')
endif
else
message('Native file dialogs disabled by option')
endif
app_c_args = c_args + [c_define_prefix + 'VKRT_FILE_DIALOGS_ENABLED=' + (file_dialogs_enabled ? '1' : '0')]
executable('vkrt',
c_args: app_c_args,
link_args: app_link_args,
sources: [app_sources, app_dialog_source, embedded_shader_sources],
dependencies: app_dependencies,
include_directories: app_includes,
link_with: app_link_with,
)
foreach oidn_runtime_file : oidn_runtime_files
configure_file(
input: oidn_runtime_file,
output: fs.name(oidn_runtime_file),
copy: true,
)
endforeach
glfw_backend_summary = 'unknown'
if glfw_build_win32
glfw_backend_summary = 'win32'
elif glfw_build_cocoa
glfw_backend_summary = 'cocoa'
elif glfw_build_x11 and glfw_build_wayland
glfw_backend_summary = 'x11 + wayland'
elif glfw_build_x11
glfw_backend_summary = 'x11'
elif glfw_build_wayland
glfw_backend_summary = 'wayland'
endif
summary({
'Host system': sys,
'GLFW backend': glfw_backend_summary,
'File dialogs': file_dialogs_backend,
'Profiling': profiling_enabled,
}, section: 'vkrt')
run_target('clang-tidy',
command: [python, files('scripts/run_clang_tidy.py')],
env: {
'CLANG_TIDY': clang_tidy.full_path(),
'RUN_CLANG_TIDY': run_clang_tidy.full_path(),
},
)
run_target('clang-tidy-fix',
command: [python, files('scripts/run_clang_tidy.py'), '--fix'],
env: {
'CLANG_TIDY': clang_tidy.full_path(),
'RUN_CLANG_TIDY': run_clang_tidy.full_path(),
},
)