]> git.proxmox.com Git - mirror_qemu.git/blame - meson.build
meson: add more sections to main meson.build
[mirror_qemu.git] / meson.build
CommitLineData
3b087f79 1project('qemu', ['c'], meson_version: '>=0.63.0',
654d6b04 2 default_options: ['warning_level=1', 'c_std=gnu11', 'cpp_std=gnu++11', 'b_colorout=auto',
0a31e3a0 3 'b_staticpic=false', 'stdsplit=false', 'optimization=2', 'b_pie=true'],
654d6b04 4 version: files('VERSION'))
a5665051 5
e287072b
TH
6add_test_setup('quick', exclude_suites: ['slow', 'thorough'], is_default: true)
7add_test_setup('slow', exclude_suites: ['thorough'], env: ['G_TEST_SLOW=1', 'SPEED=slow'])
8add_test_setup('thorough', env: ['G_TEST_SLOW=1', 'SPEED=thorough'])
3d2f73ef 9
cf60ccc3
AO
10meson.add_postconf_script(find_program('scripts/symlink-install-tree.py'))
11
ea444d91
PB
12####################
13# Global variables #
14####################
15
a5665051 16not_found = dependency('', required: false)
654d6b04 17keyval = import('keyval')
a81df1b6 18ss = import('sourceset')
8b18cdbf 19fs = import('fs')
a81df1b6 20
e5134024 21targetos = host_machine.system()
ce1c1e7a 22sh = find_program('sh')
a5665051 23config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
d7dedf42 24
e5134024
PB
25cc = meson.get_compiler('c')
26all_languages = ['c']
6db77bb2 27if targetos == 'windows' and add_languages('cpp', required: false, native: false)
e5134024
PB
28 all_languages += ['cpp']
29 cxx = meson.get_compiler('cpp')
30endif
31if targetos == 'darwin' and \
32 add_languages('objc', required: get_option('cocoa'), native: false)
33 all_languages += ['objc']
34 objc = meson.get_compiler('objc')
35endif
36
e3667660
YL
37# Temporary directory used for files created while
38# configure runs. Since it is in the build directory
39# we can safely blow away any previous version of it
40# (and we need not jump through hoops to try to delete
41# it when configure exits.)
42tmpdir = meson.current_build_dir() / 'meson-private/temp'
8fe11232
MAL
43
44if get_option('qemu_suffix').startswith('/')
45 error('qemu_suffix cannot start with a /')
46endif
47
16bf7a33 48qemu_confdir = get_option('sysconfdir') / get_option('qemu_suffix')
ab4c0996 49qemu_datadir = get_option('datadir') / get_option('qemu_suffix')
491e74c1 50qemu_docdir = get_option('docdir') / get_option('qemu_suffix')
16bf7a33
PB
51qemu_moddir = get_option('libdir') / get_option('qemu_suffix')
52
53qemu_desktopdir = get_option('datadir') / 'applications'
54qemu_icondir = get_option('datadir') / 'icons'
55
859aef02
PB
56config_host_data = configuration_data()
57genh = []
b83a80e8 58qapi_trace_events = []
a5665051 59
20cf5cb4
PB
60bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin']
61supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
278c1bce 62supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
6d0b52ed 63 'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
20cf5cb4
PB
64
65cpu = host_machine.cpu_family()
66
760e4327 67target_dirs = config_host['TARGET_DIRS'].split()
dda2da6c
WL
68have_linux_user = false
69have_bsd_user = false
760e4327
PB
70have_system = false
71foreach target : target_dirs
dda2da6c
WL
72 have_linux_user = have_linux_user or target.endswith('linux-user')
73 have_bsd_user = have_bsd_user or target.endswith('bsd-user')
760e4327
PB
74 have_system = have_system or target.endswith('-softmmu')
75endforeach
dda2da6c 76have_user = have_linux_user or have_bsd_user
20cf5cb4
PB
77have_tools = get_option('tools') \
78 .disable_auto_if(not have_system) \
79 .allowed()
80have_ga = get_option('guest_agent') \
81 .disable_auto_if(not have_system and not have_tools) \
28236ad8 82 .require(targetos in ['sunos', 'linux', 'windows', 'freebsd', 'netbsd', 'openbsd'],
20cf5cb4
PB
83 error_message: 'unsupported OS for QEMU guest agent') \
84 .allowed()
6002711c
PB
85enable_modules = get_option('modules') \
86 .require(targetos != 'windows',
87 error_message: 'Modules are not available for Windows') \
88 .require(not get_option('prefer_static'),
89 error_message: 'Modules are incompatible with static linking') \
90 .allowed()
760e4327
PB
91have_block = have_system or have_tools
92
ea444d91
PB
93############
94# Programs #
95############
96
201e8ed7
PB
97python = import('python').find_installation()
98
ea444d91
PB
99#######################################
100# Variables for host and accelerators #
101#######################################
102
823eb013
PB
103if cpu not in supported_cpus
104 host_arch = 'unknown'
105elif cpu == 'x86'
106 host_arch = 'i386'
0e3ed77d
RH
107elif cpu == 'mips64'
108 host_arch = 'mips'
278c1bce
PMD
109elif cpu in ['riscv32', 'riscv64']
110 host_arch = 'riscv'
823eb013
PB
111else
112 host_arch = cpu
113endif
114
8a19980e
PB
115if cpu in ['x86', 'x86_64']
116 kvm_targets = ['i386-softmmu', 'x86_64-softmmu']
117elif cpu == 'aarch64'
118 kvm_targets = ['aarch64-softmmu']
119elif cpu == 's390x'
120 kvm_targets = ['s390x-softmmu']
121elif cpu in ['ppc', 'ppc64']
122 kvm_targets = ['ppc-softmmu', 'ppc64-softmmu']
fbc5884c
HC
123elif cpu in ['mips', 'mips64']
124 kvm_targets = ['mips-softmmu', 'mipsel-softmmu', 'mips64-softmmu', 'mips64el-softmmu']
4de81093
PMD
125elif cpu in ['riscv32']
126 kvm_targets = ['riscv32-softmmu']
127elif cpu in ['riscv64']
128 kvm_targets = ['riscv64-softmmu']
8a19980e
PB
129else
130 kvm_targets = []
131endif
132
44d3d898 133kvm_targets_c = '""'
43a363ae 134if get_option('kvm').allowed() and targetos == 'linux'
e741aff0
IM
135 kvm_targets_c = '"' + '" ,"'.join(kvm_targets) + '"'
136endif
137config_host_data.set('CONFIG_KVM_TARGETS', kvm_targets_c)
8a19980e 138accelerator_targets = { 'CONFIG_KVM': kvm_targets }
844a06bb 139
16b6273b
PB
140if cpu in ['x86', 'x86_64']
141 xen_targets = ['i386-softmmu', 'x86_64-softmmu']
142elif cpu in ['arm', 'aarch64']
143 # i386 emulator provides xenpv machine type for multiple architectures
144 xen_targets = ['i386-softmmu', 'x86_64-softmmu', 'aarch64-softmmu']
145else
146 xen_targets = []
147endif
148accelerator_targets += { 'CONFIG_XEN': xen_targets }
149
844a06bb
AG
150if cpu in ['aarch64']
151 accelerator_targets += {
152 'CONFIG_HVF': ['aarch64-softmmu']
153 }
154endif
155
8a19980e
PB
156if cpu in ['x86', 'x86_64']
157 accelerator_targets += {
8a19980e 158 'CONFIG_HVF': ['x86_64-softmmu'],
74a414a1 159 'CONFIG_NVMM': ['i386-softmmu', 'x86_64-softmmu'],
8a19980e
PB
160 'CONFIG_WHPX': ['i386-softmmu', 'x86_64-softmmu'],
161 }
162endif
163
a1b176f9
PB
164modular_tcg = []
165# Darwin does not support references to thread-local variables in modules
166if targetos != 'darwin'
167 modular_tcg = ['i386-softmmu', 'x86_64-softmmu']
168endif
dae0ec15 169
eae9a1d1 170edk2_targets = [ 'arm-softmmu', 'aarch64-softmmu', 'i386-softmmu', 'x86_64-softmmu' ]
e49c0ef6
PB
171unpack_edk2_blobs = false
172foreach target : edk2_targets
173 if target in target_dirs
174 bzip2 = find_program('bzip2', required: get_option('install_blobs'))
175 unpack_edk2_blobs = bzip2.found()
176 break
177 endif
178endforeach
45b545dd 179
9c29b741
PB
180dtrace = not_found
181stap = not_found
182if 'dtrace' in get_option('trace_backends')
183 dtrace = find_program('dtrace', required: true)
184 stap = find_program('stap', required: false)
185 if stap.found()
186 # Workaround to avoid dtrace(1) producing a file with 'hidden' symbol
187 # visibility. Define STAP_SDT_V2 to produce 'default' symbol visibility
188 # instead. QEMU --enable-modules depends on this because the SystemTap
189 # semaphores are linked into the main binary and not the module's shared
190 # object.
191 add_global_arguments('-DSTAP_SDT_V2',
e5134024 192 native: false, language: all_languages)
9c29b741
PB
193 endif
194endif
195
40c909f5
PB
196if get_option('iasl') == ''
197 iasl = find_program('iasl', required: false)
198else
199 iasl = find_program(get_option('iasl'), required: true)
200endif
201
201e8ed7
PB
202##################
203# Compiler flags #
204##################
205
13f60de8
PB
206foreach lang : all_languages
207 compiler = meson.get_compiler(lang)
208 if compiler.get_id() == 'gcc' and compiler.version().version_compare('>=7.4')
209 # ok
210 elif compiler.get_id() == 'clang' and compiler.compiles('''
211 #ifdef __apple_build_version__
212 # if __clang_major__ < 12 || (__clang_major__ == 12 && __clang_minor__ < 0)
213 # error You need at least XCode Clang v12.0 to compile QEMU
214 # endif
215 #else
216 # if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
217 # error You need at least Clang v10.0 to compile QEMU
218 # endif
219 #endif''')
220 # ok
221 else
222 error('You either need GCC v7.4 or Clang v10.0 (or XCode Clang v12.0) to compile QEMU')
223 endif
224endforeach
225
a988b4c5
PB
226# default flags for all hosts
227# We use -fwrapv to tell the compiler that we require a C dialect where
228# left shift of signed integers is well defined and has the expected
229# 2s-complement style results. (Both clang and gcc agree that it
230# provides these semantics.)
231
232qemu_common_flags = [
233 '-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE',
234 '-fno-strict-aliasing', '-fno-common', '-fwrapv' ]
d67212d4 235qemu_cflags = []
911d4caa 236qemu_ldflags = []
8cc2d231 237
a988b4c5
PB
238if targetos == 'darwin'
239 # Disable attempts to use ObjectiveC features in os/object.h since they
240 # won't work when we're compiling with gcc as a C compiler.
2fc36530
AG
241 if compiler.get_id() == 'gcc'
242 qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
243 endif
fb0a8b0e 244elif targetos == 'sunos'
a988b4c5
PB
245 # needed for CMSG_ macros in sys/socket.h
246 qemu_common_flags += '-D_XOPEN_SOURCE=600'
247 # needed for TIOCWIN* defines in termios.h
248 qemu_common_flags += '-D__EXTENSIONS__'
249elif targetos == 'haiku'
250 qemu_common_flags += ['-DB_USE_POSITIVE_POSIX_ERRORS', '-D_BSD_SOURCE', '-fPIC']
251endif
252
253# __sync_fetch_and_and requires at least -march=i486. Many toolchains
254# use i686 as default anyway, but for those that don't, an explicit
255# specification is necessary
256if host_arch == 'i386' and not cc.links('''
257 static int sfaa(int *ptr)
258 {
259 return __sync_fetch_and_and(ptr, 0);
260 }
261
262 int main(void)
263 {
264 int val = 42;
265 val = __sync_val_compare_and_swap(&val, 0, 1);
266 sfaa(&val);
267 return val;
268 }''')
269 qemu_common_flags = ['-march=i486'] + qemu_common_flags
270endif
271
a0cbd2e8 272if get_option('prefer_static')
e4333d14
PB
273 qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static'
274endif
275
a988b4c5
PB
276# Meson currently only handles pie as a boolean for now, so if the user
277# has explicitly disabled PIE we need to extend our cflags.
b03fcd68
PB
278#
279# -no-pie is supposedly a linker flag that has no effect on the compiler
280# command line, but some distros, that didn't quite know what they were
281# doing, made local changes to gcc's specs file that turned it into
282# a compiler command-line flag.
283#
284# What about linker flags? For a static build, no PIE is implied by -static
285# which we added above (and if it's not because of the same specs patching,
286# there's nothing we can do: compilation will fail, report a bug to your
287# distro and do not use --disable-pie in the meanwhile). For dynamic linking,
288# instead, we can't add -no-pie because it overrides -shared: the linker then
289# tries to build an executable instead of a shared library and fails. So
290# don't add -no-pie anywhere and cross fingers. :(
a988b4c5 291if not get_option('b_pie')
b03fcd68 292 qemu_common_flags += cc.get_supported_arguments('-fno-pie', '-no-pie')
a988b4c5
PB
293endif
294
911d4caa
PB
295if not get_option('stack_protector').disabled()
296 stack_protector_probe = '''
297 int main(int argc, char *argv[])
298 {
299 char arr[64], *p = arr, *c = argv[argc - 1];
300 while (*c) {
301 *p++ = *c++;
302 }
303 return 0;
304 }'''
305 have_stack_protector = false
306 foreach arg : ['-fstack-protector-strong', '-fstack-protector-all']
307 # We need to check both a compile and a link, since some compiler
308 # setups fail only on a .c->.o compile and some only at link time
309 if cc.compiles(stack_protector_probe, args: ['-Werror', arg]) and \
310 cc.links(stack_protector_probe, args: ['-Werror', arg])
311 have_stack_protector = true
312 qemu_cflags += arg
313 qemu_ldflags += arg
314 break
315 endif
316 endforeach
317 get_option('stack_protector') \
318 .require(have_stack_protector, error_message: 'Stack protector not supported')
319endif
320
6739825a
PB
321coroutine_backend = get_option('coroutine_backend')
322ucontext_probe = '''
323 #include <ucontext.h>
324 #ifdef __stub_makecontext
325 #error Ignoring glibc stub makecontext which will always fail
326 #endif
327 int main(void) { makecontext(0, 0, 0); return 0; }'''
328
329# On Windows the only valid backend is the Windows specific one.
330# For POSIX prefer ucontext, but it's not always possible. The fallback
331# is sigcontext.
332supported_backends = []
333if targetos == 'windows'
334 supported_backends += ['windows']
335else
336 if targetos != 'darwin' and cc.links(ucontext_probe)
337 supported_backends += ['ucontext']
338 endif
339 supported_backends += ['sigaltstack']
340endif
341
342if coroutine_backend == 'auto'
343 coroutine_backend = supported_backends[0]
344elif coroutine_backend not in supported_backends
345 error('"@0@" backend requested but not available. Available backends: @1@' \
346 .format(coroutine_backend, ', '.join(supported_backends)))
347endif
348
721fa5e5
PB
349# Compiles if SafeStack *not* enabled
350safe_stack_probe = '''
351 int main(void)
352 {
353 #if defined(__has_feature)
354 #if __has_feature(safe_stack)
355 #error SafeStack Enabled
356 #endif
357 #endif
358 return 0;
359 }'''
360if get_option('safe_stack') != not cc.compiles(safe_stack_probe)
361 safe_stack_arg = get_option('safe_stack') ? '-fsanitize=safe-stack' : '-fno-sanitize=safe-stack'
362 if get_option('safe_stack') != not cc.compiles(safe_stack_probe, args: safe_stack_arg)
363 error(get_option('safe_stack') \
364 ? 'SafeStack not supported by your compiler' \
365 : 'Cannot disable SafeStack')
366 endif
367 qemu_cflags += safe_stack_arg
368 qemu_ldflags += safe_stack_arg
369endif
6739825a 370if get_option('safe_stack') and coroutine_backend != 'ucontext'
721fa5e5
PB
371 error('SafeStack is only supported with the ucontext coroutine backend')
372endif
373
34f983d8
PB
374if get_option('sanitizers')
375 if cc.has_argument('-fsanitize=address')
376 qemu_cflags = ['-fsanitize=address'] + qemu_cflags
377 qemu_ldflags = ['-fsanitize=address'] + qemu_ldflags
378 endif
379
380 # Detect static linking issue with ubsan - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
381 if cc.links('int main(int argc, char **argv) { return argc + 1; }',
382 args: [qemu_ldflags, '-fsanitize=undefined'])
383 qemu_cflags = ['-fsanitize=undefined'] + qemu_cflags
384 qemu_ldflags = ['-fsanitize=undefined'] + qemu_ldflags
385 endif
386endif
387
388# Thread sanitizer is, for now, much noisier than the other sanitizers;
389# keep it separate until that is not the case.
390if get_option('tsan')
391 if get_option('sanitizers')
392 error('TSAN is not supported with other sanitizers')
393 endif
394 if not cc.has_function('__tsan_create_fiber',
395 args: '-fsanitize=thread',
396 prefix: '#include <sanitizer/tsan_interface.h>')
397 error('Cannot enable TSAN due to missing fiber annotation interface')
398 endif
399 qemu_cflags = ['-fsanitize=thread'] + qemu_cflags
400 qemu_ldflags = ['-fsanitize=thread'] + qemu_ldflags
401endif
402
e4333d14
PB
403# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
404# The combination is known as "full relro", because .got.plt is read-only too.
405qemu_ldflags += cc.get_supported_link_arguments('-Wl,-z,relro', '-Wl,-z,now')
406
d2147e04
PB
407if targetos == 'windows'
408 qemu_ldflags += cc.get_supported_link_arguments('-Wl,--no-seh', '-Wl,--nxcompat')
2d73fa74 409 qemu_ldflags += cc.get_supported_link_arguments('-Wl,--dynamicbase', '-Wl,--high-entropy-va')
d2147e04
PB
410endif
411
d67212d4 412# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
34f983d8 413if targetos != 'sunos' and not get_option('tsan')
d67212d4 414 qemu_ldflags += cc.get_supported_link_arguments('-Wl,--warn-common')
c55cf6ab
PB
415endif
416
537b7248 417if get_option('fuzzing')
537b7248
PB
418 # Specify a filter to only instrument code that is directly related to
419 # virtual-devices.
420 configure_file(output: 'instrumentation-filter',
421 input: 'scripts/oss-fuzz/instrumentation-filter-template',
422 copy: true)
aa4f3a3b
AB
423
424 if cc.compiles('int main () { return 0; }',
425 name: '-fsanitize-coverage-allowlist=/dev/null',
e56d0970
AB
426 args: ['-fsanitize-coverage-allowlist=/dev/null',
427 '-fsanitize-coverage=trace-pc'] )
d67212d4 428 qemu_common_flags += ['-fsanitize-coverage-allowlist=instrumentation-filter']
aa4f3a3b 429 endif
537b7248
PB
430
431 if get_option('fuzzing_engine') == ''
432 # Add CFLAGS to tell clang to add fuzzer-related instrumentation to all the
433 # compiled code. To build non-fuzzer binaries with --enable-fuzzing, link
434 # everything with fsanitize=fuzzer-no-link. Otherwise, the linker will be
435 # unable to bind the fuzzer-related callbacks added by instrumentation.
d67212d4
PB
436 qemu_common_flags += ['-fsanitize=fuzzer-no-link']
437 qemu_ldflags += ['-fsanitize=fuzzer-no-link']
537b7248
PB
438 # For the actual fuzzer binaries, we need to link against the libfuzzer
439 # library. They need to be configurable, to support OSS-Fuzz
440 fuzz_exe_ldflags = ['-fsanitize=fuzzer']
441 else
442 # LIB_FUZZING_ENGINE was set; assume we are running on OSS-Fuzz, and
443 # the needed CFLAGS have already been provided
444 fuzz_exe_ldflags = get_option('fuzzing_engine').split()
445 endif
ff9ed62b
AB
446endif
447
d67212d4
PB
448add_global_arguments(qemu_common_flags, native: false, language: all_languages)
449add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
450
95caf1fb
PB
451# Collect warnings that we want to enable
452
453warn_flags = [
454 '-Wundef',
455 '-Wwrite-strings',
456 '-Wmissing-prototypes',
457 '-Wstrict-prototypes',
458 '-Wredundant-decls',
459 '-Wold-style-declaration',
460 '-Wold-style-definition',
461 '-Wtype-limits',
462 '-Wformat-security',
463 '-Wformat-y2k',
464 '-Winit-self',
465 '-Wignored-qualifiers',
466 '-Wempty-body',
467 '-Wnested-externs',
468 '-Wendif-labels',
469 '-Wexpansion-to-defined',
470 '-Wimplicit-fallthrough=2',
471 '-Wmissing-format-attribute',
472 '-Wno-initializer-overrides',
473 '-Wno-missing-include-dirs',
474 '-Wno-shift-negative-value',
475 '-Wno-string-plus-int',
476 '-Wno-typedef-redefinition',
477 '-Wno-tautological-type-limit-compare',
478 '-Wno-psabi',
479 '-Wno-gnu-variable-sized-type-not-at-end',
569205e4 480 '-Wshadow=local',
95caf1fb
PB
481]
482
483if targetos != 'darwin'
484 warn_flags += ['-Wthread-safety']
485endif
486
785abf0d 487# Set up C++ compiler flags
b485458e 488qemu_cxxflags = []
e5134024 489if 'cpp' in all_languages
95caf1fb 490 qemu_cxxflags = ['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS'] + qemu_cflags
b485458e
PB
491endif
492
d67212d4 493add_project_arguments(qemu_cflags, native: false, language: 'c')
95caf1fb
PB
494add_project_arguments(cc.get_supported_arguments(warn_flags), native: false, language: 'c')
495if 'cpp' in all_languages
496 add_project_arguments(qemu_cxxflags, native: false, language: 'cpp')
497 add_project_arguments(cxx.get_supported_arguments(warn_flags), native: false, language: 'cpp')
498endif
499if 'objc' in all_languages
500 # Note sanitizer flags are not applied to Objective-C sources!
501 add_project_arguments(objc.get_supported_arguments(warn_flags), native: false, language: 'objc')
502endif
1e6e616d
PB
503if targetos == 'linux'
504 add_project_arguments('-isystem', meson.current_source_dir() / 'linux-headers',
505 '-isystem', 'linux-headers',
e5134024 506 language: all_languages)
1e6e616d
PB
507endif
508
23a77b2d 509add_project_arguments('-iquote', '.',
1e6e616d 510 '-iquote', meson.current_source_dir(),
1e6e616d 511 '-iquote', meson.current_source_dir() / 'include',
e5134024 512 language: all_languages)
44fc7168
RH
513
514# If a host-specific include directory exists, list that first...
515host_include = meson.current_source_dir() / 'host/include/'
516if fs.is_dir(host_include / host_arch)
517 add_project_arguments('-iquote', host_include / host_arch,
518 language: all_languages)
519endif
520# ... followed by the generic fallback.
521add_project_arguments('-iquote', host_include / 'generic',
522 language: all_languages)
a5665051 523
deb62371
PB
524sparse = find_program('cgcc', required: get_option('sparse'))
525if sparse.found()
968b4db3
PB
526 run_target('sparse',
527 command: [find_program('scripts/check_sparse.py'),
deb62371
PB
528 'compile_commands.json', sparse.full_path(), '-Wbitwise',
529 '-Wno-transparent-union', '-Wno-old-initializer',
530 '-Wno-non-pointer-null'])
968b4db3
PB
531endif
532
ea444d91
PB
533#####################
534# Option validation #
535#####################
6ec0e15d 536
b7a75c8c 537# Fuzzing
537b7248
PB
538if get_option('fuzzing') and get_option('fuzzing_engine') == '' and \
539 not cc.links('''
540 #include <stdint.h>
541 #include <sys/types.h>
542 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
543 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; }
544 ''',
545 args: ['-Werror', '-fsanitize=fuzzer'])
546 error('Your compiler does not support -fsanitize=fuzzer')
547endif
548
b7a75c8c 549# Tracing backends
9c29b741
PB
550if 'ftrace' in get_option('trace_backends') and targetos != 'linux'
551 error('ftrace is supported only on Linux')
552endif
553if 'syslog' in get_option('trace_backends') and not cc.compiles('''
554 #include <syslog.h>
555 int main(void) {
556 openlog("qemu", LOG_PID, LOG_DAEMON);
557 syslog(LOG_INFO, "configure");
558 return 0;
559 }''')
560 error('syslog is not supported on this system')
561endif
562
b7a75c8c 563# Miscellaneous Linux-only features
a436d6d4
PB
564get_option('mpath') \
565 .require(targetos == 'linux', error_message: 'Multipath is supported only on Linux')
6ec0e15d 566
a436d6d4
PB
567multiprocess_allowed = get_option('multiprocess') \
568 .require(targetos == 'linux', error_message: 'Multiprocess QEMU is supported only on Linux') \
569 .allowed()
106ad1f9 570
55116968
JR
571vfio_user_server_allowed = get_option('vfio_user_server') \
572 .require(targetos == 'linux', error_message: 'vfio-user server is supported only on Linux') \
573 .allowed()
574
0d04c4c9
PB
575have_tpm = get_option('tpm') \
576 .require(targetos != 'windows', error_message: 'TPM emulation only available on POSIX systems') \
577 .allowed()
578
2a3129a3 579# vhost
2df89d54
PB
580have_vhost_user = get_option('vhost_user') \
581 .disable_auto_if(targetos != 'linux') \
582 .require(targetos != 'windows',
583 error_message: 'vhost-user is not available on Windows').allowed()
584have_vhost_vdpa = get_option('vhost_vdpa') \
585 .require(targetos == 'linux',
586 error_message: 'vhost-vdpa is only available on Linux').allowed()
587have_vhost_kernel = get_option('vhost_kernel') \
588 .require(targetos == 'linux',
589 error_message: 'vhost-kernel is only available on Linux').allowed()
590have_vhost_user_crypto = get_option('vhost_crypto') \
591 .require(have_vhost_user,
592 error_message: 'vhost-crypto requires vhost-user to be enabled').allowed()
593
43b6d7ee 594have_vhost = have_vhost_user or have_vhost_vdpa or have_vhost_kernel
2df89d54
PB
595
596have_vhost_net_user = have_vhost_user and get_option('vhost_net').allowed()
597have_vhost_net_vdpa = have_vhost_vdpa and get_option('vhost_net').allowed()
598have_vhost_net_kernel = have_vhost_kernel and get_option('vhost_net').allowed()
599have_vhost_net = have_vhost_net_kernel or have_vhost_net_user or have_vhost_net_vdpa
2a3129a3 600
b7a75c8c 601# Target-specific libraries and flags
7fa1c635 602libm = cc.find_library('m', required: false)
6d7c7c2d 603threads = dependency('threads')
a81df1b6 604util = cc.find_library('util', required: false)
4a96337d 605winmm = []
a81df1b6 606socket = []
04c6f1e7 607version_res = []
d92989aa
MAL
608coref = []
609iokit = []
b6c7cfd4 610emulator_link_args = []
74a414a1 611nvmm =not_found
8a19980e 612hvf = not_found
23011f44
MAL
613midl = not_found
614widl = not_found
cf60ccc3 615pathcch = not_found
a6305081 616host_dsosuf = '.so'
a81df1b6 617if targetos == 'windows'
23011f44
MAL
618 midl = find_program('midl', required: false)
619 widl = find_program('widl', required: false)
cf60ccc3 620 pathcch = cc.find_library('pathcch')
a81df1b6 621 socket = cc.find_library('ws2_32')
4a96337d 622 winmm = cc.find_library('winmm')
04c6f1e7
MAL
623
624 win = import('windows')
625 version_res = win.compile_resources('version.rc',
626 depend_files: files('pc-bios/qemu-nsis.ico'),
627 include_directories: include_directories('.'))
a6305081 628 host_dsosuf = '.dll'
d92989aa
MAL
629elif targetos == 'darwin'
630 coref = dependency('appleframeworks', modules: 'CoreFoundation')
14176c8d 631 iokit = dependency('appleframeworks', modules: 'IOKit', required: false)
a6305081 632 host_dsosuf = '.dylib'
cfad62f1
PB
633elif targetos == 'sunos'
634 socket = [cc.find_library('socket'),
635 cc.find_library('nsl'),
636 cc.find_library('resolv')]
637elif targetos == 'haiku'
638 socket = [cc.find_library('posix_error_mapper'),
639 cc.find_library('network'),
640 cc.find_library('bsd')]
b6c7cfd4 641elif targetos == 'openbsd'
43a363ae 642 if get_option('tcg').allowed() and target_dirs.length() > 0
b6c7cfd4
PB
643 # Disable OpenBSD W^X if available
644 emulator_link_args = cc.get_supported_link_arguments('-Wl,-z,wxneeded')
645 endif
a81df1b6 646endif
6ec0e15d 647
b7a75c8c 648# Target-specific configuration of accelerators
8a19980e 649accelerators = []
43a363ae 650if get_option('kvm').allowed() and targetos == 'linux'
8a19980e
PB
651 accelerators += 'CONFIG_KVM'
652endif
43a363ae 653if get_option('whpx').allowed() and targetos == 'windows'
57e2a1f8 654 if get_option('whpx').enabled() and host_machine.cpu() != 'x86_64'
8a19980e 655 error('WHPX requires 64-bit host')
641b8417
PMD
656 elif cc.has_header('winhvplatform.h', required: get_option('whpx')) and \
657 cc.has_header('winhvemulation.h', required: get_option('whpx'))
8a19980e
PB
658 accelerators += 'CONFIG_WHPX'
659 endif
660endif
43a363ae 661if get_option('hvf').allowed()
8a19980e
PB
662 hvf = dependency('appleframeworks', modules: 'Hypervisor',
663 required: get_option('hvf'))
664 if hvf.found()
665 accelerators += 'CONFIG_HVF'
666 endif
667endif
74a414a1 668if targetos == 'netbsd'
0cc49650 669 nvmm = cc.find_library('nvmm', required: get_option('nvmm'))
74a414a1
RZ
670 if nvmm.found()
671 accelerators += 'CONFIG_NVMM'
672 endif
673endif
23a77b2d 674
823eb013 675tcg_arch = host_arch
43a363ae 676if get_option('tcg').allowed()
823eb013 677 if host_arch == 'unknown'
a24f15d2 678 if not get_option('tcg_interpreter')
8a19980e
PB
679 error('Unsupported CPU @0@, try --enable-tcg-interpreter'.format(cpu))
680 endif
fa2f7b0b 681 elif get_option('tcg_interpreter')
1c282da3 682 warning('Use of the TCG interpreter is not recommended on this host')
fa2f7b0b
PMD
683 warning('architecture. There is a native TCG execution backend available')
684 warning('which provides substantially better performance and reliability.')
685 warning('It is strongly recommended to remove the --enable-tcg-interpreter')
686 warning('configuration option on this architecture to use the native')
687 warning('backend.')
8a19980e 688 endif
23a77b2d
PB
689 if get_option('tcg_interpreter')
690 tcg_arch = 'tci'
823eb013 691 elif host_arch == 'x86_64'
23a77b2d 692 tcg_arch = 'i386'
823eb013 693 elif host_arch == 'ppc64'
23a77b2d 694 tcg_arch = 'ppc'
23a77b2d
PB
695 endif
696 add_project_arguments('-iquote', meson.current_source_dir() / 'tcg' / tcg_arch,
e5134024 697 language: all_languages)
23a77b2d 698
8a19980e 699 accelerators += 'CONFIG_TCG'
8a19980e
PB
700endif
701
702if 'CONFIG_KVM' not in accelerators and get_option('kvm').enabled()
703 error('KVM not available on this platform')
704endif
705if 'CONFIG_HVF' not in accelerators and get_option('hvf').enabled()
706 error('HVF not available on this platform')
707endif
74a414a1
RZ
708if 'CONFIG_NVMM' not in accelerators and get_option('nvmm').enabled()
709 error('NVMM not available on this platform')
710endif
8a19980e
PB
711if 'CONFIG_WHPX' not in accelerators and get_option('whpx').enabled()
712 error('WHPX not available on this platform')
713endif
b4e312e9 714
6ec0e15d
PB
715################
716# Dependencies #
717################
718
fc9a809e
PB
719# When bumping glib minimum version, please check also whether to increase
720# the _WIN32_WINNT setting in osdep.h according to the value from glib
721glib_req_ver = '>=2.56.0'
722glib_pc = dependency('glib-2.0', version: glib_req_ver, required: true,
723 method: 'pkg-config')
724glib_cflags = []
6002711c 725if enable_modules
fc9a809e
PB
726 gmodule = dependency('gmodule-export-2.0', version: glib_req_ver, required: true,
727 method: 'pkg-config')
2c13c574 728elif get_option('plugins')
fc9a809e
PB
729 gmodule = dependency('gmodule-no-export-2.0', version: glib_req_ver, required: true,
730 method: 'pkg-config')
731else
732 gmodule = not_found
733endif
734
735# This workaround is required due to a bug in pkg-config file for glib as it
736# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
737if targetos == 'windows' and get_option('prefer_static')
738 glib_cflags += ['-DGLIB_STATIC_COMPILATION']
739endif
740
741# Sanity check that the current size_t matches the
742# size that glib thinks it should be. This catches
743# problems on multi-arch where people try to build
744# 32-bit QEMU while pointing at 64-bit glib headers
745
746if not cc.compiles('''
747 #include <glib.h>
748 #include <unistd.h>
749
750 #define QEMU_BUILD_BUG_ON(x) \
751 typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
752
753 int main(void) {
754 QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
755 return 0;
756 }''', dependencies: glib_pc, args: glib_cflags)
757 error('''sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T.
758 You probably need to set PKG_CONFIG_LIBDIR" to point
759 to the right pkg-config files for your build target.''')
760endif
761
762# Silence clang warnings triggered by glib < 2.57.2
763if not cc.compiles('''
764 #include <glib.h>
765 typedef struct Foo {
766 int i;
767 } Foo;
768 static void foo_free(Foo *f)
769 {
770 g_free(f);
771 }
772 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
f49d883d 773 int main(void) { return 0; }''', dependencies: glib_pc, args: ['-Wunused-function', '-Werror'])
fc9a809e 774 glib_cflags += cc.get_supported_arguments('-Wno-unused-function')
e3feb2cc 775endif
fc9a809e
PB
776glib = declare_dependency(dependencies: [glib_pc, gmodule],
777 compile_args: glib_cflags,
778 version: glib_pc.version())
779
780# Check whether glib has gslice, which we have to avoid for correctness.
781# TODO: remove this check and the corresponding workaround (qtree) when
782# the minimum supported glib is >= 2.75.3
783glib_has_gslice = glib.version().version_compare('<2.75.3')
784
785# override glib dep to include the above refinements
786meson.override_dependency('glib-2.0', glib)
787
788# The path to glib.h is added to all compilation commands.
789add_project_dependencies(glib.partial_dependency(compile_args: true, includes: true),
790 native: false, language: all_languages)
953d5a9e 791
a81df1b6 792gio = not_found
7544060e 793gdbus_codegen = not_found
bb2dc4b7 794gdbus_codegen_error = '@0@ requires gdbus-codegen, please install libgio'
7544060e
PB
795if not get_option('gio').auto() or have_system
796 gio = dependency('gio-2.0', required: get_option('gio'),
063d5119 797 method: 'pkg-config')
7544060e
PB
798 if gio.found() and not cc.links('''
799 #include <gio/gio.h>
800 int main(void)
801 {
802 g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
803 return 0;
804 }''', dependencies: [glib, gio])
805 if get_option('gio').enabled()
806 error('The installed libgio is broken for static linking')
807 endif
808 gio = not_found
809 endif
810 if gio.found()
811 gdbus_codegen = find_program(gio.get_variable('gdbus_codegen'),
812 required: get_option('gio'))
813 gio_unix = dependency('gio-unix-2.0', required: get_option('gio'),
063d5119 814 method: 'pkg-config')
7544060e
PB
815 gio = declare_dependency(dependencies: [gio, gio_unix],
816 version: gio.version())
817 endif
a81df1b6 818endif
bb2dc4b7
PB
819if gdbus_codegen.found() and get_option('cfi')
820 gdbus_codegen = not_found
821 gdbus_codegen_error = '@0@ uses gdbus-codegen, which does not support control flow integrity'
822endif
7544060e 823
6cc5a615
MAL
824xml_pp = find_program('scripts/xml-preprocess.py')
825
a81df1b6 826lttng = not_found
9c29b741 827if 'ust' in get_option('trace_backends')
e32aaa5a 828 lttng = dependency('lttng-ust', required: true, version: '>= 2.1',
063d5119 829 method: 'pkg-config')
a81df1b6 830endif
b7612f45 831pixman = not_found
cca15756
MAL
832if not get_option('pixman').auto() or have_system or have_tools
833 pixman = dependency('pixman-1', required: get_option('pixman'), version:'>=0.21.8',
063d5119 834 method: 'pkg-config')
b7612f45 835endif
cca15756 836
063d5119 837zlib = dependency('zlib', required: true)
53c22b68 838
ff66f3e5
PB
839libaio = not_found
840if not get_option('linux_aio').auto() or have_block
841 libaio = cc.find_library('aio', has_headers: ['libaio.h'],
063d5119 842 required: get_option('linux_aio'))
ff66f3e5 843endif
354081d4
LB
844
845linux_io_uring_test = '''
846 #include <liburing.h>
847 #include <linux/errqueue.h>
848
849 int main(void) { return 0; }'''
850
5e5733e5 851linux_io_uring = not_found
53c22b68 852if not get_option('linux_io_uring').auto() or have_block
a41b4fdc
DB
853 linux_io_uring = dependency('liburing', version: '>=0.3',
854 required: get_option('linux_io_uring'),
063d5119 855 method: 'pkg-config')
354081d4
LB
856 if not cc.links(linux_io_uring_test)
857 linux_io_uring = not_found
858 endif
5e5733e5 859endif
354081d4 860
5e5733e5 861libnfs = not_found
30045c05
PB
862if not get_option('libnfs').auto() or have_block
863 libnfs = dependency('libnfs', version: '>=1.9.3',
864 required: get_option('libnfs'),
063d5119 865 method: 'pkg-config')
5e5733e5 866endif
f7f2d651
PB
867
868libattr_test = '''
869 #include <stddef.h>
870 #include <sys/types.h>
871 #ifdef CONFIG_LIBATTR
872 #include <attr/xattr.h>
873 #else
874 #include <sys/xattr.h>
875 #endif
876 int main(void) { getxattr(NULL, NULL, NULL, 0); setxattr(NULL, NULL, NULL, 0, 0); return 0; }'''
877
ec0d5893 878libattr = not_found
f7f2d651 879have_old_libattr = false
43a363ae 880if get_option('attr').allowed()
f7f2d651
PB
881 if cc.links(libattr_test)
882 libattr = declare_dependency()
883 else
884 libattr = cc.find_library('attr', has_headers: ['attr/xattr.h'],
063d5119 885 required: get_option('attr'))
f7f2d651
PB
886 if libattr.found() and not \
887 cc.links(libattr_test, dependencies: libattr, args: '-DCONFIG_LIBATTR')
888 libattr = not_found
889 if get_option('attr').enabled()
890 error('could not link libattr')
891 else
892 warning('could not link libattr, disabling')
893 endif
894 else
895 have_old_libattr = libattr.found()
896 endif
897 endif
ec0d5893 898endif
f7f2d651 899
52eaefd3
AO
900cocoa = dependency('appleframeworks', modules: ['Cocoa', 'CoreVideo'],
901 required: get_option('cocoa'))
c1ec4941 902
e2c1d78d
VY
903vmnet = dependency('appleframeworks', modules: 'vmnet', required: get_option('vmnet'))
904if vmnet.found() and not cc.has_header_symbol('vmnet/vmnet.h',
905 'VMNET_BRIDGED_MODE',
906 dependencies: vmnet)
907 vmnet = not_found
908 if get_option('vmnet').enabled()
909 error('vmnet.framework API is outdated')
910 else
911 warning('vmnet.framework API is outdated, disabling')
912 endif
913endif
914
3f99cf57 915seccomp = not_found
73422d95 916seccomp_has_sysrawrc = false
90835c2b
PB
917if not get_option('seccomp').auto() or have_system or have_tools
918 seccomp = dependency('libseccomp', version: '>=2.3.0',
919 required: get_option('seccomp'),
063d5119 920 method: 'pkg-config')
73422d95
MP
921 if seccomp.found()
922 seccomp_has_sysrawrc = cc.has_header_symbol('seccomp.h',
923 'SCMP_FLTATR_API_SYSRAWRC',
924 dependencies: seccomp)
925 endif
3f99cf57 926endif
727c8bb8 927
3f99cf57 928libcap_ng = not_found
727c8bb8
PB
929if not get_option('cap_ng').auto() or have_system or have_tools
930 libcap_ng = cc.find_library('cap-ng', has_headers: ['cap-ng.h'],
063d5119 931 required: get_option('cap_ng'))
727c8bb8
PB
932endif
933if libcap_ng.found() and not cc.links('''
934 #include <cap-ng.h>
935 int main(void)
936 {
937 capng_capability_to_name(CAPNG_EFFECTIVE);
938 return 0;
939 }''', dependencies: libcap_ng)
940 libcap_ng = not_found
941 if get_option('cap_ng').enabled()
942 error('could not link libcap-ng')
943 else
944 warning('could not link libcap-ng, disabling')
945 endif
3f99cf57 946endif
727c8bb8 947
1917ec6d
PB
948if get_option('xkbcommon').auto() and not have_system and not have_tools
949 xkbcommon = not_found
950else
951 xkbcommon = dependency('xkbcommon', required: get_option('xkbcommon'),
063d5119 952 method: 'pkg-config')
ade60d4f 953endif
e1723999 954
5890258a
TH
955slirp = not_found
956if not get_option('slirp').auto() or have_system
957 slirp = dependency('slirp', required: get_option('slirp'),
063d5119 958 method: 'pkg-config')
5890258a
TH
959 # slirp < 4.7 is incompatible with CFI support in QEMU. This is because
960 # it passes function pointers within libslirp as callbacks for timers.
961 # When using a system-wide shared libslirp, the type information for the
962 # callback is missing and the timer call produces a false positive with CFI.
963 # Do not use the "version" keyword argument to produce a better error.
964 # with control-flow integrity.
965 if get_option('cfi') and slirp.found() and slirp.version().version_compare('<4.7')
966 if get_option('slirp').enabled()
967 error('Control-Flow Integrity requires libslirp 4.7.')
968 else
969 warning('Cannot use libslirp since Control-Flow Integrity requires libslirp >= 4.7.')
970 slirp = not_found
971 endif
972 endif
973endif
974
cdaf0722 975vde = not_found
e1723999
PB
976if not get_option('vde').auto() or have_system or have_tools
977 vde = cc.find_library('vdeplug', has_headers: ['libvdeplug.h'],
063d5119 978 required: get_option('vde'))
e1723999
PB
979endif
980if vde.found() and not cc.links('''
981 #include <libvdeplug.h>
982 int main(void)
983 {
984 struct vde_open_args a = {0, 0, 0};
985 char s[] = "";
986 vde_open(s, s, &a);
987 return 0;
988 }''', dependencies: vde)
989 vde = not_found
990 if get_option('cap_ng').enabled()
991 error('could not link libvdeplug')
992 else
993 warning('could not link libvdeplug, disabling')
994 endif
cdaf0722 995endif
87430d5b 996
478e943f 997pulse = not_found
87430d5b
PB
998if not get_option('pa').auto() or (targetos == 'linux' and have_system)
999 pulse = dependency('libpulse', required: get_option('pa'),
063d5119 1000 method: 'pkg-config')
478e943f
PB
1001endif
1002alsa = not_found
87430d5b
PB
1003if not get_option('alsa').auto() or (targetos == 'linux' and have_system)
1004 alsa = dependency('alsa', required: get_option('alsa'),
063d5119 1005 method: 'pkg-config')
478e943f
PB
1006endif
1007jack = not_found
87430d5b
PB
1008if not get_option('jack').auto() or have_system
1009 jack = dependency('jack', required: get_option('jack'),
063d5119 1010 method: 'pkg-config')
478e943f 1011endif
c2d3d1c2
DB
1012pipewire = not_found
1013if not get_option('pipewire').auto() or (targetos == 'linux' and have_system)
1014 pipewire = dependency('libpipewire-0.3', version: '>=0.3.60',
1015 required: get_option('pipewire'),
063d5119 1016 method: 'pkg-config')
c2d3d1c2 1017endif
663df1cc
AR
1018sndio = not_found
1019if not get_option('sndio').auto() or have_system
1020 sndio = dependency('sndio', required: get_option('sndio'),
063d5119 1021 method: 'pkg-config')
663df1cc 1022endif
87430d5b 1023
58d3f3ff 1024spice_protocol = not_found
3f0a5d55 1025if not get_option('spice_protocol').auto() or have_system
5c167b53 1026 spice_protocol = dependency('spice-protocol', version: '>=0.14.0',
3f0a5d55 1027 required: get_option('spice_protocol'),
063d5119 1028 method: 'pkg-config')
2634733c 1029endif
3f0a5d55 1030spice = not_found
c98791eb
MAL
1031if get_option('spice') \
1032 .disable_auto_if(not have_system) \
1033 .require(pixman.found(),
1034 error_message: 'cannot enable SPICE if pixman is not available') \
1035 .allowed()
34d55725 1036 spice = dependency('spice-server', version: '>=0.14.0',
3f0a5d55 1037 required: get_option('spice'),
063d5119 1038 method: 'pkg-config')
58d3f3ff 1039endif
3f0a5d55
MAL
1040spice_headers = spice.partial_dependency(compile_args: true, includes: true)
1041
5ee24e78 1042rt = cc.find_library('rt', required: false)
a399f914 1043
99650b62 1044libiscsi = not_found
9db405a3
PB
1045if not get_option('libiscsi').auto() or have_block
1046 libiscsi = dependency('libiscsi', version: '>=1.9.0',
1047 required: get_option('libiscsi'),
063d5119 1048 method: 'pkg-config')
99650b62 1049endif
5e5733e5 1050zstd = not_found
b1def33d
PB
1051if not get_option('zstd').auto() or have_block
1052 zstd = dependency('libzstd', version: '>=1.4.0',
1053 required: get_option('zstd'),
063d5119 1054 method: 'pkg-config')
5e5733e5 1055endif
ea458960 1056virgl = not_found
0265fe9e
PB
1057
1058have_vhost_user_gpu = have_tools and targetos == 'linux' and pixman.found()
1059if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu
587d59d6
PB
1060 virgl = dependency('virglrenderer',
1061 method: 'pkg-config',
063d5119 1062 required: get_option('virglrenderer'))
c1600f84
MAL
1063 if virgl.found()
1064 config_host_data.set('HAVE_VIRGL_D3D_INFO_EXT',
1065 cc.has_member('struct virgl_renderer_resource_info_ext', 'd3d_tex2d',
1066 prefix: '#include <virglrenderer.h>',
1067 dependencies: virgl))
1068 endif
ea458960 1069endif
cd9adbef
GS
1070rutabaga = not_found
1071if not get_option('rutabaga_gfx').auto() or have_system or have_vhost_user_gpu
1072 rutabaga = dependency('rutabaga_gfx_ffi',
1073 method: 'pkg-config',
1074 required: get_option('rutabaga_gfx'))
1075endif
fd66dbd4
SH
1076blkio = not_found
1077if not get_option('blkio').auto() or have_block
1078 blkio = dependency('blkio',
1079 method: 'pkg-config',
063d5119 1080 required: get_option('blkio'))
fd66dbd4 1081endif
1d7bb6ab 1082curl = not_found
f9cd86fe
PB
1083if not get_option('curl').auto() or have_block
1084 curl = dependency('libcurl', version: '>=7.29.0',
1085 method: 'pkg-config',
063d5119 1086 required: get_option('curl'))
1d7bb6ab 1087endif
f15bff25 1088libudev = not_found
f01496a3 1089if targetos == 'linux' and (have_system or have_tools)
6ec0e15d 1090 libudev = dependency('libudev',
a0fbbb6e 1091 method: 'pkg-config',
063d5119 1092 required: get_option('libudev'))
6ec0e15d
PB
1093endif
1094
5c53015a 1095mpathlibs = [libudev]
6ec0e15d 1096mpathpersist = not_found
43a363ae 1097if targetos == 'linux' and have_tools and get_option('mpath').allowed()
6b40847a 1098 mpath_test_source = '''
6ec0e15d
PB
1099 #include <libudev.h>
1100 #include <mpath_persist.h>
1101 unsigned mpath_mx_alloc_len = 1024;
1102 int logsink;
1103 static struct config *multipath_conf;
1104 extern struct udev *udev;
1105 extern struct config *get_multipath_config(void);
1106 extern void put_multipath_config(struct config *conf);
1107 struct udev *udev;
1108 struct config *get_multipath_config(void) { return multipath_conf; }
1109 void put_multipath_config(struct config *conf) { }
1110 int main(void) {
1111 udev = udev_new();
1112 multipath_conf = mpath_lib_init();
1113 return 0;
1114 }'''
5c53015a 1115 libmpathpersist = cc.find_library('mpathpersist',
063d5119 1116 required: get_option('mpath'))
5c53015a
PB
1117 if libmpathpersist.found()
1118 mpathlibs += libmpathpersist
a0cbd2e8 1119 if get_option('prefer_static')
5c53015a 1120 mpathlibs += cc.find_library('devmapper',
063d5119 1121 required: get_option('mpath'))
43b43a40 1122 endif
5c53015a 1123 mpathlibs += cc.find_library('multipath',
063d5119 1124 required: get_option('mpath'))
5c53015a
PB
1125 foreach lib: mpathlibs
1126 if not lib.found()
1127 mpathlibs = []
1128 break
1129 endif
1130 endforeach
1131 if mpathlibs.length() == 0
1132 msg = 'Dependencies missing for libmpathpersist'
6b40847a 1133 elif cc.links(mpath_test_source, dependencies: mpathlibs)
6ec0e15d
PB
1134 mpathpersist = declare_dependency(dependencies: mpathlibs)
1135 else
5c53015a
PB
1136 msg = 'Cannot detect libmpathpersist API'
1137 endif
1138 if not mpathpersist.found()
6ec0e15d 1139 if get_option('mpath').enabled()
5c53015a 1140 error(msg)
6ec0e15d 1141 else
5c53015a 1142 warning(msg + ', disabling')
6ec0e15d
PB
1143 endif
1144 endif
1145 endif
f15bff25 1146endif
6ec0e15d 1147
5285e593 1148iconv = not_found
5285e593 1149curses = not_found
43a363ae 1150if have_system and get_option('curses').allowed()
925a40df 1151 curses_test = '''
fbab8cc2
SW
1152 #if defined(__APPLE__) || defined(__OpenBSD__)
1153 #define _XOPEN_SOURCE_EXTENDED 1
1154 #endif
925a40df
PB
1155 #include <locale.h>
1156 #include <curses.h>
1157 #include <wchar.h>
1158 int main(void) {
1159 wchar_t wch = L'w';
1160 setlocale(LC_ALL, "");
1161 resize_term(0, 0);
1162 addwstr(L"wide chars\n");
1163 addnwstr(&wch, 1);
1164 add_wch(WACS_DEGREE);
1165 return 0;
1166 }'''
1167
ca31e307 1168 curses_dep_list = targetos == 'windows' ? ['ncurses', 'ncursesw'] : ['ncursesw']
6d322635
PB
1169 curses = dependency(curses_dep_list,
1170 required: false,
063d5119 1171 method: 'pkg-config')
925a40df 1172 msg = get_option('curses').enabled() ? 'curses library not found' : ''
fbab8cc2 1173 curses_compile_args = ['-DNCURSES_WIDECHAR=1']
925a40df 1174 if curses.found()
0dbce6ef 1175 if cc.links(curses_test, args: curses_compile_args, dependencies: [curses])
bd3615d6
PB
1176 curses = declare_dependency(compile_args: curses_compile_args, dependencies: [curses],
1177 version: curses.version())
925a40df
PB
1178 else
1179 msg = 'curses package not usable'
1180 curses = not_found
5285e593
YL
1181 endif
1182 endif
925a40df 1183 if not curses.found()
925a40df
PB
1184 has_curses_h = cc.has_header('curses.h', args: curses_compile_args)
1185 if targetos != 'windows' and not has_curses_h
1186 message('Trying with /usr/include/ncursesw')
1187 curses_compile_args += ['-I/usr/include/ncursesw']
1188 has_curses_h = cc.has_header('curses.h', args: curses_compile_args)
1189 endif
1190 if has_curses_h
1191 curses_libname_list = (targetos == 'windows' ? ['pdcurses'] : ['ncursesw', 'cursesw'])
1192 foreach curses_libname : curses_libname_list
5285e593 1193 libcurses = cc.find_library(curses_libname,
063d5119 1194 required: false)
925a40df
PB
1195 if libcurses.found()
1196 if cc.links(curses_test, args: curses_compile_args, dependencies: libcurses)
1197 curses = declare_dependency(compile_args: curses_compile_args,
1198 dependencies: [libcurses])
1199 break
1200 else
1201 msg = 'curses library not usable'
1202 endif
5285e593 1203 endif
925a40df
PB
1204 endforeach
1205 endif
1206 endif
43a363ae 1207 if get_option('iconv').allowed()
925a40df
PB
1208 foreach link_args : [ ['-liconv'], [] ]
1209 # Programs will be linked with glib and this will bring in libiconv on FreeBSD.
1210 # We need to use libiconv if available because mixing libiconv's headers with
1211 # the system libc does not work.
1212 # However, without adding glib to the dependencies -L/usr/local/lib will not be
1213 # included in the command line and libiconv will not be found.
1214 if cc.links('''
1215 #include <iconv.h>
1216 int main(void) {
1217 iconv_t conv = iconv_open("WCHAR_T", "UCS-2");
1218 return conv != (iconv_t) -1;
fc9a809e 1219 }''', args: link_args, dependencies: glib)
925a40df
PB
1220 iconv = declare_dependency(link_args: link_args, dependencies: glib)
1221 break
5285e593 1222 endif
30fe76b1
PB
1223 endforeach
1224 endif
925a40df
PB
1225 if curses.found() and not iconv.found()
1226 if get_option('iconv').enabled()
1227 error('iconv not available')
1228 endif
1229 msg = 'iconv required for curses UI but not available'
1230 curses = not_found
1231 endif
1232 if not curses.found() and msg != ''
1233 if get_option('curses').enabled()
1234 error(msg)
30fe76b1 1235 else
925a40df 1236 warning(msg + ', disabling')
30fe76b1 1237 endif
5285e593
YL
1238 endif
1239endif
1240
2634733c 1241brlapi = not_found
8c6d4ff4
PB
1242if not get_option('brlapi').auto() or have_system
1243 brlapi = cc.find_library('brlapi', has_headers: ['brlapi.h'],
063d5119 1244 required: get_option('brlapi'))
8c6d4ff4
PB
1245 if brlapi.found() and not cc.links('''
1246 #include <brlapi.h>
1247 #include <stddef.h>
1248 int main(void) { return brlapi__openConnection (NULL, NULL, NULL); }''', dependencies: brlapi)
1249 brlapi = not_found
1250 if get_option('brlapi').enabled()
1251 error('could not link brlapi')
1252 else
1253 warning('could not link brlapi, disabling')
1254 endif
1255 endif
2634733c 1256endif
35be72ba 1257
760e4327 1258sdl = not_found
64d3fec7 1259if not get_option('sdl').auto() or have_system
063d5119 1260 sdl = dependency('sdl2', required: get_option('sdl'))
760e4327
PB
1261 sdl_image = not_found
1262endif
35be72ba 1263if sdl.found()
6da5f22b
TH
1264 # Some versions of SDL have problems with -Wundef
1265 if not cc.compiles('''
1266 #include <SDL.h>
1267 #include <SDL_syswm.h>
1268 int main(int argc, char *argv[]) { return 0; }
1269 ''', dependencies: sdl, args: '-Werror=undef')
1270 sdl = declare_dependency(compile_args: '-Wno-undef',
1271 dependencies: sdl,
1272 version: sdl.version())
1273 endif
7161a433 1274 sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
063d5119 1275 method: 'pkg-config')
35be72ba
PB
1276else
1277 if get_option('sdl_image').enabled()
a8dc2ace
ST
1278 error('sdl-image required, but SDL was @0@'.format(
1279 get_option('sdl').disabled() ? 'disabled' : 'not found'))
35be72ba
PB
1280 endif
1281 sdl_image = not_found
2634733c 1282endif
35be72ba 1283
5e5733e5 1284rbd = not_found
fabd1e93 1285if not get_option('rbd').auto() or have_block
063d5119 1286 librados = cc.find_library('rados', required: get_option('rbd'))
fabd1e93 1287 librbd = cc.find_library('rbd', has_headers: ['rbd/librbd.h'],
063d5119 1288 required: get_option('rbd'))
c518d6c2
PB
1289 if librados.found() and librbd.found()
1290 if cc.links('''
1291 #include <stdio.h>
1292 #include <rbd/librbd.h>
1293 int main(void) {
1294 rados_t cluster;
1295 rados_create(&cluster, NULL);
48672ac0
PL
1296 #if LIBRBD_VERSION_CODE < LIBRBD_VERSION(1, 12, 0)
1297 #error
1298 #endif
c518d6c2
PB
1299 return 0;
1300 }''', dependencies: [librbd, librados])
1301 rbd = declare_dependency(dependencies: [librbd, librados])
1302 elif get_option('rbd').enabled()
48672ac0 1303 error('librbd >= 1.12.0 required')
c518d6c2 1304 else
48672ac0 1305 warning('librbd >= 1.12.0 not found, disabling')
c518d6c2 1306 endif
fabd1e93 1307 endif
5e5733e5 1308endif
fabd1e93 1309
5e5733e5 1310glusterfs = not_found
08821ca2
PB
1311glusterfs_ftruncate_has_stat = false
1312glusterfs_iocb_has_stat = false
1313if not get_option('glusterfs').auto() or have_block
1314 glusterfs = dependency('glusterfs-api', version: '>=3',
1315 required: get_option('glusterfs'),
063d5119 1316 method: 'pkg-config')
08821ca2
PB
1317 if glusterfs.found()
1318 glusterfs_ftruncate_has_stat = cc.links('''
1319 #include <glusterfs/api/glfs.h>
1320
1321 int
1322 main(void)
1323 {
1324 /* new glfs_ftruncate() passes two additional args */
1325 return glfs_ftruncate(NULL, 0, NULL, NULL);
1326 }
1327 ''', dependencies: glusterfs)
1328 glusterfs_iocb_has_stat = cc.links('''
1329 #include <glusterfs/api/glfs.h>
1330
1331 /* new glfs_io_cbk() passes two additional glfs_stat structs */
1332 static void
1333 glusterfs_iocb(glfs_fd_t *fd, ssize_t ret, struct glfs_stat *prestat, struct glfs_stat *poststat, void *data)
1334 {}
1335
1336 int
1337 main(void)
1338 {
1339 glfs_io_cbk iocb = &glusterfs_iocb;
1340 iocb(NULL, 0 , NULL, NULL, NULL);
1341 return 0;
1342 }
1343 ''', dependencies: glusterfs)
1344 endif
5e5733e5 1345endif
e6a52b36 1346
0d9e8c0b
MS
1347hv_balloon = false
1348if get_option('hv_balloon').allowed() and have_system
1349 if cc.links('''
1350 #include <string.h>
1351 #include <gmodule.h>
1352 int main(void) {
1353 GTree *tree;
1354
1355 tree = g_tree_new((GCompareFunc)strcmp);
1356 (void)g_tree_node_first(tree);
1357 g_tree_destroy(tree);
1358 return 0;
1359 }
1360 ''', dependencies: glib)
1361 hv_balloon = true
1362 else
1363 if get_option('hv_balloon').enabled()
1364 error('could not enable hv-balloon, update your glib')
1365 else
1366 warning('could not find glib support for hv-balloon, disabling')
1367 endif
1368 endif
1369endif
1370
5e5733e5 1371libssh = not_found
e6a52b36
TH
1372if not get_option('libssh').auto() or have_block
1373 libssh = dependency('libssh', version: '>=0.8.7',
1374 method: 'pkg-config',
063d5119 1375 required: get_option('libssh'))
5e5733e5 1376endif
e6a52b36 1377
5e5733e5 1378libbzip2 = not_found
29ba6116
PB
1379if not get_option('bzip2').auto() or have_block
1380 libbzip2 = cc.find_library('bz2', has_headers: ['bzlib.h'],
063d5119 1381 required: get_option('bzip2'))
29ba6116
PB
1382 if libbzip2.found() and not cc.links('''
1383 #include <bzlib.h>
1384 int main(void) { BZ2_bzlibVersion(); return 0; }''', dependencies: libbzip2)
1385 libbzip2 = not_found
1386 if get_option('bzip2').enabled()
1387 error('could not link libbzip2')
1388 else
1389 warning('could not link libbzip2, disabling')
1390 endif
1391 endif
5e5733e5 1392endif
ecea3696 1393
5e5733e5 1394liblzfse = not_found
ecea3696
PB
1395if not get_option('lzfse').auto() or have_block
1396 liblzfse = cc.find_library('lzfse', has_headers: ['lzfse.h'],
063d5119 1397 required: get_option('lzfse'))
ecea3696
PB
1398endif
1399if liblzfse.found() and not cc.links('''
1400 #include <lzfse.h>
1401 int main(void) { lzfse_decode_scratch_size(); return 0; }''', dependencies: liblzfse)
1402 liblzfse = not_found
1403 if get_option('lzfse').enabled()
1404 error('could not link liblzfse')
1405 else
1406 warning('could not link liblzfse, disabling')
1407 endif
5e5733e5 1408endif
ecea3696 1409
478e943f 1410oss = not_found
43a363ae 1411if get_option('oss').allowed() and have_system
87430d5b
PB
1412 if not cc.has_header('sys/soundcard.h')
1413 # not found
1414 elif targetos == 'netbsd'
063d5119 1415 oss = cc.find_library('ossaudio', required: get_option('oss'))
87430d5b
PB
1416 else
1417 oss = declare_dependency()
1418 endif
1419
1420 if not oss.found()
1421 if get_option('oss').enabled()
1422 error('OSS not found')
87430d5b
PB
1423 endif
1424 endif
478e943f
PB
1425endif
1426dsound = not_found
87430d5b
PB
1427if not get_option('dsound').auto() or (targetos == 'windows' and have_system)
1428 if cc.has_header('dsound.h')
1429 dsound = declare_dependency(link_args: ['-lole32', '-ldxguid'])
1430 endif
1431
1432 if not dsound.found()
1433 if get_option('dsound').enabled()
1434 error('DirectSound not found')
87430d5b
PB
1435 endif
1436 endif
478e943f 1437endif
87430d5b 1438
478e943f 1439coreaudio = not_found
87430d5b
PB
1440if not get_option('coreaudio').auto() or (targetos == 'darwin' and have_system)
1441 coreaudio = dependency('appleframeworks', modules: 'CoreAudio',
1442 required: get_option('coreaudio'))
2b1ccdf4 1443endif
8bc5184d 1444
2b1ccdf4 1445opengl = not_found
88b6e618
PB
1446if not get_option('opengl').auto() or have_system or have_vhost_user_gpu
1447 epoxy = dependency('epoxy', method: 'pkg-config',
063d5119 1448 required: get_option('opengl'))
88b6e618
PB
1449 if cc.has_header('epoxy/egl.h', dependencies: epoxy)
1450 opengl = epoxy
1451 elif get_option('opengl').enabled()
1452 error('epoxy/egl.h not found')
1453 endif
2b1ccdf4 1454endif
8bc5184d
TH
1455gbm = not_found
1456if (have_system or have_tools) and (virgl.found() or opengl.found())
063d5119 1457 gbm = dependency('gbm', method: 'pkg-config', required: false)
8bc5184d 1458endif
f0caba44 1459have_vhost_user_gpu = have_vhost_user_gpu and virgl.found() and opengl.found() and gbm.found()
1b695471 1460
57612511 1461gnutls = not_found
cc4c7c73 1462gnutls_crypto = not_found
abc14fd0 1463if get_option('gnutls').enabled() or (get_option('gnutls').auto() and have_system)
cc4c7c73
DB
1464 # For general TLS support our min gnutls matches
1465 # that implied by our platform support matrix
1466 #
1467 # For the crypto backends, we look for a newer
1468 # gnutls:
1469 #
1470 # Version 3.6.8 is needed to get XTS
1471 # Version 3.6.13 is needed to get PBKDF
1472 # Version 3.6.14 is needed to get HW accelerated XTS
1473 #
1474 # If newer enough gnutls isn't available, we can
1475 # still use a different crypto backend to satisfy
1476 # the platform support requirements
1477 gnutls_crypto = dependency('gnutls', version: '>=3.6.14',
1478 method: 'pkg-config',
063d5119 1479 required: false)
cc4c7c73
DB
1480 if gnutls_crypto.found()
1481 gnutls = gnutls_crypto
1482 else
1483 # Our min version if all we need is TLS
1484 gnutls = dependency('gnutls', version: '>=3.5.18',
1485 method: 'pkg-config',
063d5119 1486 required: get_option('gnutls'))
cc4c7c73 1487 endif
57612511
PB
1488endif
1489
8bd0931f
DB
1490# We prefer use of gnutls for crypto, unless the options
1491# explicitly asked for nettle or gcrypt.
1492#
1493# If gnutls isn't available for crypto, then we'll prefer
1494# gcrypt over nettle for performance reasons.
57612511
PB
1495gcrypt = not_found
1496nettle = not_found
4c5e512e 1497hogweed = not_found
68014044 1498xts = 'none'
8bd0931f 1499
57612511
PB
1500if get_option('nettle').enabled() and get_option('gcrypt').enabled()
1501 error('Only one of gcrypt & nettle can be enabled')
57612511 1502endif
8bd0931f
DB
1503
1504# Explicit nettle/gcrypt request, so ignore gnutls for crypto
1505if get_option('nettle').enabled() or get_option('gcrypt').enabled()
cc4c7c73
DB
1506 gnutls_crypto = not_found
1507endif
57612511 1508
8bd0931f
DB
1509if not gnutls_crypto.found()
1510 if (not get_option('gcrypt').auto() or have_system) and not get_option('nettle').enabled()
1511 gcrypt = dependency('libgcrypt', version: '>=1.8',
1512 method: 'config-tool',
063d5119 1513 required: get_option('gcrypt'))
8bd0931f
DB
1514 # Debian has removed -lgpg-error from libgcrypt-config
1515 # as it "spreads unnecessary dependencies" which in
1516 # turn breaks static builds...
a0cbd2e8 1517 if gcrypt.found() and get_option('prefer_static')
bd3615d6
PB
1518 gcrypt = declare_dependency(dependencies:
1519 [gcrypt,
1520 cc.find_library('gpg-error', required: true)],
1521 version: gcrypt.version())
8bd0931f 1522 endif
57612511 1523 endif
8bd0931f
DB
1524 if (not get_option('nettle').auto() or have_system) and not gcrypt.found()
1525 nettle = dependency('nettle', version: '>=3.4',
1526 method: 'pkg-config',
063d5119 1527 required: get_option('nettle'))
8bd0931f
DB
1528 if nettle.found() and not cc.has_header('nettle/xts.h', dependencies: nettle)
1529 xts = 'private'
1530 endif
57612511
PB
1531 endif
1532endif
1533
063d5119 1534gmp = dependency('gmp', required: false, method: 'pkg-config')
4c5e512e
LH
1535if nettle.found() and gmp.found()
1536 hogweed = dependency('hogweed', version: '>=3.4',
1537 method: 'pkg-config',
063d5119 1538 required: get_option('nettle'))
4c5e512e
LH
1539endif
1540
1541
2b1ccdf4 1542gtk = not_found
1b695471 1543gtkx11 = not_found
c23d7b4e 1544vte = not_found
29e0bfff
CF
1545have_gtk_clipboard = get_option('gtk_clipboard').enabled()
1546
da554e16
MAL
1547if get_option('gtk') \
1548 .disable_auto_if(not have_system) \
1549 .require(pixman.found(),
1550 error_message: 'cannot enable GTK if pixman is not available') \
1551 .allowed()
1b695471
PB
1552 gtk = dependency('gtk+-3.0', version: '>=3.22.0',
1553 method: 'pkg-config',
063d5119 1554 required: get_option('gtk'))
1b695471
PB
1555 if gtk.found()
1556 gtkx11 = dependency('gtk+-x11-3.0', version: '>=3.22.0',
1557 method: 'pkg-config',
063d5119 1558 required: false)
bd3615d6
PB
1559 gtk = declare_dependency(dependencies: [gtk, gtkx11],
1560 version: gtk.version())
c23d7b4e
PB
1561
1562 if not get_option('vte').auto() or have_system
1563 vte = dependency('vte-2.91',
1564 method: 'pkg-config',
063d5119 1565 required: get_option('vte'))
c23d7b4e 1566 endif
29e0bfff
CF
1567 elif have_gtk_clipboard
1568 error('GTK clipboard requested, but GTK not found')
1b695471 1569 endif
2b1ccdf4 1570endif
1b695471 1571
2b1ccdf4 1572x11 = not_found
9d49bcf6 1573if gtkx11.found()
063d5119 1574 x11 = dependency('x11', method: 'pkg-config', required: gtkx11.found())
2b1ccdf4 1575endif
2b1ccdf4 1576png = not_found
95f8510e 1577if get_option('png').allowed() and have_system
1ec8c2c0 1578 png = dependency('libpng', version: '>=1.6.34', required: get_option('png'),
063d5119 1579 method: 'pkg-config')
95f8510e
KS
1580endif
1581vnc = not_found
2b1ccdf4 1582jpeg = not_found
2b1ccdf4 1583sasl = not_found
89fd3eab
MAL
1584if get_option('vnc') \
1585 .disable_auto_if(not have_system) \
1586 .require(pixman.found(),
1587 error_message: 'cannot enable VNC if pixman is not available') \
1588 .allowed()
a0b93237 1589 vnc = declare_dependency() # dummy dependency
8e242b3c 1590 jpeg = dependency('libjpeg', required: get_option('vnc_jpeg'),
063d5119 1591 method: 'pkg-config')
a0b93237 1592 sasl = cc.find_library('sasl2', has_headers: ['sasl/sasl.h'],
063d5119 1593 required: get_option('vnc_sasl'))
a0b93237
PB
1594 if sasl.found()
1595 sasl = declare_dependency(dependencies: sasl,
1596 compile_args: '-DSTRUCT_IOVEC_DEFINED')
1597 endif
478e943f 1598endif
241611ea 1599
05e391ae
PB
1600pam = not_found
1601if not get_option('auth_pam').auto() or have_system
1602 pam = cc.find_library('pam', has_headers: ['security/pam_appl.h'],
063d5119 1603 required: get_option('auth_pam'))
05e391ae
PB
1604endif
1605if pam.found() and not cc.links('''
1606 #include <stddef.h>
1607 #include <security/pam_appl.h>
1608 int main(void) {
1609 const char *service_name = "qemu";
1610 const char *user = "frank";
1611 const struct pam_conv pam_conv = { 0 };
1612 pam_handle_t *pamh = NULL;
1613 pam_start(service_name, user, &pam_conv, &pamh);
1614 return 0;
1615 }''', dependencies: pam)
1616 pam = not_found
1617 if get_option('auth_pam').enabled()
1618 error('could not link libpam')
1619 else
1620 warning('could not link libpam, disabling')
1621 endif
1622endif
1623
708eab42 1624snappy = not_found
241611ea
PB
1625if not get_option('snappy').auto() or have_system
1626 snappy = cc.find_library('snappy', has_headers: ['snappy-c.h'],
063d5119 1627 required: get_option('snappy'))
241611ea 1628endif
785abf0d 1629if snappy.found() and not cc.links('''
241611ea
PB
1630 #include <snappy-c.h>
1631 int main(void) { snappy_max_compressed_length(4096); return 0; }''', dependencies: snappy)
1632 snappy = not_found
1633 if get_option('snappy').enabled()
1634 error('could not link libsnappy')
1635 else
1636 warning('could not link libsnappy, disabling')
1637 endif
708eab42 1638endif
0c32a0ae 1639
708eab42 1640lzo = not_found
0c32a0ae
PB
1641if not get_option('lzo').auto() or have_system
1642 lzo = cc.find_library('lzo2', has_headers: ['lzo/lzo1x.h'],
063d5119 1643 required: get_option('lzo'))
0c32a0ae
PB
1644endif
1645if lzo.found() and not cc.links('''
1646 #include <lzo/lzo1x.h>
1647 int main(void) { lzo_version(); return 0; }''', dependencies: lzo)
1648 lzo = not_found
1649 if get_option('lzo').enabled()
1650 error('could not link liblzo2')
1651 else
1652 warning('could not link liblzo2, disabling')
1653 endif
708eab42 1654endif
0c32a0ae 1655
488a8c73
PB
1656numa = not_found
1657if not get_option('numa').auto() or have_system or have_tools
1658 numa = cc.find_library('numa', has_headers: ['numa.h'],
063d5119 1659 required: get_option('numa'))
488a8c73
PB
1660endif
1661if numa.found() and not cc.links('''
1662 #include <numa.h>
1663 int main(void) { return numa_available(); }
1664 ''', dependencies: numa)
1665 numa = not_found
1666 if get_option('numa').enabled()
1667 error('could not link numa')
1668 else
1669 warning('could not link numa, disabling')
1670 endif
1671endif
1672
55166230 1673rdma = not_found
3730a734
PB
1674if not get_option('rdma').auto() or have_system
1675 libumad = cc.find_library('ibumad', required: get_option('rdma'))
1676 rdma_libs = [cc.find_library('rdmacm', has_headers: ['rdma/rdma_cma.h'],
063d5119
PB
1677 required: get_option('rdma')),
1678 cc.find_library('ibverbs', required: get_option('rdma')),
3730a734
PB
1679 libumad]
1680 rdma = declare_dependency(dependencies: rdma_libs)
1681 foreach lib: rdma_libs
1682 if not lib.found()
1683 rdma = not_found
1684 endif
1685 endforeach
55166230 1686endif
3730a734 1687
582ea95f 1688xen = not_found
14efd8d3
PB
1689if get_option('xen').enabled() or (get_option('xen').auto() and have_system)
1690 xencontrol = dependency('xencontrol', required: false,
063d5119 1691 method: 'pkg-config')
14efd8d3
PB
1692 if xencontrol.found()
1693 xen_pc = declare_dependency(version: xencontrol.version(),
1694 dependencies: [
1695 xencontrol,
1696 # disabler: true makes xen_pc.found() return false if any is not found
1697 dependency('xenstore', required: false,
063d5119 1698 method: 'pkg-config',
14efd8d3
PB
1699 disabler: true),
1700 dependency('xenforeignmemory', required: false,
063d5119 1701 method: 'pkg-config',
14efd8d3
PB
1702 disabler: true),
1703 dependency('xengnttab', required: false,
063d5119 1704 method: 'pkg-config',
14efd8d3
PB
1705 disabler: true),
1706 dependency('xenevtchn', required: false,
063d5119 1707 method: 'pkg-config',
14efd8d3
PB
1708 disabler: true),
1709 dependency('xendevicemodel', required: false,
063d5119 1710 method: 'pkg-config',
14efd8d3
PB
1711 disabler: true),
1712 # optional, no "disabler: true"
1713 dependency('xentoolcore', required: false,
063d5119 1714 method: 'pkg-config')])
14efd8d3
PB
1715 if xen_pc.found()
1716 xen = xen_pc
1717 endif
1718 endif
1719 if not xen.found()
2f20b173 1720 xen_tests = [ '4.11.0', '4.10.0', '4.9.0', '4.8.0', '4.7.1' ]
14efd8d3
PB
1721 xen_libs = {
1722 '4.11.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemory', 'xengnttab', 'xenevtchn', 'xentoolcore' ],
1723 '4.10.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemory', 'xengnttab', 'xenevtchn', 'xentoolcore' ],
1724 '4.9.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemory', 'xengnttab', 'xenevtchn' ],
1725 '4.8.0': [ 'xenstore', 'xenctrl', 'xenforeignmemory', 'xengnttab', 'xenevtchn' ],
1726 '4.7.1': [ 'xenstore', 'xenctrl', 'xenforeignmemory', 'xengnttab', 'xenevtchn' ],
14efd8d3
PB
1727 }
1728 xen_deps = {}
1729 foreach ver: xen_tests
1730 # cache the various library tests to avoid polluting the logs
1731 xen_test_deps = []
1732 foreach l: xen_libs[ver]
1733 if l not in xen_deps
1734 xen_deps += { l: cc.find_library(l, required: false) }
1735 endif
1736 xen_test_deps += xen_deps[l]
1737 endforeach
1738
1739 # Use -D to pick just one of the test programs in scripts/xen-detect.c
1740 xen_version = ver.split('.')
1741 xen_ctrl_version = xen_version[0] + \
1742 ('0' + xen_version[1]).substring(-2) + \
1743 ('0' + xen_version[2]).substring(-2)
1744 if cc.links(files('scripts/xen-detect.c'),
1745 args: '-DCONFIG_XEN_CTRL_INTERFACE_VERSION=' + xen_ctrl_version,
1746 dependencies: xen_test_deps)
1747 xen = declare_dependency(version: ver, dependencies: xen_test_deps)
1748 break
1749 endif
1750 endforeach
1751 endif
1752 if xen.found()
1753 accelerators += 'CONFIG_XEN'
1754 elif get_option('xen').enabled()
1755 error('could not compile and link Xen test program')
1756 endif
582ea95f 1757endif
14efd8d3
PB
1758have_xen_pci_passthrough = get_option('xen_pci_passthrough') \
1759 .require(xen.found(),
1760 error_message: 'Xen PCI passthrough requested but Xen not enabled') \
1761 .require(targetos == 'linux',
1762 error_message: 'Xen PCI passthrough not available on this platform') \
a4b4b40b
SS
1763 .require(cpu == 'x86' or cpu == 'x86_64',
1764 error_message: 'Xen PCI passthrough not available on this platform') \
14efd8d3
PB
1765 .allowed()
1766
1767
06677ce1 1768cacard = not_found
5f364c57
PB
1769if not get_option('smartcard').auto() or have_system
1770 cacard = dependency('libcacard', required: get_option('smartcard'),
063d5119 1771 version: '>=2.5.1', method: 'pkg-config')
06677ce1 1772endif
0a40bcb7
CB
1773u2f = not_found
1774if have_system
1775 u2f = dependency('u2f-emu', required: get_option('u2f'),
063d5119 1776 method: 'pkg-config')
0a40bcb7 1777endif
8caef850
HZZ
1778canokey = not_found
1779if have_system
1780 canokey = dependency('canokey-qemu', required: get_option('canokey'),
063d5119 1781 method: 'pkg-config')
8caef850 1782endif
06677ce1 1783usbredir = not_found
18f31e60
PB
1784if not get_option('usb_redir').auto() or have_system
1785 usbredir = dependency('libusbredirparser-0.5', required: get_option('usb_redir'),
063d5119 1786 version: '>=0.6', method: 'pkg-config')
06677ce1
PB
1787endif
1788libusb = not_found
90540f32
PB
1789if not get_option('libusb').auto() or have_system
1790 libusb = dependency('libusb-1.0', required: get_option('libusb'),
063d5119 1791 version: '>=1.0.13', method: 'pkg-config')
06677ce1 1792endif
90540f32 1793
c9322ab5 1794libpmem = not_found
e36e8c70
PB
1795if not get_option('libpmem').auto() or have_system
1796 libpmem = dependency('libpmem', required: get_option('libpmem'),
063d5119 1797 method: 'pkg-config')
c9322ab5 1798endif
c7c91a74 1799libdaxctl = not_found
83ef1682
PB
1800if not get_option('libdaxctl').auto() or have_system
1801 libdaxctl = dependency('libdaxctl', required: get_option('libdaxctl'),
063d5119 1802 version: '>=57', method: 'pkg-config')
c7c91a74 1803endif
8ce0a45f 1804tasn1 = not_found
ba7ed407
PB
1805if gnutls.found()
1806 tasn1 = dependency('libtasn1',
063d5119 1807 method: 'pkg-config')
8ce0a45f 1808endif
0db0fbb5 1809keyutils = not_found
c64023b0
TH
1810if not get_option('libkeyutils').auto() or have_block
1811 keyutils = dependency('libkeyutils', required: get_option('libkeyutils'),
1812 method: 'pkg-config')
0db0fbb5 1813endif
a81df1b6 1814
3909def8
MAL
1815has_gettid = cc.has_function('gettid')
1816
3d212b41
RJ
1817# libselinux
1818selinux = dependency('libselinux',
1819 required: get_option('selinux'),
063d5119 1820 method: 'pkg-config')
3d212b41 1821
aa087962
PB
1822# Malloc tests
1823
1824malloc = []
1825if get_option('malloc') == 'system'
1826 has_malloc_trim = \
43a363ae 1827 get_option('malloc_trim').allowed() and \
09a49afe 1828 cc.has_function('malloc_trim', prefix: '#include <malloc.h>')
aa087962
PB
1829else
1830 has_malloc_trim = false
1831 malloc = cc.find_library(get_option('malloc'), required: true)
1832endif
1833if not has_malloc_trim and get_option('malloc_trim').enabled()
1834 if get_option('malloc') == 'system'
1835 error('malloc_trim not available on this platform.')
1836 else
1837 error('malloc_trim not available with non-libc memory allocator')
1838 endif
1839endif
1840
e66420ac 1841gnu_source_prefix = '''
84e319a5
HR
1842 #ifndef _GNU_SOURCE
1843 #define _GNU_SOURCE
1844 #endif
e66420ac 1845'''
84e319a5 1846
09a49afe 1847# Check whether the glibc provides STATX_BASIC_STATS
84e319a5 1848
09a49afe 1849has_statx = cc.has_header_symbol('sys/stat.h', 'STATX_BASIC_STATS', prefix: gnu_source_prefix)
4ce7a08d 1850
09a49afe 1851# Check whether statx() provides mount ID information
4ce7a08d 1852
09a49afe 1853has_statx_mnt_id = cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', prefix: gnu_source_prefix)
4ce7a08d 1854
a436d6d4
PB
1855have_vhost_user_blk_server = get_option('vhost_user_blk_server') \
1856 .require(targetos == 'linux',
1857 error_message: 'vhost_user_blk_server requires linux') \
2a3129a3 1858 .require(have_vhost_user,
a436d6d4 1859 error_message: 'vhost_user_blk_server requires vhost-user support') \
26ed501b 1860 .disable_auto_if(not have_tools and not have_system) \
a436d6d4 1861 .allowed()
9e62ba48 1862
df4ea709
HR
1863if get_option('fuse').disabled() and get_option('fuse_lseek').enabled()
1864 error('Cannot enable fuse-lseek while fuse is disabled')
1865endif
1866
a484a719 1867fuse = dependency('fuse3', required: get_option('fuse'),
063d5119 1868 version: '>=3.1', method: 'pkg-config')
a484a719 1869
df4ea709 1870fuse_lseek = not_found
43a363ae 1871if get_option('fuse_lseek').allowed()
df4ea709
HR
1872 if fuse.version().version_compare('>=3.8')
1873 # Dummy dependency
1874 fuse_lseek = declare_dependency()
1875 elif get_option('fuse_lseek').enabled()
1876 if fuse.found()
1877 error('fuse-lseek requires libfuse >=3.8, found ' + fuse.version())
1878 else
1879 error('fuse-lseek requires libfuse, which was not found')
1880 endif
1881 endif
1882endif
1883
a6caeee8
XY
1884have_libvduse = (targetos == 'linux')
1885if get_option('libvduse').enabled()
1886 if targetos != 'linux'
1887 error('libvduse requires linux')
1888 endif
1889elif get_option('libvduse').disabled()
1890 have_libvduse = false
1891endif
1892
2a2359b8
XY
1893have_vduse_blk_export = (have_libvduse and targetos == 'linux')
1894if get_option('vduse_blk_export').enabled()
1895 if targetos != 'linux'
1896 error('vduse_blk_export requires linux')
1897 elif not have_libvduse
1898 error('vduse_blk_export requires libvduse support')
1899 endif
1900elif get_option('vduse_blk_export').disabled()
1901 have_vduse_blk_export = false
1902endif
1903
46627f41
AM
1904# libbpf
1905libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config')
1906if libbpf.found() and not cc.links('''
1907 #include <bpf/libbpf.h>
1908 int main(void)
1909 {
1910 bpf_object__destroy_skeleton(NULL);
1911 return 0;
1912 }''', dependencies: libbpf)
1913 libbpf = not_found
1914 if get_option('bpf').enabled()
1915 error('libbpf skeleton test failed')
1916 else
1917 warning('libbpf skeleton test failed, disabling')
1918 endif
1919endif
1920
cb039ef3
IM
1921# libxdp
1922libxdp = not_found
1923if not get_option('af_xdp').auto() or have_system
1924 libxdp = dependency('libxdp', required: get_option('af_xdp'),
1925 version: '>=1.4.0', method: 'pkg-config')
1926endif
1927
7c10cb38 1928# libdw
bc71d58f 1929libdw = not_found
550c6d97 1930if not get_option('libdw').auto() or \
a0cbd2e8 1931 (not get_option('prefer_static') and (have_system or have_user))
bc71d58f
IL
1932 libdw = dependency('libdw',
1933 method: 'pkg-config',
bc71d58f
IL
1934 required: get_option('libdw'))
1935endif
7c10cb38 1936
87430d5b
PB
1937#################
1938# config-host.h #
1939#################
1940
1941audio_drivers_selected = []
1942if have_system
1943 audio_drivers_available = {
1944 'alsa': alsa.found(),
1945 'coreaudio': coreaudio.found(),
1946 'dsound': dsound.found(),
1947 'jack': jack.found(),
1948 'oss': oss.found(),
1949 'pa': pulse.found(),
c2d3d1c2 1950 'pipewire': pipewire.found(),
87430d5b 1951 'sdl': sdl.found(),
663df1cc 1952 'sndio': sndio.found(),
87430d5b 1953 }
e5424a29
PB
1954 foreach k, v: audio_drivers_available
1955 config_host_data.set('CONFIG_AUDIO_' + k.to_upper(), v)
1956 endforeach
87430d5b
PB
1957
1958 # Default to native drivers first, OSS second, SDL third
1959 audio_drivers_priority = \
663df1cc 1960 [ 'pa', 'coreaudio', 'dsound', 'sndio', 'oss' ] + \
87430d5b
PB
1961 (targetos == 'linux' ? [] : [ 'sdl' ])
1962 audio_drivers_default = []
1963 foreach k: audio_drivers_priority
1964 if audio_drivers_available[k]
1965 audio_drivers_default += k
1966 endif
1967 endforeach
1968
1969 foreach k: get_option('audio_drv_list')
1970 if k == 'default'
1971 audio_drivers_selected += audio_drivers_default
1972 elif not audio_drivers_available[k]
1973 error('Audio driver "@0@" not available.'.format(k))
1974 else
1975 audio_drivers_selected += k
1976 endif
1977 endforeach
1978endif
87430d5b
PB
1979config_host_data.set('CONFIG_AUDIO_DRIVERS',
1980 '"' + '", "'.join(audio_drivers_selected) + '", ')
1981
9e62ba48
DB
1982if get_option('cfi')
1983 cfi_flags=[]
1984 # Check for dependency on LTO
1985 if not get_option('b_lto')
1986 error('Selected Control-Flow Integrity but LTO is disabled')
1987 endif
6002711c 1988 if enable_modules
9e62ba48
DB
1989 error('Selected Control-Flow Integrity is not compatible with modules')
1990 endif
1991 # Check for cfi flags. CFI requires LTO so we can't use
1992 # get_supported_arguments, but need a more complex "compiles" which allows
1993 # custom arguments
1994 if cc.compiles('int main () { return 0; }', name: '-fsanitize=cfi-icall',
1995 args: ['-flto', '-fsanitize=cfi-icall'] )
1996 cfi_flags += '-fsanitize=cfi-icall'
1997 else
1998 error('-fsanitize=cfi-icall is not supported by the compiler')
1999 endif
2000 if cc.compiles('int main () { return 0; }',
2001 name: '-fsanitize-cfi-icall-generalize-pointers',
2002 args: ['-flto', '-fsanitize=cfi-icall',
2003 '-fsanitize-cfi-icall-generalize-pointers'] )
2004 cfi_flags += '-fsanitize-cfi-icall-generalize-pointers'
2005 else
2006 error('-fsanitize-cfi-icall-generalize-pointers is not supported by the compiler')
2007 endif
2008 if get_option('cfi_debug')
2009 if cc.compiles('int main () { return 0; }',
2010 name: '-fno-sanitize-trap=cfi-icall',
2011 args: ['-flto', '-fsanitize=cfi-icall',
2012 '-fno-sanitize-trap=cfi-icall'] )
2013 cfi_flags += '-fno-sanitize-trap=cfi-icall'
2014 else
2015 error('-fno-sanitize-trap=cfi-icall is not supported by the compiler')
2016 endif
2017 endif
e5134024
PB
2018 add_global_arguments(cfi_flags, native: false, language: all_languages)
2019 add_global_link_arguments(cfi_flags, native: false, language: all_languages)
9e62ba48
DB
2020endif
2021
14176c8d
JD
2022have_host_block_device = (targetos != 'darwin' or
2023 cc.has_header('IOKit/storage/IOMedia.h'))
2024
a436d6d4
PB
2025dbus_display = get_option('dbus_display') \
2026 .require(gio.version().version_compare('>=2.64'),
2027 error_message: '-display dbus requires glib>=2.64') \
7544060e 2028 .require(gdbus_codegen.found(),
bb2dc4b7 2029 error_message: gdbus_codegen_error.format('-display dbus')) \
a436d6d4
PB
2030 .allowed()
2031
2032have_virtfs = get_option('virtfs') \
0fb1e19d
KF
2033 .require(targetos == 'linux' or targetos == 'darwin',
2034 error_message: 'virtio-9p (virtfs) requires Linux or macOS') \
2035 .require(targetos == 'linux' or cc.has_function('pthread_fchdir_np'),
2036 error_message: 'virtio-9p (virtfs) on macOS requires the presence of pthread_fchdir_np') \
1a67e07f
PF
2037 .require(targetos == 'darwin' or libattr.found(),
2038 error_message: 'virtio-9p (virtfs) on Linux requires libattr-devel') \
a436d6d4
PB
2039 .disable_auto_if(not have_tools and not have_system) \
2040 .allowed()
69202b40 2041
1a67e07f
PF
2042have_virtfs_proxy_helper = get_option('virtfs_proxy_helper') \
2043 .require(targetos != 'darwin', error_message: 'the virtfs proxy helper is incompatible with macOS') \
2044 .require(have_virtfs, error_message: 'the virtfs proxy helper requires that virtfs is enabled') \
2045 .disable_auto_if(not have_tools) \
2046 .require(libcap_ng.found(), error_message: 'the virtfs proxy helper requires libcap-ng') \
2047 .allowed()
3a489d38 2048
622d64ff
PB
2049if get_option('block_drv_ro_whitelist') == ''
2050 config_host_data.set('CONFIG_BDRV_RO_WHITELIST', '')
2051else
2052 config_host_data.set('CONFIG_BDRV_RO_WHITELIST',
2053 '"' + get_option('block_drv_ro_whitelist').replace(',', '", "') + '", ')
2054endif
2055if get_option('block_drv_rw_whitelist') == ''
2056 config_host_data.set('CONFIG_BDRV_RW_WHITELIST', '')
2057else
2058 config_host_data.set('CONFIG_BDRV_RW_WHITELIST',
2059 '"' + get_option('block_drv_rw_whitelist').replace(',', '", "') + '", ')
2060endif
2061
9c29b741
PB
2062foreach k : get_option('trace_backends')
2063 config_host_data.set('CONFIG_TRACE_' + k.to_upper(), true)
2064endforeach
2065config_host_data.set_quoted('CONFIG_TRACE_FILE', get_option('trace_file'))
41f2ae28 2066config_host_data.set_quoted('CONFIG_TLS_PRIORITY', get_option('tls_priority'))
40c909f5
PB
2067if iasl.found()
2068 config_host_data.set_quoted('CONFIG_IASL', iasl.full_path())
5dc4618e 2069endif
16bf7a33
PB
2070config_host_data.set_quoted('CONFIG_BINDIR', get_option('prefix') / get_option('bindir'))
2071config_host_data.set_quoted('CONFIG_PREFIX', get_option('prefix'))
2072config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', get_option('prefix') / qemu_confdir)
2073config_host_data.set_quoted('CONFIG_QEMU_DATADIR', get_option('prefix') / qemu_datadir)
2074config_host_data.set_quoted('CONFIG_QEMU_DESKTOPDIR', get_option('prefix') / qemu_desktopdir)
8154f5e6
AO
2075
2076qemu_firmwarepath = ''
2077foreach k : get_option('qemu_firmwarepath')
2078 qemu_firmwarepath += '"' + get_option('prefix') / k + '", '
2079endforeach
2080config_host_data.set('CONFIG_QEMU_FIRMWAREPATH', qemu_firmwarepath)
2081
16bf7a33
PB
2082config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('prefix') / get_option('libexecdir'))
2083config_host_data.set_quoted('CONFIG_QEMU_ICONDIR', get_option('prefix') / qemu_icondir)
2084config_host_data.set_quoted('CONFIG_QEMU_LOCALEDIR', get_option('prefix') / get_option('localedir'))
2085config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', get_option('prefix') / get_option('localstatedir'))
2086config_host_data.set_quoted('CONFIG_QEMU_MODDIR', get_option('prefix') / qemu_moddir)
2087config_host_data.set_quoted('CONFIG_SYSCONFDIR', get_option('prefix') / get_option('sysconfdir'))
2088
6002711c 2089if enable_modules
b0b4323e
PB
2090 config_host_data.set('CONFIG_STAMP', run_command(
2091 meson.current_source_dir() / 'scripts/qemu-stamp.py',
2092 meson.project_version(), get_option('pkgversion'), '--',
2093 meson.current_source_dir() / 'configure',
2094 capture: true, check: true).stdout().strip())
2095endif
2096
35acbb30
PB
2097have_slirp_smbd = get_option('slirp_smbd') \
2098 .require(targetos != 'windows', error_message: 'Host smbd not supported on this platform.') \
2099 .allowed()
2100if have_slirp_smbd
2101 smbd_path = get_option('smbd')
2102 if smbd_path == ''
fb0a8b0e 2103 smbd_path = (targetos == 'sunos' ? '/usr/sfw/sbin/smbd' : '/usr/sbin/smbd')
35acbb30
PB
2104 endif
2105 config_host_data.set_quoted('CONFIG_SMBD_COMMAND', smbd_path)
2106endif
2107
823eb013
PB
2108config_host_data.set('HOST_' + host_arch.to_upper(), 1)
2109
2cb2f580
PB
2110if get_option('module_upgrades') and not enable_modules
2111 error('Cannot enable module-upgrades as modules are not enabled')
2112endif
2113config_host_data.set('CONFIG_MODULE_UPGRADES', get_option('module_upgrades'))
2114
f7f2d651 2115config_host_data.set('CONFIG_ATTR', libattr.found())
c55cf6ab 2116config_host_data.set('CONFIG_BDRV_WHITELIST_TOOLS', get_option('block_drv_whitelist_in_tools'))
8c6d4ff4 2117config_host_data.set('CONFIG_BRLAPI', brlapi.found())
1f2146f7 2118config_host_data.set('CONFIG_BSD', targetos in bsd_oses)
b4e312e9 2119config_host_data.set('CONFIG_COCOA', cocoa.found())
1f2146f7 2120config_host_data.set('CONFIG_DARWIN', targetos == 'darwin')
537b7248 2121config_host_data.set('CONFIG_FUZZ', get_option('fuzzing'))
af2bb99b 2122config_host_data.set('CONFIG_GCOV', get_option('b_coverage'))
f01496a3 2123config_host_data.set('CONFIG_LIBUDEV', libudev.found())
1f2146f7
PB
2124config_host_data.set('CONFIG_LINUX', targetos == 'linux')
2125config_host_data.set('CONFIG_POSIX', targetos != 'windows')
2126config_host_data.set('CONFIG_WIN32', targetos == 'windows')
0c32a0ae 2127config_host_data.set('CONFIG_LZO', lzo.found())
6ec0e15d 2128config_host_data.set('CONFIG_MPATH', mpathpersist.found())
fd66dbd4 2129config_host_data.set('CONFIG_BLKIO', blkio.found())
98b126f5
SG
2130if blkio.found()
2131 config_host_data.set('CONFIG_BLKIO_VHOST_VDPA_FD',
2132 blkio.version().version_compare('>=1.3.0'))
2133endif
f9cd86fe 2134config_host_data.set('CONFIG_CURL', curl.found())
5285e593 2135config_host_data.set('CONFIG_CURSES', curses.found())
8bc5184d 2136config_host_data.set('CONFIG_GBM', gbm.found())
7544060e 2137config_host_data.set('CONFIG_GIO', gio.found())
08821ca2
PB
2138config_host_data.set('CONFIG_GLUSTERFS', glusterfs.found())
2139if glusterfs.found()
2140 config_host_data.set('CONFIG_GLUSTERFS_XLATOR_OPT', glusterfs.version().version_compare('>=4'))
2141 config_host_data.set('CONFIG_GLUSTERFS_DISCARD', glusterfs.version().version_compare('>=5'))
2142 config_host_data.set('CONFIG_GLUSTERFS_FALLOCATE', glusterfs.version().version_compare('>=6'))
2143 config_host_data.set('CONFIG_GLUSTERFS_ZEROFILL', glusterfs.version().version_compare('>=6'))
2144 config_host_data.set('CONFIG_GLUSTERFS_FTRUNCATE_HAS_STAT', glusterfs_ftruncate_has_stat)
2145 config_host_data.set('CONFIG_GLUSTERFS_IOCB_HAS_STAT', glusterfs_iocb_has_stat)
2146endif
1b695471 2147config_host_data.set('CONFIG_GTK', gtk.found())
c23d7b4e 2148config_host_data.set('CONFIG_VTE', vte.found())
29e0bfff 2149config_host_data.set('CONFIG_GTK_CLIPBOARD', have_gtk_clipboard)
63efb6ab 2150config_host_data.set('CONFIG_HEXAGON_IDEF_PARSER', get_option('hexagon_idef_parser'))
f7f2d651 2151config_host_data.set('CONFIG_LIBATTR', have_old_libattr)
727c8bb8 2152config_host_data.set('CONFIG_LIBCAP_NG', libcap_ng.found())
46627f41 2153config_host_data.set('CONFIG_EBPF', libbpf.found())
cb039ef3 2154config_host_data.set('CONFIG_AF_XDP', libxdp.found())
63a7f853 2155config_host_data.set('CONFIG_LIBDAXCTL', libdaxctl.found())
9db405a3 2156config_host_data.set('CONFIG_LIBISCSI', libiscsi.found())
30045c05 2157config_host_data.set('CONFIG_LIBNFS', libnfs.found())
e6a52b36 2158config_host_data.set('CONFIG_LIBSSH', libssh.found())
ff66f3e5 2159config_host_data.set('CONFIG_LINUX_AIO', libaio.found())
63a7f853
PB
2160config_host_data.set('CONFIG_LINUX_IO_URING', linux_io_uring.found())
2161config_host_data.set('CONFIG_LIBPMEM', libpmem.found())
6002711c 2162config_host_data.set('CONFIG_MODULES', enable_modules)
488a8c73 2163config_host_data.set('CONFIG_NUMA', numa.found())
6bb613f0
MP
2164if numa.found()
2165 config_host_data.set('HAVE_NUMA_HAS_PREFERRED_MANY',
2166 cc.has_function('numa_has_preferred_many',
2167 dependencies: numa))
2168endif
88b6e618 2169config_host_data.set('CONFIG_OPENGL', opengl.found())
2c13c574 2170config_host_data.set('CONFIG_PLUGIN', get_option('plugins'))
fabd1e93 2171config_host_data.set('CONFIG_RBD', rbd.found())
3730a734 2172config_host_data.set('CONFIG_RDMA', rdma.found())
655e2a77 2173config_host_data.set('CONFIG_RELOCATABLE', get_option('relocatable'))
721fa5e5 2174config_host_data.set('CONFIG_SAFESTACK', get_option('safe_stack'))
35be72ba
PB
2175config_host_data.set('CONFIG_SDL', sdl.found())
2176config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
90835c2b 2177config_host_data.set('CONFIG_SECCOMP', seccomp.found())
73422d95
MP
2178if seccomp.found()
2179 config_host_data.set('CONFIG_SECCOMP_SYSRAWRC', seccomp_has_sysrawrc)
2180endif
cca15756 2181config_host_data.set('CONFIG_PIXMAN', pixman.found())
241611ea 2182config_host_data.set('CONFIG_SNAPPY', snappy.found())
73258b38 2183config_host_data.set('CONFIG_SOLARIS', targetos == 'sunos')
875be287
PB
2184if get_option('tcg').allowed()
2185 config_host_data.set('CONFIG_TCG', 1)
2186 config_host_data.set('CONFIG_TCG_INTERPRETER', tcg_arch == 'tci')
2187endif
0d04c4c9 2188config_host_data.set('CONFIG_TPM', have_tpm)
34f983d8 2189config_host_data.set('CONFIG_TSAN', get_option('tsan'))
90540f32 2190config_host_data.set('CONFIG_USB_LIBUSB', libusb.found())
e1723999 2191config_host_data.set('CONFIG_VDE', vde.found())
c0c4f147 2192config_host_data.set('CONFIG_VHOST', have_vhost)
2df89d54
PB
2193config_host_data.set('CONFIG_VHOST_NET', have_vhost_net)
2194config_host_data.set('CONFIG_VHOST_NET_USER', have_vhost_net_user)
2195config_host_data.set('CONFIG_VHOST_NET_VDPA', have_vhost_net_vdpa)
2196config_host_data.set('CONFIG_VHOST_KERNEL', have_vhost_kernel)
2197config_host_data.set('CONFIG_VHOST_USER', have_vhost_user)
2198config_host_data.set('CONFIG_VHOST_CRYPTO', have_vhost_user_crypto)
2199config_host_data.set('CONFIG_VHOST_VDPA', have_vhost_vdpa)
e2c1d78d 2200config_host_data.set('CONFIG_VMNET', vmnet.found())
e5e856c1 2201config_host_data.set('CONFIG_VHOST_USER_BLK_SERVER', have_vhost_user_blk_server)
2a2359b8 2202config_host_data.set('CONFIG_VDUSE_BLK_EXPORT', have_vduse_blk_export)
95f8510e 2203config_host_data.set('CONFIG_PNG', png.found())
a0b93237
PB
2204config_host_data.set('CONFIG_VNC', vnc.found())
2205config_host_data.set('CONFIG_VNC_JPEG', jpeg.found())
a0b93237 2206config_host_data.set('CONFIG_VNC_SASL', sasl.found())
69202b40 2207config_host_data.set('CONFIG_VIRTFS', have_virtfs)
63a7f853 2208config_host_data.set('CONFIG_VTE', vte.found())
4113f4cf 2209config_host_data.set('CONFIG_XKBCOMMON', xkbcommon.found())
af04e89d 2210config_host_data.set('CONFIG_KEYUTILS', keyutils.found())
3909def8 2211config_host_data.set('CONFIG_GETTID', has_gettid)
57612511 2212config_host_data.set('CONFIG_GNUTLS', gnutls.found())
cc4c7c73 2213config_host_data.set('CONFIG_GNUTLS_CRYPTO', gnutls_crypto.found())
d47b83b1 2214config_host_data.set('CONFIG_TASN1', tasn1.found())
57612511
PB
2215config_host_data.set('CONFIG_GCRYPT', gcrypt.found())
2216config_host_data.set('CONFIG_NETTLE', nettle.found())
4c5e512e 2217config_host_data.set('CONFIG_HOGWEED', hogweed.found())
57612511 2218config_host_data.set('CONFIG_QEMU_PRIVATE_XTS', xts == 'private')
aa087962 2219config_host_data.set('CONFIG_MALLOC_TRIM', has_malloc_trim)
84e319a5 2220config_host_data.set('CONFIG_STATX', has_statx)
4ce7a08d 2221config_host_data.set('CONFIG_STATX_MNT_ID', has_statx_mnt_id)
b1def33d 2222config_host_data.set('CONFIG_ZSTD', zstd.found())
a484a719 2223config_host_data.set('CONFIG_FUSE', fuse.found())
df4ea709 2224config_host_data.set('CONFIG_FUSE_LSEEK', fuse_lseek.found())
3f0a5d55 2225config_host_data.set('CONFIG_SPICE_PROTOCOL', spice_protocol.found())
ddece465
MAL
2226if spice_protocol.found()
2227config_host_data.set('CONFIG_SPICE_PROTOCOL_MAJOR', spice_protocol.version().split('.')[0])
2228config_host_data.set('CONFIG_SPICE_PROTOCOL_MINOR', spice_protocol.version().split('.')[1])
2229config_host_data.set('CONFIG_SPICE_PROTOCOL_MICRO', spice_protocol.version().split('.')[2])
2230endif
3f0a5d55 2231config_host_data.set('CONFIG_SPICE', spice.found())
9d71037f 2232config_host_data.set('CONFIG_X11', x11.found())
142ca628 2233config_host_data.set('CONFIG_DBUS_DISPLAY', dbus_display)
9e62ba48 2234config_host_data.set('CONFIG_CFI', get_option('cfi'))
3d212b41 2235config_host_data.set('CONFIG_SELINUX', selinux.found())
14efd8d3 2236config_host_data.set('CONFIG_XEN_BACKEND', xen.found())
7c10cb38 2237config_host_data.set('CONFIG_LIBDW', libdw.found())
14efd8d3
PB
2238if xen.found()
2239 # protect from xen.version() having less than three components
2240 xen_version = xen.version().split('.') + ['0', '0']
2241 xen_ctrl_version = xen_version[0] + \
2242 ('0' + xen_version[1]).substring(-2) + \
2243 ('0' + xen_version[2]).substring(-2)
2244 config_host_data.set('CONFIG_XEN_CTRL_INTERFACE_VERSION', xen_ctrl_version)
2245endif
859aef02
PB
2246config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
2247config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
2248config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
2249config_host_data.set('QEMU_VERSION_MICRO', meson.project_version().split('.')[2])
2250
a6305081 2251config_host_data.set_quoted('CONFIG_HOST_DSOSUF', host_dsosuf)
69d8de7a
PB
2252config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device)
2253
728c0a2f
PB
2254have_coroutine_pool = get_option('coroutine_pool')
2255if get_option('debug_stack_usage') and have_coroutine_pool
2256 message('Disabling coroutine pool to measure stack usage')
2257 have_coroutine_pool = false
2258endif
230f6e06 2259config_host_data.set('CONFIG_COROUTINE_POOL', have_coroutine_pool)
58a2e3f5 2260config_host_data.set('CONFIG_DEBUG_GRAPH_LOCK', get_option('debug_graph_lock'))
c55cf6ab 2261config_host_data.set('CONFIG_DEBUG_MUTEX', get_option('debug_mutex'))
728c0a2f 2262config_host_data.set('CONFIG_DEBUG_STACK_USAGE', get_option('debug_stack_usage'))
1d558c90 2263config_host_data.set('CONFIG_DEBUG_TCG', get_option('debug_tcg'))
406523f6 2264config_host_data.set('CONFIG_LIVE_BLOCK_MIGRATION', get_option('live_block_migration').allowed())
c55cf6ab 2265config_host_data.set('CONFIG_QOM_CAST_DEBUG', get_option('qom_cast_debug'))
abad185c 2266config_host_data.set('CONFIG_REPLICATION', get_option('replication').allowed())
406523f6 2267
69d8de7a 2268# has_header
e66420ac 2269config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h'))
d47a8b3b
PB
2270config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h'))
2271config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind.h'))
48f670ec 2272config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h'))
2964be52 2273config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h'))
2802d91d 2274config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h'))
69d8de7a 2275config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h'))
ded5d78c 2276config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h'))
4a9d5f89 2277config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h'))
d409373b
BM
2278if targetos == 'windows'
2279 config_host_data.set('HAVE_AFUNIX_H', cc.has_header('afunix.h'))
2280endif
ded5d78c 2281
69d8de7a 2282# has_function
c891c24b 2283config_host_data.set('CONFIG_CLOSE_RANGE', cc.has_function('close_range'))
a620fbe9 2284config_host_data.set('CONFIG_ACCEPT4', cc.has_function('accept4'))
e66420ac
PB
2285config_host_data.set('CONFIG_CLOCK_ADJTIME', cc.has_function('clock_adjtime'))
2286config_host_data.set('CONFIG_DUP3', cc.has_function('dup3'))
2287config_host_data.set('CONFIG_FALLOCATE', cc.has_function('fallocate'))
2288config_host_data.set('CONFIG_POSIX_FALLOCATE', cc.has_function('posix_fallocate'))
6750485b
PB
2289config_host_data.set('CONFIG_GETCPU', cc.has_function('getcpu', prefix: gnu_source_prefix))
2290config_host_data.set('CONFIG_SCHED_GETCPU', cc.has_function('sched_getcpu', prefix: '#include <sched.h>'))
8698343b
PM
2291# Note that we need to specify prefix: here to avoid incorrectly
2292# thinking that Windows has posix_memalign()
2293config_host_data.set('CONFIG_POSIX_MEMALIGN', cc.has_function('posix_memalign', prefix: '#include <stdlib.h>'))
5c8c714a 2294config_host_data.set('CONFIG_ALIGNED_MALLOC', cc.has_function('_aligned_malloc'))
88454f84
PM
2295config_host_data.set('CONFIG_VALLOC', cc.has_function('valloc'))
2296config_host_data.set('CONFIG_MEMALIGN', cc.has_function('memalign'))
e66420ac 2297config_host_data.set('CONFIG_PPOLL', cc.has_function('ppoll'))
2b9f74ef 2298config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include <sys/uio.h>'))
029ed1bd 2299config_host_data.set('CONFIG_PTHREAD_FCHDIR_NP', cc.has_function('pthread_fchdir_np'))
e66420ac
PB
2300config_host_data.set('CONFIG_SENDFILE', cc.has_function('sendfile'))
2301config_host_data.set('CONFIG_SETNS', cc.has_function('setns') and cc.has_function('unshare'))
2302config_host_data.set('CONFIG_SYNCFS', cc.has_function('syncfs'))
2303config_host_data.set('CONFIG_SYNC_FILE_RANGE', cc.has_function('sync_file_range'))
2304config_host_data.set('CONFIG_TIMERFD', cc.has_function('timerfd_create'))
be7e89f6 2305config_host_data.set('HAVE_COPY_FILE_RANGE', cc.has_function('copy_file_range'))
59e35c7b 2306config_host_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs'))
fc9a809e 2307config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice)
e66420ac 2308config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies: util))
ed3b3f17 2309config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul'))
69d8de7a 2310config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>'))
dc864d3a 2311config_host_data.set('HAVE_GETLOADAVG_FUNCTION', cc.has_function('getloadavg', prefix: '#include <stdlib.h>'))
66dc5f96
SG
2312if rbd.found()
2313 config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS',
2314 cc.has_function('rbd_namespace_exists',
2315 dependencies: rbd,
2316 prefix: '#include <rbd/librbd.h>'))
2317endif
911965ac
LZ
2318if rdma.found()
2319 config_host_data.set('HAVE_IBV_ADVISE_MR',
2320 cc.has_function('ibv_advise_mr',
3730a734 2321 dependencies: rdma,
911965ac
LZ
2322 prefix: '#include <infiniband/verbs.h>'))
2323endif
2b9f74ef 2324
34f983d8
PB
2325have_asan_fiber = false
2326if get_option('sanitizers') and \
2327 not cc.has_function('__sanitizer_start_switch_fiber',
2328 args: '-fsanitize=address',
2329 prefix: '#include <sanitizer/asan_interface.h>')
2330 warning('Missing ASAN due to missing fiber annotation interface')
2331 warning('Without code annotation, the report may be inferior.')
2332else
2333 have_asan_fiber = true
2334endif
2335config_host_data.set('CONFIG_ASAN_IFACE_FIBER', have_asan_fiber)
2336
e66420ac 2337# has_header_symbol
6d43eaa3
SL
2338config_host_data.set('CONFIG_BLKZONED',
2339 cc.has_header_symbol('linux/blkzoned.h', 'BLKOPENZONE'))
e66420ac
PB
2340config_host_data.set('CONFIG_EPOLL_CREATE1',
2341 cc.has_header_symbol('sys/epoll.h', 'epoll_create1'))
2342config_host_data.set('CONFIG_FALLOCATE_PUNCH_HOLE',
2343 cc.has_header_symbol('linux/falloc.h', 'FALLOC_FL_PUNCH_HOLE') and
2344 cc.has_header_symbol('linux/falloc.h', 'FALLOC_FL_KEEP_SIZE'))
2345config_host_data.set('CONFIG_FALLOCATE_ZERO_RANGE',
2346 cc.has_header_symbol('linux/falloc.h', 'FALLOC_FL_ZERO_RANGE'))
2347config_host_data.set('CONFIG_FIEMAP',
2348 cc.has_header('linux/fiemap.h') and
2349 cc.has_header_symbol('linux/fs.h', 'FS_IOC_FIEMAP'))
be7e89f6
PB
2350config_host_data.set('CONFIG_GETRANDOM',
2351 cc.has_function('getrandom') and
2352 cc.has_header_symbol('sys/random.h', 'GRND_NONBLOCK'))
a620fbe9
PB
2353config_host_data.set('CONFIG_INOTIFY',
2354 cc.has_header_symbol('sys/inotify.h', 'inotify_init'))
2355config_host_data.set('CONFIG_INOTIFY1',
2356 cc.has_header_symbol('sys/inotify.h', 'inotify_init1'))
e66420ac
PB
2357config_host_data.set('CONFIG_PRCTL_PR_SET_TIMERSLACK',
2358 cc.has_header_symbol('sys/prctl.h', 'PR_SET_TIMERSLACK'))
be7e89f6
PB
2359config_host_data.set('CONFIG_RTNETLINK',
2360 cc.has_header_symbol('linux/rtnetlink.h', 'IFLA_PROTO_DOWN'))
2361config_host_data.set('CONFIG_SYSMACROS',
2362 cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
e1fbd2c4
PB
2363config_host_data.set('HAVE_OPTRESET',
2364 cc.has_header_symbol('getopt.h', 'optreset'))
653163fc
MAL
2365config_host_data.set('HAVE_IPPROTO_MPTCP',
2366 cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP'))
e66420ac
PB
2367
2368# has_member
2369config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID',
2370 cc.has_member('struct sigevent', 'sigev_notify_thread_id',
2371 prefix: '#include <signal.h>'))
ed3b3f17
PB
2372config_host_data.set('HAVE_STRUCT_STAT_ST_ATIM',
2373 cc.has_member('struct stat', 'st_atim',
2374 prefix: '#include <sys/stat.h>'))
6d43eaa3
SL
2375config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY',
2376 cc.has_member('struct blk_zone', 'capacity',
2377 prefix: '#include <linux/blkzoned.h>'))
e66420ac 2378
6a23f819
PB
2379# has_type
2380config_host_data.set('CONFIG_IOVEC',
2381 cc.has_type('struct iovec',
2382 prefix: '#include <sys/uio.h>'))
2383config_host_data.set('HAVE_UTMPX',
2384 cc.has_type('struct utmpx',
2385 prefix: '#include <utmpx.h>'))
2386
904ad5ec 2387config_host_data.set('CONFIG_EVENTFD', cc.links('''
e1fbd2c4
PB
2388 #include <sys/eventfd.h>
2389 int main(void) { return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); }'''))
904ad5ec 2390config_host_data.set('CONFIG_FDATASYNC', cc.links(gnu_source_prefix + '''
e1fbd2c4
PB
2391 #include <unistd.h>
2392 int main(void) {
2393 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
2394 return fdatasync(0);
2395 #else
2396 #error Not supported
2397 #endif
2398 }'''))
8900c204
AD
2399
2400has_madvise = cc.links(gnu_source_prefix + '''
e1fbd2c4
PB
2401 #include <sys/types.h>
2402 #include <sys/mman.h>
2403 #include <stddef.h>
8900c204
AD
2404 int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }''')
2405missing_madvise_proto = false
2406if has_madvise
2407 # Some platforms (illumos and Solaris before Solaris 11) provide madvise()
2408 # but forget to prototype it. In this case, has_madvise will be true (the
2409 # test program links despite a compile warning). To detect the
2410 # missing-prototype case, we try again with a definitely-bogus prototype.
2411 # This will only compile if the system headers don't provide the prototype;
2412 # otherwise the conflicting prototypes will cause a compiler error.
2413 missing_madvise_proto = cc.links(gnu_source_prefix + '''
2414 #include <sys/types.h>
2415 #include <sys/mman.h>
2416 #include <stddef.h>
2417 extern int madvise(int);
2418 int main(void) { return madvise(0); }''')
2419endif
2420config_host_data.set('CONFIG_MADVISE', has_madvise)
2421config_host_data.set('HAVE_MADVISE_WITHOUT_PROTOTYPE', missing_madvise_proto)
2422
904ad5ec 2423config_host_data.set('CONFIG_MEMFD', cc.links(gnu_source_prefix + '''
e1fbd2c4
PB
2424 #include <sys/mman.h>
2425 int main(void) { return memfd_create("foo", MFD_ALLOW_SEALING); }'''))
904ad5ec 2426config_host_data.set('CONFIG_OPEN_BY_HANDLE', cc.links(gnu_source_prefix + '''
d47a8b3b
PB
2427 #include <fcntl.h>
2428 #if !defined(AT_EMPTY_PATH)
2429 # error missing definition
2430 #else
2431 int main(void) { struct file_handle fh; return open_by_handle_at(0, &fh, 0); }
2432 #endif'''))
904ad5ec 2433config_host_data.set('CONFIG_POSIX_MADVISE', cc.links(gnu_source_prefix + '''
e1fbd2c4
PB
2434 #include <sys/mman.h>
2435 #include <stddef.h>
2436 int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }'''))
10f6b231 2437
6a23f819 2438config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links(gnu_source_prefix + '''
10f6b231
PB
2439 #include <pthread.h>
2440
2441 static void *f(void *p) { return NULL; }
2442 int main(void)
2443 {
2444 pthread_t thread;
2445 pthread_create(&thread, 0, f, 0);
2446 pthread_setname_np(thread, "QEMU");
2447 return 0;
2448 }''', dependencies: threads))
6a23f819 2449config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links(gnu_source_prefix + '''
10f6b231
PB
2450 #include <pthread.h>
2451
2452 static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
2453 int main(void)
2454 {
2455 pthread_t thread;
2456 pthread_create(&thread, 0, f, 0);
2457 return 0;
2458 }''', dependencies: threads))
3ada67a3
BS
2459config_host_data.set('CONFIG_PTHREAD_SET_NAME_NP', cc.links(gnu_source_prefix + '''
2460 #include <pthread.h>
2461 #include <pthread_np.h>
2462
2463 static void *f(void *p) { return NULL; }
2464 int main(void)
2465 {
2466 pthread_t thread;
2467 pthread_create(&thread, 0, f, 0);
2468 pthread_set_name_np(thread, "QEMU");
2469 return 0;
2470 }''', dependencies: threads))
657ac98b
LM
2471config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(gnu_source_prefix + '''
2472 #include <pthread.h>
2473 #include <time.h>
2474
2475 int main(void)
2476 {
2477 pthread_condattr_t attr
2478 pthread_condattr_init(&attr);
2479 pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
2480 return 0;
2481 }''', dependencies: threads))
7730f32c
DH
2482config_host_data.set('CONFIG_PTHREAD_AFFINITY_NP', cc.links(gnu_source_prefix + '''
2483 #include <pthread.h>
10f6b231 2484
7730f32c
DH
2485 static void *f(void *p) { return NULL; }
2486 int main(void)
2487 {
2488 int setsize = CPU_ALLOC_SIZE(64);
2489 pthread_t thread;
2490 cpu_set_t *cpuset;
2491 pthread_create(&thread, 0, f, 0);
2492 cpuset = CPU_ALLOC(64);
2493 CPU_ZERO_S(setsize, cpuset);
2494 pthread_setaffinity_np(thread, setsize, cpuset);
2495 pthread_getaffinity_np(thread, setsize, cpuset);
2496 CPU_FREE(cpuset);
2497 return 0;
2498 }''', dependencies: threads))
904ad5ec 2499config_host_data.set('CONFIG_SIGNALFD', cc.links(gnu_source_prefix + '''
6bd17dcc
KS
2500 #include <sys/signalfd.h>
2501 #include <stddef.h>
2502 int main(void) { return signalfd(-1, NULL, SFD_CLOEXEC); }'''))
904ad5ec 2503config_host_data.set('CONFIG_SPLICE', cc.links(gnu_source_prefix + '''
a620fbe9
PB
2504 #include <unistd.h>
2505 #include <fcntl.h>
2506 #include <limits.h>
2507
2508 int main(void)
2509 {
2510 int len, fd = 0;
2511 len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK);
2512 splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE);
2513 return 0;
2514 }'''))
e1fbd2c4 2515
96a63aeb
PB
2516config_host_data.set('HAVE_MLOCKALL', cc.links(gnu_source_prefix + '''
2517 #include <sys/mman.h>
b5d3dac1 2518 int main(void) {
96a63aeb
PB
2519 return mlockall(MCL_FUTURE);
2520 }'''))
2521
eea9453a 2522have_l2tpv3 = false
43a363ae 2523if get_option('l2tpv3').allowed() and have_system
6a23f819
PB
2524 have_l2tpv3 = cc.has_type('struct mmsghdr',
2525 prefix: gnu_source_prefix + '''
2526 #include <sys/socket.h>
2527 #include <linux/ip.h>''')
eea9453a
TH
2528endif
2529config_host_data.set('CONFIG_L2TPV3', have_l2tpv3)
2530
837b84b1 2531have_netmap = false
43a363ae 2532if get_option('netmap').allowed() and have_system
837b84b1
PB
2533 have_netmap = cc.compiles('''
2534 #include <inttypes.h>
2535 #include <net/if.h>
2536 #include <net/netmap.h>
2537 #include <net/netmap_user.h>
2538 #if (NETMAP_API < 11) || (NETMAP_API > 15)
2539 #error
2540 #endif
2541 int main(void) { return 0; }''')
2542 if not have_netmap and get_option('netmap').enabled()
2543 error('Netmap headers not available')
2544 endif
2545endif
2546config_host_data.set('CONFIG_NETMAP', have_netmap)
2547
96a63aeb
PB
2548# Work around a system header bug with some kernel/XFS header
2549# versions where they both try to define 'struct fsxattr':
2550# xfs headers will not try to redefine structs from linux headers
2551# if this macro is set.
2552config_host_data.set('HAVE_FSXATTR', cc.links('''
6a23f819 2553 #include <linux/fs.h>
96a63aeb
PB
2554 struct fsxattr foo;
2555 int main(void) {
2556 return 0;
2557 }'''))
2558
e46bd55d
PB
2559# Some versions of Mac OS X incorrectly define SIZE_MAX
2560config_host_data.set('HAVE_BROKEN_SIZE_MAX', not cc.compiles('''
2561 #include <stdint.h>
2562 #include <stdio.h>
b5d3dac1 2563 int main(void) {
e46bd55d
PB
2564 return printf("%zu", SIZE_MAX);
2565 }''', args: ['-Werror']))
2566
e61f1efe
RH
2567# See if 64-bit atomic operations are supported.
2568# Note that without __atomic builtins, we can only
2569# assume atomic loads/stores max at pointer size.
2570config_host_data.set('CONFIG_ATOMIC64', cc.links('''
bd87a367
PB
2571 #include <stdint.h>
2572 int main(void)
2573 {
e61f1efe 2574 uint64_t x = 0, y = 0;
bd87a367
PB
2575 y = __atomic_load_n(&x, __ATOMIC_RELAXED);
2576 __atomic_store_n(&x, y, __ATOMIC_RELAXED);
2577 __atomic_compare_exchange_n(&x, &y, x, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
2578 __atomic_exchange_n(&x, y, __ATOMIC_RELAXED);
2579 __atomic_fetch_add(&x, y, __ATOMIC_RELAXED);
2580 return 0;
e61f1efe 2581 }'''))
bd87a367 2582
6479dd74
RH
2583has_int128_type = cc.compiles('''
2584 __int128_t a;
2585 __uint128_t b;
2586 int main(void) { b = a; }''')
2587config_host_data.set('CONFIG_INT128_TYPE', has_int128_type)
2588
2589has_int128 = has_int128_type and cc.links('''
848126d1
MAL
2590 __int128_t a;
2591 __uint128_t b;
2592 int main (void) {
2593 a = a + b;
2594 b = a * b;
2595 a = a * a;
2596 return 0;
2597 }''')
848126d1
MAL
2598config_host_data.set('CONFIG_INT128', has_int128)
2599
6479dd74 2600if has_int128_type
d2958fb0
MAL
2601 # "do we have 128-bit atomics which are handled inline and specifically not
2602 # via libatomic". The reason we can't use libatomic is documented in the
2603 # comment starting "GCC is a house divided" in include/qemu/atomic128.h.
e61f1efe
RH
2604 # We only care about these operations on 16-byte aligned pointers, so
2605 # force 16-byte alignment of the pointer, which may be greater than
2606 # __alignof(unsigned __int128) for the host.
2607 atomic_test_128 = '''
2608 int main(int ac, char **av) {
6479dd74 2609 __uint128_t *p = __builtin_assume_aligned(av[ac - 1], 16);
e61f1efe
RH
2610 p[1] = __atomic_load_n(&p[0], __ATOMIC_RELAXED);
2611 __atomic_store_n(&p[2], p[3], __ATOMIC_RELAXED);
2612 __atomic_compare_exchange_n(&p[4], &p[5], p[6], 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
2613 return 0;
2614 }'''
2615 has_atomic128 = cc.links(atomic_test_128)
848126d1
MAL
2616
2617 config_host_data.set('CONFIG_ATOMIC128', has_atomic128)
2618
2619 if not has_atomic128
e61f1efe
RH
2620 # Even with __builtin_assume_aligned, the above test may have failed
2621 # without optimization enabled. Try again with optimizations locally
2622 # enabled for the function. See
2623 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107389
2624 has_atomic128_opt = cc.links('__attribute__((optimize("O1")))' + atomic_test_128)
2625 config_host_data.set('CONFIG_ATOMIC128_OPT', has_atomic128_opt)
2626
2627 if not has_atomic128_opt
2628 config_host_data.set('CONFIG_CMPXCHG128', cc.links('''
2629 int main(void)
2630 {
6479dd74 2631 __uint128_t x = 0, y = 0;
e61f1efe
RH
2632 __sync_val_compare_and_swap_16(&x, y, x);
2633 return 0;
2634 }
2635 '''))
2636 endif
848126d1
MAL
2637 endif
2638endif
bd87a367
PB
2639
2640config_host_data.set('CONFIG_GETAUXVAL', cc.links(gnu_source_prefix + '''
2641 #include <sys/auxv.h>
2642 int main(void) {
2643 return getauxval(AT_HWCAP) == 0;
2644 }'''))
2645
0dae95d4
PB
2646config_host_data.set('CONFIG_USBFS', have_linux_user and cc.compiles('''
2647 #include <linux/usbdevice_fs.h>
2648
2649 #ifndef USBDEVFS_GET_CAPABILITIES
2650 #error "USBDEVFS_GET_CAPABILITIES undefined"
2651 #endif
2652
2653 #ifndef USBDEVFS_DISCONNECT_CLAIM
2654 #error "USBDEVFS_DISCONNECT_CLAIM undefined"
2655 #endif
2656
2657 int main(void) { return 0; }'''))
2658
2edd2c04
PB
2659have_keyring = get_option('keyring') \
2660 .require(targetos == 'linux', error_message: 'keyring is only available on Linux') \
2661 .require(cc.compiles('''
2662 #include <errno.h>
2663 #include <asm/unistd.h>
2664 #include <linux/keyctl.h>
2665 #include <sys/syscall.h>
2666 #include <unistd.h>
2667 int main(void) {
2668 return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
2669 }'''), error_message: 'keyctl syscall not available on this system').allowed()
2670config_host_data.set('CONFIG_SECRET_KEYRING', have_keyring)
2671
622753d2
PB
2672have_cpuid_h = cc.links('''
2673 #include <cpuid.h>
2674 int main(void) {
2675 unsigned a, b, c, d;
2676 unsigned max = __get_cpuid_max(0, 0);
2677
2678 if (max >= 1) {
2679 __cpuid(1, a, b, c, d);
2680 }
2681
2682 if (max >= 7) {
2683 __cpuid_count(7, 0, a, b, c, d);
2684 }
2685
2686 return 0;
2687 }''')
2688config_host_data.set('CONFIG_CPUID_H', have_cpuid_h)
2689
2690config_host_data.set('CONFIG_AVX2_OPT', get_option('avx2') \
2691 .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX2') \
2692 .require(cc.links('''
622753d2
PB
2693 #include <cpuid.h>
2694 #include <immintrin.h>
701ea587 2695 static int __attribute__((target("avx2"))) bar(void *a) {
622753d2
PB
2696 __m256i x = *(__m256i *)a;
2697 return _mm256_testz_si256(x, x);
2698 }
b5d3dac1 2699 int main(int argc, char *argv[]) { return bar(argv[argc - 1]); }
622753d2
PB
2700 '''), error_message: 'AVX2 not available').allowed())
2701
2702config_host_data.set('CONFIG_AVX512F_OPT', get_option('avx512f') \
2703 .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX512F') \
2704 .require(cc.links('''
622753d2
PB
2705 #include <cpuid.h>
2706 #include <immintrin.h>
701ea587 2707 static int __attribute__((target("avx512f"))) bar(void *a) {
622753d2
PB
2708 __m512i x = *(__m512i *)a;
2709 return _mm512_test_epi64_mask(x, x);
2710 }
b5d3dac1 2711 int main(int argc, char *argv[]) { return bar(argv[argc - 1]); }
622753d2
PB
2712 '''), error_message: 'AVX512F not available').allowed())
2713
04ffce13 2714config_host_data.set('CONFIG_AVX512BW_OPT', get_option('avx512bw') \
2715 .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX512BW') \
2716 .require(cc.links('''
04ffce13 2717 #include <cpuid.h>
2718 #include <immintrin.h>
dc165fcd 2719 static int __attribute__((target("avx512bw"))) bar(void *a) {
04ffce13 2720 __m512i *x = a;
2721 __m512i res= _mm512_abs_epi8(*x);
2722 return res[1];
2723 }
2724 int main(int argc, char *argv[]) { return bar(argv[0]); }
2725 '''), error_message: 'AVX512BW not available').allowed())
2726
8d97f28e
RH
2727# For both AArch64 and AArch32, detect if builtins are available.
2728config_host_data.set('CONFIG_ARM_AES_BUILTIN', cc.compiles('''
2729 #include <arm_neon.h>
2730 #ifndef __ARM_FEATURE_AES
2731 __attribute__((target("+crypto")))
2732 #endif
2733 void foo(uint8x16_t *p) { *p = vaesmcq_u8(*p); }
2734 '''))
2735
3730a734
PB
2736have_pvrdma = get_option('pvrdma') \
2737 .require(rdma.found(), error_message: 'PVRDMA requires OpenFabrics libraries') \
354d2d9b
JQ
2738 .require(cc.compiles(gnu_source_prefix + '''
2739 #include <sys/mman.h>
3730a734
PB
2740 int main(void)
2741 {
2742 char buf = 0;
2743 void *addr = &buf;
2744 addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
2745
2746 return 0;
2747 }'''), error_message: 'PVRDMA requires mremap').allowed()
2748
2749if have_pvrdma
354d2d9b 2750 config_host_data.set('LEGACY_RDMA_REG_MR', not cc.links('''
3730a734
PB
2751 #include <infiniband/verbs.h>
2752 int main(void)
2753 {
2754 struct ibv_mr *mr;
2755 struct ibv_pd *pd = NULL;
2756 size_t length = 10;
2757 uint64_t iova = 0;
2758 int access = 0;
2759 void *addr = NULL;
2760
2761 mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2762 ibv_dereg_mr(mr);
2763 return 0;
2764 }'''))
2765endif
2766
b87df904
PB
2767if get_option('membarrier').disabled()
2768 have_membarrier = false
2769elif targetos == 'windows'
2770 have_membarrier = true
2771elif targetos == 'linux'
2772 have_membarrier = cc.compiles('''
2773 #include <linux/membarrier.h>
2774 #include <sys/syscall.h>
2775 #include <unistd.h>
2776 #include <stdlib.h>
2777 int main(void) {
2778 syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
2779 syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0);
2780 exit(0);
2781 }''')
2782endif
2783config_host_data.set('CONFIG_MEMBARRIER', get_option('membarrier') \
2784 .require(have_membarrier, error_message: 'membarrier system call not available') \
2785 .allowed())
2786
34b52615
PB
2787have_afalg = get_option('crypto_afalg') \
2788 .require(cc.compiles(gnu_source_prefix + '''
2789 #include <errno.h>
2790 #include <sys/types.h>
2791 #include <sys/socket.h>
2792 #include <linux/if_alg.h>
2793 int main(void) {
2794 int sock;
2795 sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
2796 return sock;
2797 }
2798 '''), error_message: 'AF_ALG requested but could not be detected').allowed()
2799config_host_data.set('CONFIG_AF_ALG', have_afalg)
2800
9d734b85
MAL
2801config_host_data.set('CONFIG_AF_VSOCK', cc.has_header_symbol(
2802 'linux/vm_sockets.h', 'AF_VSOCK',
2803 prefix: '#include <sys/socket.h>',
2804))
bd87a367 2805
8821a389 2806have_vss = false
872b69e6 2807have_vss_sdk = false # old xp/2003 SDK
785abf0d 2808if targetos == 'windows' and 'cpp' in all_languages
8821a389
MAL
2809 have_vss = cxx.compiles('''
2810 #define __MIDL_user_allocate_free_DEFINED__
32478cb6 2811 #include <vss.h>
8821a389 2812 int main(void) { return VSS_CTX_BACKUP; }''')
872b69e6 2813 have_vss_sdk = cxx.has_header('vscoordint.h')
8821a389 2814endif
872b69e6 2815config_host_data.set('HAVE_VSS_SDK', have_vss_sdk)
8821a389 2816
6391c772
RH
2817# Older versions of MinGW do not import _lock_file and _unlock_file properly.
2818# This was fixed for v6.0.0 with commit b48e3ac8969d.
2819if targetos == 'windows'
2820 config_host_data.set('HAVE__LOCK_FILE', cc.links('''
2821 #include <stdio.h>
2822 int main(void) {
2823 _lock_file(NULL);
2824 _unlock_file(NULL);
2825 return 0;
2826 }''', name: '_lock_file and _unlock_file'))
2827endif
2828
dbd672c8
PB
2829if targetos == 'windows'
2830 mingw_has_setjmp_longjmp = cc.links('''
2831 #include <setjmp.h>
2832 int main(void) {
2833 /*
2834 * These functions are not available in setjmp header, but may be
2835 * available at link time, from libmingwex.a.
2836 */
2837 extern int __mingw_setjmp(jmp_buf);
2838 extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
2839 jmp_buf env;
2840 __mingw_setjmp(env);
2841 __mingw_longjmp(env, 0);
2842 }
2843 ''', name: 'mingw setjmp and longjmp')
2844
2845 if cpu == 'aarch64' and not mingw_has_setjmp_longjmp
2846 error('mingw must provide setjmp/longjmp for windows-arm64')
2847 endif
2848endif
2849
a0c9162c
PB
2850########################
2851# Target configuration #
2852########################
2853
2becc36a 2854minikconf = find_program('scripts/minikconf.py')
1f2146f7
PB
2855config_targetos = {
2856 (targetos == 'windows' ? 'CONFIG_WIN32' : 'CONFIG_POSIX'): 'y'
2857}
2858if targetos == 'darwin'
2859 config_targetos += {'CONFIG_DARWIN': 'y'}
2860elif targetos == 'linux'
2861 config_targetos += {'CONFIG_LINUX': 'y'}
2862endif
2863if targetos in bsd_oses
2864 config_targetos += {'CONFIG_BSD': 'y'}
2865endif
2866
05512f55 2867config_all = {}
a98006bc 2868config_all_devices = {}
ca0fc784 2869config_all_disas = {}
2becc36a
PB
2870config_devices_mak_list = []
2871config_devices_h = {}
859aef02 2872config_target_h = {}
2becc36a 2873config_target_mak = {}
ca0fc784
PB
2874
2875disassemblers = {
2876 'alpha' : ['CONFIG_ALPHA_DIS'],
ca0fc784
PB
2877 'avr' : ['CONFIG_AVR_DIS'],
2878 'cris' : ['CONFIG_CRIS_DIS'],
3e7a84ee 2879 'hexagon' : ['CONFIG_HEXAGON_DIS'],
ca0fc784
PB
2880 'hppa' : ['CONFIG_HPPA_DIS'],
2881 'i386' : ['CONFIG_I386_DIS'],
2882 'x86_64' : ['CONFIG_I386_DIS'],
ca0fc784
PB
2883 'm68k' : ['CONFIG_M68K_DIS'],
2884 'microblaze' : ['CONFIG_MICROBLAZE_DIS'],
2885 'mips' : ['CONFIG_MIPS_DIS'],
ca0fc784
PB
2886 'nios2' : ['CONFIG_NIOS2_DIS'],
2887 'or1k' : ['CONFIG_OPENRISC_DIS'],
2888 'ppc' : ['CONFIG_PPC_DIS'],
2889 'riscv' : ['CONFIG_RISCV_DIS'],
2890 'rx' : ['CONFIG_RX_DIS'],
2891 's390' : ['CONFIG_S390_DIS'],
2892 'sh4' : ['CONFIG_SH4_DIS'],
2893 'sparc' : ['CONFIG_SPARC_DIS'],
2894 'xtensa' : ['CONFIG_XTENSA_DIS'],
aae1746c 2895 'loongarch' : ['CONFIG_LOONGARCH_DIS'],
ca0fc784 2896}
ca0fc784 2897
e1fbd2c4 2898have_ivshmem = config_host_data.get('CONFIG_EVENTFD')
0a189110 2899host_kconfig = \
537b7248 2900 (get_option('fuzzing') ? ['CONFIG_FUZZ=y'] : []) + \
0d04c4c9 2901 (have_tpm ? ['CONFIG_TPM=y'] : []) + \
cca15756 2902 (pixman.found() ? ['CONFIG_PIXMAN=y'] : []) + \
3f0a5d55 2903 (spice.found() ? ['CONFIG_SPICE=y'] : []) + \
ccd250aa 2904 (have_ivshmem ? ['CONFIG_IVSHMEM=y'] : []) + \
88b6e618 2905 (opengl.found() ? ['CONFIG_OPENGL=y'] : []) + \
9d71037f 2906 (x11.found() ? ['CONFIG_X11=y'] : []) + \
2a3129a3
PB
2907 (have_vhost_user ? ['CONFIG_VHOST_USER=y'] : []) + \
2908 (have_vhost_vdpa ? ['CONFIG_VHOST_VDPA=y'] : []) + \
2909 (have_vhost_kernel ? ['CONFIG_VHOST_KERNEL=y'] : []) + \
69202b40 2910 (have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \
1f2146f7 2911 (targetos == 'linux' ? ['CONFIG_LINUX=y'] : []) + \
3730a734 2912 (have_pvrdma ? ['CONFIG_PVRDMA=y'] : []) + \
55116968 2913 (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + \
0d9e8c0b
MS
2914 (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=y'] : []) + \
2915 (hv_balloon ? ['CONFIG_HV_BALLOON_POSSIBLE=y'] : [])
0a189110 2916
a9a74907 2917ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ]
05512f55 2918
fdb75aef
PB
2919default_targets = 'CONFIG_DEFAULT_TARGETS' in config_host
2920actual_target_dirs = []
fbb4121d 2921fdt_required = []
a81df1b6 2922foreach target : target_dirs
765686d6
PB
2923 config_target = { 'TARGET_NAME': target.split('-')[0] }
2924 if target.endswith('linux-user')
fdb75aef
PB
2925 if targetos != 'linux'
2926 if default_targets
2927 continue
2928 endif
2929 error('Target @0@ is only available on a Linux host'.format(target))
2930 endif
765686d6
PB
2931 config_target += { 'CONFIG_LINUX_USER': 'y' }
2932 elif target.endswith('bsd-user')
1f2146f7 2933 if targetos not in bsd_oses
fdb75aef
PB
2934 if default_targets
2935 continue
2936 endif
2937 error('Target @0@ is only available on a BSD host'.format(target))
2938 endif
765686d6
PB
2939 config_target += { 'CONFIG_BSD_USER': 'y' }
2940 elif target.endswith('softmmu')
bd0c03b2 2941 config_target += { 'CONFIG_SYSTEM_ONLY': 'y' }
765686d6
PB
2942 config_target += { 'CONFIG_SOFTMMU': 'y' }
2943 endif
2944 if target.endswith('-user')
2945 config_target += {
2946 'CONFIG_USER_ONLY': 'y',
2947 'CONFIG_QEMU_INTERP_PREFIX':
ce6119dc 2948 get_option('interp_prefix').replace('%M', config_target['TARGET_NAME'])
765686d6
PB
2949 }
2950 endif
859aef02 2951
0a189110 2952 accel_kconfig = []
8a19980e
PB
2953 foreach sym: accelerators
2954 if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, [])
2955 config_target += { sym: 'y' }
2956 config_all += { sym: 'y' }
dae0ec15
GH
2957 if target in modular_tcg
2958 config_target += { 'CONFIG_TCG_MODULAR': 'y' }
2959 else
2960 config_target += { 'CONFIG_TCG_BUILTIN': 'y' }
2961 endif
0a189110 2962 accel_kconfig += [ sym + '=y' ]
8a19980e
PB
2963 endif
2964 endforeach
0a189110 2965 if accel_kconfig.length() == 0
fdb75aef
PB
2966 if default_targets
2967 continue
2968 endif
2969 error('No accelerator available for target @0@'.format(target))
2970 endif
8a19980e 2971
fdb75aef 2972 actual_target_dirs += target
812b31d3 2973 config_target += keyval.load('configs/targets' / target + '.mak')
a9a74907 2974 config_target += { 'TARGET_' + config_target['TARGET_ARCH'].to_upper(): 'y' }
765686d6 2975
fbb4121d
PB
2976 if 'TARGET_NEED_FDT' in config_target
2977 fdt_required += target
2978 endif
2979
fa73168b
PB
2980 # Add default keys
2981 if 'TARGET_BASE_ARCH' not in config_target
2982 config_target += {'TARGET_BASE_ARCH': config_target['TARGET_ARCH']}
2983 endif
2984 if 'TARGET_ABI_DIR' not in config_target
2985 config_target += {'TARGET_ABI_DIR': config_target['TARGET_ARCH']}
2986 endif
ee3eb3a7
MAL
2987 if 'TARGET_BIG_ENDIAN' not in config_target
2988 config_target += {'TARGET_BIG_ENDIAN': 'n'}
2989 endif
859aef02 2990
ca0fc784 2991 foreach k, v: disassemblers
823eb013 2992 if host_arch.startswith(k) or config_target['TARGET_BASE_ARCH'].startswith(k)
ca0fc784
PB
2993 foreach sym: v
2994 config_target += { sym: 'y' }
2995 config_all_disas += { sym: 'y' }
2996 endforeach
2997 endif
2998 endforeach
2999
859aef02
PB
3000 config_target_data = configuration_data()
3001 foreach k, v: config_target
3002 if not k.startswith('TARGET_') and not k.startswith('CONFIG_')
3003 # do nothing
3004 elif ignored.contains(k)
3005 # do nothing
3006 elif k == 'TARGET_BASE_ARCH'
a9a74907
PB
3007 # Note that TARGET_BASE_ARCH ends up in config-target.h but it is
3008 # not used to select files from sourcesets.
859aef02 3009 config_target_data.set('TARGET_' + v.to_upper(), 1)
765686d6 3010 elif k == 'TARGET_NAME' or k == 'CONFIG_QEMU_INTERP_PREFIX'
859aef02
PB
3011 config_target_data.set_quoted(k, v)
3012 elif v == 'y'
3013 config_target_data.set(k, 1)
ee3eb3a7
MAL
3014 elif v == 'n'
3015 config_target_data.set(k, 0)
859aef02
PB
3016 else
3017 config_target_data.set(k, v)
3018 endif
3019 endforeach
cb2c5531
PM
3020 config_target_data.set('QEMU_ARCH',
3021 'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
859aef02
PB
3022 config_target_h += {target: configure_file(output: target + '-config-target.h',
3023 configuration: config_target_data)}
2becc36a
PB
3024
3025 if target.endswith('-softmmu')
d1d5e9ee 3026 config_input = meson.get_external_property(target, 'default')
2becc36a
PB
3027 config_devices_mak = target + '-config-devices.mak'
3028 config_devices_mak = configure_file(
d1d5e9ee 3029 input: ['configs/devices' / target / config_input + '.mak', 'Kconfig'],
2becc36a
PB
3030 output: config_devices_mak,
3031 depfile: config_devices_mak + '.d',
3032 capture: true,
7bc3ca7f
PB
3033 command: [minikconf,
3034 get_option('default_devices') ? '--defconfig' : '--allnoconfig',
2becc36a 3035 config_devices_mak, '@DEPFILE@', '@INPUT@',
f4063f9c
PMD
3036 host_kconfig, accel_kconfig,
3037 'CONFIG_' + config_target['TARGET_ARCH'].to_upper() + '=y'])
859aef02
PB
3038
3039 config_devices_data = configuration_data()
3040 config_devices = keyval.load(config_devices_mak)
3041 foreach k, v: config_devices
3042 config_devices_data.set(k, 1)
3043 endforeach
2becc36a 3044 config_devices_mak_list += config_devices_mak
859aef02
PB
3045 config_devices_h += {target: configure_file(output: target + '-config-devices.h',
3046 configuration: config_devices_data)}
3047 config_target += config_devices
a98006bc 3048 config_all_devices += config_devices
2becc36a
PB
3049 endif
3050 config_target_mak += {target: config_target}
a81df1b6 3051endforeach
fdb75aef 3052target_dirs = actual_target_dirs
a81df1b6 3053
2becc36a
PB
3054# This configuration is used to build files that are shared by
3055# multiple binaries, and then extracted out of the "common"
3056# static_library target.
3057#
3058# We do not use all_sources()/all_dependencies(), because it would
3059# build literally all source files, including devices only used by
3060# targets that are not built for this compilation. The CONFIG_ALL
3061# pseudo symbol replaces it.
3062
05512f55 3063config_all += config_all_devices
1f2146f7 3064config_all += config_targetos
2becc36a
PB
3065config_all += config_all_disas
3066config_all += {
14efd8d3 3067 'CONFIG_XEN': xen.found(),
c7b64948 3068 'CONFIG_SYSTEM_ONLY': have_system,
2becc36a
PB
3069 'CONFIG_USER_ONLY': have_user,
3070 'CONFIG_ALL': true,
3071}
3072
eed56e9a
PB
3073target_configs_h = []
3074foreach target: target_dirs
3075 target_configs_h += config_target_h[target]
3076 target_configs_h += config_devices_h.get(target, [])
3077endforeach
3078genh += custom_target('config-poison.h',
3079 input: [target_configs_h],
3080 output: 'config-poison.h',
3081 capture: true,
3082 command: [find_program('scripts/make-config-poison.sh'),
3083 target_configs_h])
3084
a0c9162c
PB
3085##############
3086# Submodules #
3087##############
8b18cdbf
RH
3088
3089capstone = not_found
83602083 3090if not get_option('capstone').auto() or have_system or have_user
43ecd166 3091 capstone = dependency('capstone', version: '>=3.0.5',
063d5119 3092 method: 'pkg-config',
83602083 3093 required: get_option('capstone'))
8f4aea71
DB
3094
3095 # Some versions of capstone have broken pkg-config file
3096 # that reports a wrong -I path, causing the #include to
3097 # fail later. If the system has such a broken version
3098 # do not use it.
3099 if capstone.found() and not cc.compiles('#include <capstone.h>',
3100 dependencies: [capstone])
3101 capstone = not_found
83602083
TH
3102 if get_option('capstone').enabled()
3103 error('capstone requested, but it does not appear to work')
8f4aea71
DB
3104 endif
3105 endif
8b18cdbf 3106endif
4d34a86b 3107
55116968
JR
3108libvfio_user_dep = not_found
3109if have_system and vfio_user_server_allowed
2019cabf 3110 libvfio_user_proj = subproject('libvfio-user', required: true)
5328353c 3111 libvfio_user_dep = libvfio_user_proj.get_variable('libvfio_user_dep')
55116968
JR
3112endif
3113
fbb4121d 3114fdt = not_found
577bdbcf
PB
3115fdt_opt = get_option('fdt')
3116if fdt_required.length() > 0 or fdt_opt == 'enabled'
3117 if fdt_opt == 'disabled'
3118 error('fdt disabled but required by targets ' + ', '.join(fdt_required))
3119 endif
3120
fbb4121d 3121 if fdt_opt in ['enabled', 'auto', 'system']
f0df613b
PB
3122 if get_option('wrap_mode') == 'nodownload'
3123 fdt_opt = 'system'
3124 endif
577bdbcf 3125 fdt = cc.find_library('fdt', required: fdt_opt == 'system')
fbb4121d
PB
3126 if fdt.found() and cc.links('''
3127 #include <libfdt.h>
3128 #include <libfdt_env.h>
de47b0ff 3129 int main(void) { fdt_find_max_phandle(NULL, NULL); return 0; }''',
fbb4121d
PB
3130 dependencies: fdt)
3131 fdt_opt = 'system'
6c22853c
TH
3132 elif fdt_opt == 'system'
3133 error('system libfdt requested, but it is too old (1.5.1 or newer required)')
fbb4121d 3134 else
577bdbcf 3135 fdt_opt = 'internal'
87daf898 3136 fdt = not_found
fbb4121d
PB
3137 endif
3138 endif
577bdbcf
PB
3139 if not fdt.found()
3140 assert(fdt_opt == 'internal')
58e48b2e
PB
3141 libfdt_proj = subproject('dtc', required: true,
3142 default_options: ['tools=false', 'yaml=disabled',
3143 'python=disabled', 'default_library=static'])
3144 fdt = libfdt_proj.get_variable('libfdt_dep')
fbb4121d 3145 endif
c593d841
PMD
3146else
3147 fdt_opt = 'disabled'
fbb4121d 3148endif
fbb4121d 3149
8b18cdbf 3150config_host_data.set('CONFIG_CAPSTONE', capstone.found())
fbb4121d 3151config_host_data.set('CONFIG_FDT', fdt.found())
4d34a86b 3152config_host_data.set('CONFIG_SLIRP', slirp.found())
8b18cdbf 3153
a0c9162c
PB
3154#####################
3155# Generated sources #
3156#####################
8b18cdbf 3157
a0c9162c 3158genh += configure_file(output: 'config-host.h', configuration: config_host_data)
a81df1b6 3159
3f885659 3160hxtool = find_program('scripts/hxtool')
e2c4012b 3161shaderinclude = find_program('scripts/shaderinclude.py')
a81df1b6 3162qapi_gen = find_program('scripts/qapi-gen.py')
654d6b04
PB
3163qapi_gen_depends = [ meson.current_source_dir() / 'scripts/qapi/__init__.py',
3164 meson.current_source_dir() / 'scripts/qapi/commands.py',
3165 meson.current_source_dir() / 'scripts/qapi/common.py',
3166 meson.current_source_dir() / 'scripts/qapi/error.py',
3167 meson.current_source_dir() / 'scripts/qapi/events.py',
3168 meson.current_source_dir() / 'scripts/qapi/expr.py',
3169 meson.current_source_dir() / 'scripts/qapi/gen.py',
3170 meson.current_source_dir() / 'scripts/qapi/introspect.py',
88d357d2 3171 meson.current_source_dir() / 'scripts/qapi/main.py',
654d6b04
PB
3172 meson.current_source_dir() / 'scripts/qapi/parser.py',
3173 meson.current_source_dir() / 'scripts/qapi/schema.py',
3174 meson.current_source_dir() / 'scripts/qapi/source.py',
3175 meson.current_source_dir() / 'scripts/qapi/types.py',
3176 meson.current_source_dir() / 'scripts/qapi/visit.py',
654d6b04 3177 meson.current_source_dir() / 'scripts/qapi-gen.py'
a81df1b6
PB
3178]
3179
3180tracetool = [
3181 python, files('scripts/tracetool.py'),
9c29b741 3182 '--backend=' + ','.join(get_option('trace_backends'))
a81df1b6 3183]
0572d6cd
SH
3184tracetool_depends = files(
3185 'scripts/tracetool/backend/log.py',
3186 'scripts/tracetool/backend/__init__.py',
3187 'scripts/tracetool/backend/dtrace.py',
3188 'scripts/tracetool/backend/ftrace.py',
3189 'scripts/tracetool/backend/simple.py',
3190 'scripts/tracetool/backend/syslog.py',
3191 'scripts/tracetool/backend/ust.py',
0572d6cd
SH
3192 'scripts/tracetool/format/ust_events_c.py',
3193 'scripts/tracetool/format/ust_events_h.py',
3194 'scripts/tracetool/format/__init__.py',
3195 'scripts/tracetool/format/d.py',
0572d6cd
SH
3196 'scripts/tracetool/format/simpletrace_stap.py',
3197 'scripts/tracetool/format/c.py',
3198 'scripts/tracetool/format/h.py',
0572d6cd
SH
3199 'scripts/tracetool/format/log_stap.py',
3200 'scripts/tracetool/format/stap.py',
0572d6cd 3201 'scripts/tracetool/__init__.py',
0572d6cd
SH
3202 'scripts/tracetool/vcpu.py'
3203)
a81df1b6 3204
2c273f32
MAL
3205qemu_version_cmd = [find_program('scripts/qemu-version.sh'),
3206 meson.current_source_dir(),
b0b4323e 3207 get_option('pkgversion'), meson.project_version()]
2c273f32
MAL
3208qemu_version = custom_target('qemu-version.h',
3209 output: 'qemu-version.h',
3210 command: qemu_version_cmd,
3211 capture: true,
3212 build_by_default: true,
3213 build_always_stale: true)
3214genh += qemu_version
3215
3f885659
MAL
3216hxdep = []
3217hx_headers = [
3218 ['qemu-options.hx', 'qemu-options.def'],
3219 ['qemu-img-cmds.hx', 'qemu-img-cmds.h'],
3220]
3221if have_system
3222 hx_headers += [
3223 ['hmp-commands.hx', 'hmp-commands.h'],
3224 ['hmp-commands-info.hx', 'hmp-commands-info.h'],
3225 ]
3226endif
3227foreach d : hx_headers
b7c70bf2 3228 hxdep += custom_target(d[1],
3f885659
MAL
3229 input: files(d[0]),
3230 output: d[1],
3231 capture: true,
3f885659
MAL
3232 command: [hxtool, '-h', '@INPUT0@'])
3233endforeach
3234genh += hxdep
3235
a0c9162c
PB
3236###################
3237# Collect sources #
3238###################
a81df1b6 3239
55567891 3240authz_ss = ss.source_set()
4a96337d 3241blockdev_ss = ss.source_set()
7e2b888f 3242block_ss = ss.source_set()
c2306d71 3243chardev_ss = ss.source_set()
7e2b888f 3244common_ss = ss.source_set()
2389304a 3245crypto_ss = ss.source_set()
f73fb063 3246hwcore_ss = ss.source_set()
f78536b1 3247io_ss = ss.source_set()
7e2b888f 3248qmp_ss = ss.source_set()
da33fc09 3249qom_ss = ss.source_set()
de6cd759 3250system_ss = ss.source_set()
64ed6f92 3251specific_fuzz_ss = ss.source_set()
7e2b888f
PMD
3252specific_ss = ss.source_set()
3253stub_ss = ss.source_set()
3254trace_ss = ss.source_set()
3255user_ss = ss.source_set()
3256util_ss = ss.source_set()
2becc36a 3257
c94a7b88
GH
3258# accel modules
3259qtest_module_ss = ss.source_set()
dae0ec15 3260tcg_module_ss = ss.source_set()
c94a7b88 3261
3154fee4 3262modules = {}
db2e89df 3263target_modules = {}
2becc36a
PB
3264hw_arch = {}
3265target_arch = {}
01c85e60 3266target_system_arch = {}
46369b50 3267target_user_arch = {}
a81df1b6
PB
3268
3269###############
3270# Trace files #
3271###############
3272
c9322ab5
MAL
3273# TODO: add each directory to the subdirs from its own meson.build, once
3274# we have those
a81df1b6 3275trace_events_subdirs = [
a81df1b6 3276 'crypto',
69ff4d0a
PMD
3277 'qapi',
3278 'qom',
a81df1b6 3279 'monitor',
69ff4d0a 3280 'util',
842b42df 3281 'gdbstub',
a81df1b6 3282]
6ddc1abe 3283if have_linux_user
a81df1b6
PB
3284 trace_events_subdirs += [ 'linux-user' ]
3285endif
6ddc1abe
WL
3286if have_bsd_user
3287 trace_events_subdirs += [ 'bsd-user' ]
3288endif
a81df1b6
PB
3289if have_block
3290 trace_events_subdirs += [
3291 'authz',
3292 'block',
3293 'io',
3294 'nbd',
3295 'scsi',
3296 ]
3297endif
3298if have_system
3299 trace_events_subdirs += [
8985db26 3300 'accel/kvm',
a81df1b6
PB
3301 'audio',
3302 'backends',
3303 'backends/tpm',
3304 'chardev',
46627f41 3305 'ebpf',
a81df1b6
PB
3306 'hw/9pfs',
3307 'hw/acpi',
77c05b0b 3308 'hw/adc',
a81df1b6
PB
3309 'hw/alpha',
3310 'hw/arm',
3311 'hw/audio',
3312 'hw/block',
3313 'hw/block/dataplane',
3314 'hw/char',
3315 'hw/display',
3316 'hw/dma',
a81df1b6
PB
3317 'hw/hyperv',
3318 'hw/i2c',
3319 'hw/i386',
3320 'hw/i386/xen',
aa98ee38 3321 'hw/i386/kvm',
a81df1b6
PB
3322 'hw/ide',
3323 'hw/input',
3324 'hw/intc',
3325 'hw/isa',
3326 'hw/mem',
3327 'hw/mips',
3328 'hw/misc',
3329 'hw/misc/macio',
3330 'hw/net',
98e5d7a2 3331 'hw/net/can',
ce0e6a2c 3332 'hw/nubus',
88eea45c 3333 'hw/nvme',
a81df1b6
PB
3334 'hw/nvram',
3335 'hw/pci',
3336 'hw/pci-host',
3337 'hw/ppc',
3338 'hw/rdma',
3339 'hw/rdma/vmw',
3340 'hw/rtc',
3341 'hw/s390x',
3342 'hw/scsi',
3343 'hw/sd',
ad52cfc1 3344 'hw/sh4',
a81df1b6
PB
3345 'hw/sparc',
3346 'hw/sparc64',
3347 'hw/ssi',
3348 'hw/timer',
3349 'hw/tpm',
bc4e68d3 3350 'hw/ufs',
a81df1b6
PB
3351 'hw/usb',
3352 'hw/vfio',
3353 'hw/virtio',
3354 'hw/watchdog',
3355 'hw/xen',
3356 'hw/gpio',
a81df1b6
PB
3357 'migration',
3358 'net',
8d7f2e76 3359 'system',
a81df1b6 3360 'ui',
ad22c308 3361 'hw/remote',
a81df1b6
PB
3362 ]
3363endif
8985db26
PMD
3364if have_system or have_user
3365 trace_events_subdirs += [
3366 'accel/tcg',
3367 'hw/core',
3368 'target/arm',
a1477da3 3369 'target/arm/hvf',
8985db26
PMD
3370 'target/hppa',
3371 'target/i386',
3372 'target/i386/kvm',
34b8ff25 3373 'target/mips/tcg',
6f83e277 3374 'target/nios2',
8985db26
PMD
3375 'target/ppc',
3376 'target/riscv',
3377 'target/s390x',
67043607 3378 'target/s390x/kvm',
8985db26
PMD
3379 'target/sparc',
3380 ]
3381endif
a81df1b6 3382
0df750e9 3383vhost_user = not_found
2a3129a3 3384if targetos == 'linux' and have_vhost_user
0df750e9
MAL
3385 libvhost_user = subproject('libvhost-user')
3386 vhost_user = libvhost_user.get_variable('vhost_user_dep')
3387endif
3388
a6caeee8
XY
3389libvduse = not_found
3390if have_libvduse
3391 libvduse_proj = subproject('libvduse')
3392 libvduse = libvduse_proj.get_variable('libvduse_dep')
3393endif
3394
b83a80e8
VSO
3395# NOTE: the trace/ subdirectory needs the qapi_trace_events variable
3396# that is filled in by qapi/.
a81df1b6
PB
3397subdir('qapi')
3398subdir('qobject')
3399subdir('stubs')
3400subdir('trace')
3401subdir('util')
5582c58f
MAL
3402subdir('qom')
3403subdir('authz')
a81df1b6 3404subdir('crypto')
2d78b56e 3405subdir('ui')
7d5983e3 3406subdir('hw')
842b42df 3407subdir('gdbstub')
a81df1b6 3408
3154fee4
MAL
3409if enable_modules
3410 libmodulecommon = static_library('module-common', files('module-common.c') + genh, pic: true, c_args: '-DBUILD_DSO')
3411 modulecommon = declare_dependency(link_whole: libmodulecommon, compile_args: '-DBUILD_DSO')
3412endif
3413
1f2146f7 3414qom_ss = qom_ss.apply(config_targetos, strict: false)
7d5983e3
NSJ
3415libqom = static_library('qom', qom_ss.sources() + genh,
3416 dependencies: [qom_ss.dependencies()],
4c545a05
PB
3417 name_suffix: 'fa',
3418 build_by_default: false)
7d5983e3
NSJ
3419qom = declare_dependency(link_whole: libqom)
3420
3421event_loop_base = files('event-loop-base.c')
4c545a05
PB
3422event_loop_base = static_library('event-loop-base',
3423 sources: event_loop_base + genh,
3424 name_suffix: 'fa',
3425 build_by_default: false)
7d5983e3
NSJ
3426event_loop_base = declare_dependency(link_whole: event_loop_base,
3427 dependencies: [qom])
3428
2becc36a 3429stub_ss = stub_ss.apply(config_all, strict: false)
a81df1b6
PB
3430
3431util_ss.add_all(trace_ss)
2becc36a 3432util_ss = util_ss.apply(config_all, strict: false)
a81df1b6 3433libqemuutil = static_library('qemuutil',
4c545a05 3434 build_by_default: false,
a81df1b6 3435 sources: util_ss.sources() + stub_ss.sources() + genh,
6d7c7c2d 3436 dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman])
a81df1b6 3437qemuutil = declare_dependency(link_with: libqemuutil,
70ac26b9
NSJ
3438 sources: genh + version_res,
3439 dependencies: [event_loop_base])
a81df1b6 3440
957b31f6
PMD
3441if have_system or have_user
3442 decodetree = generator(find_program('scripts/decodetree.py'),
3443 output: 'decode-@BASENAME@.c.inc',
3444 arguments: ['@INPUT@', '@EXTRA_ARGS@', '-o', '@OUTPUT@'])
3445 subdir('libdecnumber')
3446 subdir('target')
3447endif
abff1abf 3448
478e943f 3449subdir('audio')
7fcfd456 3450subdir('io')
848e8ff6 3451subdir('chardev')
ec0d5893 3452subdir('fsdev')
708eab42 3453subdir('dump')
ec0d5893 3454
f285bd3f
PMD
3455if have_block
3456 block_ss.add(files(
3457 'block.c',
3458 'blockjob.c',
3459 'job.c',
3460 'qemu-io-cmds.c',
3461 ))
406523f6
PB
3462 if config_host_data.get('CONFIG_REPLICATION')
3463 block_ss.add(files('replication.c'))
3464 endif
f285bd3f
PMD
3465
3466 subdir('nbd')
3467 subdir('scsi')
3468 subdir('block')
3469
3470 blockdev_ss.add(files(
3471 'blockdev.c',
3472 'blockdev-nbd.c',
3473 'iothread.c',
3474 'job-qmp.c',
3475 ), gnutls)
3476
3477 # os-posix.c contains POSIX-specific functions used by qemu-storage-daemon,
3478 # os-win32.c does not
3479 blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c'))
de6cd759 3480 system_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')])
f285bd3f 3481endif
4a96337d 3482
fe0007f3
PMD
3483common_ss.add(files('cpu-common.c'))
3484specific_ss.add(files('cpu-target.c'))
4a96337d 3485
8d7f2e76 3486subdir('system')
c9322ab5 3487
44b99a6d
RH
3488# Work around a gcc bug/misfeature wherein constant propagation looks
3489# through an alias:
3490# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99696
3491# to guess that a const variable is always zero. Without lto, this is
3492# impossible, as the alias is restricted to page-vary-common.c. Indeed,
3493# without lto, not even the alias is required -- we simply use different
3494# declarations in different compilation units.
3495pagevary = files('page-vary-common.c')
3496if get_option('b_lto')
3497 pagevary_flags = ['-fno-lto']
3498 if get_option('cfi')
3499 pagevary_flags += '-fno-sanitize=cfi-icall'
3500 endif
54c9b194 3501 pagevary = static_library('page-vary-common', sources: pagevary + genh,
44b99a6d
RH
3502 c_args: pagevary_flags)
3503 pagevary = declare_dependency(link_with: pagevary)
3504endif
3505common_ss.add(pagevary)
8c7907a1 3506specific_ss.add(files('page-vary-target.c'))
6670d4d0 3507
ab318051 3508subdir('backends')
c574e161 3509subdir('disas')
55166230 3510subdir('migration')
ff219dca 3511subdir('monitor')
cdaf0722 3512subdir('net')
17ef2af6 3513subdir('replay')
8df9f0c3 3514subdir('semihosting')
aa09b3d5 3515subdir('stats')
104cc2c0 3516subdir('tcg')
c6347541 3517subdir('fpu')
1a82878a 3518subdir('accel')
f556b4a1 3519subdir('plugins')
bbf15aaf
RH
3520subdir('ebpf')
3521
3522common_user_inc = []
3523
3524subdir('common-user')
b309c321 3525subdir('bsd-user')
3a30446a 3526subdir('linux-user')
46627f41 3527
a2ce7dbd
PB
3528# needed for fuzzing binaries
3529subdir('tests/qtest/libqos')
64ed6f92 3530subdir('tests/qtest/fuzz')
a2ce7dbd 3531
c94a7b88 3532# accel modules
dae0ec15
GH
3533tcg_real_module_ss = ss.source_set()
3534tcg_real_module_ss.add_all(when: 'CONFIG_TCG_MODULAR', if_true: tcg_module_ss)
3535specific_ss.add_all(when: 'CONFIG_TCG_BUILTIN', if_true: tcg_module_ss)
3536target_modules += { 'accel' : { 'qtest': qtest_module_ss,
3537 'tcg': tcg_real_module_ss }}
c94a7b88 3538
ea444d91
PB
3539##############################################
3540# Internal static_libraries and dependencies #
3541##############################################
a0c9162c 3542
f5723ab6 3543modinfo_collect = find_program('scripts/modinfo-collect.py')
5ebbfecc 3544modinfo_generate = find_program('scripts/modinfo-generate.py')
f5723ab6
GH
3545modinfo_files = []
3546
3154fee4 3547block_mods = []
21d2140d 3548system_mods = []
3154fee4 3549foreach d, list : modules
ef709860
PB
3550 if not (d == 'block' ? have_block : have_system)
3551 continue
3552 endif
3553
3154fee4 3554 foreach m, module_ss : list
6002711c 3555 if enable_modules
3e292c51 3556 module_ss = module_ss.apply(config_all, strict: false)
3154fee4
MAL
3557 sl = static_library(d + '-' + m, [genh, module_ss.sources()],
3558 dependencies: [modulecommon, module_ss.dependencies()], pic: true)
3559 if d == 'block'
3560 block_mods += sl
3561 else
21d2140d 3562 system_mods += sl
3154fee4 3563 endif
f5723ab6
GH
3564 if module_ss.sources() != []
3565 # FIXME: Should use sl.extract_all_objects(recursive: true) as
3566 # input. Sources can be used multiple times but objects are
3567 # unique when it comes to lookup in compile_commands.json.
3568 # Depnds on a mesion version with
3569 # https://github.com/mesonbuild/meson/pull/8900
3570 modinfo_files += custom_target(d + '-' + m + '.modinfo',
3571 output: d + '-' + m + '.modinfo',
ac347111 3572 input: module_ss.sources() + genh,
f5723ab6 3573 capture: true,
ac347111 3574 command: [modinfo_collect, module_ss.sources()])
f5723ab6 3575 endif
3154fee4
MAL
3576 else
3577 if d == 'block'
3578 block_ss.add_all(module_ss)
3579 else
de6cd759 3580 system_ss.add_all(module_ss)
3154fee4
MAL
3581 endif
3582 endif
3583 endforeach
3584endforeach
3585
db2e89df
GH
3586foreach d, list : target_modules
3587 foreach m, module_ss : list
6002711c 3588 if enable_modules
db2e89df
GH
3589 foreach target : target_dirs
3590 if target.endswith('-softmmu')
3591 config_target = config_target_mak[target]
1f2146f7 3592 config_target += config_targetos
db2e89df
GH
3593 target_inc = [include_directories('target' / config_target['TARGET_BASE_ARCH'])]
3594 c_args = ['-DNEED_CPU_H',
3595 '-DCONFIG_TARGET="@0@-config-target.h"'.format(target),
3596 '-DCONFIG_DEVICES="@0@-config-devices.h"'.format(target)]
3597 target_module_ss = module_ss.apply(config_target, strict: false)
3598 if target_module_ss.sources() != []
3599 module_name = d + '-' + m + '-' + config_target['TARGET_NAME']
3600 sl = static_library(module_name,
3601 [genh, target_module_ss.sources()],
3602 dependencies: [modulecommon, target_module_ss.dependencies()],
3603 include_directories: target_inc,
3604 c_args: c_args,
3605 pic: true)
21d2140d 3606 system_mods += sl
db2e89df
GH
3607 # FIXME: Should use sl.extract_all_objects(recursive: true) too.
3608 modinfo_files += custom_target(module_name + '.modinfo',
3609 output: module_name + '.modinfo',
917ddc27 3610 input: target_module_ss.sources() + genh,
db2e89df 3611 capture: true,
917ddc27 3612 command: [modinfo_collect, '--target', target, target_module_ss.sources()])
db2e89df
GH
3613 endif
3614 endif
3615 endforeach
3616 else
3617 specific_ss.add_all(module_ss)
3618 endif
3619 endforeach
3620endforeach
3621
5ebbfecc 3622if enable_modules
05d6814c
JZ
3623 foreach target : target_dirs
3624 if target.endswith('-softmmu')
3625 config_target = config_target_mak[target]
3626 config_devices_mak = target + '-config-devices.mak'
3627 modinfo_src = custom_target('modinfo-' + target + '.c',
3628 output: 'modinfo-' + target + '.c',
3629 input: modinfo_files,
3630 command: [modinfo_generate, '--devices', config_devices_mak, '@INPUT@'],
3631 capture: true)
3632
3633 modinfo_lib = static_library('modinfo-' + target + '.c', modinfo_src)
3634 modinfo_dep = declare_dependency(link_with: modinfo_lib)
3635
3636 arch = config_target['TARGET_NAME'] == 'sparc64' ? 'sparc64' : config_target['TARGET_BASE_ARCH']
3637 hw_arch[arch].add(modinfo_dep)
3638 endif
3639 endforeach
5ebbfecc
GH
3640endif
3641
3154fee4 3642nm = find_program('nm')
604f3e4e 3643undefsym = find_program('scripts/undefsym.py')
3154fee4
MAL
3644block_syms = custom_target('block.syms', output: 'block.syms',
3645 input: [libqemuutil, block_mods],
3646 capture: true,
3647 command: [undefsym, nm, '@INPUT@'])
3648qemu_syms = custom_target('qemu.syms', output: 'qemu.syms',
21d2140d 3649 input: [libqemuutil, system_mods],
3154fee4
MAL
3650 capture: true,
3651 command: [undefsym, nm, '@INPUT@'])
3652
1f2146f7 3653authz_ss = authz_ss.apply(config_targetos, strict: false)
55567891
PMD
3654libauthz = static_library('authz', authz_ss.sources() + genh,
3655 dependencies: [authz_ss.dependencies()],
3656 name_suffix: 'fa',
3657 build_by_default: false)
3658
3659authz = declare_dependency(link_whole: libauthz,
3660 dependencies: qom)
3661
1f2146f7 3662crypto_ss = crypto_ss.apply(config_targetos, strict: false)
2389304a
PMD
3663libcrypto = static_library('crypto', crypto_ss.sources() + genh,
3664 dependencies: [crypto_ss.dependencies()],
3665 name_suffix: 'fa',
3666 build_by_default: false)
3667
3668crypto = declare_dependency(link_whole: libcrypto,
3669 dependencies: [authz, qom])
3670
1f2146f7 3671io_ss = io_ss.apply(config_targetos, strict: false)
f78536b1
PMD
3672libio = static_library('io', io_ss.sources() + genh,
3673 dependencies: [io_ss.dependencies()],
3674 link_with: libqemuutil,
3675 name_suffix: 'fa',
3676 build_by_default: false)
3677
3678io = declare_dependency(link_whole: libio, dependencies: [crypto, qom])
3679
7e6edef3
PMD
3680libmigration = static_library('migration', sources: migration_files + genh,
3681 name_suffix: 'fa',
3682 build_by_default: false)
3683migration = declare_dependency(link_with: libmigration,
3684 dependencies: [zlib, qom, io])
de6cd759 3685system_ss.add(migration)
7e6edef3 3686
1f2146f7 3687block_ss = block_ss.apply(config_targetos, strict: false)
5e5733e5
MAL
3688libblock = static_library('block', block_ss.sources() + genh,
3689 dependencies: block_ss.dependencies(),
3690 link_depends: block_syms,
3691 name_suffix: 'fa',
3692 build_by_default: false)
3693
3694block = declare_dependency(link_whole: [libblock],
b7c70bf2
MAL
3695 link_args: '@block.syms',
3696 dependencies: [crypto, io])
5e5733e5 3697
1f2146f7 3698blockdev_ss = blockdev_ss.apply(config_targetos, strict: false)
4fb9071f
SH
3699libblockdev = static_library('blockdev', blockdev_ss.sources() + genh,
3700 dependencies: blockdev_ss.dependencies(),
3701 name_suffix: 'fa',
3702 build_by_default: false)
3703
3704blockdev = declare_dependency(link_whole: [libblockdev],
7d5983e3 3705 dependencies: [block, event_loop_base])
4fb9071f 3706
1f2146f7 3707qmp_ss = qmp_ss.apply(config_targetos, strict: false)
ff219dca
PB
3708libqmp = static_library('qmp', qmp_ss.sources() + genh,
3709 dependencies: qmp_ss.dependencies(),
3710 name_suffix: 'fa',
3711 build_by_default: false)
3712
3713qmp = declare_dependency(link_whole: [libqmp])
3714
c2306d71
PMD
3715libchardev = static_library('chardev', chardev_ss.sources() + genh,
3716 name_suffix: 'fa',
22d1f7a8 3717 dependencies: chardev_ss.dependencies(),
c2306d71
PMD
3718 build_by_default: false)
3719
3720chardev = declare_dependency(link_whole: libchardev)
3721
1f2146f7 3722hwcore_ss = hwcore_ss.apply(config_targetos, strict: false)
f73fb063 3723libhwcore = static_library('hwcore', sources: hwcore_ss.sources() + genh,
e28ab096
PMD
3724 name_suffix: 'fa',
3725 build_by_default: false)
3726hwcore = declare_dependency(link_whole: libhwcore)
3727common_ss.add(hwcore)
3728
064f8ee7
PMD
3729###########
3730# Targets #
3731###########
3732
fb72176b 3733emulator_modules = []
21d2140d 3734foreach m : block_mods + system_mods
fb72176b
PB
3735 emulator_modules += shared_module(m.name(),
3736 build_by_default: true,
3154fee4
MAL
3737 name_prefix: '',
3738 link_whole: m,
3739 install: true,
16bf7a33 3740 install_dir: qemu_moddir)
3154fee4 3741endforeach
d8f3a609
PB
3742if emulator_modules.length() > 0
3743 alias_target('modules', emulator_modules)
3744endif
3154fee4 3745
de6cd759 3746system_ss.add(authz, blockdev, chardev, crypto, io, qmp)
64ed6f92
PB
3747common_ss.add(qom, qemuutil)
3748
de6cd759 3749common_ss.add_all(when: 'CONFIG_SYSTEM_ONLY', if_true: [system_ss])
2becc36a
PB
3750common_ss.add_all(when: 'CONFIG_USER_ONLY', if_true: user_ss)
3751
3752common_all = common_ss.apply(config_all, strict: false)
3753common_all = static_library('common',
3754 build_by_default: false,
3755 sources: common_all.sources() + genh,
9d24fb73 3756 include_directories: common_user_inc,
75eebe0b 3757 implicit_include_directories: false,
2becc36a
PB
3758 dependencies: common_all.dependencies(),
3759 name_suffix: 'fa')
3760
956af7da 3761feature_to_c = find_program('scripts/feature_to_c.py')
c9322ab5 3762
30cfa50d
PMD
3763if targetos == 'darwin'
3764 entitlement = find_program('scripts/entitlement.sh')
3765endif
3766
fd5eef85 3767emulators = {}
2becc36a
PB
3768foreach target : target_dirs
3769 config_target = config_target_mak[target]
3770 target_name = config_target['TARGET_NAME']
ffb91f68 3771 target_base_arch = config_target['TARGET_BASE_ARCH']
859aef02 3772 arch_srcs = [config_target_h[target]]
64ed6f92
PB
3773 arch_deps = []
3774 c_args = ['-DNEED_CPU_H',
3775 '-DCONFIG_TARGET="@0@-config-target.h"'.format(target),
3776 '-DCONFIG_DEVICES="@0@-config-devices.h"'.format(target)]
b6c7cfd4 3777 link_args = emulator_link_args
2becc36a 3778
1f2146f7 3779 config_target += config_targetos
2becc36a
PB
3780 target_inc = [include_directories('target' / config_target['TARGET_BASE_ARCH'])]
3781 if targetos == 'linux'
3782 target_inc += include_directories('linux-headers', is_system: true)
3783 endif
3784 if target.endswith('-softmmu')
2becc36a 3785 target_type='system'
01c85e60 3786 t = target_system_arch[target_base_arch].apply(config_target, strict: false)
abff1abf 3787 arch_srcs += t.sources()
64ed6f92 3788 arch_deps += t.dependencies()
abff1abf 3789
ffb91f68 3790 hw_dir = target_name == 'sparc64' ? 'sparc64' : target_base_arch
2c44220d
MAL
3791 hw = hw_arch[hw_dir].apply(config_target, strict: false)
3792 arch_srcs += hw.sources()
64ed6f92 3793 arch_deps += hw.dependencies()
2c44220d 3794
2becc36a 3795 arch_srcs += config_devices_h[target]
64ed6f92 3796 link_args += ['@block.syms', '@qemu.syms']
2becc36a 3797 else
3a30446a 3798 abi = config_target['TARGET_ABI_DIR']
2becc36a 3799 target_type='user'
a3a576b0 3800 target_inc += common_user_inc
ffb91f68
PB
3801 if target_base_arch in target_user_arch
3802 t = target_user_arch[target_base_arch].apply(config_target, strict: false)
46369b50
PMD
3803 arch_srcs += t.sources()
3804 arch_deps += t.dependencies()
3805 endif
2becc36a
PB
3806 if 'CONFIG_LINUX_USER' in config_target
3807 base_dir = 'linux-user'
e2a74729
WL
3808 endif
3809 if 'CONFIG_BSD_USER' in config_target
2becc36a 3810 base_dir = 'bsd-user'
e2a74729 3811 target_inc += include_directories('bsd-user/' / targetos)
85fc1b5d 3812 target_inc += include_directories('bsd-user/host/' / host_arch)
e2a74729 3813 dir = base_dir / abi
19bf129f 3814 arch_srcs += files(dir / 'signal.c', dir / 'target_arch_cpu.c')
2becc36a
PB
3815 endif
3816 target_inc += include_directories(
3817 base_dir,
3a30446a 3818 base_dir / abi,
2becc36a 3819 )
3a30446a
MAL
3820 if 'CONFIG_LINUX_USER' in config_target
3821 dir = base_dir / abi
3822 arch_srcs += files(dir / 'signal.c', dir / 'cpu_loop.c')
3823 if config_target.has_key('TARGET_SYSTBL_ABI')
3824 arch_srcs += \
3825 syscall_nr_generators[abi].process(base_dir / abi / config_target['TARGET_SYSTBL'],
3826 extra_args : config_target['TARGET_SYSTBL_ABI'])
3827 endif
3828 endif
2becc36a
PB
3829 endif
3830
c9322ab5
MAL
3831 if 'TARGET_XML_FILES' in config_target
3832 gdbstub_xml = custom_target(target + '-gdbstub-xml.c',
3833 output: target + '-gdbstub-xml.c',
3834 input: files(config_target['TARGET_XML_FILES'].split()),
3835 command: [feature_to_c, '@INPUT@'],
3836 capture: true)
3837 arch_srcs += gdbstub_xml
3838 endif
3839
ffb91f68 3840 t = target_arch[target_base_arch].apply(config_target, strict: false)
abff1abf 3841 arch_srcs += t.sources()
64ed6f92 3842 arch_deps += t.dependencies()
abff1abf 3843
2becc36a
PB
3844 target_common = common_ss.apply(config_target, strict: false)
3845 objects = common_all.extract_objects(target_common.sources())
64ed6f92 3846 deps = target_common.dependencies()
2becc36a 3847
2becc36a
PB
3848 target_specific = specific_ss.apply(config_target, strict: false)
3849 arch_srcs += target_specific.sources()
64ed6f92 3850 arch_deps += target_specific.dependencies()
2becc36a 3851
64ed6f92 3852 lib = static_library('qemu-' + target,
859aef02 3853 sources: arch_srcs + genh,
b7612f45 3854 dependencies: arch_deps,
2becc36a
PB
3855 objects: objects,
3856 include_directories: target_inc,
64ed6f92
PB
3857 c_args: c_args,
3858 build_by_default: false,
2becc36a 3859 name_suffix: 'fa')
64ed6f92
PB
3860
3861 if target.endswith('-softmmu')
3862 execs = [{
3863 'name': 'qemu-system-' + target_name,
654d6b04 3864 'win_subsystem': 'console',
8d7f2e76 3865 'sources': files('system/main.c'),
64ed6f92
PB
3866 'dependencies': []
3867 }]
35be72ba 3868 if targetos == 'windows' and (sdl.found() or gtk.found())
64ed6f92
PB
3869 execs += [{
3870 'name': 'qemu-system-' + target_name + 'w',
654d6b04 3871 'win_subsystem': 'windows',
8d7f2e76 3872 'sources': files('system/main.c'),
64ed6f92
PB
3873 'dependencies': []
3874 }]
3875 endif
537b7248 3876 if get_option('fuzzing')
64ed6f92
PB
3877 specific_fuzz = specific_fuzz_ss.apply(config_target, strict: false)
3878 execs += [{
3879 'name': 'qemu-fuzz-' + target_name,
654d6b04 3880 'win_subsystem': 'console',
64ed6f92
PB
3881 'sources': specific_fuzz.sources(),
3882 'dependencies': specific_fuzz.dependencies(),
64ed6f92
PB
3883 }]
3884 endif
3885 else
3886 execs = [{
3887 'name': 'qemu-' + target_name,
654d6b04 3888 'win_subsystem': 'console',
64ed6f92
PB
3889 'sources': [],
3890 'dependencies': []
3891 }]
3892 endif
3893 foreach exe: execs
8a74ce61 3894 exe_name = exe['name']
3983a767 3895 if targetos == 'darwin'
8a74ce61
AG
3896 exe_name += '-unsigned'
3897 endif
3898
3899 emulator = executable(exe_name, exe['sources'],
237377ac 3900 install: true,
64ed6f92
PB
3901 c_args: c_args,
3902 dependencies: arch_deps + deps + exe['dependencies'],
3903 objects: lib.extract_all_objects(recursive: true),
64ed6f92
PB
3904 link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
3905 link_args: link_args,
654d6b04 3906 win_subsystem: exe['win_subsystem'])
8a74ce61 3907
3983a767 3908 if targetos == 'darwin'
411ad8dd
AO
3909 icon = 'pc-bios/qemu.rsrc'
3910 build_input = [emulator, files(icon)]
3911 install_input = [
3912 get_option('bindir') / exe_name,
3913 meson.current_source_dir() / icon
3914 ]
3915 if 'CONFIG_HVF' in config_target
3916 entitlements = 'accel/hvf/entitlements.plist'
3917 build_input += files(entitlements)
3918 install_input += meson.current_source_dir() / entitlements
3919 endif
3920
8a74ce61 3921 emulators += {exe['name'] : custom_target(exe['name'],
411ad8dd 3922 input: build_input,
8a74ce61 3923 output: exe['name'],
235b523d 3924 command: [entitlement, '@OUTPUT@', '@INPUT@'])
8a74ce61 3925 }
237377ac 3926
235b523d 3927 meson.add_install_script(entitlement, '--install',
237377ac 3928 get_option('bindir') / exe['name'],
411ad8dd 3929 install_input)
8a74ce61
AG
3930 else
3931 emulators += {exe['name']: emulator}
3932 endif
10e1d263 3933
9c29b741 3934 if stap.found()
10e1d263 3935 foreach stp: [
bd5f973a
SH
3936 {'ext': '.stp-build', 'fmt': 'stap', 'bin': meson.current_build_dir() / exe['name'], 'install': false},
3937 {'ext': '.stp', 'fmt': 'stap', 'bin': get_option('prefix') / get_option('bindir') / exe['name'], 'install': true},
10e1d263
MAL
3938 {'ext': '-simpletrace.stp', 'fmt': 'simpletrace-stap', 'bin': '', 'install': true},
3939 {'ext': '-log.stp', 'fmt': 'log-stap', 'bin': '', 'install': true},
3940 ]
bd5f973a 3941 custom_target(exe['name'] + stp['ext'],
10e1d263 3942 input: trace_events_all,
bd5f973a 3943 output: exe['name'] + stp['ext'],
10e1d263 3944 install: stp['install'],
16bf7a33 3945 install_dir: get_option('datadir') / 'systemtap/tapset',
10e1d263
MAL
3946 command: [
3947 tracetool, '--group=all', '--format=' + stp['fmt'],
3948 '--binary=' + stp['bin'],
3949 '--target-name=' + target_name,
3950 '--target-type=' + target_type,
3951 '--probe-prefix=qemu.' + target_type + '.' + target_name,
c05012a3 3952 '@INPUT@', '@OUTPUT@'
0572d6cd
SH
3953 ],
3954 depend_files: tracetool_depends)
10e1d263
MAL
3955 endforeach
3956 endif
64ed6f92 3957 endforeach
2becc36a
PB
3958endforeach
3959
931049b4 3960# Other build targets
897b5afa 3961
2c13c574 3962if get_option('plugins')
f556b4a1 3963 install_headers('include/qemu/qemu-plugin.h')
36fa0773
GM
3964 if targetos == 'windows'
3965 # On windows, we want to deliver the qemu_plugin_api.lib file in the qemu installer,
3966 # so that plugin authors can compile against it.
3967 install_data(win32_qemu_plugin_api_lib, install_dir: 'lib')
3968 endif
f556b4a1
PB
3969endif
3970
20cf5cb4 3971subdir('qga')
f15bff25 3972
9755c94a
LV
3973# Don't build qemu-keymap if xkbcommon is not explicitly enabled
3974# when we don't build tools or system
4113f4cf 3975if xkbcommon.found()
28742467
MAL
3976 # used for the update-keymaps target, so include rules even if !have_tools
3977 qemu_keymap = executable('qemu-keymap', files('qemu-keymap.c', 'ui/input-keymap.c') + genh,
3978 dependencies: [qemuutil, xkbcommon], install: have_tools)
3979endif
3980
931049b4 3981if have_tools
b7c70bf2
MAL
3982 qemu_img = executable('qemu-img', [files('qemu-img.c'), hxdep],
3983 dependencies: [authz, block, crypto, io, qom, qemuutil], install: true)
3984 qemu_io = executable('qemu-io', files('qemu-io.c'),
3985 dependencies: [block, qemuutil], install: true)
eb705985 3986 qemu_nbd = executable('qemu-nbd', files('qemu-nbd.c'),
3d212b41
RJ
3987 dependencies: [blockdev, qemuutil, gnutls, selinux],
3988 install: true)
b7c70bf2 3989
7c58bb76 3990 subdir('storage-daemon')
a9c9727c 3991 subdir('contrib/rdmacm-mux')
1d7bb6ab 3992 subdir('contrib/elf2dmp')
a9c9727c 3993
157e7b13
MAL
3994 executable('qemu-edid', files('qemu-edid.c', 'hw/display/edid-generate.c'),
3995 dependencies: qemuutil,
3996 install: true)
3997
2a3129a3 3998 if have_vhost_user
2d7ac0af 3999 subdir('contrib/vhost-user-blk')
b7612f45 4000 subdir('contrib/vhost-user-gpu')
32fcc624 4001 subdir('contrib/vhost-user-input')
99650b62 4002 subdir('contrib/vhost-user-scsi')
931049b4 4003 endif
8f51e01c
MAL
4004
4005 if targetos == 'linux'
4006 executable('qemu-bridge-helper', files('qemu-bridge-helper.c'),
4007 dependencies: [qemuutil, libcap_ng],
4008 install: true,
4009 install_dir: get_option('libexecdir'))
897b5afa
MAL
4010
4011 executable('qemu-pr-helper', files('scsi/qemu-pr-helper.c', 'scsi/utils.c'),
4012 dependencies: [authz, crypto, io, qom, qemuutil,
6ec0e15d 4013 libcap_ng, mpathpersist],
897b5afa 4014 install: true)
8f51e01c
MAL
4015 endif
4016
ccd250aa 4017 if have_ivshmem
5ee24e78
MAL
4018 subdir('contrib/ivshmem-client')
4019 subdir('contrib/ivshmem-server')
4020 endif
931049b4
PB
4021endif
4022
f5aa6320 4023subdir('scripts')
3f99cf57 4024subdir('tools')
bdcbea7a 4025subdir('pc-bios')
f8aa24ea 4026subdir('docs')
e3667660 4027subdir('tests')
1b695471 4028if gtk.found()
e8f3bd71
MAL
4029 subdir('po')
4030endif
3f99cf57 4031
8adfeba9
MAL
4032if host_machine.system() == 'windows'
4033 nsis_cmd = [
4034 find_program('scripts/nsis.py'),
4035 '@OUTPUT@',
4036 get_option('prefix'),
4037 meson.current_source_dir(),
fc9a809e 4038 glib_pc.get_variable('bindir'),
24bdcc96 4039 host_machine.cpu(),
8adfeba9
MAL
4040 '--',
4041 '-DDISPLAYVERSION=' + meson.project_version(),
4042 ]
4043 if build_docs
4044 nsis_cmd += '-DCONFIG_DOCUMENTATION=y'
4045 endif
1b695471 4046 if gtk.found()
8adfeba9
MAL
4047 nsis_cmd += '-DCONFIG_GTK=y'
4048 endif
4049
4050 nsis = custom_target('nsis',
4051 output: 'qemu-setup-' + meson.project_version() + '.exe',
4052 input: files('qemu.nsi'),
4053 build_always_stale: true,
4054 command: nsis_cmd + ['@INPUT@'])
4055 alias_target('installer', nsis)
4056endif
4057
a0c9162c
PB
4058#########################
4059# Configuration summary #
4060#########################
4061
ac4ccac7 4062# Build environment
f9332757 4063summary_info = {}
ac4ccac7
PB
4064summary_info += {'Build directory': meson.current_build_dir()}
4065summary_info += {'Source path': meson.current_source_dir()}
ac4ccac7
PB
4066summary_info += {'Download dependencies': get_option('wrap_mode') != 'nodownload'}
4067summary(summary_info, bool_yn: true, section: 'Build environment')
4068
4069# Directories
16bf7a33
PB
4070summary_info += {'Install prefix': get_option('prefix')}
4071summary_info += {'BIOS directory': qemu_datadir}
8154f5e6
AO
4072pathsep = targetos == 'windows' ? ';' : ':'
4073summary_info += {'firmware path': pathsep.join(get_option('qemu_firmwarepath'))}
f7fb6c6a
PB
4074summary_info += {'binary directory': get_option('prefix') / get_option('bindir')}
4075summary_info += {'library directory': get_option('prefix') / get_option('libdir')}
16bf7a33 4076summary_info += {'module directory': qemu_moddir}
f7fb6c6a
PB
4077summary_info += {'libexec directory': get_option('prefix') / get_option('libexecdir')}
4078summary_info += {'include directory': get_option('prefix') / get_option('includedir')}
4079summary_info += {'config directory': get_option('prefix') / get_option('sysconfdir')}
f9332757 4080if targetos != 'windows'
f7fb6c6a
PB
4081 summary_info += {'local state directory': get_option('prefix') / get_option('localstatedir')}
4082 summary_info += {'Manual directory': get_option('prefix') / get_option('mandir')}
f9332757
PB
4083else
4084 summary_info += {'local state directory': 'queried at runtime'}
4085endif
f7fb6c6a 4086summary_info += {'Doc directory': get_option('prefix') / get_option('docdir')}
983d0a75
PMD
4087summary(summary_info, bool_yn: true, section: 'Directories')
4088
e11a0e17
PMD
4089# Host binaries
4090summary_info = {}
e11a0e17 4091summary_info += {'python': '@0@ (version: @1@)'.format(python.full_path(), python.language_version())}
bb647c49 4092summary_info += {'sphinx-build': sphinx_build}
b4d61d3d
PB
4093
4094# FIXME: the [binaries] section of machine files, which can be probed
4095# with find_program(), would be great for passing gdb and genisoimage
4096# paths from configure to Meson. However, there seems to be no way to
4097# hide a program (for example if gdb is too old).
a47dd5c5
PB
4098if config_host.has_key('GDB')
4099 summary_info += {'gdb': config_host['GDB']}
e11a0e17 4100endif
40c909f5 4101summary_info += {'iasl': iasl}
e11a0e17 4102summary_info += {'genisoimage': config_host['GENISOIMAGE']}
20cf5cb4 4103if targetos == 'windows' and have_ga
bb647c49 4104 summary_info += {'wixl': wixl}
e11a0e17 4105endif
5890258a 4106if slirp.found() and have_system
35acbb30 4107 summary_info += {'smbd': have_slirp_smbd ? smbd_path : false}
e11a0e17
PMD
4108endif
4109summary(summary_info, bool_yn: true, section: 'Host binaries')
4110
1d718865
PMD
4111# Configurable features
4112summary_info = {}
4113summary_info += {'Documentation': build_docs}
aa3ca634
PMD
4114summary_info += {'system-mode emulation': have_system}
4115summary_info += {'user-mode emulation': have_user}
813803aa 4116summary_info += {'block layer': have_block}
1d718865 4117summary_info += {'Install blobs': get_option('install_blobs')}
6002711c
PB
4118summary_info += {'module support': enable_modules}
4119if enable_modules
2cb2f580 4120 summary_info += {'alternative module path': get_option('module_upgrades')}
1d718865 4121endif
537b7248 4122summary_info += {'fuzzing support': get_option('fuzzing')}
1d718865 4123if have_system
87430d5b 4124 summary_info += {'Audio drivers': ' '.join(audio_drivers_selected)}
1d718865 4125endif
9c29b741
PB
4126summary_info += {'Trace backends': ','.join(get_option('trace_backends'))}
4127if 'simple' in get_option('trace_backends')
4128 summary_info += {'Trace output file': get_option('trace_file') + '-<pid>'}
1d718865 4129endif
142ca628 4130summary_info += {'D-Bus display': dbus_display}
c55cf6ab 4131summary_info += {'QOM debugging': get_option('qom_cast_debug')}
655e2a77 4132summary_info += {'Relocatable install': get_option('relocatable')}
2a3129a3
PB
4133summary_info += {'vhost-kernel support': have_vhost_kernel}
4134summary_info += {'vhost-net support': have_vhost_net}
4135summary_info += {'vhost-user support': have_vhost_user}
4136summary_info += {'vhost-user-crypto support': have_vhost_user_crypto}
1d718865 4137summary_info += {'vhost-user-blk server support': have_vhost_user_blk_server}
2a3129a3 4138summary_info += {'vhost-vdpa support': have_vhost_vdpa}
20cf5cb4 4139summary_info += {'build guest agent': have_ga}
1d718865
PMD
4140summary(summary_info, bool_yn: true, section: 'Configurable features')
4141
2e864b8b 4142# Compilation information
983d0a75 4143summary_info = {}
2e864b8b
PMD
4144summary_info += {'host CPU': cpu}
4145summary_info += {'host endianness': build_machine.endian()}
63de9353
AB
4146summary_info += {'C compiler': ' '.join(meson.get_compiler('c').cmd_array())}
4147summary_info += {'Host C compiler': ' '.join(meson.get_compiler('c', native: true).cmd_array())}
785abf0d 4148if 'cpp' in all_languages
63de9353 4149 summary_info += {'C++ compiler': ' '.join(meson.get_compiler('cpp').cmd_array())}
f9332757
PB
4150else
4151 summary_info += {'C++ compiler': false}
4152endif
da6f5544 4153if 'objc' in all_languages
63de9353 4154 summary_info += {'Objective-C compiler': ' '.join(meson.get_compiler('objc').cmd_array())}
da6f5544
PMD
4155else
4156 summary_info += {'Objective-C compiler': false}
f9332757 4157endif
6a97f393
PB
4158option_cflags = (get_option('debug') ? ['-g'] : [])
4159if get_option('optimization') != 'plain'
4160 option_cflags += ['-O' + get_option('optimization')]
4161endif
4162summary_info += {'CFLAGS': ' '.join(get_option('c_args') + option_cflags)}
785abf0d 4163if 'cpp' in all_languages
6a97f393 4164 summary_info += {'CXXFLAGS': ' '.join(get_option('cpp_args') + option_cflags)}
47b30835 4165endif
da6f5544 4166if 'objc' in all_languages
6a97f393 4167 summary_info += {'OBJCFLAGS': ' '.join(get_option('objc_args') + option_cflags)}
e910c7d9 4168endif
785abf0d 4169link_args = get_option('c_link_args')
47b30835
PB
4170if link_args.length() > 0
4171 summary_info += {'LDFLAGS': ' '.join(link_args)}
4172endif
d67212d4 4173summary_info += {'QEMU_CFLAGS': ' '.join(qemu_common_flags + qemu_cflags)}
e5134024 4174if 'cpp' in all_languages
d67212d4 4175 summary_info += {'QEMU_CXXFLAGS': ' '.join(qemu_common_flags + qemu_cxxflags)}
e5134024
PB
4176endif
4177if 'objc' in all_languages
95caf1fb 4178 summary_info += {'QEMU_OBJCFLAGS': ' '.join(qemu_common_flags)}
e5134024 4179endif
d065177e 4180summary_info += {'QEMU_LDFLAGS': ' '.join(qemu_ldflags)}
cdad781d 4181summary_info += {'link-time optimization (LTO)': get_option('b_lto')}
2e864b8b 4182summary_info += {'PIE': get_option('b_pie')}
e58e55dd 4183summary_info += {'static build': get_option('prefer_static')}
2e864b8b 4184summary_info += {'malloc trim support': has_malloc_trim}
b87df904 4185summary_info += {'membarrier': have_membarrier}
58a2e3f5 4186summary_info += {'debug graph lock': get_option('debug_graph_lock')}
728c0a2f 4187summary_info += {'debug stack usage': get_option('debug_stack_usage')}
c55cf6ab 4188summary_info += {'mutex debugging': get_option('debug_mutex')}
2e864b8b 4189summary_info += {'memory allocator': get_option('malloc')}
622753d2 4190summary_info += {'avx2 optimization': config_host_data.get('CONFIG_AVX2_OPT')}
04ffce13 4191summary_info += {'avx512bw optimization': config_host_data.get('CONFIG_AVX512BW_OPT')}
622753d2 4192summary_info += {'avx512f optimization': config_host_data.get('CONFIG_AVX512F_OPT')}
2e864b8b 4193summary_info += {'gcov': get_option('b_coverage')}
34f983d8 4194summary_info += {'thread sanitizer': get_option('tsan')}
2e864b8b
PMD
4195summary_info += {'CFI support': get_option('cfi')}
4196if get_option('cfi')
4197 summary_info += {'CFI debug support': get_option('cfi_debug')}
4198endif
4199summary_info += {'strip binaries': get_option('strip')}
bb647c49 4200summary_info += {'sparse': sparse}
2e864b8b 4201summary_info += {'mingw32 support': targetos == 'windows'}
12640f05 4202summary(summary_info, bool_yn: true, section: 'Compilation')
49e8565b
AB
4203
4204# snarf the cross-compilation information for tests
12640f05
PB
4205summary_info = {}
4206have_cross = false
49e8565b 4207foreach target: target_dirs
c7022a70 4208 tcg_mak = meson.current_build_dir() / 'tests/tcg' / target / 'config-target.mak'
49e8565b
AB
4209 if fs.exists(tcg_mak)
4210 config_cross_tcg = keyval.load(tcg_mak)
85b141ea 4211 if 'CC' in config_cross_tcg
12640f05
PB
4212 summary_info += {config_cross_tcg['TARGET_NAME']: config_cross_tcg['CC']}
4213 have_cross = true
49e8565b 4214 endif
12640f05 4215 endif
49e8565b 4216endforeach
12640f05
PB
4217if have_cross
4218 summary(summary_info, bool_yn: true, section: 'Cross compilers')
4219endif
2e864b8b 4220
aa3ca634 4221# Targets and accelerators
2e864b8b 4222summary_info = {}
aa3ca634
PMD
4223if have_system
4224 summary_info += {'KVM support': config_all.has_key('CONFIG_KVM')}
aa3ca634
PMD
4225 summary_info += {'HVF support': config_all.has_key('CONFIG_HVF')}
4226 summary_info += {'WHPX support': config_all.has_key('CONFIG_WHPX')}
74a414a1 4227 summary_info += {'NVMM support': config_all.has_key('CONFIG_NVMM')}
14efd8d3
PB
4228 summary_info += {'Xen support': xen.found()}
4229 if xen.found()
4230 summary_info += {'xen ctrl version': xen.version()}
aa3ca634 4231 endif
820c1aba 4232 summary_info += {'Xen emulation': config_all.has_key('CONFIG_XEN_EMU')}
aa3ca634
PMD
4233endif
4234summary_info += {'TCG support': config_all.has_key('CONFIG_TCG')}
4235if config_all.has_key('CONFIG_TCG')
39687aca 4236 if get_option('tcg_interpreter')
f1f727ac 4237 summary_info += {'TCG backend': 'TCI (TCG with bytecode interpreter, slow)'}
39687aca
PMD
4238 else
4239 summary_info += {'TCG backend': 'native (@0@)'.format(cpu)}
4240 endif
2c13c574 4241 summary_info += {'TCG plugins': get_option('plugins')}
1d558c90 4242 summary_info += {'TCG debug enabled': get_option('debug_tcg')}
aa3ca634 4243endif
2e864b8b 4244summary_info += {'target list': ' '.join(target_dirs)}
aa3ca634
PMD
4245if have_system
4246 summary_info += {'default devices': get_option('default_devices')}
106ad1f9 4247 summary_info += {'out of process emulation': multiprocess_allowed}
55116968 4248 summary_info += {'vfio-user server': vfio_user_server_allowed}
aa3ca634
PMD
4249endif
4250summary(summary_info, bool_yn: true, section: 'Targets and accelerators')
4251
813803aa
PMD
4252# Block layer
4253summary_info = {}
6739825a 4254summary_info += {'coroutine backend': coroutine_backend}
728c0a2f 4255summary_info += {'coroutine pool': have_coroutine_pool}
813803aa 4256if have_block
622d64ff
PB
4257 summary_info += {'Block whitelist (rw)': get_option('block_drv_rw_whitelist')}
4258 summary_info += {'Block whitelist (ro)': get_option('block_drv_ro_whitelist')}
c55cf6ab 4259 summary_info += {'Use block whitelist in tools': get_option('block_drv_whitelist_in_tools')}
3887702e 4260 summary_info += {'VirtFS (9P) support': have_virtfs}
71d72ece 4261 summary_info += {'VirtFS (9P) Proxy Helper support (deprecated)': have_virtfs_proxy_helper}
406523f6
PB
4262 summary_info += {'Live block migration': config_host_data.get('CONFIG_LIVE_BLOCK_MIGRATION')}
4263 summary_info += {'replication support': config_host_data.get('CONFIG_REPLICATION')}
ed793c2c
PB
4264 summary_info += {'bochs support': get_option('bochs').allowed()}
4265 summary_info += {'cloop support': get_option('cloop').allowed()}
4266 summary_info += {'dmg support': get_option('dmg').allowed()}
4267 summary_info += {'qcow v1 support': get_option('qcow1').allowed()}
4268 summary_info += {'vdi support': get_option('vdi').allowed()}
11cea42e
VSO
4269 summary_info += {'vhdx support': get_option('vhdx').allowed()}
4270 summary_info += {'vmdk support': get_option('vmdk').allowed()}
4271 summary_info += {'vpc support': get_option('vpc').allowed()}
ed793c2c
PB
4272 summary_info += {'vvfat support': get_option('vvfat').allowed()}
4273 summary_info += {'qed support': get_option('qed').allowed()}
4274 summary_info += {'parallels support': get_option('parallels').allowed()}
bb647c49 4275 summary_info += {'FUSE exports': fuse}
2a2359b8 4276 summary_info += {'VDUSE block exports': have_vduse_blk_export}
813803aa
PMD
4277endif
4278summary(summary_info, bool_yn: true, section: 'Block layer support')
4279
aa58028a 4280# Crypto
aa3ca634 4281summary_info = {}
41f2ae28 4282summary_info += {'TLS priority': get_option('tls_priority')}
bb647c49
PB
4283summary_info += {'GNUTLS support': gnutls}
4284if gnutls.found()
4285 summary_info += {' GNUTLS crypto': gnutls_crypto.found()}
4286endif
4287summary_info += {'libgcrypt': gcrypt}
4288summary_info += {'nettle': nettle}
57612511
PB
4289if nettle.found()
4290 summary_info += {' XTS': xts != 'private'}
f9332757 4291endif
34b52615 4292summary_info += {'AF_ALG support': have_afalg}
c55cf6ab 4293summary_info += {'rng-none': get_option('rng_none')}
2edd2c04 4294summary_info += {'Linux keyring': have_keyring}
c64023b0 4295summary_info += {'Linux keyutils': keyutils}
aa58028a
PMD
4296summary(summary_info, bool_yn: true, section: 'Crypto')
4297
9e48afa3 4298# UI
aa58028a
PMD
4299summary_info = {}
4300if targetos == 'darwin'
e2c1d78d 4301 summary_info += {'Cocoa support': cocoa}
bb647c49
PB
4302endif
4303summary_info += {'SDL support': sdl}
4304summary_info += {'SDL image support': sdl_image}
4305summary_info += {'GTK support': gtk}
4306summary_info += {'pixman': pixman}
4307summary_info += {'VTE support': vte}
95f8510e 4308summary_info += {'PNG support': png}
bb647c49 4309summary_info += {'VNC support': vnc}
a0b93237 4310if vnc.found()
bb647c49
PB
4311 summary_info += {'VNC SASL support': sasl}
4312 summary_info += {'VNC JPEG support': jpeg}
f9332757 4313endif
9e48afa3
TH
4314summary_info += {'spice protocol support': spice_protocol}
4315if spice_protocol.found()
4316 summary_info += {' spice server support': spice}
4317endif
4318summary_info += {'curses support': curses}
4319summary_info += {'brlapi support': brlapi}
4320summary(summary_info, bool_yn: true, section: 'User interface')
4321
aece7238
TH
4322# Audio backends
4323summary_info = {}
87430d5b
PB
4324if targetos not in ['darwin', 'haiku', 'windows']
4325 summary_info += {'OSS support': oss}
663df1cc 4326 summary_info += {'sndio support': sndio}
87430d5b
PB
4327elif targetos == 'darwin'
4328 summary_info += {'CoreAudio support': coreaudio}
4329elif targetos == 'windows'
4330 summary_info += {'DirectSound support': dsound}
4331endif
4332if targetos == 'linux'
4333 summary_info += {'ALSA support': alsa}
4334 summary_info += {'PulseAudio support': pulse}
4335endif
20c51248 4336summary_info += {'PipeWire support': pipewire}
87430d5b 4337summary_info += {'JACK support': jack}
aece7238
TH
4338summary(summary_info, bool_yn: true, section: 'Audio backends')
4339
c3527c5e 4340# Network backends
9e48afa3
TH
4341summary_info = {}
4342if targetos == 'darwin'
4343 summary_info += {'vmnet.framework support': vmnet}
4344endif
cb039ef3 4345summary_info += {'AF_XDP support': libxdp}
5890258a 4346summary_info += {'slirp support': slirp}
e1723999 4347summary_info += {'vde support': vde}
837b84b1 4348summary_info += {'netmap support': have_netmap}
eea9453a 4349summary_info += {'l2tpv3 support': have_l2tpv3}
c3527c5e
TH
4350summary(summary_info, bool_yn: true, section: 'Network backends')
4351
4352# Libraries
4353summary_info = {}
bb647c49
PB
4354summary_info += {'libtasn1': tasn1}
4355summary_info += {'PAM': pam}
4356summary_info += {'iconv support': iconv}
bb647c49 4357summary_info += {'virgl support': virgl}
cd9adbef 4358summary_info += {'rutabaga support': rutabaga}
fd66dbd4 4359summary_info += {'blkio support': blkio}
bb647c49
PB
4360summary_info += {'curl support': curl}
4361summary_info += {'Multipath support': mpathpersist}
ff66f3e5 4362summary_info += {'Linux AIO support': libaio}
bb647c49
PB
4363summary_info += {'Linux io_uring support': linux_io_uring}
4364summary_info += {'ATTR/XATTR support': libattr}
3730a734
PB
4365summary_info += {'RDMA support': rdma}
4366summary_info += {'PVRDMA support': have_pvrdma}
fbb4121d 4367summary_info += {'fdt support': fdt_opt == 'disabled' ? false : fdt_opt}
bb647c49
PB
4368summary_info += {'libcap-ng support': libcap_ng}
4369summary_info += {'bpf support': libbpf}
bb647c49 4370summary_info += {'rbd support': rbd}
bb647c49
PB
4371summary_info += {'smartcard support': cacard}
4372summary_info += {'U2F support': u2f}
4373summary_info += {'libusb': libusb}
4374summary_info += {'usb net redir': usbredir}
88b6e618 4375summary_info += {'OpenGL support (epoxy)': opengl}
bb647c49
PB
4376summary_info += {'GBM': gbm}
4377summary_info += {'libiscsi support': libiscsi}
4378summary_info += {'libnfs support': libnfs}
f9332757 4379if targetos == 'windows'
20cf5cb4 4380 if have_ga
8821a389 4381 summary_info += {'QGA VSS support': have_qga_vss}
b846ab7c 4382 endif
f9332757 4383endif
bb647c49
PB
4384summary_info += {'seccomp support': seccomp}
4385summary_info += {'GlusterFS support': glusterfs}
0d9e8c0b 4386summary_info += {'hv-balloon support': hv_balloon}
0d04c4c9 4387summary_info += {'TPM support': have_tpm}
e6a52b36 4388summary_info += {'libssh support': libssh}
bb647c49
PB
4389summary_info += {'lzo support': lzo}
4390summary_info += {'snappy support': snappy}
4391summary_info += {'bzip2 support': libbzip2}
4392summary_info += {'lzfse support': liblzfse}
4393summary_info += {'zstd support': zstd}
488a8c73 4394summary_info += {'NUMA host support': numa}
83602083 4395summary_info += {'capstone': capstone}
bb647c49
PB
4396summary_info += {'libpmem support': libpmem}
4397summary_info += {'libdaxctl support': libdaxctl}
4398summary_info += {'libudev': libudev}
4399# Dummy dependency, keep .found()
df4ea709 4400summary_info += {'FUSE lseek': fuse_lseek.found()}
3d212b41 4401summary_info += {'selinux': selinux}
7c10cb38 4402summary_info += {'libdw': libdw}
69a78cce 4403summary(summary_info, bool_yn: true, section: 'Dependencies')
f9332757 4404
a24f15d2 4405if host_arch == 'unknown'
f9332757 4406 message()
a24f15d2 4407 warning('UNSUPPORTED HOST CPU')
f9332757 4408 message()
a24f15d2
PB
4409 message('Support for CPU host architecture ' + cpu + ' is not currently')
4410 message('maintained. The QEMU project does not guarantee that QEMU will')
4411 message('compile or work on this host CPU. You can help by volunteering')
4412 message('to maintain it and providing a build host for our continuous')
4413 message('integration setup.')
4414 if get_option('tcg').allowed() and target_dirs.length() > 0
4415 message()
4416 message('configure has succeeded and you can continue to build, but')
4417 message('QEMU will use a slow interpreter to emulate the target CPU.')
4418 endif
f9332757
PB
4419endif
4420
4421if not supported_oses.contains(targetos)
4422 message()
a24f15d2 4423 warning('UNSUPPORTED HOST OS')
f9332757 4424 message()
a24f15d2 4425 message('Support for host OS ' + targetos + 'is not currently maintained.')
f9332757 4426 message('configure has succeeded and you can continue to build, but')
a24f15d2
PB
4427 message('the QEMU project does not guarantee that QEMU will compile or')
4428 message('work on this operating system. You can help by volunteering')
4429 message('to maintain it and providing a build host for our continuous')
4430 message('integration setup. This will ensure that future versions of QEMU')
4431 message('will keep working on ' + targetos + '.')
4432endif
4433
4434if host_arch == 'unknown' or not supported_oses.contains(targetos)
4435 message()
4436 message('If you want to help supporting QEMU on this platform, please')
4437 message('contact the developers at qemu-devel@nongnu.org.')
f9332757 4438endif
655e2a77
PB
4439
4440actually_reloc = get_option('relocatable')
4441# check if get_relocated_path() is actually able to relocate paths
4442if get_option('relocatable') and \
4443 not (get_option('prefix') / get_option('bindir')).startswith(get_option('prefix') / '')
4444 message()
4445 warning('bindir not included within prefix, the installation will not be relocatable.')
4446 actually_reloc = false
4447endif
4448if not actually_reloc and (targetos == 'windows' or get_option('relocatable'))
4449 if targetos == 'windows'
4450 message()
4451 warning('Windows installs should usually be relocatable.')
4452 endif
4453 message()
4454 message('QEMU will have to be installed under ' + get_option('prefix') + '.')
4455 message('Use --disable-relocatable to remove this warning.')
4456endif