From 45078831351f3276a8f1b124eada532f66f6903b Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 5 Sep 2023 19:58:01 +0200 Subject: Tests: Rename RunCMake.FindPkgConfig LIBRARY_PATH case to SYSTEM_PATH Prepare to cover CFLAGS too. --- .../FindPkgConfig_LIBRARY_PATH-stdout.txt | 3 -- .../FindPkgConfig/FindPkgConfig_LIBRARY_PATH.cmake | 34 ---------------------- .../FindPkgConfig_SYSTEM_PATH-stdout.txt | 3 ++ .../FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake | 34 ++++++++++++++++++++++ Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake | 2 +- 5 files changed, 38 insertions(+), 38 deletions(-) delete mode 100644 Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-stdout.txt delete mode 100644 Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH.cmake create mode 100644 Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-stdout.txt create mode 100644 Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-stdout.txt b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-stdout.txt deleted file mode 100644 index 539e5ef..0000000 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-stdout.txt +++ /dev/null @@ -1,3 +0,0 @@ --- ZOT_LIBRARIES='zot' --- ZOT_LINK_LIBRARIES='[^']*/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-build/root/lib/prefix-zot-suffix' --- ZOT_LDFLAGS='-L[^']*/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH-build/root/lib;-lzot' diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH.cmake deleted file mode 100644 index 1278c49..0000000 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LIBRARY_PATH.cmake +++ /dev/null @@ -1,34 +0,0 @@ -find_package(PkgConfig REQUIRED) - -set(ROOT "${CMAKE_CURRENT_BINARY_DIR}/root") -string(REPLACE " " "\\ " ESCAPED_ROOT "${ROOT}") -set(LIB_DIR "${ROOT}/lib") -set(PKGCONFIG_DIR "${LIB_DIR}/pkgconfig") - -file(WRITE "${PKGCONFIG_DIR}/zot.pc" " -prefix=${ESCAPED_ROOT} -libdir=\${prefix}/lib - -Name: Zot -Description: Dummy package 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 "${LIB_DIR}/prefix-zot-suffix") - -# 'pkg-config --libs' drops -L flags in PKG_CONFIG_SYSTEM_LIBRARY_PATH by default. -set(ENV{PKG_CONFIG_SYSTEM_LIBRARY_PATH} "${LIB_DIR}") - -# 'pkgconf --libs' also drops -L flags in LIBRARY_PATH by default. -set(ENV{LIBRARY_PATH} "${LIB_DIR}") - -set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_DIR}") -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/FindPkgConfig_SYSTEM_PATH-stdout.txt b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-stdout.txt new file mode 100644 index 0000000..46c9a65 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-stdout.txt @@ -0,0 +1,3 @@ +-- ZOT_LIBRARIES='zot' +-- ZOT_LINK_LIBRARIES='[^']*/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-build/root/lib/prefix-zot-suffix' +-- ZOT_LDFLAGS='-L[^']*/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-build/root/lib;-lzot' diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake new file mode 100644 index 0000000..1278c49 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake @@ -0,0 +1,34 @@ +find_package(PkgConfig REQUIRED) + +set(ROOT "${CMAKE_CURRENT_BINARY_DIR}/root") +string(REPLACE " " "\\ " ESCAPED_ROOT "${ROOT}") +set(LIB_DIR "${ROOT}/lib") +set(PKGCONFIG_DIR "${LIB_DIR}/pkgconfig") + +file(WRITE "${PKGCONFIG_DIR}/zot.pc" " +prefix=${ESCAPED_ROOT} +libdir=\${prefix}/lib + +Name: Zot +Description: Dummy package 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 "${LIB_DIR}/prefix-zot-suffix") + +# 'pkg-config --libs' drops -L flags in PKG_CONFIG_SYSTEM_LIBRARY_PATH by default. +set(ENV{PKG_CONFIG_SYSTEM_LIBRARY_PATH} "${LIB_DIR}") + +# 'pkgconf --libs' also drops -L flags in LIBRARY_PATH by default. +set(ENV{LIBRARY_PATH} "${LIB_DIR}") + +set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_DIR}") +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 6b8e884..2bfe028 100644 --- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake @@ -59,6 +59,6 @@ Libs: -L\${libdir} run_cmake(FindPkgConfig_GET_MATCHING_MODULE_NAME) run_cmake(FindPkgConfig_empty_target) if(NOT PKG_CONFIG_DONT_SUPPORT_SPACES_IN_PATH) - run_cmake(FindPkgConfig_LIBRARY_PATH) + run_cmake(FindPkgConfig_SYSTEM_PATH) endif() endif () -- cgit v0.12 From 252c66c697e163c192938fd0ee64aacc7626ee60 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 5 Sep 2023 19:18:24 +0200 Subject: FindPkgConfig: Tolerate PKG_CONFIG_SYSTEM_INCLUDE_PATH in environment Tell `pkg-config --cflags` not to filter out `-I` flags for entries of `PKG_CONFIG_SYSTEM_INCLUDE_PATH` (and `CPATH` for `pkgconf`). Fixes: #25228 --- Modules/FindPkgConfig.cmake | 14 +++++++++++++- .../FindPkgConfig/FindPkgConfig_SYSTEM_PATH-stdout.txt | 1 + .../RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 02f7fb4..4d29f45 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -425,13 +425,19 @@ macro(_pkg_set_path_internal) unset(_pkgconfig_path) endif() - # Tell pkg-config not to strip any -L paths so we can search them all. + # Tell pkg-config not to strip any -I or -L paths so we can search them all. if(DEFINED ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS}) set(_pkgconfig_allow_system_libs_old "$ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS}") else() unset(_pkgconfig_allow_system_libs_old) endif() set(ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS} 1) + if(DEFINED ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}) + set(_pkgconfig_allow_system_cflags_old "$ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}") + else() + unset(_pkgconfig_allow_system_cflags_old) + endif() + set(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS} 1) endmacro() macro(_pkg_restore_path_internal) @@ -445,6 +451,12 @@ macro(_pkg_restore_path_internal) else() unset(ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS}) endif() + if(DEFINED _pkgconfig_allow_system_cflags_old) + set(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS} "${_pkgconfig_allow_system_cflags_old}") + unset(_pkgconfig_allow_system_cflags_old) + else() + unset(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}) + endif() unset(_extra_paths) unset(_pkgconfig_path_old) diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-stdout.txt b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-stdout.txt index 46c9a65..012458d 100644 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-stdout.txt +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-stdout.txt @@ -1,3 +1,4 @@ -- ZOT_LIBRARIES='zot' -- ZOT_LINK_LIBRARIES='[^']*/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-build/root/lib/prefix-zot-suffix' -- ZOT_LDFLAGS='-L[^']*/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-build/root/lib;-lzot' +-- ZOT_CFLAGS='-I[^']*/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH-build/root/include' diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake index 1278c49..e58cefb 100644 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_SYSTEM_PATH.cmake @@ -3,16 +3,19 @@ find_package(PkgConfig REQUIRED) set(ROOT "${CMAKE_CURRENT_BINARY_DIR}/root") string(REPLACE " " "\\ " ESCAPED_ROOT "${ROOT}") set(LIB_DIR "${ROOT}/lib") +set(INCLUDE_DIR "${ROOT}/include") set(PKGCONFIG_DIR "${LIB_DIR}/pkgconfig") file(WRITE "${PKGCONFIG_DIR}/zot.pc" " prefix=${ESCAPED_ROOT} libdir=\${prefix}/lib +includedir=\${prefix}/include Name: Zot Description: Dummy package to test LIBRARY_DIR support Version: 1.0 Libs: -L\${libdir} -lzot +Cflags: -I\${includedir} ") # Create a "library" file to find in libdir. @@ -22,9 +25,13 @@ file(WRITE "${LIB_DIR}/prefix-zot-suffix") # 'pkg-config --libs' drops -L flags in PKG_CONFIG_SYSTEM_LIBRARY_PATH by default. set(ENV{PKG_CONFIG_SYSTEM_LIBRARY_PATH} "${LIB_DIR}") +# 'pkg-config --cflags' drops -I flags in PKG_CONFIG_SYSTEM_INCLUDE_PATH by default. +set(ENV{PKG_CONFIG_SYSTEM_INCLUDE_PATH} "${INCLUDE_DIR}") # 'pkgconf --libs' also drops -L flags in LIBRARY_PATH by default. set(ENV{LIBRARY_PATH} "${LIB_DIR}") +# 'pkgconf --cflags' also drops -I flags in CPATH by default. +set(ENV{CPATH} "${INCLUDE_DIR}") set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_DIR}") pkg_check_modules(ZOT REQUIRED zot) @@ -32,3 +39,4 @@ 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}'") +message(STATUS "ZOT_CFLAGS='${ZOT_CFLAGS}'") -- cgit v0.12