cmGeneratorTarget: add the concept of a "family" name

With synthetic targets, a name which is the same between all synthetic
targets which share a base target is warranted.
This commit is contained in:
Ben Boeckel
2024-03-20 21:09:04 -04:00
parent 5b89e46c11
commit c66821b22b
4 changed files with 27 additions and 0 deletions
+14
View File
@@ -173,6 +173,20 @@ const std::string& cmGeneratorTarget::GetName() const
return this->Target->GetName();
}
std::string cmGeneratorTarget::GetFamilyName() const
{
if (!this->IsImported() && !this->IsSynthetic()) {
return this->Target->GetTemplateName();
}
cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_512);
constexpr size_t HASH_TRUNCATION = 12;
auto dirhash =
hasher.HashString(this->GetLocalGenerator()->GetCurrentBinaryDirectory());
auto targetIdent = hasher.HashString(cmStrCat("@d_", dirhash));
return cmStrCat(this->Target->GetTemplateName(), '@',
targetIdent.substr(0, HASH_TRUNCATION));
}
std::string cmGeneratorTarget::GetExportName() const
{
cmValue exportName = this->GetProperty("EXPORT_NAME");
+1
View File
@@ -108,6 +108,7 @@ public:
cmStateEnums::TargetType GetType() const;
const std::string& GetName() const;
std::string GetFamilyName() const;
std::string GetExportName() const;
std::string GetFilesystemExportName() const;
+11
View File
@@ -645,6 +645,7 @@ public:
cmStateEnums::TargetType TargetType;
cmMakefile* Makefile;
cmPolicies::PolicyMap PolicyMap;
cmTarget const* TemplateTarget;
std::string Name;
std::string InstallPath;
std::string RuntimeInstallPath;
@@ -931,6 +932,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
this->impl->TargetType = type;
this->impl->Makefile = mf;
this->impl->Name = name;
this->impl->TemplateTarget = nullptr;
this->impl->IsGeneratorProvided = false;
this->impl->HaveInstallRule = false;
this->impl->IsDLLPlatform = false;
@@ -1186,6 +1188,14 @@ const std::string& cmTarget::GetName() const
return this->impl->Name;
}
const std::string& cmTarget::GetTemplateName() const
{
if (this->impl->TemplateTarget) {
return this->impl->TemplateTarget->GetTemplateName();
}
return this->impl->Name;
}
cmPolicies::PolicyStatus cmTarget::GetPolicyStatus(
cmPolicies::PolicyID policy) const
{
@@ -1784,6 +1794,7 @@ void cmTarget::CopyPolicyStatuses(cmTarget const* tgt)
assert(tgt->IsImported());
this->impl->PolicyMap = tgt->impl->PolicyMap;
this->impl->TemplateTarget = tgt;
}
void cmTarget::CopyImportedCxxModulesEntries(cmTarget const* tgt)
+1
View File
@@ -78,6 +78,7 @@ public:
//! Set/Get the name of the target
const std::string& GetName() const;
const std::string& GetTemplateName() const;
//! Get the policy map
cmPolicies::PolicyMap const& GetPolicyMap() const;