added if else endif add definition
This commit is contained in:
parent
24bce99cbf
commit
b5f62159ca
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "cmSystemTools.h"
|
||||
#include "cmSourceGroup.h"
|
||||
#include "cmTarget.h"
|
||||
class cmFunctionBlocker;
|
||||
class cmCommand;
|
||||
class cmMakefileGenerator;
|
||||
|
||||
|
@ -54,6 +55,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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue