meson: autodetect Qt dependencies

Configuring the build directory with meson often fails if you don't have
the right Qt dependencies. As they are used only to build some examples,
it is better to autodetect them and, if present, then build the
examples but skip them otherwise.

Still accept forcing qt=true or qt=false as before.

Note that there is a option type called "feature" whose purpose is to
support exactly this: features with enable/disable/auto possible values:
https://mesonbuild.com/Build-options.html#features.  However, they don't
accept true/false values so scripts using qt=true/false would start
failing. Since meson 0.60 the "deprecated" argument can be used for
options (https://mesonbuild.com/Build-options.html#deprecated-options),
but that's a too new version of meson.

Also, this fixes some Gitlab-CI failures that happen when generating the
tarball with make distcheck or meson dist. This is because it tries to
check that the tarball content can be configured and built, but it uses
the default configurations so it was using qt=yes. Now it will use
qt=auto, avoiding the failure.

Fixes: 61f0531509 ('gitlab-ci: test re-buildability of distribution tarballs')
This commit is contained in:
Íñigo Huguet
2024-03-27 13:04:20 +01:00
committed by Íñigo Huguet
parent d534f984f7
commit f57513097f
2 changed files with 11 additions and 8 deletions

View File

@@ -961,15 +961,18 @@ test(
subdir('examples/C/glib') subdir('examples/C/glib')
enable_qt = get_option('qt') enable_qt = get_option('qt')
if enable_qt if enable_qt != 'false'
qt_core_dep = dependency('QtCore', version: '>= 4', required: enable_qt == 'yes')
qt_dbus_dep = dependency('QtDBus', required: enable_qt == 'yes')
qt_network_dep = dependency('QtNetwork', required: enable_qt == 'yes')
# If enable_qt=='yes' we have all the dependencies. If it's 'auto', skip
# building the Qt examples if any dependency is missing.
if qt_core_dep.found() and qt_dbus_dep.found() and qt_network_dep.found()
add_languages('cpp') add_languages('cpp')
qt_core_dep = dependency('QtCore', version: '>= 4')
qt_dbus_dep = dependency('QtDBus')
qt_network_dep = dependency('QtNetwork')
subdir('examples/C/qt') subdir('examples/C/qt')
endif endif
endif
if enable_docs if enable_docs
assert(enable_introspection, '-Ddocs=true requires -Dintrospection=true') assert(enable_introspection, '-Ddocs=true requires -Dintrospection=true')

View File

@@ -74,5 +74,5 @@ option('valgrind_suppressions', type: 'string', value: '', description: 'Use spe
option('ld_gc', type: 'boolean', value: true, description: 'Enable garbage collection of unused symbols on linking') option('ld_gc', type: 'boolean', value: true, description: 'Enable garbage collection of unused symbols on linking')
option('libpsl', type: 'boolean', value: true, description: 'Link against libpsl') option('libpsl', type: 'boolean', value: true, description: 'Link against libpsl')
option('crypto', type: 'combo', choices: ['nss', 'gnutls', 'null'], value: 'nss', description: 'Cryptography library to use for certificate and key operations') option('crypto', type: 'combo', choices: ['nss', 'gnutls', 'null'], value: 'nss', description: 'Cryptography library to use for certificate and key operations')
option('qt', type: 'boolean', value: true, description: 'enable Qt examples') option('qt', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'enable Qt examples')
option('readline', type: 'combo', choices: ['auto', 'libreadline', 'libedit', 'none'], description: 'Using readline (auto) or libedit)') option('readline', type: 'combo', choices: ['auto', 'libreadline', 'libedit', 'none'], description: 'Using readline (auto) or libedit)')