meson: use prefer_static option

The option is new in Meson 0.63 and removes the need to pass "static:
true" to all dependency and find_library invocation.  Actually cleaning
up the invocations is left for a separate patch.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2022-07-14 14:33:49 +02:00
parent 3b087f79a4
commit a0cbd2e849
4 changed files with 8 additions and 14 deletions

4
configure vendored
View File

@ -2409,9 +2409,6 @@ fi
if test "$solaris" = "yes" ; then if test "$solaris" = "yes" ; then
echo "CONFIG_SOLARIS=y" >> $config_host_mak echo "CONFIG_SOLARIS=y" >> $config_host_mak
fi fi
if test "$static" = "yes" ; then
echo "CONFIG_STATIC=y" >> $config_host_mak
fi
echo "SRC_PATH=$source_path" >> $config_host_mak echo "SRC_PATH=$source_path" >> $config_host_mak
echo "TARGET_DIRS=$target_list" >> $config_host_mak echo "TARGET_DIRS=$target_list" >> $config_host_mak
if test "$modules" = "yes"; then if test "$modules" = "yes"; then
@ -2654,6 +2651,7 @@ if test "$skip_meson" = no; then
# Built-in options # Built-in options
test "$bindir" != "bin" && meson_option_add "-Dbindir=$bindir" test "$bindir" != "bin" && meson_option_add "-Dbindir=$bindir"
test "$default_feature" = no && meson_option_add -Dauto_features=disabled test "$default_feature" = no && meson_option_add -Dauto_features=disabled
test "$static" = yes && meson_option_add -Dprefer_static=true
test "$pie" = no && meson_option_add -Db_pie=false test "$pie" = no && meson_option_add -Db_pie=false
test "$werror" = yes && meson_option_add -Dwerror=true test "$werror" = yes && meson_option_add -Dwerror=true

View File

@ -311,8 +311,7 @@ dependency will be used::
sdl_image = not_found sdl_image = not_found
if not get_option('sdl_image').auto() or have_system if not get_option('sdl_image').auto() or have_system
sdl_image = dependency('SDL2_image', required: get_option('sdl_image'), sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
method: 'pkg-config', method: 'pkg-config')
static: enable_static)
endif endif
This avoids warnings on static builds of user-mode emulators, for example. This avoids warnings on static builds of user-mode emulators, for example.

View File

@ -18,10 +18,7 @@ targetos = host_machine.system()
sh = find_program('sh') sh = find_program('sh')
config_host = keyval.load(meson.current_build_dir() / 'config-host.mak') config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
enable_modules = 'CONFIG_MODULES' in config_host enable_modules = 'CONFIG_MODULES' in config_host
enable_static = 'CONFIG_STATIC' in config_host static_kwargs = {}
# Allow both shared and static libraries unless --enable-static
static_kwargs = enable_static ? {'static': true} : {}
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
all_languages = ['c'] all_languages = ['c']
@ -193,7 +190,7 @@ qemu_cflags = config_host['QEMU_CFLAGS'].split()
qemu_objcflags = config_host['QEMU_OBJCFLAGS'].split() qemu_objcflags = config_host['QEMU_OBJCFLAGS'].split()
qemu_ldflags = config_host['QEMU_LDFLAGS'].split() qemu_ldflags = config_host['QEMU_LDFLAGS'].split()
if enable_static if get_option('prefer_static')
qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static' qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static'
endif endif
@ -841,7 +838,7 @@ if targetos == 'linux' and have_tools and get_option('mpath').allowed()
kwargs: static_kwargs) kwargs: static_kwargs)
if libmpathpersist.found() if libmpathpersist.found()
mpathlibs += libmpathpersist mpathlibs += libmpathpersist
if enable_static if get_option('prefer_static')
mpathlibs += cc.find_library('devmapper', mpathlibs += cc.find_library('devmapper',
required: get_option('mpath'), required: get_option('mpath'),
kwargs: static_kwargs) kwargs: static_kwargs)
@ -1225,7 +1222,7 @@ if not gnutls_crypto.found()
# Debian has removed -lgpg-error from libgcrypt-config # Debian has removed -lgpg-error from libgcrypt-config
# as it "spreads unnecessary dependencies" which in # as it "spreads unnecessary dependencies" which in
# turn breaks static builds... # turn breaks static builds...
if gcrypt.found() and enable_static if gcrypt.found() and get_option('prefer_static')
gcrypt = declare_dependency(dependencies: [ gcrypt = declare_dependency(dependencies: [
gcrypt, gcrypt,
cc.find_library('gpg-error', required: true, kwargs: static_kwargs)]) cc.find_library('gpg-error', required: true, kwargs: static_kwargs)])
@ -1657,7 +1654,7 @@ endif
# libdw # libdw
libdw = not_found libdw = not_found
if not get_option('libdw').auto() or \ if not get_option('libdw').auto() or \
(not enable_static and (have_system or have_user)) (not get_option('prefer_static') and (have_system or have_user))
libdw = dependency('libdw', libdw = dependency('libdw',
method: 'pkg-config', method: 'pkg-config',
kwargs: static_kwargs, kwargs: static_kwargs,

View File

@ -22,7 +22,7 @@ have_qga_vss = get_option('qga_vss') \
Then run configure with: --extra-cxxflags="-isystem /path/to/vss/inc/win2003"''') \ Then run configure with: --extra-cxxflags="-isystem /path/to/vss/inc/win2003"''') \
.require(midl.found() or widl.found(), .require(midl.found() or widl.found(),
error_message: 'VSS support requires midl or widl') \ error_message: 'VSS support requires midl or widl') \
.require(not enable_static, .require(not get_option('prefer_static'),
error_message: 'VSS support requires dynamic linking with GLib') \ error_message: 'VSS support requires dynamic linking with GLib') \
.allowed() .allowed()