cmTarget: Use else/if trees rather than an if tree

Skips lots of unnecessary string comparisons.
This commit is contained in:
Ben Boeckel 2014-02-03 16:09:16 -05:00
parent a0dc1354fe
commit 85242b7df6
1 changed files with 38 additions and 50 deletions

View File

@ -1750,15 +1750,14 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return;
}
if (prop == "NAME")
else if (prop == "NAME")
{
cmOStringStream e;
e << "NAME property is read-only\n";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return;
}
if(prop == "INCLUDE_DIRECTORIES")
else if(prop == "INCLUDE_DIRECTORIES")
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(&lfbt);
@ -1766,9 +1765,8 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
this->Internal->IncludeDirectoriesEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(cge));
return;
}
if(prop == "COMPILE_OPTIONS")
else if(prop == "COMPILE_OPTIONS")
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(&lfbt);
@ -1776,9 +1774,8 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
this->Internal->CompileOptionsEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(cge));
return;
}
if(prop == "COMPILE_FEATURES")
else if(prop == "COMPILE_FEATURES")
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(&lfbt);
@ -1786,9 +1783,8 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
this->Internal->CompileFeaturesEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(cge));
return;
}
if(prop == "COMPILE_DEFINITIONS")
else if(prop == "COMPILE_DEFINITIONS")
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(&lfbt);
@ -1796,25 +1792,22 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
this->Internal->CompileDefinitionsEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(cge));
return;
}
if(prop == "EXPORT_NAME" && this->IsImported())
else if(prop == "EXPORT_NAME" && this->IsImported())
{
cmOStringStream e;
e << "EXPORT_NAME property can't be set on imported targets (\""
<< this->Name << "\")\n";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return;
}
if (prop == "LINK_LIBRARIES")
else if (prop == "LINK_LIBRARIES")
{
this->Internal->LinkImplementationPropertyEntries.clear();
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmValueWithOrigin entry(value, lfbt);
this->Internal->LinkImplementationPropertyEntries.push_back(entry);
return;
}
if (prop == "SOURCES")
else if (prop == "SOURCES")
{
if(this->IsImported())
{
@ -1831,10 +1824,12 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
this->Internal->SourceEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(cge));
return;
}
this->Properties.SetProperty(prop, value, cmProperty::TARGET);
this->MaybeInvalidatePropertyCache(prop);
else
{
this->Properties.SetProperty(prop, value, cmProperty::TARGET);
this->MaybeInvalidatePropertyCache(prop);
}
}
//----------------------------------------------------------------------------
@ -1850,61 +1845,55 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value,
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return;
}
if (prop == "NAME")
else if (prop == "NAME")
{
cmOStringStream e;
e << "NAME property is read-only\n";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return;
}
if(prop == "INCLUDE_DIRECTORIES")
else if(prop == "INCLUDE_DIRECTORIES")
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(&lfbt);
this->Internal->IncludeDirectoriesEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
return;
}
if(prop == "COMPILE_OPTIONS")
else if(prop == "COMPILE_OPTIONS")
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(&lfbt);
this->Internal->CompileOptionsEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
return;
}
if(prop == "COMPILE_FEATURES")
else if(prop == "COMPILE_FEATURES")
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(&lfbt);
this->Internal->CompileFeaturesEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
return;
}
if(prop == "COMPILE_DEFINITIONS")
else if(prop == "COMPILE_DEFINITIONS")
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(&lfbt);
this->Internal->CompileDefinitionsEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
return;
}
if(prop == "EXPORT_NAME" && this->IsImported())
else if(prop == "EXPORT_NAME" && this->IsImported())
{
cmOStringStream e;
e << "EXPORT_NAME property can't be set on imported targets (\""
<< this->Name << "\")\n";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return;
}
if (prop == "LINK_LIBRARIES")
else if (prop == "LINK_LIBRARIES")
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmValueWithOrigin entry(value, lfbt);
this->Internal->LinkImplementationPropertyEntries.push_back(entry);
return;
}
if (prop == "SOURCES")
else if (prop == "SOURCES")
{
if(this->IsImported())
{
@ -1920,10 +1909,12 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value,
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
this->Internal->SourceEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(cge));
return;
}
this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
this->MaybeInvalidatePropertyCache(prop);
else
{
this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
this->MaybeInvalidatePropertyCache(prop);
}
}
//----------------------------------------------------------------------------
@ -3022,11 +3013,6 @@ const char *cmTarget::GetProperty(const std::string& prop,
return 0;
}
if (prop == "NAME")
{
return this->GetName().c_str();
}
// Watch for special "computed" properties that are dependent on
// other properties or variables. Always recompute them.
if(this->GetType() == cmTarget::EXECUTABLE ||
@ -3106,7 +3092,7 @@ const char *cmTarget::GetProperty(const std::string& prop,
}
return output.c_str();
}
if(prop == "COMPILE_OPTIONS")
else if(prop == "COMPILE_OPTIONS")
{
if (this->Internal->CompileOptionsEntries.empty())
{
@ -3129,7 +3115,7 @@ const char *cmTarget::GetProperty(const std::string& prop,
}
return output.c_str();
}
if(prop == "COMPILE_FEATURES")
else if(prop == "COMPILE_FEATURES")
{
if (this->Internal->CompileFeaturesEntries.empty())
{
@ -3152,7 +3138,7 @@ const char *cmTarget::GetProperty(const std::string& prop,
}
return output.c_str();
}
if(prop == "COMPILE_DEFINITIONS")
else if(prop == "COMPILE_DEFINITIONS")
{
if (this->Internal->CompileDefinitionsEntries.empty())
{
@ -3175,7 +3161,7 @@ const char *cmTarget::GetProperty(const std::string& prop,
}
return output.c_str();
}
if(prop == "LINK_LIBRARIES")
else if(prop == "LINK_LIBRARIES")
{
if (this->Internal->LinkImplementationPropertyEntries.empty())
{
@ -3196,13 +3182,15 @@ const char *cmTarget::GetProperty(const std::string& prop,
}
return output.c_str();
}
if (prop == "IMPORTED")
else if (prop == "IMPORTED")
{
return this->IsImported()?"TRUE":"FALSE";
}
if(prop == "SOURCES")
else if (prop == "NAME")
{
return this->GetName().c_str();
}
else if(prop == "SOURCES")
{
if (this->Internal->SourceEntries.empty())
{
@ -3299,12 +3287,12 @@ const char *cmTarget::GetProperty(const std::string& prop,
this->Properties.SetProperty("SOURCES", ss.str().c_str(),
cmProperty::TARGET);
}
// the type property returns what type the target is
if (prop == "TYPE")
else if (prop == "TYPE")
{
return cmTarget::GetTargetTypeName(this->GetType());
}
bool chain = false;
const char *retVal =
this->Properties.GetPropertyValue(prop, cmProperty::TARGET, chain);