mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 13:20:47 -06:00
FindPkgConfig: Set linker flags on imported targets
This commit is contained in:
5
Help/release/dev/pkg-config-linker-flags.rst
Normal file
5
Help/release/dev/pkg-config-linker-flags.rst
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pkg-config-linker-flags
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
* The :module:`FindPkgConfig` now populates :prop_tgt:`INTERFACE_LINK_OPTIONS`
|
||||||
|
property of imported targets with other (non-library) linker flags.
|
||||||
@@ -242,7 +242,7 @@ endfunction()
|
|||||||
function(_pkg_create_imp_target _prefix _imp_target_global)
|
function(_pkg_create_imp_target _prefix _imp_target_global)
|
||||||
# only create the target if it is linkable, i.e. no executables
|
# only create the target if it is linkable, i.e. no executables
|
||||||
if (NOT TARGET PkgConfig::${_prefix}
|
if (NOT TARGET PkgConfig::${_prefix}
|
||||||
AND ( ${_prefix}_INCLUDE_DIRS OR ${_prefix}_LINK_LIBRARIES OR ${_prefix}_CFLAGS_OTHER ))
|
AND ( ${_prefix}_INCLUDE_DIRS OR ${_prefix}_LINK_LIBRARIES OR ${_prefix}_LDFLAGS_OTHER OR ${_prefix}_CFLAGS_OTHER ))
|
||||||
if(${_imp_target_global})
|
if(${_imp_target_global})
|
||||||
set(_global_opt "GLOBAL")
|
set(_global_opt "GLOBAL")
|
||||||
else()
|
else()
|
||||||
@@ -258,6 +258,10 @@ function(_pkg_create_imp_target _prefix _imp_target_global)
|
|||||||
set_property(TARGET PkgConfig::${_prefix} PROPERTY
|
set_property(TARGET PkgConfig::${_prefix} PROPERTY
|
||||||
INTERFACE_LINK_LIBRARIES "${${_prefix}_LINK_LIBRARIES}")
|
INTERFACE_LINK_LIBRARIES "${${_prefix}_LINK_LIBRARIES}")
|
||||||
endif()
|
endif()
|
||||||
|
if(${_prefix}_LDFLAGS_OTHER)
|
||||||
|
set_property(TARGET PkgConfig::${_prefix} PROPERTY
|
||||||
|
INTERFACE_LINK_OPTIONS "${${_prefix}_LDFLAGS_OTHER}")
|
||||||
|
endif()
|
||||||
if(${_prefix}_CFLAGS_OTHER)
|
if(${_prefix}_CFLAGS_OTHER)
|
||||||
set_property(TARGET PkgConfig::${_prefix} PROPERTY
|
set_property(TARGET PkgConfig::${_prefix} PROPERTY
|
||||||
INTERFACE_COMPILE_OPTIONS "${${_prefix}_CFLAGS_OTHER}")
|
INTERFACE_COMPILE_OPTIONS "${${_prefix}_CFLAGS_OTHER}")
|
||||||
|
|||||||
@@ -109,3 +109,24 @@ pkg_check_modules(FakePackage2 REQUIRED QUIET IMPORTED_TARGET cmakeinternalfakep
|
|||||||
if (NOT FakePackage2_LINK_LIBRARIES STREQUAL "${fakePkgDir}/lib/libcmakeinternalfakepackage2.a")
|
if (NOT FakePackage2_LINK_LIBRARIES STREQUAL "${fakePkgDir}/lib/libcmakeinternalfakepackage2.a")
|
||||||
message(FATAL_ERROR "FakePackage2_LINK_LIBRARIES has bad content on second run: ${FakePackage2_LINK_LIBRARIES}")
|
message(FATAL_ERROR "FakePackage2_LINK_LIBRARIES has bad content on second run: ${FakePackage2_LINK_LIBRARIES}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(pname fakelinkoptionspackage)
|
||||||
|
file(WRITE ${fakePkgDir}/lib/pkgconfig/${pname}.pc
|
||||||
|
"Name: FakeLinkOptionsPackage
|
||||||
|
Description: Dummy package for FindPkgConfig IMPORTED_TARGET INTERFACE_LINK_OPTIONS test
|
||||||
|
Version: 1.2.3
|
||||||
|
Libs: -e dummy_main
|
||||||
|
")
|
||||||
|
|
||||||
|
set(expected_link_options -e dummy_main)
|
||||||
|
pkg_check_modules(FakeLinkOptionsPackage REQUIRED QUIET IMPORTED_TARGET fakelinkoptionspackage)
|
||||||
|
if (NOT TARGET PkgConfig::FakeLinkOptionsPackage)
|
||||||
|
message(FATAL_ERROR "No import target for fake link options package")
|
||||||
|
endif()
|
||||||
|
get_target_property(link_options PkgConfig::FakeLinkOptionsPackage INTERFACE_LINK_OPTIONS)
|
||||||
|
if (NOT link_options STREQUAL expected_link_options)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"Additional link options not present in INTERFACE_LINK_OPTIONS property"
|
||||||
|
"expected: \"${expected_link_options}\", but got \"${link_options}\""
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user