mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 13:51:33 -06:00
Merge topic 'objlib-transitive-deps'
a833aa1167Fix dependencies on targets linked through object libraries3b3de0fd17Tests: Extend ObjectLibrary test with case for object lib dependencies Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4427
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,3 +73,5 @@ add_executable(UseABstaticObjs $<TARGET_OBJECTS:UseABstatic>)
|
||||
target_link_libraries(UseABstaticObjs ABstatic)
|
||||
|
||||
add_subdirectory(ExportLanguages)
|
||||
|
||||
add_subdirectory(Transitive)
|
||||
|
||||
12
Tests/ObjectLibrary/Transitive/CMakeLists.txt
Normal file
12
Tests/ObjectLibrary/Transitive/CMakeLists.txt
Normal 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)
|
||||
4
Tests/ObjectLibrary/Transitive/FooObject.c
Normal file
4
Tests/ObjectLibrary/Transitive/FooObject.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int FooObject(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
4
Tests/ObjectLibrary/Transitive/FooStatic.c
Normal file
4
Tests/ObjectLibrary/Transitive/FooStatic.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int FooStatic(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
7
Tests/ObjectLibrary/Transitive/Transitive.c
Normal file
7
Tests/ObjectLibrary/Transitive/Transitive.c
Normal file
@@ -0,0 +1,7 @@
|
||||
extern int FooObject(void);
|
||||
extern int FooStatic(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return FooObject() + FooStatic();
|
||||
}
|
||||
@@ -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$",
|
||||
|
||||
@@ -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$",
|
||||
|
||||
Reference in New Issue
Block a user