cmGeneratorTarget: Add GetLinkImplementationClosure mode for linking

Previously this method always returned the closure for compile-only
usage requirements.  Add an option to get the closure for linking, which
pierces `$<LINK_ONLY>`.
This commit is contained in:
Brad King
2024-05-08 15:49:26 -04:00
parent a11cbcc268
commit e64d09a729
4 changed files with 24 additions and 14 deletions

View File

@@ -511,6 +511,8 @@ void cmGeneratorTarget::ClearSourcesCache()
this->SourcesAreContextDependent = Tribool::Indeterminate;
this->Objects.clear();
this->VisitedConfigsForObjects.clear();
this->LinkImplClosureForLinkMap.clear();
this->LinkImplClosureForUsageMap.clear();
this->LinkImplMap.clear();
this->LinkImplUsageRequirementsOnlyMap.clear();
this->IncludeDirectoriesCache.clear();
@@ -1186,7 +1188,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(
}
std::vector<cmGeneratorTarget const*> const& deps =
this->GetLinkImplementationClosure(config);
this->GetLinkImplementationClosure(config, UseTo::Compile);
for (cmGeneratorTarget const* dep : deps) {
handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
&dagChecker, result, excludeImported, language);

View File

@@ -1087,7 +1087,8 @@ private:
{
bool Done = false;
};
mutable std::map<std::string, LinkImplClosure> LinkImplClosureMap;
mutable std::map<std::string, LinkImplClosure> LinkImplClosureForLinkMap;
mutable std::map<std::string, LinkImplClosure> LinkImplClosureForUsageMap;
using LinkInterfaceMapType = std::map<std::string, cmHeadToLinkInterfaceMap>;
mutable LinkInterfaceMapType LinkInterfaceMap;
@@ -1307,7 +1308,7 @@ private:
public:
const std::vector<const cmGeneratorTarget*>& GetLinkImplementationClosure(
const std::string& config) const;
const std::string& config, UseTo usage) const;
mutable std::map<std::string, std::string> MaxLanguageStandards;
std::map<std::string, std::string> const& GetMaxLanguageStandards() const

View File

@@ -31,6 +31,10 @@
#include "cmSystemTools.h"
#include "cmValue.h"
namespace {
using UseTo = cmGeneratorTarget::UseTo;
}
const cmGeneratorTarget::CompatibleInterfacesBase&
cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
{
@@ -41,7 +45,7 @@ cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
compat.PropsString.insert("AUTOUIC_OPTIONS");
std::vector<cmGeneratorTarget const*> const& deps =
this->GetLinkImplementationClosure(config);
this->GetLinkImplementationClosure(config, UseTo::Compile);
for (cmGeneratorTarget const* li : deps) {
#define CM_READ_COMPATIBLE_INTERFACE(X, x) \
if (cmValue prop = li->GetProperty("COMPATIBLE_INTERFACE_" #X)) { \
@@ -573,7 +577,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
std::vector<cmGeneratorTarget const*> const& deps =
tgt->GetLinkImplementationClosure(config);
tgt->GetLinkImplementationClosure(config, UseTo::Compile);
if (deps.empty()) {
return propContent;

View File

@@ -268,23 +268,23 @@ static void processILibs(const std::string& config,
cmGeneratorTarget const* headTarget,
cmLinkItem const& item, cmGlobalGenerator* gg,
std::vector<cmGeneratorTarget const*>& tgts,
std::set<cmGeneratorTarget const*>& emitted)
std::set<cmGeneratorTarget const*>& emitted,
UseTo usage)
{
if (item.Target && emitted.insert(item.Target).second) {
tgts.push_back(item.Target);
if (cmLinkInterfaceLibraries const* iface =
item.Target->GetLinkInterfaceLibraries(config, headTarget,
UseTo::Compile)) {
item.Target->GetLinkInterfaceLibraries(config, headTarget, usage)) {
for (cmLinkItem const& lib : iface->Libraries) {
processILibs(config, headTarget, lib, gg, tgts, emitted);
processILibs(config, headTarget, lib, gg, tgts, emitted, usage);
}
}
}
}
const std::vector<const cmGeneratorTarget*>&
cmGeneratorTarget::GetLinkImplementationClosure(
const std::string& config) const
cmGeneratorTarget::GetLinkImplementationClosure(const std::string& config,
UseTo usage) const
{
// There is no link implementation for targets that cannot compile sources.
if (!this->CanCompileSources()) {
@@ -292,18 +292,21 @@ cmGeneratorTarget::GetLinkImplementationClosure(
return empty;
}
LinkImplClosure& tgts = this->LinkImplClosureMap[config];
LinkImplClosure& tgts =
(usage == UseTo::Compile ? this->LinkImplClosureForUsageMap[config]
: this->LinkImplClosureForLinkMap[config]);
if (!tgts.Done) {
tgts.Done = true;
std::set<cmGeneratorTarget const*> emitted;
cmLinkImplementationLibraries const* impl =
this->GetLinkImplementationLibraries(config, UseTo::Compile);
this->GetLinkImplementationLibraries(config, usage);
assert(impl);
for (cmLinkImplItem const& lib : impl->Libraries) {
processILibs(config, this, lib,
this->LocalGenerator->GetGlobalGenerator(), tgts, emitted);
this->LocalGenerator->GetGlobalGenerator(), tgts, emitted,
usage);
}
}
return tgts;