From bab24e782c1bf56ef7263e91e5cf78879699a036 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 10 Dec 2018 10:39:22 -0500 Subject: target_link_libraries: Propagate dependencies of object libraries Prior to this commit, linking against an object library did not propagate private link dependencies of object libraries to their consuming targets. This change implements the correct behavior. Fixes: #18692 Co-Author: Brad King --- Help/release/dev/object-library-link.rst | 5 +++++ Source/cmTargetLinkLibrariesCommand.cxx | 3 ++- Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake | 1 + Tests/RunCMake/ObjectLibrary/TransitiveDependencies.cmake | 7 +++++++ Tests/RunCMake/ObjectLibrary/exe2.c | 6 ++++++ 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Help/release/dev/object-library-link.rst create mode 100644 Tests/RunCMake/ObjectLibrary/TransitiveDependencies.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/exe2.c diff --git a/Help/release/dev/object-library-link.rst b/Help/release/dev/object-library-link.rst new file mode 100644 index 0000000..990d915 --- /dev/null +++ b/Help/release/dev/object-library-link.rst @@ -0,0 +1,5 @@ +object-library-link +------------------- + +* Object library linking has been fixed to propagate transitive link + dependencies of object libraries to consuming targets. diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 66cc6ee..eebf7a0 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -451,7 +451,8 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, // STATIC library.) if (this->CurrentProcessingState == ProcessingKeywordPrivateInterface || this->CurrentProcessingState == ProcessingPlainPrivateInterface) { - if (this->Target->GetType() == cmStateEnums::STATIC_LIBRARY) { + if (this->Target->GetType() == cmStateEnums::STATIC_LIBRARY || + this->Target->GetType() == cmStateEnums::OBJECT_LIBRARY) { std::string configLib = this->Target->GetDebugGeneratorExpressions(libRef, llt); if (cmGeneratorExpression::IsValidTargetName(libRef) || diff --git a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake index c73732f..6ca33b8 100644 --- a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake +++ b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake @@ -45,6 +45,7 @@ run_object_lib_build2(LinkObjRHSObject) run_object_lib_build(LinkObjRHSShared2) run_object_lib_build(LinkObjRHSStatic2) run_object_lib_build2(LinkObjRHSObject2) +run_object_lib_build(TransitiveDependencies) run_cmake(MissingSource) run_cmake(ObjWithObj) diff --git a/Tests/RunCMake/ObjectLibrary/TransitiveDependencies.cmake b/Tests/RunCMake/ObjectLibrary/TransitiveDependencies.cmake new file mode 100644 index 0000000..e41cf2e --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/TransitiveDependencies.cmake @@ -0,0 +1,7 @@ +add_library(lib1 STATIC depends_obj0.c) +add_library(lib2 OBJECT a.c) +target_link_libraries(lib2 PRIVATE lib1) + +add_executable(test exe2.c) + +target_link_libraries(test PUBLIC lib2) diff --git a/Tests/RunCMake/ObjectLibrary/exe2.c b/Tests/RunCMake/ObjectLibrary/exe2.c new file mode 100644 index 0000000..66e0caf --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/exe2.c @@ -0,0 +1,6 @@ +extern int myobj_foo(void); + +int main(void) +{ + return myobj_foo(); +} -- cgit v0.12