summaryrefslogtreecommitdiffstats
path: root/Source/cmComputeTargetDepends.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-03-04 14:40:39 (GMT)
committerBrad King <brad.king@kitware.com>2020-03-04 18:07:41 (GMT)
commita833aa1167f879544e17a41b36948f4059622db5 (patch)
tree72b82cf80742a49c8c91bb382f4d1a4852ff8caf /Source/cmComputeTargetDepends.cxx
parent3b3de0fd17d45f1927a28b4c52ba5146325b1bb0 (diff)
downloadCMake-a833aa1167f879544e17a41b36948f4059622db5.zip
CMake-a833aa1167f879544e17a41b36948f4059622db5.tar.gz
CMake-a833aa1167f879544e17a41b36948f4059622db5.tar.bz2
Fix dependencies on targets linked through object libraries
When an object library is used via `target_link_libraries`, any targets listed in the object library's `INTERFACE_LINK_LIBRARIES` closure should become direct dependencies of the consuming target. However, these were accidentally left out by `cmComputeTargetDepends::CollectTargetDepends` because object libraries are encountered through external object sources first and then added to the `emitted` set which blocks them from being processed as link dependencies. This was not noticed by the test case in commit bab24e782c (target_link_libraries: Propagate dependencies of object libraries, 2018-12-10, v3.14.0-rc1~260^2) because the relevant dependency appears transitively through the object library target itself. Re-order the logic to process link dependencies first, and then external object sources. That way object libraries used via `target_link_libraries` will be treated as such by dependency analysis. This also adds missing backtrace information for object libraries used via `target_link_libraries`. The missing information was mentioned in a FIXME comment in the RunCMake.FileAPI test added by commit ea0a060168 (fileapi: Add test for codemodel v2, 2018-11-09, v3.14.0-rc1~257^2~7). That comment itself was dropped by commit a0de350e2f (FileAPI test: Break gen_check_targets() into JSON files, 2020-02-07), but we can now update the corresponding location in the `.json` files to have the now-expected backtrace information. Fixes: #20421
Diffstat (limited to 'Source/cmComputeTargetDepends.cxx')
-rw-r--r--Source/cmComputeTargetDepends.cxx27
1 files changed, 14 insertions, 13 deletions
diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx
index a98a608..41f5346 100644
--- a/Source/cmComputeTargetDepends.cxx
+++ b/Source/cmComputeTargetDepends.cxx
@@ -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);
- }
- }
}
}