cmMakefile: Separate storage of buildsystem properties and their origins.

This simplifies some existing and upcoming algorithms.
This commit is contained in:
Stephen Kelly 2015-07-08 00:29:41 +02:00
parent a89c02ce3d
commit ef17bbefd7
2 changed files with 89 additions and 65 deletions

View File

@ -275,17 +275,47 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
std::vector<cmValueWithOrigin> cmMakefile::GetIncludeDirectoriesEntries() const std::vector<cmValueWithOrigin> cmMakefile::GetIncludeDirectoriesEntries() const
{ {
return this->IncludeDirectoriesEntries; std::vector<cmValueWithOrigin> entries;
entries.reserve(this->IncludeDirectoriesEntries.size());
std::vector<cmListFileBacktrace>::const_iterator btIt =
this->IncludeDirectoriesEntryBacktraces.begin();
for(std::vector<std::string>::const_iterator it =
this->IncludeDirectoriesEntries.begin();
it != this->IncludeDirectoriesEntries.end(); ++it, ++btIt)
{
entries.push_back(cmValueWithOrigin(*it, *btIt));
}
return entries;
} }
std::vector<cmValueWithOrigin> cmMakefile::GetCompileOptionsEntries() const std::vector<cmValueWithOrigin> cmMakefile::GetCompileOptionsEntries() const
{ {
return this->CompileOptionsEntries; std::vector<cmValueWithOrigin> entries;
entries.reserve(this->CompileOptionsEntries.size());
std::vector<cmListFileBacktrace>::const_iterator btIt =
this->CompileOptionsEntryBacktraces.begin();
for(std::vector<std::string>::const_iterator it =
this->CompileOptionsEntries.begin();
it != this->CompileOptionsEntries.end(); ++it, ++btIt)
{
entries.push_back(cmValueWithOrigin(*it, *btIt));
}
return entries;
} }
std::vector<cmValueWithOrigin> cmMakefile::GetCompileDefinitionsEntries() const std::vector<cmValueWithOrigin> cmMakefile::GetCompileDefinitionsEntries() const
{ {
return this->CompileDefinitionsEntries; std::vector<cmValueWithOrigin> entries;
entries.reserve(this->CompileDefinitionsEntries.size());
std::vector<cmListFileBacktrace>::const_iterator btIt =
this->CompileDefinitionsEntryBacktraces.begin();
for(std::vector<std::string>::const_iterator it =
this->CompileDefinitionsEntries.begin();
it != this->CompileDefinitionsEntries.end(); ++it, ++btIt)
{
entries.push_back(cmValueWithOrigin(*it, *btIt));
}
return entries;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -1542,23 +1572,32 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
this->GetCurrentBinaryDirectory()); this->GetCurrentBinaryDirectory());
const std::vector<cmValueWithOrigin>& parentIncludes = this->IncludeDirectoriesEntries.insert(
parent->GetIncludeDirectoriesEntries(); this->IncludeDirectoriesEntries.end(),
this->IncludeDirectoriesEntries.insert(this->IncludeDirectoriesEntries.end(), parent->IncludeDirectoriesEntries.begin(),
parentIncludes.begin(), parent->IncludeDirectoriesEntries.end());
parentIncludes.end()); this->IncludeDirectoriesEntryBacktraces.insert(
this->IncludeDirectoriesEntryBacktraces.end(),
parent->IncludeDirectoriesEntryBacktraces.begin(),
parent->IncludeDirectoriesEntryBacktraces.end());
const std::vector<cmValueWithOrigin>& parentOptions = this->CompileOptionsEntries.insert(
parent->GetCompileOptionsEntries(); this->CompileOptionsEntries.end(),
this->CompileOptionsEntries.insert(this->CompileOptionsEntries.end(), parent->CompileOptionsEntries.begin(),
parentOptions.begin(), parent->CompileOptionsEntries.end());
parentOptions.end()); this->CompileOptionsEntryBacktraces.insert(
this->CompileOptionsEntryBacktraces.end(),
parent->CompileOptionsEntryBacktraces.begin(),
parent->CompileOptionsEntryBacktraces.end());
const std::vector<cmValueWithOrigin>& parentDefines = this->CompileDefinitionsEntries.insert(
parent->GetCompileDefinitionsEntries(); this->CompileDefinitionsEntries.end(),
this->CompileDefinitionsEntries.insert(this->CompileDefinitionsEntries.end(), parent->CompileDefinitionsEntries.begin(),
parentDefines.begin(), parent->CompileDefinitionsEntries.end());
parentDefines.end()); this->CompileDefinitionsEntryBacktraces.insert(
this->CompileDefinitionsEntryBacktraces.end(),
parent->CompileDefinitionsEntryBacktraces.begin(),
parent->CompileDefinitionsEntryBacktraces.end());
this->SystemIncludeDirectories = parent->SystemIncludeDirectories; this->SystemIncludeDirectories = parent->SystemIncludeDirectories;
@ -1902,13 +1941,18 @@ void cmMakefile::AddIncludeDirectories(const std::vector<std::string> &incs,
return; return;
} }
std::vector<cmValueWithOrigin>::iterator position = std::vector<std::string>::iterator position =
before ? this->IncludeDirectoriesEntries.begin() before ? this->IncludeDirectoriesEntries.begin()
: this->IncludeDirectoriesEntries.end(); : this->IncludeDirectoriesEntries.end();
std::vector<cmListFileBacktrace>::iterator btPos =
this->IncludeDirectoriesEntryBacktraces.begin()
+ std::distance(this->IncludeDirectoriesEntries.begin(), position);
cmListFileBacktrace lfbt = this->GetBacktrace(); cmListFileBacktrace lfbt = this->GetBacktrace();
cmValueWithOrigin entry(cmJoin(incs, ";"), lfbt); std::string entryString = cmJoin(incs, ";");
this->IncludeDirectoriesEntries.insert(position, entry); cmValueWithOrigin entry(entryString, lfbt);
this->IncludeDirectoriesEntries.insert(position, entryString);
this->IncludeDirectoriesEntryBacktraces.insert(btPos, lfbt);
// Property on each target: // Property on each target:
for (cmTargets::iterator l = this->Targets.begin(); for (cmTargets::iterator l = this->Targets.begin();
@ -4135,36 +4179,40 @@ void cmMakefile::SetProperty(const std::string& prop, const char* value)
if (prop == "INCLUDE_DIRECTORIES") if (prop == "INCLUDE_DIRECTORIES")
{ {
this->IncludeDirectoriesEntries.clear(); this->IncludeDirectoriesEntries.clear();
this->IncludeDirectoriesEntryBacktraces.clear();
if (!value) if (!value)
{ {
return; return;
} }
cmListFileBacktrace lfbt = this->GetBacktrace(); cmListFileBacktrace lfbt = this->GetBacktrace();
this->IncludeDirectoriesEntries.push_back( this->IncludeDirectoriesEntries.push_back(value);
cmValueWithOrigin(value, lfbt)); this->IncludeDirectoriesEntryBacktraces.push_back(lfbt);
return; return;
} }
if (prop == "COMPILE_OPTIONS") if (prop == "COMPILE_OPTIONS")
{ {
this->CompileOptionsEntries.clear(); this->CompileOptionsEntries.clear();
this->CompileDefinitionsEntryBacktraces.clear();
if (!value) if (!value)
{ {
return; return;
} }
cmListFileBacktrace lfbt = this->GetBacktrace(); cmListFileBacktrace lfbt = this->GetBacktrace();
this->CompileOptionsEntries.push_back(cmValueWithOrigin(value, lfbt)); this->CompileOptionsEntries.push_back(value);
this->CompileOptionsEntryBacktraces.push_back(lfbt);
return; return;
} }
if (prop == "COMPILE_DEFINITIONS") if (prop == "COMPILE_DEFINITIONS")
{ {
this->CompileDefinitionsEntries.clear(); this->CompileDefinitionsEntries.clear();
this->CompileDefinitionsEntryBacktraces.clear();
if (!value) if (!value)
{ {
return; return;
} }
cmListFileBacktrace lfbt = this->GetBacktrace(); cmListFileBacktrace lfbt = this->GetBacktrace();
cmValueWithOrigin entry(value, lfbt); this->CompileDefinitionsEntries.push_back(value);
this->CompileDefinitionsEntries.push_back(entry); this->CompileDefinitionsEntryBacktraces.push_back(lfbt);
return; return;
} }
@ -4178,22 +4226,22 @@ void cmMakefile::AppendProperty(const std::string& prop,
if (prop == "INCLUDE_DIRECTORIES") if (prop == "INCLUDE_DIRECTORIES")
{ {
cmListFileBacktrace lfbt = this->GetBacktrace(); cmListFileBacktrace lfbt = this->GetBacktrace();
this->IncludeDirectoriesEntries.push_back( this->IncludeDirectoriesEntries.push_back(value);
cmValueWithOrigin(value, lfbt)); this->IncludeDirectoriesEntryBacktraces.push_back(lfbt);
return; return;
} }
if (prop == "COMPILE_OPTIONS") if (prop == "COMPILE_OPTIONS")
{ {
cmListFileBacktrace lfbt = this->GetBacktrace(); cmListFileBacktrace lfbt = this->GetBacktrace();
this->CompileOptionsEntries.push_back( this->CompileOptionsEntries.push_back(value);
cmValueWithOrigin(value, lfbt)); this->CompileOptionsEntryBacktraces.push_back(lfbt);
return; return;
} }
if (prop == "COMPILE_DEFINITIONS") if (prop == "COMPILE_DEFINITIONS")
{ {
cmListFileBacktrace lfbt = this->GetBacktrace(); cmListFileBacktrace lfbt = this->GetBacktrace();
this->CompileDefinitionsEntries.push_back( this->CompileDefinitionsEntries.push_back(value);
cmValueWithOrigin(value, lfbt)); this->CompileDefinitionsEntryBacktraces.push_back(lfbt);
return; return;
} }
@ -4248,44 +4296,17 @@ const char *cmMakefile::GetProperty(const std::string& prop,
} }
else if (prop == "INCLUDE_DIRECTORIES") else if (prop == "INCLUDE_DIRECTORIES")
{ {
std::string sep; output = cmJoin(this->IncludeDirectoriesEntries, ";");
for (std::vector<cmValueWithOrigin>::const_iterator
it = this->IncludeDirectoriesEntries.begin(),
end = this->IncludeDirectoriesEntries.end();
it != end; ++it)
{
output += sep;
output += it->Value;
sep = ";";
}
return output.c_str(); return output.c_str();
} }
else if (prop == "COMPILE_OPTIONS") else if (prop == "COMPILE_OPTIONS")
{ {
std::string sep; output = cmJoin(this->CompileOptionsEntries, ";");
for (std::vector<cmValueWithOrigin>::const_iterator
it = this->CompileOptionsEntries.begin(),
end = this->CompileOptionsEntries.end();
it != end; ++it)
{
output += sep;
output += it->Value;
sep = ";";
}
return output.c_str(); return output.c_str();
} }
else if (prop == "COMPILE_DEFINITIONS") else if (prop == "COMPILE_DEFINITIONS")
{ {
std::string sep; output = cmJoin(this->CompileDefinitionsEntries, ";");
for (std::vector<cmValueWithOrigin>::const_iterator
it = this->CompileDefinitionsEntries.begin(),
end = this->CompileDefinitionsEntries.end();
it != end; ++it)
{
output += sep;
output += it->Value;
sep = ";";
}
return output.c_str(); return output.c_str();
} }

View File

@ -842,9 +842,12 @@ protected:
std::vector<std::string> HeaderFileExtensions; std::vector<std::string> HeaderFileExtensions;
std::string DefineFlags; std::string DefineFlags;
std::vector<cmValueWithOrigin> IncludeDirectoriesEntries; std::vector<std::string> IncludeDirectoriesEntries;
std::vector<cmValueWithOrigin> CompileOptionsEntries; std::vector<cmListFileBacktrace> IncludeDirectoriesEntryBacktraces;
std::vector<cmValueWithOrigin> CompileDefinitionsEntries; std::vector<std::string> CompileOptionsEntries;
std::vector<cmListFileBacktrace> CompileOptionsEntryBacktraces;
std::vector<std::string> CompileDefinitionsEntries;
std::vector<cmListFileBacktrace> CompileDefinitionsEntryBacktraces;
// Track the value of the computed DEFINITIONS property. // Track the value of the computed DEFINITIONS property.
void AddDefineFlag(const char*, std::string&); void AddDefineFlag(const char*, std::string&);