mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 10:47:59 +08:00
cmComputeLinkInformation: track OBJECT library dependencies
In commit b6a5382217
(Ninja: depend on language module information files
directly, 2023-02-10), introduced via !8197, language-specific module
information files (`CMakeFiles/<target>.dir/<lang>Modules.json`) files
were added as real dependencies to the dyndep collation steps.
Previously, the behavior was to inform the collator of all possible
targets and search for the files manually ignoring those which did not
exist with ordering enforced by depending on the linker output of all
dependent targets. This behavior could lead to stale information being
used (e.g., if a target stops providing any targets) and also did not
reliably build everything needed on rebuilds. Afterwards, the internal
computation changed the dependency from all possible targets to an exact
set of "these targets might have modules" query, however one that did
not include `OBJECT` libraries since do not have `LinkEntry` items
internally (their objects are instead treated as source files).
As a stopgap measure, track `OBJECT` libraries in a separate list and
query them explicitly when gathering targets which may have interesting
information. Future work can add `LinkEntry` items to represent these
targets once all `LinkEntry` consumers have been audited to make sure
they are not surprised by any `OBJECT` library entries.
Fixes: #25112
This commit is contained in:
@@ -170,9 +170,15 @@ std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories(
|
||||
cmGlobalCommonGenerator* const gg = this->GlobalCommonGenerator;
|
||||
if (cmComputeLinkInformation* cli =
|
||||
this->GeneratorTarget->GetLinkInformation(config)) {
|
||||
cmComputeLinkInformation::ItemVector const& items = cli->GetItems();
|
||||
for (auto const& item : items) {
|
||||
cmGeneratorTarget const* linkee = item.Target;
|
||||
std::vector<cmGeneratorTarget const*> targets;
|
||||
for (auto const& item : cli->GetItems()) {
|
||||
targets.push_back(item.Target);
|
||||
}
|
||||
for (auto const* target : cli->GetObjectLibrariesLinked()) {
|
||||
targets.push_back(target);
|
||||
}
|
||||
|
||||
for (auto const* linkee : targets) {
|
||||
if (linkee &&
|
||||
!linkee->IsImported()
|
||||
// Skip targets that build after this one in a static lib cycle.
|
||||
|
@@ -525,6 +525,12 @@ cmComputeLinkInformation::GetSharedLibrariesLinked() const
|
||||
return this->SharedLibrariesLinked;
|
||||
}
|
||||
|
||||
const std::vector<const cmGeneratorTarget*>&
|
||||
cmComputeLinkInformation::GetObjectLibrariesLinked() const
|
||||
{
|
||||
return this->ObjectLibrariesLinked;
|
||||
}
|
||||
|
||||
bool cmComputeLinkInformation::Compute()
|
||||
{
|
||||
// Skip targets that do not link.
|
||||
@@ -1147,8 +1153,12 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry)
|
||||
this->AddItem(BT<std::string>(libName, item.Backtrace));
|
||||
}
|
||||
} else if (tgt->GetType() == cmStateEnums::OBJECT_LIBRARY) {
|
||||
// Ignore object library!
|
||||
// Its object-files should already have been extracted for linking.
|
||||
if (!tgt->HaveCxx20ModuleSources() && !tgt->HaveFortranSources(config)) {
|
||||
// Ignore object library!
|
||||
// Its object-files should already have been extracted for linking.
|
||||
} else {
|
||||
this->ObjectLibrariesLinked.push_back(entry.Target);
|
||||
}
|
||||
} else {
|
||||
// Decide whether to use an import library.
|
||||
cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(config)
|
||||
|
@@ -96,6 +96,8 @@ public:
|
||||
std::string GetRPathString(bool for_install) const;
|
||||
std::string GetChrpathString() const;
|
||||
std::set<cmGeneratorTarget const*> const& GetSharedLibrariesLinked() const;
|
||||
std::vector<cmGeneratorTarget const*> const& GetObjectLibrariesLinked()
|
||||
const;
|
||||
std::vector<cmGeneratorTarget const*> const& GetRuntimeDLLs() const
|
||||
{
|
||||
return this->RuntimeDLLs;
|
||||
@@ -132,6 +134,7 @@ private:
|
||||
std::vector<std::string> FrameworkPaths;
|
||||
std::vector<std::string> RuntimeSearchPath;
|
||||
std::set<cmGeneratorTarget const*> SharedLibrariesLinked;
|
||||
std::vector<cmGeneratorTarget const*> ObjectLibrariesLinked;
|
||||
std::vector<cmGeneratorTarget const*> RuntimeDLLs;
|
||||
|
||||
// Context information.
|
||||
|
Reference in New Issue
Block a user