diff options
-rw-r--r-- | Source/cmCommands.cxx | 2 | ||||
-rw-r--r-- | Source/cmElseCommand.cxx | 39 | ||||
-rw-r--r-- | Source/cmIfCommand.cxx | 54 | ||||
-rw-r--r-- | Source/cmIfCommand.h | 5 | ||||
-rw-r--r-- | Source/cmSetCommand.cxx | 70 | ||||
-rw-r--r-- | Source/cmSetCommand.h | 103 | ||||
-rw-r--r-- | Source/cmVTKWrapPythonCommand.cxx | 7 | ||||
-rw-r--r-- | Source/cmVTKWrapTclCommand.cxx | 8 |
8 files changed, 266 insertions, 22 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index cc49f89..e542786 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -50,6 +50,7 @@ #include "cmIfCommand.cxx" #include "cmElseCommand.cxx" #include "cmEndIfCommand.cxx" +#include "cmSetCommand.cxx" #include "cmAddDefinitionsCommand.cxx" #include "cmOptionCommand.cxx" #include "cmIncludeCommand.cxx" @@ -100,6 +101,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands) commands.push_back(new cmIfCommand); commands.push_back(new cmElseCommand); commands.push_back(new cmEndIfCommand); + commands.push_back(new cmSetCommand); commands.push_back(new cmAddDefinitionsCommand); commands.push_back(new cmOptionCommand); commands.push_back(new cmIncludeCommand); diff --git a/Source/cmElseCommand.cxx b/Source/cmElseCommand.cxx index b905945..9684de1 100644 --- a/Source/cmElseCommand.cxx +++ b/Source/cmElseCommand.cxx @@ -49,19 +49,40 @@ bool cmElseCommand::Invoke(std::vector<std::string>& args) return false; } - // check to see if the argument is defined first - const char *def = m_Makefile->GetDefinition(args[0].c_str()); - if(!cmSystemTools::IsOff(def)) + // check for the NOT vale + const char *def; + if (args.size() == 2 && (args[0] == "NOT")) { - // add block - cmIfFunctionBlocker *f = new cmIfFunctionBlocker(); - f->m_Define = args[0]; - m_Makefile->AddFunctionBlocker(f); + def = m_Makefile->GetDefinition(args[1].c_str()); + if(!cmSystemTools::IsOff(def)) + { + // remove any function blockers for this define + m_Makefile->RemoveFunctionBlocker("ENDIF",args); + } + else + { + // create a function blocker + cmIfFunctionBlocker *f = new cmIfFunctionBlocker(); + f->m_Define = args[1]; + f->m_Not = true; + m_Makefile->AddFunctionBlocker(f); + } } else { - // remove any function blockers for this define - m_Makefile->RemoveFunctionBlocker("ENDIF",args); + def = m_Makefile->GetDefinition(args[0].c_str()); + if(!cmSystemTools::IsOff(def)) + { + // create a function blocker + cmIfFunctionBlocker *f = new cmIfFunctionBlocker(); + f->m_Define = args[0]; + m_Makefile->AddFunctionBlocker(f); + } + else + { + // remove any function blockers for this define + m_Makefile->RemoveFunctionBlocker("ENDIF",args); + } } return true; diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 86803de..37daba6 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -49,9 +49,23 @@ IsFunctionBlocked(const char *name, const std::vector<std::string> &args, { return true; } - if (strcmp(args[0].c_str(),m_Define.c_str())) + if (m_Not && args.size() == 2) { - return true; + if (strcmp(args[0].c_str(),"NOT")) + { + return true; + } + if (strcmp(args[1].c_str(),m_Define.c_str())) + { + return true; + } + } + else + { + if (strcmp(args[0].c_str(),m_Define.c_str())) + { + return true; + } } return false; } @@ -71,18 +85,38 @@ bool cmIfCommand::Invoke(std::vector<std::string>& args) return false; } - // check to see if the argument is defined first - const char *def = m_Makefile->GetDefinition(args[0].c_str()); - if(!cmSystemTools::IsOff(def)) + // check for the NOT vale + const char *def; + if (args.size() == 2 && (args[0] == "NOT")) { - // do nothing + def = m_Makefile->GetDefinition(args[1].c_str()); + if(!cmSystemTools::IsOff(def)) + { + // create a function blocker + cmIfFunctionBlocker *f = new cmIfFunctionBlocker(); + f->m_Define = args[1]; + f->m_Not = true; + m_Makefile->AddFunctionBlocker(f); + } + else + { + // do nothing + } } else { - // create a function blocker - cmIfFunctionBlocker *f = new cmIfFunctionBlocker(); - f->m_Define = args[0]; - m_Makefile->AddFunctionBlocker(f); + def = m_Makefile->GetDefinition(args[0].c_str()); + if(!cmSystemTools::IsOff(def)) + { + // do nothing + } + else + { + // create a function blocker + cmIfFunctionBlocker *f = new cmIfFunctionBlocker(); + f->m_Define = args[0]; + m_Makefile->AddFunctionBlocker(f); + } } return true; diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index 2887196..6bb3102 100644 --- a/Source/cmIfCommand.h +++ b/Source/cmIfCommand.h @@ -53,12 +53,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class cmIfFunctionBlocker : public cmFunctionBlocker { public: + cmIfFunctionBlocker() {m_Not = false;} virtual ~cmIfFunctionBlocker() {} virtual bool IsFunctionBlocked(const char *name, const std::vector<std::string> &args, const cmMakefile &mf) const; virtual bool ShouldRemove(const char *name, const std::vector<std::string> &args, const cmMakefile &mf) const; std::string m_Define; + bool m_Not; }; /** \class cmIfCommand @@ -108,7 +110,8 @@ public: virtual const char* GetFullDocumentation() { return - "IF(define)"; + "IF (define) Starts an if block. Optionally there it can be invoked as\n" + "IF (NOT Define) the matching ELSE and ENDIF require the NOT as well."; } cmTypeMacro(cmIfCommand, cmCommand); diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx new file mode 100644 index 0000000..dab5dbb --- /dev/null +++ b/Source/cmSetCommand.cxx @@ -0,0 +1,70 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + +Copyright (c) 2001 Insight Consortium +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * The name of the Insight Consortium, nor the names of any consortium members, + nor of any contributors, may be used to endorse or promote products derived + from this software without specific prior written permission. + + * Modified source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=========================================================================*/ +#include "cmSetCommand.h" + +// cmSetCommand +bool cmSetCommand::Invoke(std::vector<std::string>& args) +{ + if(args.size() < 1 ) + { + this->SetError("called with incorrect number of arguments"); + return false; + } + if (args.size() == 1) + { + return true; + } + + // expand value + m_Makefile->ExpandVariablesInString(args[1]); + m_Makefile->AddDefinition(args[0].c_str(), args[1].c_str()); + + // should we store the result in the cache ? + if (args.size() > 2 && args[2] == "CACHE") + { + cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(), + args[1].c_str(), + "Value Computed by CMake", + cmCacheManager::STRING); + } + return true; +} + diff --git a/Source/cmSetCommand.h b/Source/cmSetCommand.h new file mode 100644 index 0000000..45bccbd --- /dev/null +++ b/Source/cmSetCommand.h @@ -0,0 +1,103 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + +Copyright (c) 2001 Insight Consortium +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * The name of the Insight Consortium, nor the names of any consortium members, + nor of any contributors, may be used to endorse or promote products derived + from this software without specific prior written permission. + + * Modified source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=========================================================================*/ +#ifndef cmSetCommand_h +#define cmSetCommand_h + +#include "cmStandardIncludes.h" +#include "cmCommand.h" + +/** \class cmSetCommand + * \brief Set a CMAKE variable + * + * cmSetCommand sets a variable to a value with expansion. + */ +class cmSetCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + virtual cmCommand* Clone() + { + return new cmSetCommand; + } + + /** + * This is called when the command is first encountered in + * the CMakeLists.txt file. + */ + virtual bool Invoke(std::vector<std::string>& args); + + /** + * This determines if the command gets propagated down + * to makefiles located in subdirectories. + */ + virtual bool IsInherited() {return true;} + + /** + * The name of the command as specified in CMakeList.txt. + */ + virtual const char* GetName() {return "SET";} + + /** + * Succinct documentation. + */ + virtual const char* GetTerseDocumentation() + { + return "Set a CMAKE variable to a value"; + } + + /** + * More documentation. + */ + virtual const char* GetFullDocumentation() + { + return + "SET(FOO BAR)\n" + "Within CMAKE sets FOO to the value BAR. BAR is expanded before FOO is set to it."; + } + + cmTypeMacro(cmSetCommand, cmCommand); +}; + + + +#endif diff --git a/Source/cmVTKWrapPythonCommand.cxx b/Source/cmVTKWrapPythonCommand.cxx index d1977cc..2c84b5f 100644 --- a/Source/cmVTKWrapPythonCommand.cxx +++ b/Source/cmVTKWrapPythonCommand.cxx @@ -185,7 +185,8 @@ bool cmVTKWrapPythonCommand::WriteInit(const char *kitName, { unsigned int i; - FILE *fout = fopen(outFileName.c_str(),"w"); + std::string tempOutputFile = outFileName + ".tmp"; + FILE *fout = fopen(tempOutputFile.c_str(),"w"); if (!fout) { return false; @@ -230,6 +231,10 @@ bool cmVTKWrapPythonCommand::WriteInit(const char *kitName, fclose(fout); + // copy the file if different + cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(), + outFileName.c_str()); + cmSystemTools::RemoveFile(tempOutputFile.c_str()); return true; } diff --git a/Source/cmVTKWrapTclCommand.cxx b/Source/cmVTKWrapTclCommand.cxx index 995f863..44579d9 100644 --- a/Source/cmVTKWrapTclCommand.cxx +++ b/Source/cmVTKWrapTclCommand.cxx @@ -184,7 +184,8 @@ bool cmVTKWrapTclCommand::WriteInit(const char *kitName, std::vector<std::string>& classes) { unsigned int i; - FILE *fout = fopen(outFileName.c_str(),"w"); + std::string tempOutputFile = outFileName + ".tmp"; + FILE *fout = fopen(tempOutputFile.c_str(),"w"); if (!fout) { return false; @@ -259,6 +260,11 @@ bool cmVTKWrapTclCommand::WriteInit(const char *kitName, fprintf(fout," return TCL_OK;\n}\n"); fclose(fout); + // copy the file if different + cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(), + outFileName.c_str()); + cmSystemTools::RemoveFile(tempOutputFile.c_str()); + return true; } |