mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-20 12:53:55 +08:00
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 <brad.king@kitware.com>
This commit is contained in:
5
Help/release/dev/object-library-link.rst
Normal file
5
Help/release/dev/object-library-link.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
object-library-link
|
||||
-------------------
|
||||
|
||||
* Object library linking has been fixed to propagate transitive link
|
||||
dependencies of object libraries to consuming targets.
|
@@ -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) ||
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
6
Tests/RunCMake/ObjectLibrary/exe2.c
Normal file
6
Tests/RunCMake/ObjectLibrary/exe2.c
Normal file
@@ -0,0 +1,6 @@
|
||||
extern int myobj_foo(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return myobj_foo();
|
||||
}
|
Reference in New Issue
Block a user