Fix include dir propagation from conditionally linked targets
Generator expressions, including configuration-specific expressions may be used as link libraries of targets. The old-style keywords of target_link_libraries are handled in terms of new generator expressions. However, the generator expressions expect target names to be valid against a regular expression, whereas target_link_libraries does not require validation. In generator expression constructed without any action from the user we need to ensure that only valid expressions are generated. Ensure that strings which are not valid target names are not used in generator expressions which validate the argument. Code like target_link_libraries(B debug A) generates usage requirement references such as "$<$<CONFIG:DEBUG>:A>". When cmTarget::GetIncludeDirectories uses such references it generates expressions like: $<TARGET_PROPERTY:$<$<CONFIG:DEBUG>:A>,INTERFACE_INCLUDE_DIRECTORIES> When the conditions are false such references evaluate as an empty string and the expression fails with an error such as: $<TARGET_PROPERTY:tgt,prop> expression requires a non-empty target name. Fix this by teaching cmTarget::GetIncludeDirectories to wrap the above expression inside a conditional: $<$<BOOL:$<$<CONFIG:DEBUG>:A>>:...> so that $<TARGET_PROPERTY:...> will not be evaluated with an empty target.
This commit is contained in:
parent
b8259c3d69
commit
26dba6a162
|
@ -2709,10 +2709,14 @@ void cmTarget::SetProperty(const char* prop, const char* value)
|
||||||
if (strcmp(prop, "LINK_LIBRARIES") == 0)
|
if (strcmp(prop, "LINK_LIBRARIES") == 0)
|
||||||
{
|
{
|
||||||
this->Internal->LinkInterfaceIncludeDirectoriesEntries.clear();
|
this->Internal->LinkInterfaceIncludeDirectoriesEntries.clear();
|
||||||
cmListFileBacktrace lfbt;
|
if (cmGeneratorExpression::IsValidTargetName(value)
|
||||||
this->Makefile->GetBacktrace(lfbt);
|
|| cmGeneratorExpression::Find(value) != std::string::npos)
|
||||||
cmValueWithOrigin entry(value, lfbt);
|
{
|
||||||
this->Internal->LinkInterfaceIncludeDirectoriesEntries.push_back(entry);
|
cmListFileBacktrace lfbt;
|
||||||
|
this->Makefile->GetBacktrace(lfbt);
|
||||||
|
cmValueWithOrigin entry(value, lfbt);
|
||||||
|
this->Internal->LinkInterfaceIncludeDirectoriesEntries.push_back(entry);
|
||||||
|
}
|
||||||
// Fall through
|
// Fall through
|
||||||
}
|
}
|
||||||
this->Properties.SetProperty(prop, value, cmProperty::TARGET);
|
this->Properties.SetProperty(prop, value, cmProperty::TARGET);
|
||||||
|
@ -2738,10 +2742,14 @@ void cmTarget::AppendProperty(const char* prop, const char* value,
|
||||||
}
|
}
|
||||||
if (strcmp(prop, "LINK_LIBRARIES") == 0)
|
if (strcmp(prop, "LINK_LIBRARIES") == 0)
|
||||||
{
|
{
|
||||||
cmListFileBacktrace lfbt;
|
if (cmGeneratorExpression::IsValidTargetName(value)
|
||||||
this->Makefile->GetBacktrace(lfbt);
|
|| cmGeneratorExpression::Find(value) != std::string::npos)
|
||||||
cmValueWithOrigin entry(value, lfbt);
|
{
|
||||||
this->Internal->LinkInterfaceIncludeDirectoriesEntries.push_back(entry);
|
cmListFileBacktrace lfbt;
|
||||||
|
this->Makefile->GetBacktrace(lfbt);
|
||||||
|
cmValueWithOrigin entry(value, lfbt);
|
||||||
|
this->Internal->LinkInterfaceIncludeDirectoriesEntries.push_back(entry);
|
||||||
|
}
|
||||||
// Fall through
|
// Fall through
|
||||||
}
|
}
|
||||||
this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
|
this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
|
||||||
|
@ -2950,16 +2958,23 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
|
||||||
ge.Parse(it->Value);
|
ge.Parse(it->Value);
|
||||||
std::string result = cge->Evaluate(this->Makefile, config,
|
std::string result = cge->Evaluate(this->Makefile, config,
|
||||||
false, this, 0, 0);
|
false, this, 0, 0);
|
||||||
if (!cmGeneratorExpression::IsValidTargetName(result.c_str())
|
if (!this->Makefile->FindTargetToUse(result.c_str()))
|
||||||
|| !this->Makefile->FindTargetToUse(result.c_str()))
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::string includeGenex = "$<TARGET_PROPERTY:" +
|
||||||
|
it->Value + ",INTERFACE_INCLUDE_DIRECTORIES>";
|
||||||
|
if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
|
||||||
|
{
|
||||||
|
// Because it->Value is a generator expression, ensure that it
|
||||||
|
// evaluates to the non-empty string before being used in the
|
||||||
|
// TARGET_PROPERTY expression.
|
||||||
|
includeGenex = "$<$<BOOL:" + it->Value + ">:" + includeGenex + ">";
|
||||||
|
}
|
||||||
cmGeneratorExpression ge(it->Backtrace);
|
cmGeneratorExpression ge(it->Backtrace);
|
||||||
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
|
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
|
||||||
"$<TARGET_PROPERTY:" +
|
includeGenex);
|
||||||
it->Value + ",INTERFACE_INCLUDE_DIRECTORIES>");
|
|
||||||
|
|
||||||
this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries.push_back(
|
this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries.push_back(
|
||||||
new cmTargetInternals::IncludeDirectoriesEntry(cge,
|
new cmTargetInternals::IncludeDirectoriesEntry(cge,
|
||||||
|
|
Loading…
Reference in New Issue