diff options
author | Corentin Noël <corentin.noel@collabora.com> | 2023-09-17 16:44:26 (GMT) |
---|---|---|
committer | Corentin Noël <corentin.noel@collabora.com> | 2023-09-19 07:08:48 (GMT) |
commit | e0d00b9218bc458ae6cdd5e7ce514c0ba7b4dec4 (patch) | |
tree | 80e715b467497e994d9f2d24ee46e27fdfab0631 /Modules | |
parent | aa6213848d66fa27049754e61a677dfc378e02d6 (diff) | |
download | CMake-e0d00b9218bc458ae6cdd5e7ce514c0ba7b4dec4.zip CMake-e0d00b9218bc458ae6cdd5e7ce514c0ba7b4dec4.tar.gz CMake-e0d00b9218bc458ae6cdd5e7ce514c0ba7b4dec4.tar.bz2 |
FindPkgConfig: Allow to override variables when calling pkg_get_variable
This is specifically useful when building applications within containers as we
sometimes need to redefine the prefix used in a variable.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindPkgConfig.cmake | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 6e8b784..5466e79 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -923,11 +923,20 @@ endmacro() .. code-block:: cmake - pkg_get_variable(<resultVar> <moduleName> <varName>) + pkg_get_variable(<resultVar> <moduleName> <varName> + [DEFINE_VARIABLES <key>=<value>...]) If ``pkg-config`` returns multiple values for the specified variable, ``resultVar`` will contain a :ref:`;-list <CMake Language Lists>`. + Options: + + ``DEFINE_VARIABLES <key>=<value>...`` + .. versionadded:: 3.28 + + Specify key-value pairs to redefine variables affecting the variable + retrieved with ``pkg-config``. + For example: .. code-block:: cmake @@ -935,8 +944,20 @@ endmacro() pkg_get_variable(GI_GIRDIR gobject-introspection-1.0 girdir) #]========================================] function (pkg_get_variable result pkg variable) + set(_multiValueArgs DEFINE_VARIABLES) + + CMAKE_PARSE_ARGUMENTS(_parsedArguments "" "" "${_multiValueArgs}" ${ARGN}) + set(defined_variables ) + foreach(_def_var ${_parsedArguments_DEFINE_VARIABLES}) + if(NOT _def_var MATCHES "^.+=.*$") + message(FATAL_ERROR "DEFINE_VARIABLES should contain arguments in the form of key=value") + endif() + + list(APPEND defined_variables "--define-variable=${_def_var}") + endforeach() + _pkg_set_path_internal() - _pkgconfig_invoke("${pkg}" "prefix" "result" "" "--variable=${variable}") + _pkgconfig_invoke("${pkg}" "prefix" "result" "" "--variable=${variable}" ${defined_variables}) set("${result}" "${prefix_result}" PARENT_SCOPE) |