cmTarget: Simplify CMP0027 logic in processIncludeDirectories

Evaluate and lookup the target name only once per TargetPropertyEntry
instead of repeating it for each include directory entry.  Use a local
checkCMP0027 variable to record whether the policy should be checked.
Evaluate the target name as a generator expression only if it looks like
one.  Lookup the target by name only after evaluation of generator
expressions.
This commit is contained in:
Brad King 2014-06-30 11:41:54 -04:00
parent 5e07dcf7c8
commit b5b098ebb3
1 changed files with 20 additions and 26 deletions

View File

@ -2012,6 +2012,24 @@ static void processIncludeDirectories(cmTarget const* tgt,
for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
it = entries.begin(), end = entries.end(); it != end; ++it) it = entries.begin(), end = entries.end(); it != end; ++it)
{ {
std::string targetName = (*it)->TargetName;
bool checkCMP0027 = false;
if(!cmGeneratorExpression::IsValidTargetName(targetName)
&& cmGeneratorExpression::Find(targetName) != std::string::npos)
{
std::string evaluatedTargetName;
cmGeneratorExpression ge;
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(targetName);
evaluatedTargetName = cge->Evaluate(mf, config, false, tgt, 0, 0);
checkCMP0027 = evaluatedTargetName != targetName;
targetName = evaluatedTargetName;
}
cmTarget *dependentTarget = mf->FindTargetToUse(targetName);
const bool fromImported =
dependentTarget && dependentTarget->IsImported();
bool testIsOff = true; bool testIsOff = true;
bool cacheIncludes = false; bool cacheIncludes = false;
std::vector<std::string>& entryIncludes = (*it)->CachedEntries; std::vector<std::string>& entryIncludes = (*it)->CachedEntries;
@ -2037,36 +2055,12 @@ static void processIncludeDirectories(cmTarget const* tgt,
for(std::vector<std::string>::iterator for(std::vector<std::string>::iterator
li = entryIncludes.begin(); li != entryIncludes.end(); ++li) li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
{ {
std::string targetName = (*it)->TargetName; if (fromImported
std::string evaluatedTargetName;
{
cmGeneratorExpression ge;
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(targetName);
evaluatedTargetName = cge->Evaluate(mf, config, false, tgt, 0, 0);
}
cmTarget *dependentTarget = mf->FindTargetToUse(targetName);
const bool fromImported = dependentTarget
&& dependentTarget->IsImported();
cmTarget *evaluatedDependentTarget =
(targetName != evaluatedTargetName)
? mf->FindTargetToUse(evaluatedTargetName)
: 0;
targetName = evaluatedTargetName;
const bool fromEvaluatedImported = evaluatedDependentTarget
&& evaluatedDependentTarget->IsImported();
if ((fromImported || fromEvaluatedImported)
&& !cmSystemTools::FileExists(li->c_str())) && !cmSystemTools::FileExists(li->c_str()))
{ {
cmOStringStream e; cmOStringStream e;
cmake::MessageType messageType = cmake::FATAL_ERROR; cmake::MessageType messageType = cmake::FATAL_ERROR;
if (fromEvaluatedImported) if (checkCMP0027)
{ {
switch(tgt->GetPolicyStatusCMP0027()) switch(tgt->GetPolicyStatusCMP0027())
{ {