summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2004-03-03 23:18:47 (GMT)
committerBrad King <brad.king@kitware.com>2004-03-03 23:18:47 (GMT)
commit1dd718457fe1d410314d9443fa5d82462c5ae8ea (patch)
tree8b72677237a10327cdcde6dbedbe7b0191260b79 /Source/cmMakefile.cxx
parentbe45b5d20556ce5863fa0fc3a50b0a2b270a0a0f (diff)
downloadCMake-1dd718457fe1d410314d9443fa5d82462c5ae8ea.zip
CMake-1dd718457fe1d410314d9443fa5d82462c5ae8ea.tar.gz
CMake-1dd718457fe1d410314d9443fa5d82462c5ae8ea.tar.bz2
ENH: Moved variable and #cmakedefine replacement from cmConfigureFileCommand.cxx to a ConfigureString method on cmMakefile. This will give other commands access to the configuration code.
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx64
1 files changed, 63 insertions, 1 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 25be6cd..02ae60f 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -67,7 +67,8 @@ cmMakefile::cmMakefile()
this->AddSourceGroup("Header Files", "\\.(h|h\\+\\+|hm|hpp|hxx|in|txx|inl)$");
this->AddSourceGroup("CMake Rules", "\\.rule$");
this->AddDefaultDefinitions();
-}
+ m_cmDefineRegex.compile("#cmakedefine[ \t]*([A-Za-z_0-9]*)");
+ }
const char* cmMakefile::GetReleaseVersion()
{
@@ -2207,3 +2208,64 @@ std::string cmMakefile::GetModulesFile(const char* filename)
}
return "";
}
+
+void cmMakefile::ConfigureString(const std::string& input,
+ std::string& output, bool atOnly,
+ bool escapeQuotes)
+{
+ // Split input to handle one line at a time.
+ std::string::const_iterator lineStart = input.begin();
+ while(lineStart != input.end())
+ {
+ // Find the end of this line.
+ std::string::const_iterator lineEnd = lineStart;
+ while(lineEnd != input.end() && *lineEnd != '\n')
+ {
+ ++lineEnd;
+ }
+
+ // Copy the line.
+ std::string line(lineStart, lineEnd);
+
+ // Skip the newline character.
+ bool haveNewline = (lineEnd != input.end());
+ if(haveNewline)
+ {
+ ++lineEnd;
+ }
+
+ // Replace #cmakedefine instances.
+ if(m_cmDefineRegex.find(line))
+ {
+ const char* def = this->GetDefinition(m_cmDefineRegex.match(1).c_str());
+ if(!cmSystemTools::IsOff(def))
+ {
+ cmSystemTools::ReplaceString(line, "#cmakedefine", "#define");
+ output += line;
+ }
+ else
+ {
+ cmSystemTools::ReplaceString(line, "#cmakedefine", "#undef");
+ output += "/* ";
+ output += line;
+ output += " */";
+ }
+ }
+ else
+ {
+ output += line;
+ }
+
+ if(haveNewline)
+ {
+ output += "\n";
+ }
+
+ // Move to the next line.
+ lineStart = lineEnd;
+ }
+
+ // Perform variable replacements.
+ this->ExpandVariablesInString(output, escapeQuotes, atOnly);
+ this->RemoveVariablesInString(output, atOnly);
+}