meson: use .require() and .disable_auto_if() method for features

The method is now in 0.59, using it simplifies some conditionals.

There is a small change, which is to build virtfs-proxy-helper in a
tools-only build.  This is done for consistency with other tools,
which are not culled by the absence of system emulator binaries.

.disable_auto_if() would also be useful to check for packages,
for example

-linux_io_uring = not_found
-if not get_option('linux_io_uring').auto() or have_block
-  linux_io_uring = dependency('liburing', required: get_option('linux_io_uring'),
-                              method: 'pkg-config', kwargs: static_kwargs)
-endif
+linux_io_uring = dependency('liburing',
+  required: get_option('linux_io_uring').disable_auto_if(not have_block),
+  method: 'pkg-config', kwargs: static_kwargs)

This change however is much larger and I am not sure about the improved
readability, so I am not performing it right now.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2021-12-18 16:39:43 +01:00
parent 43a363ae35
commit a436d6d412
2 changed files with 37 additions and 68 deletions

View File

@ -269,14 +269,12 @@ if 'syslog' in get_option('trace_backends') and not cc.compiles('''
endif endif
# Miscellaneous Linux-only features # Miscellaneous Linux-only features
if targetos != 'linux' and get_option('mpath').enabled() get_option('mpath') \
error('Multipath is supported only on Linux') .require(targetos == 'linux', error_message: 'Multipath is supported only on Linux')
endif
if targetos != 'linux' and get_option('multiprocess').enabled() multiprocess_allowed = get_option('multiprocess') \
error('Multiprocess QEMU is supported only on Linux') .require(targetos == 'linux', error_message: 'Multiprocess QEMU is supported only on Linux') \
endif .allowed()
multiprocess_allowed = targetos == 'linux' and get_option('multiprocess').allowed()
# Target-specific libraries and flags # Target-specific libraries and flags
libm = cc.find_library('m', required: false) libm = cc.find_library('m', required: false)
@ -1268,19 +1266,13 @@ statx_test = gnu_source_prefix + '''
has_statx = cc.links(statx_test) has_statx = cc.links(statx_test)
have_vhost_user_blk_server = (targetos == 'linux' and have_vhost_user_blk_server = get_option('vhost_user_blk_server') \
'CONFIG_VHOST_USER' in config_host) .require(targetos == 'linux',
error_message: 'vhost_user_blk_server requires linux') \
if get_option('vhost_user_blk_server').enabled() .require('CONFIG_VHOST_USER' in config_host,
if targetos != 'linux' error_message: 'vhost_user_blk_server requires vhost-user support') \
error('vhost_user_blk_server requires linux') .disable_auto_if(not have_system) \
elif 'CONFIG_VHOST_USER' not in config_host .allowed()
error('vhost_user_blk_server requires vhost-user support')
endif
elif get_option('vhost_user_blk_server').disabled() or not have_system
have_vhost_user_blk_server = false
endif
if get_option('fuse').disabled() and get_option('fuse_lseek').enabled() if get_option('fuse').disabled() and get_option('fuse_lseek').enabled()
error('Cannot enable fuse-lseek while fuse is disabled') error('Cannot enable fuse-lseek while fuse is disabled')
@ -1407,36 +1399,26 @@ endif
have_host_block_device = (targetos != 'darwin' or have_host_block_device = (targetos != 'darwin' or
cc.has_header('IOKit/storage/IOMedia.h')) cc.has_header('IOKit/storage/IOMedia.h'))
dbus_display = false # FIXME enable_modules shouldn't be necessary, but: https://github.com/mesonbuild/meson/issues/8333
if not get_option('dbus_display').disabled() dbus_display = get_option('dbus_display') \
# FIXME enable_modules shouldn't be necessary, but: https://github.com/mesonbuild/meson/issues/8333 .require(gio.version().version_compare('>=2.64'),
dbus_display = gio.version().version_compare('>=2.64') and config_host.has_key('GDBUS_CODEGEN') and enable_modules error_message: '-display dbus requires glib>=2.64') \
if get_option('dbus_display').enabled() and not dbus_display .require(enable_modules,
error('Requirements missing to enable -display dbus (glib>=2.64 && --enable-modules)') error_message: '-display dbus requires --enable-modules') \
endif .require(config_host.has_key('GDBUS_CODEGEN'),
endif error_message: '-display dbus requires gdbus-codegen') \
.allowed()
have_virtfs = (targetos == 'linux' and have_virtfs = get_option('virtfs') \
have_system and .require(targetos == 'linux',
libattr.found() and error_message: 'virtio-9p (virtfs) requires Linux') \
libcap_ng.found()) .require(libattr.found() and libcap_ng.found(),
error_message: 'virtio-9p (virtfs) requires libcap-ng-devel and libattr-devel') \
.disable_auto_if(not have_tools and not have_system) \
.allowed()
have_virtfs_proxy_helper = have_virtfs and have_tools have_virtfs_proxy_helper = have_virtfs and have_tools
if get_option('virtfs').enabled()
if not have_virtfs
if targetos != 'linux'
error('virtio-9p (virtfs) requires Linux')
elif not libcap_ng.found() or not libattr.found()
error('virtio-9p (virtfs) requires libcap-ng-devel and libattr-devel')
elif not have_system
error('virtio-9p (virtfs) needs system emulation support')
endif
endif
elif get_option('virtfs').disabled()
have_virtfs = false
endif
foreach k : get_option('trace_backends') foreach k : get_option('trace_backends')
config_host_data.set('CONFIG_TRACE_' + k.to_upper(), true) config_host_data.set('CONFIG_TRACE_' + k.to_upper(), true)
endforeach endforeach

View File

@ -1,25 +1,12 @@
have_virtiofsd = (targetos == 'linux' and have_virtiofsd = get_option('virtiofsd') \
have_tools and .require(targetos == 'linux',
seccomp.found() and error_message: 'virtiofsd requires Linux') \
libcap_ng.found() and .require(seccomp.found() and libcap_ng.found(),
'CONFIG_VHOST_USER' in config_host) error_message: 'virtiofsd requires libcap-ng-devel and seccomp-devel') \
.require('CONFIG_VHOST_USER' in config_host,
if get_option('virtiofsd').enabled() error_message: 'virtiofsd needs vhost-user-support') \
if not have_virtiofsd .disable_auto_if(not have_tools and not have_system) \
if targetos != 'linux' .allowed()
error('virtiofsd requires Linux')
elif not seccomp.found() or not libcap_ng.found()
error('virtiofsd requires libcap-ng-devel and seccomp-devel')
elif 'CONFIG_VHOST_USER' not in config_host
error('virtiofsd needs vhost-user support')
else
# Disabled all the tools but virtiofsd.
have_virtiofsd = true
endif
endif
elif get_option('virtiofsd').disabled() or not have_system
have_virtiofsd = false
endif
if have_virtiofsd if have_virtiofsd
subdir('virtiofsd') subdir('virtiofsd')