Commit b5f62159 authored by Ken Martin's avatar Ken Martin
Browse files

added if else endif add definition

parent 24bce99c
/*=========================================================================
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;
}
/*=========================================================================
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);
}
/*=========================================================================
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;
}
/*=========================================================================
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
/*=========================================================================
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;
}
/*=========================================================================
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
/*=========================================================================
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
/*=========================================================================
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;
}
/*=========================================================================
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;