mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 12:16:40 +08:00
CMP0189: Restore support for linking $<TARGET_PROPERTY:tgt,LINK_LIBRARIES>
In general we disallow references to transitive target properties, such
as `COMPILE_DEFINITIONS`, in `[INTERFACE_]LINK_LIBRARIES` properties,
because the latter establish the transitivity itself. Prior to CMP0189,
the `[INTERFACE_]LINK_LIBRARIES` properties were not themselves transitive
in `$<TARGET_PROPERTY>` expressions, so existing projects have code like
target_link_libraries(foo PRIVATE "$<TARGET_PROPERTY:tgt,LINK_LIBRARIES>")
Policy CMP0189's NEW behavior, introduced by commit b3da9c6d60
(GenEx:
Evaluate LINK_LIBRARIES target properties transitively, 2025-02-24,
v4.1.0-rc1~731^2), makes `$<TARGET_PROPERTY:tgt,LINK_LIBRARIES>`
transitive, causing the above to be rejected. Since evaluation of a
target's link libraries can already encounter and handle other targets'
link libraries, allow it in this case.
Fixes: #27265
This commit is contained in:
@@ -2903,7 +2903,8 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
|
||||
dagCheckerParent->EvaluatingLinkerLauncher()) {
|
||||
// No check required.
|
||||
} else if (evaluatingLinkLibraries) {
|
||||
if (!interfacePropertyName.empty()) {
|
||||
if (!interfacePropertyName.empty() &&
|
||||
interfacePropertyName != "INTERFACE_LINK_LIBRARIES"_s) {
|
||||
reportError(
|
||||
eval, content->GetOriginalExpression(),
|
||||
"$<TARGET_PROPERTY:...> expression in link libraries "
|
||||
|
@@ -0,0 +1,5 @@
|
||||
cmake_policy(SET CMP0189 NEW)
|
||||
include(LinkLikewise-common.cmake)
|
||||
|
||||
# Test that CMP0189 NEW tolerates circular LINK_LIBRARIES references.
|
||||
target_link_libraries(main1 PRIVATE "$<TARGET_PROPERTY:main2,LINK_LIBRARIES>")
|
@@ -0,0 +1,2 @@
|
||||
cmake_policy(SET CMP0189 OLD)
|
||||
include(LinkLikewise-common.cmake)
|
@@ -0,0 +1,12 @@
|
||||
enable_language(C)
|
||||
|
||||
add_library(foo STATIC LinkLikewiseLib.c)
|
||||
|
||||
add_executable(main1 LinkLikewiseMain.c)
|
||||
add_executable(main2 LinkLikewiseMain.c)
|
||||
|
||||
# main1 depends on foo.
|
||||
target_link_libraries(main1 PRIVATE foo)
|
||||
|
||||
# main2 depends on foo, but express it by referencing main1's dependency.
|
||||
target_link_libraries(main2 PRIVATE "$<TARGET_PROPERTY:main1,LINK_LIBRARIES>")
|
4
Tests/RunCMake/GenEx-TARGET_PROPERTY/LinkLikewiseLib.c
Normal file
4
Tests/RunCMake/GenEx-TARGET_PROPERTY/LinkLikewiseLib.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int LinkLikewiseLib(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
5
Tests/RunCMake/GenEx-TARGET_PROPERTY/LinkLikewiseMain.c
Normal file
5
Tests/RunCMake/GenEx-TARGET_PROPERTY/LinkLikewiseMain.c
Normal file
@@ -0,0 +1,5 @@
|
||||
extern int LinkLikewiseLib(void);
|
||||
int main(void)
|
||||
{
|
||||
return LinkLikewiseLib();
|
||||
}
|
@@ -17,6 +17,15 @@ run_cmake(TransitiveLink-CMP0166-OLD)
|
||||
run_cmake(TransitiveLink-CMP0166-NEW)
|
||||
run_cmake(Unset)
|
||||
|
||||
function(run_LinkLikewise case)
|
||||
run_cmake(LinkLikewise-${case})
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/LinkLikewise-${case}-build)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
run_cmake_command(LinkLikewise-${case}-build ${CMAKE_COMMAND} --build . --config Debug)
|
||||
endfunction()
|
||||
run_LinkLikewise(CMP0189-OLD)
|
||||
run_LinkLikewise(CMP0189-NEW)
|
||||
|
||||
block()
|
||||
run_cmake(Scope)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Scope-build)
|
||||
|
Reference in New Issue
Block a user