Make internal TARGET_PROPERTY generator expressions more robust
While collecting usage requirements from the `INTERFACE_*` properties of directly linked targets, we internally generate `TARGET_PROPERTY:` and `TARGET_OBJECTS:` generator expressions to refer to those properties on those targets. At the point we generate these expressions we already have a pointer to an exact `cmGeneratorTarget` instance. Switch from using the target name in these generator expressions to using an internal unique name generated for each `cmGeneratorTarget` instance to be referenced. This avoids depending on the user-facing target name to find the same target we already have.
This commit is contained in:
parent
94a75801c8
commit
2f708f5d65
@ -1054,7 +1054,9 @@ std::string getLinkedTargetsContent(
|
|||||||
// Don't follow such link interface entries so as not to create a
|
// Don't follow such link interface entries so as not to create a
|
||||||
// self-referencing loop.
|
// self-referencing loop.
|
||||||
if (l.Target && l.Target != target) {
|
if (l.Target && l.Target != target) {
|
||||||
depString += sep + "$<TARGET_PROPERTY:" + l.Target->GetName() + "," +
|
std::string uniqueName =
|
||||||
|
target->GetGlobalGenerator()->IndexGeneratorTargetUniquely(l.Target);
|
||||||
|
depString += sep + "$<TARGET_PROPERTY:" + std::move(uniqueName) + "," +
|
||||||
interfacePropertyName + ">";
|
interfacePropertyName + ">";
|
||||||
sep = ";";
|
sep = ";";
|
||||||
}
|
}
|
||||||
|
@ -819,8 +819,11 @@ static void AddInterfaceEntries(
|
|||||||
thisTarget->GetLinkImplementationLibraries(config)) {
|
thisTarget->GetLinkImplementationLibraries(config)) {
|
||||||
for (cmLinkImplItem const& lib : impl->Libraries) {
|
for (cmLinkImplItem const& lib : impl->Libraries) {
|
||||||
if (lib.Target) {
|
if (lib.Target) {
|
||||||
|
std::string uniqueName =
|
||||||
|
thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
|
||||||
|
lib.Target);
|
||||||
std::string genex =
|
std::string genex =
|
||||||
"$<TARGET_PROPERTY:" + lib.AsStr() + "," + prop + ">";
|
"$<TARGET_PROPERTY:" + std::move(uniqueName) + "," + prop + ">";
|
||||||
cmGeneratorExpression ge(lib.Backtrace);
|
cmGeneratorExpression ge(lib.Backtrace);
|
||||||
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
|
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
|
||||||
cge->SetEvaluateForBuildsystem(true);
|
cge->SetEvaluateForBuildsystem(true);
|
||||||
@ -840,7 +843,10 @@ static void AddObjectEntries(
|
|||||||
for (cmLinkImplItem const& lib : impl->Libraries) {
|
for (cmLinkImplItem const& lib : impl->Libraries) {
|
||||||
if (lib.Target &&
|
if (lib.Target &&
|
||||||
lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
|
lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
|
||||||
std::string genex = "$<TARGET_OBJECTS:" + lib.AsStr() + ">";
|
std::string uniqueName =
|
||||||
|
thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
|
||||||
|
lib.Target);
|
||||||
|
std::string genex = "$<TARGET_OBJECTS:" + std::move(uniqueName) + ">";
|
||||||
cmGeneratorExpression ge(lib.Backtrace);
|
cmGeneratorExpression ge(lib.Backtrace);
|
||||||
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
|
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
|
||||||
cge->SetEvaluateForBuildsystem(true);
|
cge->SetEvaluateForBuildsystem(true);
|
||||||
|
@ -2155,6 +2155,24 @@ void cmGlobalGenerator::IndexGeneratorTarget(cmGeneratorTarget* gt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string cmGlobalGenerator::IndexGeneratorTargetUniquely(
|
||||||
|
cmGeneratorTarget const* gt)
|
||||||
|
{
|
||||||
|
// Use the pointer value to uniquely identify the target instance.
|
||||||
|
// Use a "T" prefix to indicate that this identifier is for a target.
|
||||||
|
// We must satisfy cmGeneratorExpression::IsValidTargetName so use no
|
||||||
|
// other special characters.
|
||||||
|
char buf[64];
|
||||||
|
sprintf(buf, "::T%p",
|
||||||
|
static_cast<void const*>(gt)); // cast avoids format warning
|
||||||
|
std::string id = gt->GetName() + buf;
|
||||||
|
// We internally index pointers to non-const generator targets
|
||||||
|
// but our callers only have pointers to const generator targets.
|
||||||
|
// They will give up non-const privileges when looking up anyway.
|
||||||
|
this->GeneratorTargetSearchIndex[id] = const_cast<cmGeneratorTarget*>(gt);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
void cmGlobalGenerator::IndexMakefile(cmMakefile* mf)
|
void cmGlobalGenerator::IndexMakefile(cmMakefile* mf)
|
||||||
{
|
{
|
||||||
// FIXME: add_subdirectory supports multiple build directories
|
// FIXME: add_subdirectory supports multiple build directories
|
||||||
|
@ -303,6 +303,10 @@ public:
|
|||||||
void IndexTarget(cmTarget* t);
|
void IndexTarget(cmTarget* t);
|
||||||
void IndexGeneratorTarget(cmGeneratorTarget* gt);
|
void IndexGeneratorTarget(cmGeneratorTarget* gt);
|
||||||
|
|
||||||
|
// Index the target using a name that is unique to that target
|
||||||
|
// even if other targets have the same name.
|
||||||
|
std::string IndexGeneratorTargetUniquely(cmGeneratorTarget const* gt);
|
||||||
|
|
||||||
static bool IsReservedTarget(std::string const& name);
|
static bool IsReservedTarget(std::string const& name);
|
||||||
|
|
||||||
virtual const char* GetAllTargetName() const { return "ALL_BUILD"; }
|
virtual const char* GetAllTargetName() const { return "ALL_BUILD"; }
|
||||||
|
Loading…
Reference in New Issue
Block a user