From ef17bbefd7c504af65f2e6c52f5d7fa8e82d087e Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 8 Jul 2015 00:29:41 +0200 Subject: [PATCH] cmMakefile: Separate storage of buildsystem properties and their origins. This simplifies some existing and upcoming algorithms. --- Source/cmMakefile.cxx | 145 ++++++++++++++++++++++++------------------ Source/cmMakefile.h | 9 ++- 2 files changed, 89 insertions(+), 65 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d5775fbf8..dc8d98323 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -275,17 +275,47 @@ void cmMakefile::IssueMessage(cmake::MessageType t, std::vector cmMakefile::GetIncludeDirectoriesEntries() const { - return this->IncludeDirectoriesEntries; + std::vector entries; + entries.reserve(this->IncludeDirectoriesEntries.size()); + std::vector::const_iterator btIt = + this->IncludeDirectoriesEntryBacktraces.begin(); + for(std::vector::const_iterator it = + this->IncludeDirectoriesEntries.begin(); + it != this->IncludeDirectoriesEntries.end(); ++it, ++btIt) + { + entries.push_back(cmValueWithOrigin(*it, *btIt)); + } + return entries; } std::vector cmMakefile::GetCompileOptionsEntries() const { - return this->CompileOptionsEntries; + std::vector entries; + entries.reserve(this->CompileOptionsEntries.size()); + std::vector::const_iterator btIt = + this->CompileOptionsEntryBacktraces.begin(); + for(std::vector::const_iterator it = + this->CompileOptionsEntries.begin(); + it != this->CompileOptionsEntries.end(); ++it, ++btIt) + { + entries.push_back(cmValueWithOrigin(*it, *btIt)); + } + return entries; } std::vector cmMakefile::GetCompileDefinitionsEntries() const { - return this->CompileDefinitionsEntries; + std::vector entries; + entries.reserve(this->CompileDefinitionsEntries.size()); + std::vector::const_iterator btIt = + this->CompileDefinitionsEntryBacktraces.begin(); + for(std::vector::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->GetCurrentBinaryDirectory()); - const std::vector& parentIncludes = - parent->GetIncludeDirectoriesEntries(); - this->IncludeDirectoriesEntries.insert(this->IncludeDirectoriesEntries.end(), - parentIncludes.begin(), - parentIncludes.end()); + this->IncludeDirectoriesEntries.insert( + this->IncludeDirectoriesEntries.end(), + parent->IncludeDirectoriesEntries.begin(), + parent->IncludeDirectoriesEntries.end()); + this->IncludeDirectoriesEntryBacktraces.insert( + this->IncludeDirectoriesEntryBacktraces.end(), + parent->IncludeDirectoriesEntryBacktraces.begin(), + parent->IncludeDirectoriesEntryBacktraces.end()); - const std::vector& parentOptions = - parent->GetCompileOptionsEntries(); - this->CompileOptionsEntries.insert(this->CompileOptionsEntries.end(), - parentOptions.begin(), - parentOptions.end()); + this->CompileOptionsEntries.insert( + this->CompileOptionsEntries.end(), + parent->CompileOptionsEntries.begin(), + parent->CompileOptionsEntries.end()); + this->CompileOptionsEntryBacktraces.insert( + this->CompileOptionsEntryBacktraces.end(), + parent->CompileOptionsEntryBacktraces.begin(), + parent->CompileOptionsEntryBacktraces.end()); - const std::vector& parentDefines = - parent->GetCompileDefinitionsEntries(); - this->CompileDefinitionsEntries.insert(this->CompileDefinitionsEntries.end(), - parentDefines.begin(), - parentDefines.end()); + this->CompileDefinitionsEntries.insert( + this->CompileDefinitionsEntries.end(), + parent->CompileDefinitionsEntries.begin(), + parent->CompileDefinitionsEntries.end()); + this->CompileDefinitionsEntryBacktraces.insert( + this->CompileDefinitionsEntryBacktraces.end(), + parent->CompileDefinitionsEntryBacktraces.begin(), + parent->CompileDefinitionsEntryBacktraces.end()); this->SystemIncludeDirectories = parent->SystemIncludeDirectories; @@ -1902,13 +1941,18 @@ void cmMakefile::AddIncludeDirectories(const std::vector &incs, return; } - std::vector::iterator position = + std::vector::iterator position = before ? this->IncludeDirectoriesEntries.begin() : this->IncludeDirectoriesEntries.end(); + std::vector::iterator btPos = + this->IncludeDirectoriesEntryBacktraces.begin() + + std::distance(this->IncludeDirectoriesEntries.begin(), position); cmListFileBacktrace lfbt = this->GetBacktrace(); - cmValueWithOrigin entry(cmJoin(incs, ";"), lfbt); - this->IncludeDirectoriesEntries.insert(position, entry); + std::string entryString = cmJoin(incs, ";"); + cmValueWithOrigin entry(entryString, lfbt); + this->IncludeDirectoriesEntries.insert(position, entryString); + this->IncludeDirectoriesEntryBacktraces.insert(btPos, lfbt); // Property on each target: 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") { this->IncludeDirectoriesEntries.clear(); + this->IncludeDirectoriesEntryBacktraces.clear(); if (!value) { return; } cmListFileBacktrace lfbt = this->GetBacktrace(); - this->IncludeDirectoriesEntries.push_back( - cmValueWithOrigin(value, lfbt)); + this->IncludeDirectoriesEntries.push_back(value); + this->IncludeDirectoriesEntryBacktraces.push_back(lfbt); return; } if (prop == "COMPILE_OPTIONS") { this->CompileOptionsEntries.clear(); + this->CompileDefinitionsEntryBacktraces.clear(); if (!value) { return; } cmListFileBacktrace lfbt = this->GetBacktrace(); - this->CompileOptionsEntries.push_back(cmValueWithOrigin(value, lfbt)); + this->CompileOptionsEntries.push_back(value); + this->CompileOptionsEntryBacktraces.push_back(lfbt); return; } if (prop == "COMPILE_DEFINITIONS") { this->CompileDefinitionsEntries.clear(); + this->CompileDefinitionsEntryBacktraces.clear(); if (!value) { return; } cmListFileBacktrace lfbt = this->GetBacktrace(); - cmValueWithOrigin entry(value, lfbt); - this->CompileDefinitionsEntries.push_back(entry); + this->CompileDefinitionsEntries.push_back(value); + this->CompileDefinitionsEntryBacktraces.push_back(lfbt); return; } @@ -4178,22 +4226,22 @@ void cmMakefile::AppendProperty(const std::string& prop, if (prop == "INCLUDE_DIRECTORIES") { cmListFileBacktrace lfbt = this->GetBacktrace(); - this->IncludeDirectoriesEntries.push_back( - cmValueWithOrigin(value, lfbt)); + this->IncludeDirectoriesEntries.push_back(value); + this->IncludeDirectoriesEntryBacktraces.push_back(lfbt); return; } if (prop == "COMPILE_OPTIONS") { cmListFileBacktrace lfbt = this->GetBacktrace(); - this->CompileOptionsEntries.push_back( - cmValueWithOrigin(value, lfbt)); + this->CompileOptionsEntries.push_back(value); + this->CompileOptionsEntryBacktraces.push_back(lfbt); return; } if (prop == "COMPILE_DEFINITIONS") { cmListFileBacktrace lfbt = this->GetBacktrace(); - this->CompileDefinitionsEntries.push_back( - cmValueWithOrigin(value, lfbt)); + this->CompileDefinitionsEntries.push_back(value); + this->CompileDefinitionsEntryBacktraces.push_back(lfbt); return; } @@ -4248,44 +4296,17 @@ const char *cmMakefile::GetProperty(const std::string& prop, } else if (prop == "INCLUDE_DIRECTORIES") { - std::string sep; - for (std::vector::const_iterator - it = this->IncludeDirectoriesEntries.begin(), - end = this->IncludeDirectoriesEntries.end(); - it != end; ++it) - { - output += sep; - output += it->Value; - sep = ";"; - } + output = cmJoin(this->IncludeDirectoriesEntries, ";"); return output.c_str(); } else if (prop == "COMPILE_OPTIONS") { - std::string sep; - for (std::vector::const_iterator - it = this->CompileOptionsEntries.begin(), - end = this->CompileOptionsEntries.end(); - it != end; ++it) - { - output += sep; - output += it->Value; - sep = ";"; - } + output = cmJoin(this->CompileOptionsEntries, ";"); return output.c_str(); } else if (prop == "COMPILE_DEFINITIONS") { - std::string sep; - for (std::vector::const_iterator - it = this->CompileDefinitionsEntries.begin(), - end = this->CompileDefinitionsEntries.end(); - it != end; ++it) - { - output += sep; - output += it->Value; - sep = ";"; - } + output = cmJoin(this->CompileDefinitionsEntries, ";"); return output.c_str(); } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 783658d48..57dcdb6f0 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -842,9 +842,12 @@ protected: std::vector HeaderFileExtensions; std::string DefineFlags; - std::vector IncludeDirectoriesEntries; - std::vector CompileOptionsEntries; - std::vector CompileDefinitionsEntries; + std::vector IncludeDirectoriesEntries; + std::vector IncludeDirectoriesEntryBacktraces; + std::vector CompileOptionsEntries; + std::vector CompileOptionsEntryBacktraces; + std::vector CompileDefinitionsEntries; + std::vector CompileDefinitionsEntryBacktraces; // Track the value of the computed DEFINITIONS property. void AddDefineFlag(const char*, std::string&);