summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LINK_LIBRARIES.cmake
diff options
context:
space:
mode:
authorAlex Birch <51103-Birchlabs@users.noreply.gitlab.kitware.com>2021-12-31 16:48:56 (GMT)
committerBrad King <brad.king@kitware.com>2022-05-20 13:45:12 (GMT)
commit020976d637bc85ed688d57bb79828bc153a5369b (patch)
tree306a1702e665cacb00f8d35b24603a5dc4b327f8 /Tests/RunCMake/FindPkgConfig/FindPkgConfig_LINK_LIBRARIES.cmake
parent3c5cc79adbbe8524eb712b8c36d5d29a1d968d75 (diff)
downloadCMake-020976d637bc85ed688d57bb79828bc153a5369b.zip
CMake-020976d637bc85ed688d57bb79828bc153a5369b.tar.gz
CMake-020976d637bc85ed688d57bb79828bc153a5369b.tar.bz2
FindPkgConfig: Populate _STATIC_LINK_LIBRARIES. Add STATIC_TARGET.
Add LINK_LIBRARIES test to demonstrate static linking of transitive dependencies. Add STATIC_TARGET argument to pkg_check_modules() and pkg_search_module(). Influences the properties of target produced by IMPORTED_TARGET. When enabled: target's properties will be populated from <XXX>_STATIC_* variables instead of from <XXX>_* variables. Update existing tests concerning properties of targets produced via IMPORTED_TARGET, to test STATIC_TARGET variant too. Update existing tests concerning <XXX>_* variables to test <XXX>_STATIC_* variables too. Breaking changes to pkg_check_modules() and pkg_search_module(): - Variables CMAKE_FIND_LIBRARY_PREFIXES and CMAKE_FIND_LIBRARY_SUFFIXES can no longer be used to influence library lookup (i.e. the internal call to find_library()), because FindPkgConfig now internally relies on these variables to differentiate between shared and static library lookup. Prefer CMAKE_SHARED_LIBRARY_PREFIX + CMAKE_SHARED_LIBRARY_SUFFIX, or CMAKE_STATIC_LIBRARY_PREFIX + CMAKE_STATIC_LIBRARY_SUFFIX, depending on whether you wish to impact static or shared lookup. - <XXX>_LINK_LIBRARIES will now be populated only with libraries located via CMAKE_SHARED_LIBRARY_PREFIX + CMAKE_SHARED_LIBRARY_SUFFIX match - <XXX>_STATIC_LIBRARIES now processes -framework options - <XXX>_STATIC_LDFLAGS_OTHER now processes -framework options - <XXX>_STATIC_CFLAGS_OTHER now processes -isystem options - <XXX>_STATIC_INCLUDE_DIRS now processes -isystem options Fixes: #21714
Diffstat (limited to 'Tests/RunCMake/FindPkgConfig/FindPkgConfig_LINK_LIBRARIES.cmake')
-rw-r--r--Tests/RunCMake/FindPkgConfig/FindPkgConfig_LINK_LIBRARIES.cmake53
1 files changed, 53 insertions, 0 deletions
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LINK_LIBRARIES.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LINK_LIBRARIES.cmake
new file mode 100644
index 0000000..bf4ee1e
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_LINK_LIBRARIES.cmake
@@ -0,0 +1,53 @@
+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}/imm.pc" "
+prefix=${ESCAPED_ROOT}
+libdir=\${prefix}/lib
+
+Name: Immediate
+Description: Dummy package to test *LINK_LIBRARIES support
+Version: 1.0
+Libs: -L\${libdir} -limm
+Libs.private: -ltrns
+")
+file(WRITE "${PKGCONFIG_DIR}/trns.pc" "
+prefix=${ESCAPED_ROOT}
+libdir=\${prefix}/lib
+
+Name: Transitive
+Description: Dummy package to test *LINK_LIBRARIES support
+Version: 1.0
+Libs: -L\${libdir} -ltrns
+")
+
+set(shared_lib_prefix "dyprefix-")
+set(shared_lib_suffix "-dysuffix")
+set(static_lib_prefix "stprefix-")
+set(static_lib_suffix "-stsuffix")
+
+set(CMAKE_SHARED_LIBRARY_PREFIX ${shared_lib_prefix})
+set(CMAKE_SHARED_LIBRARY_SUFFIX ${shared_lib_suffix})
+set(CMAKE_STATIC_LIBRARY_PREFIX ${static_lib_prefix})
+set(CMAKE_STATIC_LIBRARY_SUFFIX ${static_lib_suffix})
+
+# Create "library" files to find in libdir.
+foreach(lib imm trns)
+ foreach(variant shared static)
+ file(WRITE "${LIB_DIR}/${${variant}_lib_prefix}${lib}${${variant}_lib_suffix}")
+ endforeach()
+endforeach()
+
+set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_DIR}")
+pkg_check_modules(IMM REQUIRED imm)
+
+message(STATUS "IMM_LIBRARIES='${IMM_LIBRARIES}'")
+message(STATUS "IMM_LINK_LIBRARIES='${IMM_LINK_LIBRARIES}'")
+message(STATUS "IMM_LDFLAGS='${IMM_LDFLAGS}'")
+message(STATUS "IMM_STATIC_LIBRARIES='${IMM_STATIC_LIBRARIES}'")
+message(STATUS "IMM_STATIC_LINK_LIBRARIES='${IMM_STATIC_LINK_LIBRARIES}'")
+message(STATUS "IMM_STATIC_LDFLAGS='${IMM_STATIC_LDFLAGS}'")