summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/cmConfigureFileCommand.cxx29
-rw-r--r--Source/cmMakefile.cxx64
-rw-r--r--Source/cmMakefile.h13
3 files changed, 79 insertions, 27 deletions
diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx
index 3bf97c8..b63e863 100644
--- a/Source/cmConfigureFileCommand.cxx
+++ b/Source/cmConfigureFileCommand.cxx
@@ -110,33 +110,12 @@ void cmConfigureFileCommand::ConfigureFile()
// now copy input to output and expand variables in the
// input file at the same time
std::string inLine;
- cmsys::RegularExpression cmdefine("#cmakedefine[ \t]*([A-Za-z_0-9]*)");
+ std::string outLine;
while( cmSystemTools::GetLineFromStream(fin, inLine) )
{
- m_Makefile->ExpandVariablesInString(inLine, m_EscapeQuotes, m_AtOnly);
- m_Makefile->RemoveVariablesInString(inLine, m_AtOnly);
- // look for special cmakedefine symbol and handle it
- // is the symbol defined
- if (cmdefine.find(inLine))
- {
- const char *def = m_Makefile->GetDefinition(cmdefine.match(1).c_str());
- if(!cmSystemTools::IsOff(def))
- {
- cmSystemTools::ReplaceString(inLine,
- "#cmakedefine", "#define");
- fout << inLine << "\n";
- }
- else
- {
- cmSystemTools::ReplaceString(inLine,
- "#cmakedefine", "#undef");
- fout << "/* " << inLine << " */\n";
- }
- }
- else
- {
- fout << inLine << "\n";
- }
+ outLine = "";
+ m_Makefile->ConfigureString(inLine, outLine, m_AtOnly, m_EscapeQuotes);
+ fout << outLine.c_str() << "\n";
}
// close the files before attempting to copy
fin.close();
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);
+}
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 620691b..ffba58d 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -24,6 +24,8 @@
#include "cmListFileCache.h"
#include "cmCacheManager.h"
+#include <cmsys/RegularExpression.hxx>
+
class cmFunctionBlocker;
class cmCommand;
class cmLocalGenerator;
@@ -541,7 +543,14 @@ public:
*/
void ExpandVariables();
void ExpandVariablesInCustomCommands();
-
+
+ /**
+ * Replace variables and #cmakedefine lines in the given string.
+ * See cmConfigureFileCommand for details.
+ */
+ void ConfigureString(const std::string& input, std::string& output,
+ bool atOnly, bool escapeQuotes);
+
/**
* find what source group this source is in
*/
@@ -693,6 +702,8 @@ private:
// used in AddDefinition for performance improvement
DefinitionMap::key_type m_TemporaryDefinitionKey;
+
+ cmsys::RegularExpression m_cmDefineRegex;
};