diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2019-05-21 21:57:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-21 21:57:05 +0300 |
commit | e9bd7d49bdc8c630cca3bf4cc02c437841b6aaf6 (patch) | |
tree | 3a7c2127d8ca71027248589d5d326c3bb23ace35 /docs/markdown | |
parent | 60f34a1f51d455598143c1c55fd49a5eb1bb1fd6 (diff) | |
parent | 27b6c62ffdf51fed9a55ecfdd4ed47ac2ea79c1e (diff) | |
download | meson-e9bd7d49bdc8c630cca3bf4cc02c437841b6aaf6.zip meson-e9bd7d49bdc8c630cca3bf4cc02c437841b6aaf6.tar.gz meson-e9bd7d49bdc8c630cca3bf4cc02c437841b6aaf6.tar.bz2 |
Merge pull request #5372 from dcbaker/get_variable
Dependency.get_variable method
Diffstat (limited to 'docs/markdown')
-rw-r--r-- | docs/markdown/Dependencies.md | 23 | ||||
-rw-r--r-- | docs/markdown/Reference-manual.md | 8 | ||||
-rw-r--r-- | docs/markdown/snippets/dependency_get_variable_method.md | 17 |
3 files changed, 48 insertions, 0 deletions
diff --git a/docs/markdown/Dependencies.md b/docs/markdown/Dependencies.md index 50dbcf5..0cdd353 100644 --- a/docs/markdown/Dependencies.md +++ b/docs/markdown/Dependencies.md @@ -64,6 +64,29 @@ pkg-config files. Meson has autodetection support for some of these, and they are described [later in this page](#dependencies-with-custom-lookup-functionality). +# Arbitrary variables from dependencies that can be found multiple ways + +*Note* new in 0.51.0 + +When you need to get an arbitrary variables from a dependency that can be +found multiple ways and you don't want to constrain the type you can use +the generic `get_variable` method. This currently supports cmake, pkg-config, +and config-tool based variables. + +```meson +foo_dep = dependency('foo') +var = foo.get_variable(cmake : 'CMAKE_VAR', pkgconfig : 'pkg-config-var', configtool : 'get-var', default_value : 'default') +``` + +It accepts the keywords 'cmake', 'pkgconfig', 'pkgconfig_define', +'configtool', and 'default_value'. 'pkgconfig_define' works just like the +'define_variable' argument to `get_pkgconfig_variable`. When this method is +invoked the keyword corresponding to the underlying type of the dependency +will be used to look for a variable. If that variable cannot be found or if +the caller does not provide an argument for the type of dependency, one of +the following will happen: If 'default_value' was provided that value will be +returned, if 'default_value' was not provided then an error will be raised. + # Declaring your own You can declare your own dependency objects that can be used diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 2fc3d6a..477790b 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -2188,6 +2188,14 @@ an external dependency with the following methods: - includes: any include_directories - sources: any compiled or static sources the dependency has + - `get_variable(cmake : str, pkgconfig : str, configtool : str, + default_value : str, pkgconfig_define : [str, str]) *(Added in 0.51.0)* A + generic variable getter method, which repalces the get_*type*_variable + methods. This allows one to get the variable from a dependency without + knowing specifically how that dependency was found. If default_value is set and + the value cannot be gotten from the object then default_value is returned, + if it is not set then an error is raised. + ### `disabler` object A disabler object is an object that behaves in much the same way as diff --git a/docs/markdown/snippets/dependency_get_variable_method.md b/docs/markdown/snippets/dependency_get_variable_method.md new file mode 100644 index 0000000..aaeac9c --- /dev/null +++ b/docs/markdown/snippets/dependency_get_variable_method.md @@ -0,0 +1,17 @@ +## Dependency objects now have a get_variable method + +This is a generic replacement for type specific variable getters such as +`ConfigToolDependency.get_configtool_variable` and +`PkgConfigDependency.get_pkgconfig_variable`, and is the only way to query +such variables from cmake dependencies. + +This method allows you to get variables without knowing the kind of +dependency you have. + +```meson +dep = dependency('could_be_cmake_or_pkgconfig') +# cmake returns 'YES', pkg-config returns 'ON' +if ['YES', 'ON'].contains(dep.get_variable(pkg-config : 'var-name', cmake : 'COP_VAR_NAME', default_value : 'NO')) + error('Cannot build your project when dep is built with var-name support') +endif +``` |