Merge topic 'objlib-transitive-deps'

a833aa1167 Fix dependencies on targets linked through object libraries
3b3de0fd17 Tests: Extend ObjectLibrary test with case for object lib dependencies

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4427
This commit is contained in:
Brad King
2020-03-05 12:26:12 +00:00
committed by Kitware Robot
8 changed files with 71 additions and 15 deletions

View File

@@ -198,6 +198,20 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
std::vector<std::string> const& configs =
depender->Makefile->GetGeneratorConfigs();
for (std::string const& it : configs) {
cmLinkImplementation const* impl = depender->GetLinkImplementation(it);
// A target should not depend on itself.
emitted.insert(cmLinkItem(depender, false, cmListFileBacktrace()));
emitted.insert(cmLinkItem(depender, true, cmListFileBacktrace()));
for (cmLinkImplItem const& lib : impl->Libraries) {
// Don't emit the same library twice for this target.
if (emitted.insert(lib).second) {
this->AddTargetDepend(depender_index, lib, true, false);
this->AddInterfaceDepends(depender_index, lib, it, emitted);
}
}
// Add dependencies on object libraries not otherwise handled above.
std::vector<cmSourceFile const*> objectFiles;
depender->GetExternalObjects(objectFiles, it);
for (cmSourceFile const* o : objectFiles) {
@@ -222,19 +236,6 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
}
}
}
cmLinkImplementation const* impl = depender->GetLinkImplementation(it);
// A target should not depend on itself.
emitted.insert(cmLinkItem(depender, false, cmListFileBacktrace()));
emitted.insert(cmLinkItem(depender, true, cmListFileBacktrace()));
for (cmLinkImplItem const& lib : impl->Libraries) {
// Don't emit the same library twice for this target.
if (emitted.insert(lib).second) {
this->AddTargetDepend(depender_index, lib, true, false);
this->AddInterfaceDepends(depender_index, lib, it, emitted);
}
}
}
}

View File

@@ -73,3 +73,5 @@ add_executable(UseABstaticObjs $<TARGET_OBJECTS:UseABstatic>)
target_link_libraries(UseABstaticObjs ABstatic)
add_subdirectory(ExportLanguages)
add_subdirectory(Transitive)

View File

@@ -0,0 +1,12 @@
cmake_policy(SET CMP0022 NEW)
add_library(FooStatic STATIC FooStatic.c)
add_library(FooObject1 OBJECT FooObject.c)
target_link_libraries(FooObject1 PRIVATE FooStatic)
add_executable(Transitive1 Transitive.c)
target_link_libraries(Transitive1 PRIVATE FooObject1)
add_library(FooObject2 OBJECT FooObject.c)
target_link_libraries(FooObject2 INTERFACE FooStatic)
add_executable(Transitive2 Transitive.c)
target_link_libraries(Transitive2 PRIVATE FooObject2)

View File

@@ -0,0 +1,4 @@
int FooObject(void)
{
return 0;
}

View File

@@ -0,0 +1,4 @@
int FooStatic(void)
{
return 0;
}

View File

@@ -0,0 +1,7 @@
extern int FooObject(void);
extern int FooStatic(void);
int main(void)
{
return FooObject() + FooStatic();
}

View File

@@ -131,7 +131,20 @@
"dependencies": [
{
"id": "^c_object_lib::@5ed5358f70faf8d8af7a$",
"backtrace": null
"backtrace": [
{
"file": "^object/CMakeLists\\.txt$",
"line": 7,
"command": "target_link_libraries",
"hasParent": true
},
{
"file": "^object/CMakeLists\\.txt$",
"line": null,
"command": null,
"hasParent": false
}
]
},
{
"id": "^ZERO_CHECK::@5ed5358f70faf8d8af7a$",

View File

@@ -131,7 +131,20 @@
"dependencies": [
{
"id": "^cxx_object_lib::@5ed5358f70faf8d8af7a$",
"backtrace": null
"backtrace": [
{
"file": "^object/CMakeLists\\.txt$",
"line": 11,
"command": "target_link_libraries",
"hasParent": true
},
{
"file": "^object/CMakeLists\\.txt$",
"line": null,
"command": null,
"hasParent": false
}
]
},
{
"id": "^ZERO_CHECK::@5ed5358f70faf8d8af7a$",