From 726b82205492a9e1f2dfd0fba96b237b51eeb428 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 8 Oct 2020 12:05:51 +0200 Subject: dependency: support boolean argument "allow_fallback" Sometimes, distros want to configure a project so that it does not use any bundled library. In this case, meson.build might want to do something like this, where slirp is a combo option with values auto/system/internal: slirp = dependency('', required: false) if get_option('slirp') != 'internal' slirp = dependency('slirp', required: get_option('slirp') == 'system') endif if not slirp.found() slirp = subproject('libslirp', ...) .variable('...') endif and we cannot use "fallback" because the "system" value should never look for a subproject. This worked until 0.54.x, but in 0.55.x this breaks because of the automatic subproject search. Note that the desired effect here is backwards compared to the policy of doing an automatic search on "required: true"; we only want to do the search if "required" is false! It would be possible to look for the dependency with `required: false` and issue the error manually, but it's ugly and it may produce an error message that looks "different" from Meson's. Instead, with this change it is possible to achieve this effect in an even simpler way: slirp = dependency('slirp', required: get_option('slirp') != 'auto', allow_fallback: get_option('slirp') == 'system' ? false : ['slirp', 'libslirp_dep']) The patch also adds support for "allow_fallback: true", which is simple and enables automatic fallback to a wrap even for non-required dependencies. --- test cases/common/239 dependency allow_fallback/meson.build | 12 ++++++++++++ .../subprojects/foob/meson.build | 2 ++ .../subprojects/foob3/meson.build | 2 ++ 3 files changed, 16 insertions(+) create mode 100644 test cases/common/239 dependency allow_fallback/meson.build create mode 100644 test cases/common/239 dependency allow_fallback/subprojects/foob/meson.build create mode 100644 test cases/common/239 dependency allow_fallback/subprojects/foob3/meson.build (limited to 'test cases/common') diff --git a/test cases/common/239 dependency allow_fallback/meson.build b/test cases/common/239 dependency allow_fallback/meson.build new file mode 100644 index 0000000..b189faf --- /dev/null +++ b/test cases/common/239 dependency allow_fallback/meson.build @@ -0,0 +1,12 @@ +project('subproject fallback', 'c') + +foob_dep = dependency('foob', allow_fallback: true, required: false) +assert(foob_dep.found()) + +# Careful! Once a submodule has been triggered and it has +# overridden the dependency, it sticks. +foob_dep = dependency('foob', allow_fallback: false, required: false) +assert(foob_dep.found()) + +foob3_dep = dependency('foob3', allow_fallback: false, required: false) +assert(not foob3_dep.found()) diff --git a/test cases/common/239 dependency allow_fallback/subprojects/foob/meson.build b/test cases/common/239 dependency allow_fallback/subprojects/foob/meson.build new file mode 100644 index 0000000..b2c4814 --- /dev/null +++ b/test cases/common/239 dependency allow_fallback/subprojects/foob/meson.build @@ -0,0 +1,2 @@ +project('foob', 'c') +meson.override_dependency('foob', declare_dependency()) diff --git a/test cases/common/239 dependency allow_fallback/subprojects/foob3/meson.build b/test cases/common/239 dependency allow_fallback/subprojects/foob3/meson.build new file mode 100644 index 0000000..9fdb188 --- /dev/null +++ b/test cases/common/239 dependency allow_fallback/subprojects/foob3/meson.build @@ -0,0 +1,2 @@ +project('foob3', 'c') +# Note that there is no override_dependency here -- cgit v1.1