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.
This commit is contained in:
parent
be45b5d205
commit
1dd718457f
|
@ -110,33 +110,12 @@ void cmConfigureFileCommand::ConfigureFile()
|
||||||
// now copy input to output and expand variables in the
|
// now copy input to output and expand variables in the
|
||||||
// input file at the same time
|
// input file at the same time
|
||||||
std::string inLine;
|
std::string inLine;
|
||||||
cmsys::RegularExpression cmdefine("#cmakedefine[ \t]*([A-Za-z_0-9]*)");
|
std::string outLine;
|
||||||
while( cmSystemTools::GetLineFromStream(fin, inLine) )
|
while( cmSystemTools::GetLineFromStream(fin, inLine) )
|
||||||
{
|
{
|
||||||
m_Makefile->ExpandVariablesInString(inLine, m_EscapeQuotes, m_AtOnly);
|
outLine = "";
|
||||||
m_Makefile->RemoveVariablesInString(inLine, m_AtOnly);
|
m_Makefile->ConfigureString(inLine, outLine, m_AtOnly, m_EscapeQuotes);
|
||||||
// look for special cmakedefine symbol and handle it
|
fout << outLine.c_str() << "\n";
|
||||||
// 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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// close the files before attempting to copy
|
// close the files before attempting to copy
|
||||||
fin.close();
|
fin.close();
|
||||||
|
|
|
@ -67,7 +67,8 @@ cmMakefile::cmMakefile()
|
||||||
this->AddSourceGroup("Header Files", "\\.(h|h\\+\\+|hm|hpp|hxx|in|txx|inl)$");
|
this->AddSourceGroup("Header Files", "\\.(h|h\\+\\+|hm|hpp|hxx|in|txx|inl)$");
|
||||||
this->AddSourceGroup("CMake Rules", "\\.rule$");
|
this->AddSourceGroup("CMake Rules", "\\.rule$");
|
||||||
this->AddDefaultDefinitions();
|
this->AddDefaultDefinitions();
|
||||||
}
|
m_cmDefineRegex.compile("#cmakedefine[ \t]*([A-Za-z_0-9]*)");
|
||||||
|
}
|
||||||
|
|
||||||
const char* cmMakefile::GetReleaseVersion()
|
const char* cmMakefile::GetReleaseVersion()
|
||||||
{
|
{
|
||||||
|
@ -2207,3 +2208,64 @@ std::string cmMakefile::GetModulesFile(const char* filename)
|
||||||
}
|
}
|
||||||
return "";
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "cmListFileCache.h"
|
#include "cmListFileCache.h"
|
||||||
#include "cmCacheManager.h"
|
#include "cmCacheManager.h"
|
||||||
|
|
||||||
|
#include <cmsys/RegularExpression.hxx>
|
||||||
|
|
||||||
class cmFunctionBlocker;
|
class cmFunctionBlocker;
|
||||||
class cmCommand;
|
class cmCommand;
|
||||||
class cmLocalGenerator;
|
class cmLocalGenerator;
|
||||||
|
@ -541,7 +543,14 @@ public:
|
||||||
*/
|
*/
|
||||||
void ExpandVariables();
|
void ExpandVariables();
|
||||||
void ExpandVariablesInCustomCommands();
|
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
|
* find what source group this source is in
|
||||||
*/
|
*/
|
||||||
|
@ -693,6 +702,8 @@ private:
|
||||||
|
|
||||||
// used in AddDefinition for performance improvement
|
// used in AddDefinition for performance improvement
|
||||||
DefinitionMap::key_type m_TemporaryDefinitionKey;
|
DefinitionMap::key_type m_TemporaryDefinitionKey;
|
||||||
|
|
||||||
|
cmsys::RegularExpression m_cmDefineRegex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue