mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Merge topic 'genex-transitive-link-libraries'
e0bbe79cea
CMP0189: Restore support for linking `$<TARGET_PROPERTY:tgt,LINK_LIBRARIES>`cb69f750bf
cmGeneratorTarget: Factor out helper to detect LINK_LIBRARIES evaluation Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !11262
This commit is contained in:
@@ -3113,7 +3113,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 "
|
||||
|
@@ -30,6 +30,11 @@
|
||||
namespace {
|
||||
using UseTo = cmGeneratorTarget::UseTo;
|
||||
using TransitiveProperty = cmGeneratorTarget::TransitiveProperty;
|
||||
|
||||
bool ComputingLinkLibraries(cmGeneratorExpressionDAGChecker const* dagChecker)
|
||||
{
|
||||
return dagChecker && dagChecker->IsComputingLinkLibraries();
|
||||
}
|
||||
}
|
||||
|
||||
std::map<cm::string_view, TransitiveProperty> const
|
||||
@@ -206,7 +211,7 @@ cmGeneratorTarget::IsTransitiveProperty(
|
||||
result->Usage = cmGeneratorTarget::UseTo::Compile;
|
||||
}
|
||||
}
|
||||
} else if (!dagChecker || !dagChecker->IsComputingLinkLibraries()) {
|
||||
} else if (!ComputingLinkLibraries(dagChecker)) {
|
||||
// Honor TRANSITIVE_COMPILE_PROPERTIES and TRANSITIVE_LINK_PROPERTIES
|
||||
// from the link closure when we are not evaluating the closure itself.
|
||||
CustomTransitiveProperties const& ctp =
|
||||
|
@@ -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