summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2001-04-19 21:39:03 (GMT)
committerKen Martin <ken.martin@kitware.com>2001-04-19 21:39:03 (GMT)
commitb5f62159ca57dfa074b3985e17df2b2a29ab6d0f (patch)
treeafc12bc65ac93fbba86f360ca8d73eef2fba4867 /Source
parent24bce99cbff13cb337c543dce55f056351caa2fc (diff)
downloadCMake-b5f62159ca57dfa074b3985e17df2b2a29ab6d0f.zip
CMake-b5f62159ca57dfa074b3985e17df2b2a29ab6d0f.tar.gz
CMake-b5f62159ca57dfa074b3985e17df2b2a29ab6d0f.tar.bz2
added if else endif add definition
Diffstat (limited to 'Source')
-rw-r--r--Source/cmAddDefinitionsCommand.cxx33
-rw-r--r--Source/cmAddDefinitionsCommand.h79
-rw-r--r--Source/cmCommands.cxx8
-rw-r--r--Source/cmElseCommand.cxx45
-rw-r--r--Source/cmElseCommand.h69
-rw-r--r--Source/cmEndIfCommand.cxx32
-rw-r--r--Source/cmEndIfCommand.h69
-rw-r--r--Source/cmFunctionBlocker.h44
-rw-r--r--Source/cmIfCommand.cxx66
-rw-r--r--Source/cmIfCommand.h86
-rw-r--r--Source/cmMakefile.cxx44
-rw-r--r--Source/cmMakefile.h18
12 files changed, 585 insertions, 8 deletions
diff --git a/Source/cmAddDefinitionsCommand.cxx b/Source/cmAddDefinitionsCommand.cxx
new file mode 100644
index 0000000..de8841f
--- /dev/null
+++ b/Source/cmAddDefinitionsCommand.cxx
@@ -0,0 +1,33 @@
+/*=========================================================================
+
+ Program: Insight Segmentation & Registration Toolkit
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+
+ Copyright (c) 2000 National Library of Medicine
+ All rights reserved.
+
+ See COPYRIGHT.txt for copyright details.
+
+=========================================================================*/
+#include "cmAddDefinitionsCommand.h"
+
+// cmAddDefinitionsCommand
+bool cmAddDefinitionsCommand::Invoke(std::vector<std::string>& args)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ for(std::vector<std::string>::iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ m_Makefile->AddDefineFlag((*i).c_str());
+ }
+ return true;
+}
+
diff --git a/Source/cmAddDefinitionsCommand.h b/Source/cmAddDefinitionsCommand.h
new file mode 100644
index 0000000..66996da
--- /dev/null
+++ b/Source/cmAddDefinitionsCommand.h
@@ -0,0 +1,79 @@
+/*=========================================================================
+
+ Program: Insight Segmentation & Registration Toolkit
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+
+ Copyright (c) 2000 National Library of Medicine
+ All rights reserved.
+
+ See COPYRIGHT.txt for copyright details.
+
+=========================================================================*/
+#ifndef cmAddDefinitionsCommand_h
+#define cmAddDefinitionsCommand_h
+
+#include "cmStandardIncludes.h"
+#include "cmCommand.h"
+
+/** \class cmAddDefinitionsCommand
+ * \brief Specify a list of compiler defines
+ *
+ * cmAddDefinitionsCommand specifies a list of compiler defines. These defines will
+ * be added to the compile command.
+ */
+class cmAddDefinitionsCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddDefinitionsCommand;
+ }
+
+ /**
+ * 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 "ADD_DEFINITIONS";}
+
+ /**
+ * Succinct documentation.
+ */
+ virtual const char* GetTerseDocumentation()
+ {
+ return "Add -D define flags to command line for environments.";
+ }
+
+ /**
+ * More documentation.
+ */
+ virtual const char* GetFullDocumentation()
+ {
+ return
+ "ADD_DEFINITIONS(-DFOO -DBAR ...)\n"
+ "Add -D define flags to command line for environments.";
+ }
+
+ cmTypeMacro(cmAddDefinitionsCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 4e1f38a..2865806 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -43,6 +43,10 @@
#include "cmUtilitySourceCommand.cxx"
#include "cmIncludeRegularExpressionCommand.cxx"
#include "cmSourceGroupCommand.cxx"
+#include "cmIfCommand.cxx"
+#include "cmElseCommand.cxx"
+#include "cmEndIfCommand.cxx"
+#include "cmAddDefinitionsCommand.cxx"
void GetPredefinedCommands(std::list<cmCommand*>& commands)
{
@@ -83,6 +87,10 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
commands.push_back(new cmUtilitySourceCommand);
commands.push_back(new cmIncludeRegularExpressionCommand);
commands.push_back(new cmSourceGroupCommand);
+ commands.push_back(new cmIfCommand);
+ commands.push_back(new cmElseCommand);
+ commands.push_back(new cmEndIfCommand);
+ commands.push_back(new cmAddDefinitionsCommand);
}
diff --git a/Source/cmElseCommand.cxx b/Source/cmElseCommand.cxx
new file mode 100644
index 0000000..ff396fc
--- /dev/null
+++ b/Source/cmElseCommand.cxx
@@ -0,0 +1,45 @@
+/*=========================================================================
+
+ Program: Insight Segmentation & Registration Toolkit
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+
+ Copyright (c) 2000 National Library of Medicine
+ All rights reserved.
+
+ See COPYRIGHT.txt for copyright details.
+
+=========================================================================*/
+#include "cmElseCommand.h"
+#include "cmCacheManager.h"
+
+bool cmElseCommand::Invoke(std::vector<std::string>& args)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // check to see if the argument is defined first
+ const char *def = m_Makefile->GetDefinition(args[0].c_str());
+ if(def && strcmp(def,"0") && strcmp(def,"false") && strcmp(def,"") &&
+ strcmp(def,"NOTFOUND"))
+ {
+ // add block
+ 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/cmElseCommand.h b/Source/cmElseCommand.h
new file mode 100644
index 0000000..b418b7e
--- /dev/null
+++ b/Source/cmElseCommand.h
@@ -0,0 +1,69 @@
+/*=========================================================================
+
+ Program: Insight Segmentation & Registration Toolkit
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+
+ Copyright (c) 2000 National Library of Medicine
+ All rights reserved.
+
+ See COPYRIGHT.txt for copyright details.
+
+=========================================================================*/
+#ifndef cmElseCommand_h
+#define cmElseCommand_h
+
+#include "cmIfCommand.h"
+
+/** \class cmElseCommand
+ * \brief ends an if block
+ *
+ * cmElseCommand ends an if block
+ */
+class cmElseCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmElseCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool Invoke(std::vector<std::string>& args);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual const char* GetName() { return "ELSE";}
+
+ /**
+ * Succinct documentation.
+ */
+ virtual const char* GetTerseDocumentation()
+ {
+ return "starts the else portion of an if block";
+ }
+
+ /**
+ * More documentation.
+ */
+ virtual const char* GetFullDocumentation()
+ {
+ return
+ "ELSE(define)";
+ }
+
+ cmTypeMacro(cmElseCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmEndIfCommand.cxx b/Source/cmEndIfCommand.cxx
new file mode 100644
index 0000000..c87c659
--- /dev/null
+++ b/Source/cmEndIfCommand.cxx
@@ -0,0 +1,32 @@
+/*=========================================================================
+
+ Program: Insight Segmentation & Registration Toolkit
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+
+ Copyright (c) 2000 National Library of Medicine
+ All rights reserved.
+
+ See COPYRIGHT.txt for copyright details.
+
+=========================================================================*/
+#include "cmEndIfCommand.h"
+#include "cmCacheManager.h"
+
+bool cmEndIfCommand::Invoke(std::vector<std::string>& args)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // remove any function blockers for this define
+ m_Makefile->RemoveFunctionBlocker("ENDIF",args);
+
+ return true;
+}
+
diff --git a/Source/cmEndIfCommand.h b/Source/cmEndIfCommand.h
new file mode 100644
index 0000000..ad399c7
--- /dev/null
+++ b/Source/cmEndIfCommand.h
@@ -0,0 +1,69 @@
+/*=========================================================================
+
+ Program: Insight Segmentation & Registration Toolkit
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+
+ Copyright (c) 2000 National Library of Medicine
+ All rights reserved.
+
+ See COPYRIGHT.txt for copyright details.
+
+=========================================================================*/
+#ifndef cmEndIfCommand_h
+#define cmEndIfCommand_h
+
+#include "cmIfCommand.h"
+
+/** \class cmEndIfCommand
+ * \brief ends an if block
+ *
+ * cmEndIfCommand ends an if block
+ */
+class cmEndIfCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmEndIfCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool Invoke(std::vector<std::string>& args);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual const char* GetName() { return "ENDIF";}
+
+ /**
+ * Succinct documentation.
+ */
+ virtual const char* GetTerseDocumentation()
+ {
+ return "ends an if block";
+ }
+
+ /**
+ * More documentation.
+ */
+ virtual const char* GetFullDocumentation()
+ {
+ return
+ "ENDIF(define)";
+ }
+
+ cmTypeMacro(cmEndIfCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmFunctionBlocker.h b/Source/cmFunctionBlocker.h
new file mode 100644
index 0000000..7ec6e25
--- /dev/null
+++ b/Source/cmFunctionBlocker.h
@@ -0,0 +1,44 @@
+/*=========================================================================
+
+ Program: Insight Segmentation & Registration Toolkit
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+
+ Copyright (c) 2000 National Library of Medicine
+ All rights reserved.
+
+ See COPYRIGHT.txt for copyright details.
+
+=========================================================================*/
+#ifndef cmFunctionBlocker_h
+#define cmFunctionBlocker_h
+
+#include "cmStandardIncludes.h"
+class cmMakefile;
+
+/** \class cmFunctionBlocker
+ * \brief A class that defines an interface for blocking cmake functions
+ *
+ * This is the superclass for any classes that need to block a cmake function
+ */
+class cmFunctionBlocker
+{
+public:
+ /**
+ * should a function be blocked
+ */
+ virtual bool IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
+ const cmMakefile &mf) const = 0;
+
+ /**
+ * should this function blocker be removed, useful when one function adds a blocker
+ * and another must remove it
+ */
+ virtual bool ShouldRemove(const char *name, const std::vector<std::string> &args,
+ const cmMakefile &mf) const {return false;}
+};
+
+#endif
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
new file mode 100644
index 0000000..5dab24b
--- /dev/null
+++ b/Source/cmIfCommand.cxx
@@ -0,0 +1,66 @@
+/*=========================================================================
+
+ Program: Insight Segmentation & Registration Toolkit
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+
+ Copyright (c) 2000 National Library of Medicine
+ All rights reserved.
+
+ See COPYRIGHT.txt for copyright details.
+
+=========================================================================*/
+#include "cmIfCommand.h"
+#include "cmCacheManager.h"
+
+bool cmIfFunctionBlocker::
+IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
+ const cmMakefile &mf) const
+{
+ if (strcmp(name,"ELSE") && strcmp(name,"ENDIF"))
+ {
+ return true;
+ }
+ if (strcmp(args[0].c_str(),m_Define.c_str()))
+ {
+ return true;
+ }
+ return false;
+}
+
+bool cmIfFunctionBlocker::
+ShouldRemove(const char *name, const std::vector<std::string> &args,
+ const cmMakefile &mf) const
+{
+ return !this->IsFunctionBlocked(name,args,mf);
+}
+
+bool cmIfCommand::Invoke(std::vector<std::string>& args)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // check to see if the argument is defined first
+ const char *def = m_Makefile->GetDefinition(args[0].c_str());
+ if(def && strcmp(def,"0") && strcmp(def,"false") && strcmp(def,"") &&
+ strcmp(def,"NOTFOUND"))
+ {
+ // 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
new file mode 100644
index 0000000..2523f8b
--- /dev/null
+++ b/Source/cmIfCommand.h
@@ -0,0 +1,86 @@
+/*=========================================================================
+
+ Program: Insight Segmentation & Registration Toolkit
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+
+ Copyright (c) 2000 National Library of Medicine
+ All rights reserved.
+
+ See COPYRIGHT.txt for copyright details.
+
+=========================================================================*/
+#ifndef cmIfCommand_h
+#define cmIfCommand_h
+
+#include "cmStandardIncludes.h"
+#include "cmCommand.h"
+#include "cmFunctionBlocker.h"
+
+/** \class cmIfFunctionBlocker
+ * \brief subclass of function blocker
+ *
+ *
+ */
+class cmIfFunctionBlocker : public cmFunctionBlocker
+{
+public:
+ 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;
+};
+
+/** \class cmIfCommand
+ * \brief starts an if block
+ *
+ * cmIfCommand starts an if block
+ */
+class cmIfCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmIfCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool Invoke(std::vector<std::string>& args);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual const char* GetName() { return "IF";}
+
+ /**
+ * Succinct documentation.
+ */
+ virtual const char* GetTerseDocumentation()
+ {
+ return "start an if block";
+ }
+
+ /**
+ * More documentation.
+ */
+ virtual const char* GetFullDocumentation()
+ {
+ return
+ "IF(define)";
+ }
+
+ cmTypeMacro(cmIfCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 139bcd0..4dd27b4 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -22,6 +22,7 @@
#include "cmMakefileGenerator.h"
#include "cmCommands.h"
#include "cmCacheManager.h"
+#include "cmFunctionBlocker.h"
// default is not to be building executables
cmMakefile::cmMakefile()
@@ -74,10 +75,10 @@ cmMakefile::~cmMakefile()
delete m_MakefileGenerator;
}
-void cmMakefile::PrintStringVector(const char* s, std::vector<std::string>& v)
+void cmMakefile::PrintStringVector(const char* s, const std::vector<std::string>& v) const
{
std::cout << s << ": ( \n";
- for(std::vector<std::string>::iterator i = v.begin();
+ for(std::vector<std::string>::const_iterator i = v.begin();
i != v.end(); ++i)
{
std::cout << (*i).c_str() << " ";
@@ -87,7 +88,7 @@ void cmMakefile::PrintStringVector(const char* s, std::vector<std::string>& v)
// call print on all the classes in the makefile
-void cmMakefile::Print()
+void cmMakefile::Print() const
{
// print the class lists
std::cout << "classes:\n";
@@ -178,7 +179,8 @@ bool cmMakefile::ReadListFile(const char* filename)
std::vector<std::string> arguments;
while ( fin )
{
- if(cmSystemTools::ParseFunction(fin, name, arguments) )
+ if(cmSystemTools::ParseFunction(fin, name, arguments) &&
+ !this->IsFunctionBlocked(name.c_str(),arguments))
{
// Special command that needs to be removed when
// ADD_COMMAND is implemented
@@ -681,3 +683,37 @@ cmMakefile::GetClassesFromSourceLists(
return result;
}
+bool cmMakefile::IsFunctionBlocked(const char *name,
+ std::vector<std::string> &args) const
+{
+ // loop over all function blockers to see if any block this command
+ std::set<cmFunctionBlocker *>::const_iterator pos;
+ for (pos = m_FunctionBlockers.begin();
+ pos != m_FunctionBlockers.end(); ++pos)
+ {
+ if ((*pos)->IsFunctionBlocked(name, args, *this))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void cmMakefile::RemoveFunctionBlocker(const char *name,
+ const std::vector<std::string> &args)
+{
+ // loop over all function blockers to see if any block this command
+ std::set<cmFunctionBlocker *>::const_iterator pos;
+ for (pos = m_FunctionBlockers.begin();
+ pos != m_FunctionBlockers.end(); ++pos)
+ {
+ if ((*pos)->ShouldRemove(name, args, *this))
+ {
+ m_FunctionBlockers.erase(*pos);
+ return;
+ }
+ }
+
+ return;
+}
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index fd12074..604a9ed 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -21,6 +21,7 @@
#include "cmSystemTools.h"
#include "cmSourceGroup.h"
#include "cmTarget.h"
+class cmFunctionBlocker;
class cmCommand;
class cmMakefileGenerator;
@@ -55,6 +56,15 @@ public:
void AddCommand(cmCommand* );
/**
+ * Add a function blocker to this makefile
+ */
+ void AddFunctionBlocker(cmFunctionBlocker *fb)
+ { m_FunctionBlockers.insert(fb);}
+ void RemoveFunctionBlocker(cmFunctionBlocker *fb)
+ { m_FunctionBlockers.erase(fb);}
+ void RemoveFunctionBlocker(const char *name, const std::vector<std::string> &args);
+
+ /**
* Specify the makefile generator. This is platform/compiler
* dependent, although the interface is through a generic
* superclass.
@@ -69,7 +79,7 @@ public:
/**
* Print the object state to std::cout.
*/
- void Print();
+ void Print() const;
/**
* Add a custom command to the build.
@@ -465,7 +475,7 @@ protected:
RegisteredCommandsMap m_Commands;
std::vector<cmCommand*> m_UsedCommands;
cmMakefileGenerator* m_MakefileGenerator;
-
+ bool IsFunctionBlocked(const char *name, std::vector<std::string> &args) const;
private:
/**
@@ -477,10 +487,10 @@ private:
void ReadClasses(std::ifstream& fin, bool t);
friend class cmMakeDepend; // make depend needs direct access
// to the m_Classes array
- void PrintStringVector(const char* s, std::vector<std::string>& v);
+ void PrintStringVector(const char* s, const std::vector<std::string>& v) const;
void AddDefaultCommands();
void AddDefaultDefinitions();
-
+ std::set<cmFunctionBlocker *> m_FunctionBlockers;
};