diff options
author | Brad King <brad.king@kitware.com> | 2021-07-13 14:28:48 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-07-13 14:33:16 (GMT) |
commit | 36979f5b438b39599b074a291ad3cca3bfafc6bc (patch) | |
tree | abe174f084aaf47e6bf177ff72c555de11fe84e1 /Tests/RunCMake/FindPkgConfig | |
parent | 460e812369db398da34e14c9d40c3ecec06afaf1 (diff) | |
download | CMake-36979f5b438b39599b074a291ad3cca3bfafc6bc.zip CMake-36979f5b438b39599b074a291ad3cca3bfafc6bc.tar.gz CMake-36979f5b438b39599b074a291ad3cca3bfafc6bc.tar.bz2 |
FindPkgConfig: Tolerate PKG_CONFIG_SYSTEM_LIBRARY_PATH in environment
Tell `pkg-config --libs` not to filter out `-L` flags for entries of
`PKG_CONFIG_SYSTEM_LIBRARY_PATH` (and `LIBRARY_PATH` for `pkgconf`).
We should always search everywhere the `.pc` file expects.
Fixes: #22148
Diffstat (limited to 'Tests/RunCMake/FindPkgConfig')
3 files changed, 36 insertions, 0 deletions
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-stdout.txt b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-stdout.txt new file mode 100644 index 0000000..6615d80 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-stdout.txt @@ -0,0 +1,3 @@ +-- ZOT_LIBRARIES='zot' +-- ZOT_LINK_LIBRARIES='[^']*/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-build/zot/lib/prefix-zot-suffix' +-- ZOT_LDFLAGS='-L[^']*/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-build/zot/lib;-lzot' diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH.cmake new file mode 100644 index 0000000..9f654b5 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH.cmake @@ -0,0 +1,29 @@ +find_package(PkgConfig REQUIRED) + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/zot/lib/pkgconfig/zot.pc" " +prefix=${CMAKE_CURRENT_BINARY_DIR}/zot +libdir=\${prefix}/lib + +Name: Zot +Description: Dummy packaget to test LIBRARY_DIR support +Version: 1.0 +Libs: -L\${libdir} -lzot +") + +# Create a "library" file to find in libdir. +set(CMAKE_FIND_LIBRARY_PREFIXES "prefix-") +set(CMAKE_FIND_LIBRARY_SUFFIXES "-suffix") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/zot/lib/prefix-zot-suffix") + +# 'pkg-config --libs' drops -L flags in PKG_CONFIG_SYSTEM_LIBRARY_PATH by default. +set(ENV{PKG_CONFIG_SYSTEM_LIBRARY_PATH} "${CMAKE_CURRENT_BINARY_DIR}/zot/lib") + +# 'pkgconf --libs' also drops -L flags in LIBRARY_PATH by default. +set(ENV{LIBRARY_PATH} "${CMAKE_CURRENT_BINARY_DIR}/zot/lib") + +set(ENV{PKG_CONFIG_PATH} "${CMAKE_CURRENT_BINARY_DIR}/zot/lib/pkgconfig") +pkg_check_modules(ZOT REQUIRED zot) + +message(STATUS "ZOT_LIBRARIES='${ZOT_LIBRARIES}'") +message(STATUS "ZOT_LINK_LIBRARIES='${ZOT_LINK_LIBRARIES}'") +message(STATUS "ZOT_LDFLAGS='${ZOT_LDFLAGS}'") diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake index 17e046a..81a4732 100644 --- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake @@ -31,4 +31,8 @@ if (PKG_CONFIG_FOUND) run_cmake(FindPkgConfig_VERSION_OPERATORS) run_cmake(FindPkgConfig_GET_MATCHING_MODULE_NAME) run_cmake(FindPkgConfig_empty_target) + + if(NOT RunCMake_BINARY_DIR MATCHES " ") + run_cmake(FindPkgConfig_LIBRARY_PATH) + endif() endif () |