dependency()
Finds an external dependency (usually a library installed on your
system) with the given name with pkg-config and with
CMake if pkg-config fails. Additionally,
frameworks (OSX only) and library-specific fallback detection
logic
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.
- Since 0.64.0 a dependency fallback can be provided by WrapDB. Simply download
the database locally using
meson wrap update-dbcommand and Meson will automatically fallback to subprojects provided by WrapDB if the dependency is not found on the system and the project does not ship their own.wrapfile.
Dependencies can also be resolved in two other ways:
-
if the same name was used in a
meson.override_dependencyprior to the call todependency, the overriding dependency will be returned unconditionally; that is, the overriding dependency will be used independent of whether an external dependency is installed in the system. Typically,meson.override_dependencywill have been used by a subproject. -
by a fallback subproject which, if needed, will be brought into the current build specification as if
subproject()had been called. The subproject can be specified with thefallbackargument. Alternatively, if thefallbackargument is absent, since 0.55.0 Meson can automatically identify a subproject as a fallback if a wrap file provides the dependency, or if a subproject has the same name as the dependency. In the latter case, the subproject must usemeson.override_dependencyto specify the replacement, or Meson will report a hard error. See the Wrap documentation for more details. This automatic search can be controlled using theallow_fallbackkeyword argument.
If dependency_name is '', the dependency is always not found. So
with required: false, this always returns a dependency object for
which the found() method returns false, and which can be passed
like any other dependency to the dependencies: keyword argument of a
build_target. This can be used to implement a dependency which is
sometimes not required e.g. in some branches of a conditional, or with
a fallback: kwarg, can be used to declare an optional dependency
that only looks in the specified subproject, and only if that's
allowed by --wrap-mode.
The returned object dep also has additional methods.
Signature
# Finds an external dependency (usually a library installed on your
dep dependency(
str names..., # The names of the dependency to look up
# Keyword arguments:
allow_fallback : bool # Specifies whether Meson should automatically pick a fallback subproject
default_options : array[str] | dict[str | bool | int | array[str]] # An array of default option values
disabler : bool # Returns a disabler() object instead of a not-found dependency
fallback : array[str] | str # Manually specifies a subproject fallback
include_type : str # An enum flag, marking how the dependency
language : str # Defines what language-specific dependency to find
method : str # Defines the way the dependency is detected, the default is
native : bool # If set to `true`, causes Meson to find the dependency on
not_found_message : str # An optional string that will be printed as a message() if the dependency was not found.
required : bool | feature # When set to `false`, Meson will proceed with the build
static : bool # Tells the dependency provider to try to get static
version : array[str] | str # Specifies the required version,
)
Arguments
The
function accepts between 1 and infinity variadic
arguments (names...) of type .str
The names of the dependency to look up. The dependencies are looked up in
the order they are provided here. The first found dependency will then 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.
NOTE: Before 0.60.0 only a single dependency name was allowed.
(since 0.60.0)
The function dependency()
accepts the following keyword arguments:
| Name | Type | Description | Tags |
|---|---|---|---|
allow_fallback |
bool |
Specifies whether Meson should automatically pick a fallback subproject
in case the dependency
is not found in the system. If |
(since 0.56.0) |
default_options |
array[str] | dict[str | bool | int | array[str]] |
An array of default option values
that override those set in the subproject's |
(since 0.38.0) |
disabler |
bool |
Returns a |
(since 0.49.0)
|
fallback |
array[str] | str
|
Manually specifies a subproject fallback
to use in case the dependency is not found in the system.
This is useful if the automatic search is not applicable or if you
want to support versions of Meson older than 0.55.0. If the value is an
array |
|
include_type |
str |
An enum flag, marking how the dependency
flags should be converted. Supported values are |
(since 0.52.0)
|
language |
str |
Defines what language-specific dependency to find if it's available for multiple languages. |
(since 0.42.0) |
method |
str |
Defines the way the dependency is detected, the default is
|
(since 0.40.0)
|
native |
bool |
If set to |
|
not_found_message |
str |
An optional string that will be printed as a |
(since 0.50.0) |
required |
bool | feature
|
When set to When set to a (since 0.47.0) The value of a |
|
static |
bool |
Tells the dependency provider to try to get static libraries instead of dynamic ones (note that this is not supported by all dependency backends) Leaving this value unset will result in an implementation defined default
value. For most dependencies this means the value of the Since 0.60.0 it also sets Since 0.63.0 when the |
|
version |
array[str] | str
|
Specifies the required version,
a string containing a
comparison operator followed by the version string, examples include
|
(since 0.37.0) |
The results of the search are