diff options
author | Brad King <brad.king@kitware.com> | 2021-06-08 12:00:12 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-06-08 12:00:24 (GMT) |
commit | 34eefc6ea328092e565f13736e853004aaece640 (patch) | |
tree | f239d7a9b6f4e96b59d0d1086297504ff50af31a | |
parent | 4c940e50bf0233accd68aa2f202d36dd956da18e (diff) | |
parent | 6f14205e0885853184d482f901d62fa5c10ac4f9 (diff) | |
download | CMake-34eefc6ea328092e565f13736e853004aaece640.zip CMake-34eefc6ea328092e565f13736e853004aaece640.tar.gz CMake-34eefc6ea328092e565f13736e853004aaece640.tar.bz2 |
Merge topic 'FindPkgConfigAlwaysAddTarget'
6f14205e08 FindPkgConfig: Always create the imported target
07d6390728 Tests: Add case covering FindPkgConfig creation of empty targets
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6113
4 files changed, 24 insertions, 3 deletions
diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 38c8da7..3bc9dba 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -265,9 +265,7 @@ endfunction() # create an imported target from all the information returned by pkg-config function(_pkg_create_imp_target _prefix _imp_target_global) - # only create the target if it is linkable, i.e. no executables - if (NOT TARGET PkgConfig::${_prefix} - AND ( ${_prefix}_INCLUDE_DIRS OR ${_prefix}_LINK_LIBRARIES OR ${_prefix}_LDFLAGS_OTHER OR ${_prefix}_CFLAGS_OTHER )) + if (NOT TARGET PkgConfig::${_prefix}) if(${_imp_target_global}) set(_global_opt "GLOBAL") else() diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_empty_target.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_empty_target.cmake new file mode 100644 index 0000000..cb3dd69 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_empty_target.cmake @@ -0,0 +1,17 @@ +# Prepare environment to reuse empty.pc +file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pc-empty/lib/pkgconfig" PC_PATH) +if(UNIX) + string(REPLACE "\\ " " " PC_PATH "${PC_PATH}") +endif() +set(ENV{PKG_CONFIG_PATH} "${PC_PATH}") + +find_package(PkgConfig REQUIRED) +pkg_search_module(Empty REQUIRED empty IMPORTED_TARGET) + +if(NOT Empty_MODULE_NAME STREQUAL "empty") + message(FATAL_ERROR "Wrong value for Empty_MODULE_NAME. Expected: empty, got: ${Empty_MODULE_NAME}") +endif() + +if(NOT TARGET PkgConfig::Empty) + message(FATAL_ERROR "PkgConfig::Empty target not created") +endif() diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake index 4e6eef6..e7f008c 100644 --- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake @@ -29,4 +29,5 @@ if (PKG_CONFIG_FOUND) run_cmake(FindPkgConfig_IMPORTED_TARGET) run_cmake(FindPkgConfig_VERSION_OPERATORS) run_cmake(FindPkgConfig_GET_MATCHING_MODULE_NAME) + run_cmake(FindPkgConfig_empty_target) endif () diff --git a/Tests/RunCMake/FindPkgConfig/pc-empty/lib/pkgconfig/empty.pc b/Tests/RunCMake/FindPkgConfig/pc-empty/lib/pkgconfig/empty.pc new file mode 100644 index 0000000..954c5f8 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/pc-empty/lib/pkgconfig/empty.pc @@ -0,0 +1,5 @@ +Name: Empty +Description: Dummy package to test empty target +Version: 1.0 +Libs: +Cflags: |