diff options
author | Christopher Degawa <ccom@randomderp.com> | 2021-06-11 20:17:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-06-18 15:10:12 (GMT) |
commit | 35d3e00e4e9b138dec1d1a646766fc342d04b8f5 (patch) | |
tree | a27895e2748c4ab00ce77d30f2dbb6191ac86027 /Tests/RunCMake/FindPkgConfig | |
parent | 11695f5985e9cbd7a5206908fe6d2ea7e77865e9 (diff) | |
download | CMake-35d3e00e4e9b138dec1d1a646766fc342d04b8f5.zip CMake-35d3e00e4e9b138dec1d1a646766fc342d04b8f5.tar.gz CMake-35d3e00e4e9b138dec1d1a646766fc342d04b8f5.tar.bz2 |
FindPkgConfig: split args if loaded from environment
It's common for some people to use the PKG_CONFIG environment variable
to not only load a custom pkg-config/pkgconf but also to load some
default arguments such as `--static` or `--keep-system-libs` which often
worked since shell scripts would call `$PKG_CONFIG --libs pkg` without
quotes, but this breaks FindPkgConfig since it uses the full string as
`argv[0]` and might try looking for a binary called `pkgconf --static`,
instead of looking for `pkgconf` and adding `--static` as the `argv[1]`
Additionally adds RunCMake.FindPkgConfig ARGN test case
Fixes: #22305
Signed-off-by: Christopher Degawa <ccom@randomderp.com>
Diffstat (limited to 'Tests/RunCMake/FindPkgConfig')
4 files changed, 54 insertions, 0 deletions
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_GET_MATCHING_ARGN.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_GET_MATCHING_ARGN.cmake new file mode 100644 index 0000000..e49ff22 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_GET_MATCHING_ARGN.cmake @@ -0,0 +1,17 @@ +if(WIN32) + set(ENV{PKG_CONFIG} "\"${CMAKE_CURRENT_SOURCE_DIR}\\dummy-pkg-config.bat\" --static --print-errors") +else() + set(ENV{PKG_CONFIG} "\"${CMAKE_CURRENT_SOURCE_DIR}/dummy-pkg-config.sh\" --static --print-errors") +endif() + +find_package(PkgConfig REQUIRED) + +if(NOT PKG_CONFIG_ARGN STREQUAL "--static;--print-errors") + message(SEND_ERROR "PKG_CONFIG_ARGN has wrong value '${PKG_CONFIG_ARGN}'") +endif() + +_pkgconfig_invoke("none" "prefix" "output" "") + +if(NOT prefix_output STREQUAL "Received;--static;Received;--print-errors") + message(SEND_ERROR "prefix_output has wrong value '${prefix_output}'") +endif() diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake index e7f008c..17e046a 100644 --- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake @@ -12,6 +12,7 @@ run_cmake(FindPkgConfig_PKGCONFIG_PATH) run_cmake(FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH) run_cmake(FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH) run_cmake(FindPkgConfig_extract_frameworks) +run_cmake(FindPkgConfig_GET_MATCHING_ARGN) if(APPLE) run_cmake(FindPkgConfig_extract_frameworks_target) diff --git a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat index b038370..c91713b 100755 --- a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat +++ b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat @@ -1,5 +1,10 @@ @ECHO OFF +rem variables to get around `--static --version` printing the received +rem message and then version +set static=false +set print_errors=false + :LOOP IF "%1"=="" ( @@ -21,7 +26,19 @@ IF "%1"=="--exists" ( EXIT /B 0 ) ) +IF "%1"=="--static" ( + set static=true +) +IF "%1"=="--print-errors" ( + set print_errors=true +) SHIFT IF NOT "%~1"=="" GOTO LOOP +IF "%static%"=="true" ECHO Received --static +IF "%print_errors%"=="true" ECHO Received --print-errors + +IF "%static%"=="true" GOTO :EOF +IF "%print_errors%"=="true" GOTO :EOF + EXIT /B 255 diff --git a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh index 56bba30..4021bf7 100755 --- a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh +++ b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh @@ -4,6 +4,11 @@ # to the --exists argument with the PKG_CONFIG_PATH environment variable # and returns 1 if they are different. +# variables to get around `--static --version` printing the received +# message and then version +static=false +print_errors=false + while [ $# -gt 0 ]; do case $1 in --version) @@ -17,7 +22,21 @@ while [ $# -gt 0 ]; do echo "Found: ${PKG_CONFIG_PATH}" [ "${last}" = "${PKG_CONFIG_PATH}" ] && exit 0 || exit 1 ;; + --static) + static=true + ;; + --print-errors) + print_errors=true + ;; esac shift done + +$static && echo "Received --static" +$print_errors && echo "Received --print-errors" + +if $static || $print_errors; then + exit 0 +fi + exit 255 |