diff options
author | Kerem Aksu <kerem.aksu@users.noreply.gitlab.kitware.com> | 2024-04-20 17:31:50 (GMT) |
---|---|---|
committer | Kerem Aksu <kerem.aksu@users.noreply.gitlab.kitware.com> | 2024-04-20 18:03:56 (GMT) |
commit | 9ddef32ba0ee22bf26fcc9669d9e7c49df64691a (patch) | |
tree | 9fc8fc8a2d225ef86c6b3710af87aecf7c8b4d21 /Modules | |
parent | 70413d2c3501fe229e9b2d46c745aca5c9f2dc4a (diff) | |
download | CMake-9ddef32ba0ee22bf26fcc9669d9e7c49df64691a.zip CMake-9ddef32ba0ee22bf26fcc9669d9e7c49df64691a.tar.gz CMake-9ddef32ba0ee22bf26fcc9669d9e7c49df64691a.tar.bz2 |
FindPkgConfig: Fix parsing of quoted lists with pkgconf <1.5.1
Unquote pkg-config output if they are printed within quotes. pkgconf
<1.5.1 and classic pkg-config <0.29.1 prints quoted variables without
unquoting them, this breaks returning variables with multiple values
as a list behavior of CMake.
Add a new test case for pkg_get_variable with multiple values to test
list behavior and backslash escaped spaces within variable values.
Fixes: #25904
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindPkgConfig.cmake | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index f3bacc3..450acf4 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -158,6 +158,17 @@ macro(_pkgconfig_invoke _pkglist _prefix _varname _regexp) string(REGEX REPLACE "${_regexp}" " " _pkgconfig_invoke_result "${_pkgconfig_invoke_result}") endif() + # pkg-config <0.29.1 and pkgconf <1.5.1 prints quoted variables without unquoting + # unquote only if quotes are first and last characters + if((PKG_CONFIG_VERSION_STRING VERSION_LESS 0.29.1) OR + (PKG_CONFIG_VERSION_STRING VERSION_GREATER_EQUAL 1.0 AND PKG_CONFIG_VERSION_STRING VERSION_LESS 1.5.1)) + if (_pkgconfig_invoke_result MATCHES "^\"(.*)\"$") + set(_pkgconfig_invoke_result "${CMAKE_MATCH_1}") + elseif(_pkgconfig_invoke_result MATCHES "^'(.*)'$") + set(_pkgconfig_invoke_result "${CMAKE_MATCH_1}") + endif() + endif() + # pkg-config can represent "spaces within an argument" by backslash-escaping the space. # UNIX_COMMAND mode treats backslash-escaped spaces as "not a space that delimits arguments". separate_arguments(_pkgconfig_invoke_result UNIX_COMMAND "${_pkgconfig_invoke_result}") |