diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index cdcf79d1c..12d156c0b 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -15,6 +15,8 @@ =========================================================================*/ #include "cmIfCommand.h" +#include "cmStringCommand.h" + #include // required for atof #include #include @@ -215,7 +217,7 @@ namespace bool cmIfCommand::IsTrue(const std::vector &args, - char **errorString, const cmMakefile *makefile) + char **errorString, cmMakefile *makefile) { // check for the different signatures const char *def; @@ -369,6 +371,7 @@ bool cmIfCommand::IsTrue(const std::vector &args, { def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile); const char* rex = (argP2)->c_str(); + cmStringCommand::ClearMatches(makefile); cmsys::RegularExpression regEntry; if ( !regEntry.compile(rex) ) { @@ -382,6 +385,7 @@ bool cmIfCommand::IsTrue(const std::vector &args, if (regEntry.find(def)) { *arg = "1"; + cmStringCommand::StoreMatches(makefile, regEntry); } else { diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index 6b855a29c..7698595d6 100644 --- a/Source/cmIfCommand.h +++ b/Source/cmIfCommand.h @@ -174,7 +174,7 @@ public: // arguments were valid, and if so, was the response true. If there is // an error, the errorString will be set. static bool IsTrue(const std::vector &args, - char** errorString, const cmMakefile *mf); + char** errorString, cmMakefile *mf); // Get a definition from the makefile. If it doesn't exist, // return the original string. diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 437b121d7..f746f82fd 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -248,7 +248,7 @@ bool cmStringCommand::RegexMatch(std::vector const& args) input += args[i]; } - this->ClearMatches(); + this->ClearMatches(this->Makefile); // Compile the regular expression. cmsys::RegularExpression re; if(!re.compile(regex.c_str())) @@ -263,7 +263,7 @@ bool cmStringCommand::RegexMatch(std::vector const& args) std::string output; if(re.find(input.c_str())) { - this->StoreMatches(re); + this->StoreMatches(this->Makefile, re); std::string::size_type l = re.start(); std::string::size_type r = re.end(); if(r-l == 0) @@ -297,7 +297,7 @@ bool cmStringCommand::RegexMatchAll(std::vector const& args) input += args[i]; } - this->ClearMatches(); + this->ClearMatches(this->Makefile); // Compile the regular expression. cmsys::RegularExpression re; if(!re.compile(regex.c_str())) @@ -314,7 +314,7 @@ bool cmStringCommand::RegexMatchAll(std::vector const& args) const char* p = input.c_str(); while(re.find(p)) { - this->StoreMatches(re); + this->StoreMatches(this->Makefile, re); std::string::size_type l = re.start(); std::string::size_type r = re.end(); if(r-l == 0) @@ -401,7 +401,7 @@ bool cmStringCommand::RegexReplace(std::vector const& args) input += args[i]; } - this->ClearMatches(); + this->ClearMatches(this->Makefile); // Compile the regular expression. cmsys::RegularExpression re; if(!re.compile(regex.c_str())) @@ -418,7 +418,7 @@ bool cmStringCommand::RegexReplace(std::vector const& args) std::string::size_type base = 0; while(re.find(input.c_str()+base)) { - this->StoreMatches(re); + this->StoreMatches(this->Makefile, re); std::string::size_type l2 = re.start(); std::string::size_type r = re.end(); @@ -479,24 +479,24 @@ bool cmStringCommand::RegexReplace(std::vector const& args) } //---------------------------------------------------------------------------- -void cmStringCommand::ClearMatches() +void cmStringCommand::ClearMatches(cmMakefile* mf) { for (unsigned int i=0; i<10; i++) { char name[128]; sprintf(name, "CMAKE_MATCH_%d", i); - this->Makefile->AddDefinition(name, ""); + mf->AddDefinition(name, ""); } } //---------------------------------------------------------------------------- -void cmStringCommand::StoreMatches(cmsys::RegularExpression& re) +void cmStringCommand::StoreMatches(cmMakefile* mf,cmsys::RegularExpression& re) { for (unsigned int i=0; i<10; i++) { char name[128]; sprintf(name, "CMAKE_MATCH_%d", i); - this->Makefile->AddDefinition(name, re.match(i).c_str()); + mf->AddDefinition(name, re.match(i).c_str()); } } diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index e94f762b3..e32370706 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -19,6 +19,7 @@ #include "cmCommand.h" +class cmMakefile; namespace cmsys { class RegularExpression; @@ -122,6 +123,8 @@ public: } cmTypeMacro(cmStringCommand, cmCommand); + static void ClearMatches(cmMakefile* mf); + static void StoreMatches(cmMakefile* mf, cmsys::RegularExpression& re); protected: bool HandleConfigureCommand(std::vector const& args); bool HandleAsciiCommand(std::vector const& args); @@ -137,8 +140,6 @@ protected: bool HandleSubstringCommand(std::vector const& args); bool HandleStripCommand(std::vector const& args); bool HandleRandomCommand(std::vector const& args); - void ClearMatches(); - void StoreMatches(cmsys::RegularExpression& re); class RegexReplacement {