summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.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_IMPORTED_TARGET.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_IMPORTED_TARGET.cmake')
-rw-r--r--Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake138
1 files changed, 87 insertions, 51 deletions
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake
index f149d99..04286cc 100644
--- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake
@@ -1,40 +1,59 @@
-cmake_minimum_required(VERSION 3.12)
+cmake_minimum_required(VERSION 3.17)
project(FindPkgConfig_IMPORTED_TARGET C)
-find_package(PkgConfig REQUIRED)
-pkg_check_modules(NCURSES IMPORTED_TARGET QUIET ncurses)
+set(shared_lib_prefix "")
+set(shared_lib_suffix ".lib")
+set(static_lib_prefix "lib")
+set(static_lib_suffix ".a")
-message(STATUS "source: ${CMAKE_CURRENT_SOURCE_DIR} bin ${CMAKE_CURRENT_BINARY_DIR}")
+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})
-if (NCURSES_FOUND)
- set(tgt PkgConfig::NCURSES)
- if (NOT TARGET ${tgt})
- message(FATAL_ERROR "FindPkgConfig found ncurses, but did not create an imported target for it")
- endif ()
- set(prop_found FALSE)
- foreach (prop IN ITEMS INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES INTERFACE_COMPILE_OPTIONS)
- get_target_property(value ${tgt} ${prop})
- if (value)
- message(STATUS "Found property ${prop} on target: ${value}")
- set(prop_found TRUE)
+find_package(PkgConfig REQUIRED)
+
+# to test multiple variations, we must pick unique prefix names (same-named targets are cached for re-use)
+set(prefix_uniquifiers 0 1)
+# whether to apply STATIC_TARGET argument
+set(static_target_args "" STATIC_TARGET)
+foreach (prefix_uniquifier static_target_arg IN ZIP_LISTS prefix_uniquifiers static_target_args)
+ set(prefix "NCURSES${prefix_uniquifier}")
+ message(STATUS "static_target_arg: ${static_target_arg}")
+ pkg_check_modules(${prefix} IMPORTED_TARGET QUIET ${static_target_arg} ncurses)
+
+ message(STATUS "source: ${CMAKE_CURRENT_SOURCE_DIR} bin ${CMAKE_CURRENT_BINARY_DIR}")
+
+ if (${prefix}_FOUND)
+ set(tgt PkgConfig::${prefix})
+ message(STATUS "Verifying target \"${tgt}\"")
+ if (NOT TARGET ${tgt})
+ message(FATAL_ERROR "FindPkgConfig found ncurses, but did not create an imported target for it")
endif ()
- endforeach ()
- if (NOT prop_found)
- message(FATAL_ERROR "target ${tgt} found, but it has no properties")
+ set(prop_found FALSE)
+ foreach (prop IN ITEMS INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES INTERFACE_COMPILE_OPTIONS)
+ get_target_property(value ${tgt} ${prop})
+ if (value)
+ message(STATUS "Found property ${prop} on target: ${value}")
+ set(prop_found TRUE)
+ endif ()
+ endforeach ()
+ if (NOT prop_found)
+ message(FATAL_ERROR "target ${tgt} found, but it has no properties")
+ endif ()
+ else ()
+ message(STATUS "skipping test; ncurses not found")
endif ()
-else ()
- message(STATUS "skipping test; ncurses not found")
-endif ()
-
+endforeach ()
# Setup for the remaining package tests below
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH)
set(fakePkgDir ${CMAKE_CURRENT_BINARY_DIR}/pc-fakepackage)
foreach(i 1 2)
set(pname cmakeinternalfakepackage${i})
- file(WRITE ${fakePkgDir}/lib/lib${pname}.a "")
- file(WRITE ${fakePkgDir}/lib/${pname}.lib "")
+ file(WRITE ${fakePkgDir}/lib/${static_lib_prefix}${pname}${static_lib_suffix} "")
+ file(WRITE ${fakePkgDir}/lib/${shared_lib_prefix}${pname}${shared_lib_suffix} "")
file(WRITE ${fakePkgDir}/lib/pkgconfig/${pname}.pc
"Name: CMakeInternalFakePackage${i}
Description: Dummy package (${i}) for FindPkgConfig IMPORTED_TARGET test
@@ -66,35 +85,52 @@ unset(CMAKE_PREFIX_PATH)
unset(ENV{CMAKE_PREFIX_PATH})
set(ENV{CMAKE_PREFIX_PATH} ${fakePkgDir})
-pkg_check_modules(FakePackage2 REQUIRED QUIET IMPORTED_TARGET cmakeinternalfakepackage2)
-if (NOT TARGET PkgConfig::FakePackage2)
- message(FATAL_ERROR "No import target for fake package 2 with prefix path")
-endif()
-# check that 2 library entries exist
-list(LENGTH FakePackage2_LINK_LIBRARIES fp2_nlibs)
-if (NOT fp2_nlibs EQUAL 2)
- message(FATAL_ERROR "FakePackage2_LINK_LIBRARIES has ${fp2_nlibs} entries but should have exactly 2")
-endif()
-
-# check that the full library path is also returned
-list(GET FakePackage2_LINK_LIBRARIES 0 fp2_lib0)
-if (NOT fp2_lib0 STREQUAL "${fakePkgDir}/lib/libcmakeinternalfakepackage2.a")
- message(FATAL_ERROR "FakePackage2_LINK_LIBRARIES has bad content on first run: ${FakePackage2_LINK_LIBRARIES}")
-endif()
-
-# check that the library that couldn't be found still shows up
-list(GET FakePackage2_LINK_LIBRARIES 1 fp2_lib1)
-if (NOT fp2_lib1 STREQUAL "cmakeinternalfakepackage2-doesnotexist")
- message(FATAL_ERROR "FakePackage2_LINK_LIBRARIES has bad content on first run: ${FakePackage2_LINK_LIBRARIES}")
-endif()
+# to test multiple variations, we must pick unique prefix names (same-named targets are cached for re-use)
+set(prefix_uniquifiers 0 1)
+# whether to apply STATIC_TARGET argument
+set(static_target_args "" STATIC_TARGET)
+# whether target properties are populated from the unqualified (i.e. shared library) series of vars, or the STATIC_ series of vars
+set(target_var_qualifiers "" STATIC_)
+set(lib_types shared static)
+foreach (prefix_uniquifier static_target_arg target_var_qualifier lib_type IN ZIP_LISTS prefix_uniquifiers static_target_args target_var_qualifiers lib_types)
+ set(prefix "FakePackage2${prefix_uniquifier}")
+ set(tgt "PkgConfig::${prefix}")
+ pkg_check_modules(${prefix} REQUIRED QUIET IMPORTED_TARGET ${static_target_arg} cmakeinternalfakepackage2)
-# the information in *_LINK_LIBRARIES is not cached, so ensure is also is present on second run
-unset(FakePackage2_LINK_LIBRARIES)
-pkg_check_modules(FakePackage2 REQUIRED QUIET IMPORTED_TARGET cmakeinternalfakepackage2)
-if (NOT FakePackage2_LINK_LIBRARIES STREQUAL "${fakePkgDir}/lib/libcmakeinternalfakepackage2.a;cmakeinternalfakepackage2-doesnotexist")
- message(FATAL_ERROR "FakePackage2_LINK_LIBRARIES has bad content on second run: ${FakePackage2_LINK_LIBRARIES}")
-endif()
+ message(STATUS "Verifying library path resolution for lib type \"${lib_type}\"")
+ if (NOT TARGET ${tgt})
+ message(FATAL_ERROR "No import target for fake package 2 with prefix path")
+ endif()
+
+ set(link_libraries_var ${prefix}_${target_var_qualifier}LINK_LIBRARIES)
+ # check that 2 library entries exist
+ list(LENGTH ${link_libraries_var} fp2_nlibs)
+ if (NOT fp2_nlibs EQUAL 2)
+ message(FATAL_ERROR "${link_libraries_var} has ${fp2_nlibs} entries but should have exactly 2")
+ endif()
+
+ set(lib_leafname ${${lib_type}_lib_prefix}cmakeinternalfakepackage2${${lib_type}_lib_suffix})
+ message(STATUS "Expecting library leafname \"${lib_leafname}\"")
+ # check that the full library path is also returned
+ list(GET ${link_libraries_var} 0 fp2_lib0)
+ if (NOT fp2_lib0 STREQUAL "${fakePkgDir}/lib/${lib_leafname}")
+ message(FATAL_ERROR "${link_libraries_var} has bad content on first run: ${${link_libraries_var}}")
+ endif()
+
+ # check that the library that couldn't be found still shows up
+ list(GET ${link_libraries_var} 1 fp2_lib1)
+ if (NOT fp2_lib1 STREQUAL "cmakeinternalfakepackage2-doesnotexist")
+ message(FATAL_ERROR "${link_libraries_var} has bad content on first run: ${${link_libraries_var}}")
+ endif()
+
+ # the information in *_LINK_LIBRARIES is not cached, so ensure is also is present on second run
+ unset(${link_libraries_var})
+ pkg_check_modules(${prefix} REQUIRED QUIET IMPORTED_TARGET ${static_target_arg} cmakeinternalfakepackage2)
+ if (NOT ${link_libraries_var} STREQUAL "${fakePkgDir}/lib/${lib_leafname};cmakeinternalfakepackage2-doesnotexist")
+ message(FATAL_ERROR "${link_libraries_var} has bad content on second run: ${${link_libraries_var}}")
+ endif()
+endforeach()
set(pname fakelinkoptionspackage)
file(WRITE ${fakePkgDir}/lib/pkgconfig/${pname}.pc