aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Reference-manual.md9
-rw-r--r--docs/markdown/snippets/dependency_names.md8
-rw-r--r--mesonbuild/interpreter/interpreter.py6
-rw-r--r--test cases/common/245 dependency fallbacks/meson.build10
-rw-r--r--test cases/common/245 dependency fallbacks/subprojects/png/meson.build3
5 files changed, 33 insertions, 3 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index a91fa3e..0139bec 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -496,7 +496,7 @@ keyword arguments:
### dependency()
``` meson
- dependency_object dependency(*dependency_name*, ...)
+ dependency_object dependency(*name1*, *name2*, ...)
```
Finds an external dependency (usually a library installed on your
@@ -506,6 +506,13 @@ frameworks (OSX only) and [library-specific fallback detection
logic](Dependencies.md#dependencies-with-custom-lookup-functionality)
are also supported.
+*Since 0.60.0* more than one name can be provided, they will be tried in order
+and the first name to be found will be used. The fallback subproject will be
+used only if none of the names are found on the system. Once one of the name has
+been found, all other names are added into the cache so subsequent calls for any
+of those name will return the same value. This is useful in case a dependency
+could have different names, such as `png` and `libpng`.
+
Dependencies can also be resolved in two other ways:
* if the same name was used in a `meson.override_dependency` prior to
diff --git a/docs/markdown/snippets/dependency_names.md b/docs/markdown/snippets/dependency_names.md
new file mode 100644
index 0000000..3ea1019
--- /dev/null
+++ b/docs/markdown/snippets/dependency_names.md
@@ -0,0 +1,8 @@
+## Dependencies with multiple names
+
+More than one name can now be passed to `dependency()`, they will be tried in order
+and the first name to be found will be used. The fallback subproject will be
+used only if none of the names are found on the system. Once one of the name has
+been found, all other names are added into the cache so subsequent calls for any
+of those name will return the same value. This is useful in case a dependency
+could have different names, such as `png` and `libpng`.
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index c5997f2..11f2970 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -1490,10 +1490,12 @@ external dependencies (including libraries) must go to "dependencies".''')
@FeatureNewKwargs('dependency', '0.38.0', ['default_options'])
@disablerIfNotFound
@permittedKwargs(permitted_dependency_kwargs)
- @typed_pos_args('dependency', str)
+ @typed_pos_args('dependency', varargs=str, min_varargs=1)
def func_dependency(self, node, args, kwargs):
# Replace '' by empty list of names
- names = [args[0]] if args[0] else []
+ names = [n for n in args[0] if n]
+ if len(names) > 1:
+ FeatureNew('dependency with more than one name', '0.60.0').use(self.subproject)
allow_fallback = kwargs.get('allow_fallback')
if allow_fallback is not None and not isinstance(allow_fallback, bool):
raise InvalidArguments('"allow_fallback" argument must be boolean')
diff --git a/test cases/common/245 dependency fallbacks/meson.build b/test cases/common/245 dependency fallbacks/meson.build
new file mode 100644
index 0000000..fe5a168
--- /dev/null
+++ b/test cases/common/245 dependency fallbacks/meson.build
@@ -0,0 +1,10 @@
+project('dependency fallbacks', 'c')
+
+# pkg-config has 'libpng' but cmake has 'png' and we have a 'png' subproject
+# for platforms that have neither.
+d = dependency('libpng', 'png', 'foo')
+assert(d.found())
+
+# Check that dependency 'foo' has been implicitly overriden.
+d = dependency('foo')
+assert(d.found())
diff --git a/test cases/common/245 dependency fallbacks/subprojects/png/meson.build b/test cases/common/245 dependency fallbacks/subprojects/png/meson.build
new file mode 100644
index 0000000..5efc60a
--- /dev/null
+++ b/test cases/common/245 dependency fallbacks/subprojects/png/meson.build
@@ -0,0 +1,3 @@
+project('png')
+
+meson.override_dependency('libpng', declare_dependency())