new set command and IF NOT
This commit is contained in:
parent
2fb2207c10
commit
a99dfa60ae
|
@ -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);
|
||||
|
|
|
@ -49,11 +49,31 @@ 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());
|
||||
// check for the NOT vale
|
||||
const char *def;
|
||||
if (args.size() == 2 && (args[0] == "NOT"))
|
||||
{
|
||||
def = m_Makefile->GetDefinition(args[1].c_str());
|
||||
if(!cmSystemTools::IsOff(def))
|
||||
{
|
||||
// add block
|
||||
// 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
|
||||
{
|
||||
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);
|
||||
|
@ -63,6 +83,7 @@ bool cmElseCommand::Invoke(std::vector<std::string>& args)
|
|||
// remove any function blockers for this define
|
||||
m_Makefile->RemoveFunctionBlocker("ENDIF",args);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -49,10 +49,24 @@ IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
|
|||
{
|
||||
return true;
|
||||
}
|
||||
if (m_Not && args.size() == 2)
|
||||
{
|
||||
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,8 +85,27 @@ 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());
|
||||
// check for the NOT vale
|
||||
const char *def;
|
||||
if (args.size() == 2 && (args[0] == "NOT"))
|
||||
{
|
||||
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
|
||||
{
|
||||
def = m_Makefile->GetDefinition(args[0].c_str());
|
||||
if(!cmSystemTools::IsOff(def))
|
||||
{
|
||||
// do nothing
|
||||
|
@ -84,6 +117,7 @@ bool cmIfCommand::Invoke(std::vector<std::string>& args)
|
|||
f->m_Define = args[0];
|
||||
m_Makefile->AddFunctionBlocker(f);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue