From 4ab2650802f7b0addce7860aff4fd5a2709eae24 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Wed, 25 Jul 2001 16:53:13 -0400 Subject: added for each command --- Source/cmCommands.cxx | 4 +++ Source/cmFunctionBlocker.h | 6 ++-- Source/cmIfCommand.cxx | 6 ++-- Source/cmIfCommand.h | 6 ++-- Source/cmMakefile.cxx | 90 +++++++++++++++++++++++++--------------------- Source/cmMakefile.h | 10 +++++- 6 files changed, 71 insertions(+), 51 deletions(-) diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index d791395..6f474e7 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -19,12 +19,14 @@ #include "cmConfigureGccXmlCommand.cxx" #include "cmElseCommand.cxx" #include "cmEnableTestingCommand.cxx" +#include "cmEndForEachCommand.cxx" #include "cmEndIfCommand.cxx" #include "cmExecProgramCommand.cxx" #include "cmFindFileCommand.cxx" #include "cmFindLibraryCommand.cxx" #include "cmFindPathCommand.cxx" #include "cmFindProgramCommand.cxx" +#include "cmForEachCommand.cxx" #include "cmGetFilenameComponentCommand.cxx" #include "cmIfCommand.cxx" #include "cmIncludeCommand.cxx" @@ -71,12 +73,14 @@ void GetPredefinedCommands(std::list& commands) commands.push_back(new cmConfigureGccXmlCommand); commands.push_back(new cmElseCommand); commands.push_back(new cmEnableTestingCommand); + commands.push_back(new cmEndForEachCommand); commands.push_back(new cmEndIfCommand); commands.push_back(new cmExecProgramCommand); commands.push_back(new cmFindFileCommand); commands.push_back(new cmFindLibraryCommand); commands.push_back(new cmFindPathCommand); commands.push_back(new cmFindProgramCommand); + commands.push_back(new cmForEachCommand); commands.push_back(new cmGetFilenameComponentCommand); commands.push_back(new cmIfCommand); commands.push_back(new cmIncludeCommand); diff --git a/Source/cmFunctionBlocker.h b/Source/cmFunctionBlocker.h index 3891ff1..c717b43 100644 --- a/Source/cmFunctionBlocker.h +++ b/Source/cmFunctionBlocker.h @@ -56,7 +56,7 @@ public: * should a function be blocked */ virtual bool IsFunctionBlocked(const char *name, const std::vector &args, - const cmMakefile &mf) const = 0; + cmMakefile &mf) = 0; /** * should this function blocker be removed, useful when one function adds a @@ -64,14 +64,14 @@ public: */ virtual bool ShouldRemove(const char *name, const std::vector &args, - const cmMakefile &mf) const {return false;} + cmMakefile &mf) {return false;} /** * When the end of a CMakeList file is reached this method is called. It * is not called on the end of an INCLUDE cmake file, just at the end of a * regular CMakeList file */ - virtual void ScopeEnded(const cmMakefile &mf) const {} + virtual void ScopeEnded(cmMakefile &mf) {} virtual ~cmFunctionBlocker() {} }; diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index ab98d41..d0bd577 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. bool cmIfFunctionBlocker:: IsFunctionBlocked(const char *name, const std::vector &args, - const cmMakefile &mf) const + cmMakefile &mf) { if (!strcmp(name,"ELSE") || !strcmp(name,"ENDIF")) { @@ -63,13 +63,13 @@ IsFunctionBlocked(const char *name, const std::vector &args, bool cmIfFunctionBlocker:: ShouldRemove(const char *name, const std::vector &args, - const cmMakefile &mf) const + cmMakefile &mf) { return !this->IsFunctionBlocked(name,args,mf); } void cmIfFunctionBlocker:: -ScopeEnded(const cmMakefile &mf) const +ScopeEnded(cmMakefile &mf) { cmSystemTools::Error("The end of a CMakeLists file was reached with an IF statement that was not closed properly. Within the directory: ", mf.GetCurrentDirectory(), diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index 1092bbf..3a2b269 100644 --- a/Source/cmIfCommand.h +++ b/Source/cmIfCommand.h @@ -57,11 +57,11 @@ public: virtual ~cmIfFunctionBlocker() {} virtual bool IsFunctionBlocked(const char *name, const std::vector &args, - const cmMakefile &mf) const; + cmMakefile &mf); virtual bool ShouldRemove(const char *name, const std::vector &args, - const cmMakefile &mf) const; - virtual void ScopeEnded(const cmMakefile &mf) const; + cmMakefile &mf); + virtual void ScopeEnded(cmMakefile &mf); std::string m_Define; bool m_Not; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 9ead3e3..3fc0d96 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -217,6 +217,52 @@ void cmMakefile::Print() const } } + + +void cmMakefile::ExecuteCommand(std::string &name, + std::vector &arguments) +{ + RegisteredCommandsMap::iterator pos = m_Commands.find(name); + if(pos != m_Commands.end()) + { + cmCommand* rm = (*pos).second; + cmCommand* usedCommand = rm->Clone(); + usedCommand->SetMakefile(this); + bool keepCommand = false; + if(usedCommand->GetEnabled()) + { + // if not running in inherit mode or + // if the command is inherited then InitialPass it. + if(!m_Inheriting || usedCommand->IsInherited()) + { + if(!usedCommand->InitialPass(arguments)) + { + cmSystemTools::Error(usedCommand->GetName(), + ": Error : \n", + usedCommand->GetError(), + m_cmCurrentDirectory.c_str()); + } + else + { + // use the command + keepCommand = true; + m_UsedCommands.push_back(usedCommand); + } + } + } + // if the Cloned command was not used + // then delete it + if(!keepCommand) + { + delete usedCommand; + } + } + else + { + cmSystemTools::Error("unknown CMake command ", name.c_str()); + } +} + // Parse the given CMakeLists.txt file into a list of classes. // Reads in current CMakeLists file and all parent CMakeLists files // executing all inherited commands in the parents @@ -273,7 +319,7 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external) // // this might, or might not be true, irrespective if we are // off looking at an external makefile. - bool inheriting = (m_cmCurrentDirectory != m_cmStartDirectory); + m_Inheriting = (m_cmCurrentDirectory != m_cmStartDirectory); // Now read the input file const char *filenametoread= filename; @@ -299,45 +345,7 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external) if(cmSystemTools::ParseFunction(fin, name, arguments) && !this->IsFunctionBlocked(name.c_str(),arguments)) { - RegisteredCommandsMap::iterator pos = m_Commands.find(name); - if(pos != m_Commands.end()) - { - cmCommand* rm = (*pos).second; - cmCommand* usedCommand = rm->Clone(); - usedCommand->SetMakefile(this); - bool keepCommand = false; - if(usedCommand->GetEnabled()) - { - // if not running in inherit mode or - // if the command is inherited then InitialPass it. - if(!inheriting || usedCommand->IsInherited()) - { - if(!usedCommand->InitialPass(arguments)) - { - cmSystemTools::Error(usedCommand->GetName(), - ": Error : \n", - usedCommand->GetError(), - m_cmCurrentDirectory.c_str()); - } - else - { - // use the command - keepCommand = true; - m_UsedCommands.push_back(usedCommand); - } - } - } - // if the Cloned command was not used - // then delete it - if(!keepCommand) - { - delete usedCommand; - } - } - else - { - cmSystemTools::Error("unknown CMake command ", name.c_str(), filename); - } + this->ExecuteCommand(name,arguments); } } @@ -923,7 +931,7 @@ cmMakefile::FindSourceGroup(const char* source, bool cmMakefile::IsFunctionBlocked(const char *name, - std::vector &args) const + std::vector &args) { // loop over all function blockers to see if any block this command std::set::const_iterator pos; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index c20c589..5907c25 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -493,6 +493,13 @@ public: void RegisterData(const char*, cmData*); cmData* LookupData(const char*) const; + /** + * execute a single CMake command + */ + void cmMakefile::ExecuteCommand(std::string &name, + std::vector &args); + + protected: std::string m_Prefix; std::vector m_AuxSourceDirectories; // @@ -531,7 +538,7 @@ protected: RegisteredCommandsMap m_Commands; std::vector m_UsedCommands; cmMakefileGenerator* m_MakefileGenerator; - bool IsFunctionBlocked(const char *name, std::vector &args) const; + bool IsFunctionBlocked(const char *name, std::vector &args); private: /** @@ -550,6 +557,7 @@ private: typedef std::map DataMap; DataMap m_DataMap; + bool m_Inheriting; }; -- cgit v0.12