added new if commands
This commit is contained in:
parent
f70e0d6b1e
commit
d7702b4c30
|
@ -49,41 +49,78 @@ bool cmElseCommand::InitialPass(std::vector<std::string>& args)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for the NOT vale
|
// create a function blocker
|
||||||
|
cmIfFunctionBlocker *f = NULL;
|
||||||
|
|
||||||
|
// check for the different signatures
|
||||||
const char *def;
|
const char *def;
|
||||||
if (args.size() == 2 && (args[0] == "NOT"))
|
const char *def2;
|
||||||
{
|
|
||||||
def = m_Makefile->GetDefinition(args[1].c_str());
|
if (args.size() == 1)
|
||||||
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
|
|
||||||
{
|
{
|
||||||
def = m_Makefile->GetDefinition(args[0].c_str());
|
def = m_Makefile->GetDefinition(args[0].c_str());
|
||||||
if(!cmSystemTools::IsOff(def))
|
if(!cmSystemTools::IsOff(def))
|
||||||
{
|
{
|
||||||
// create a function blocker
|
f = new cmIfFunctionBlocker();
|
||||||
cmIfFunctionBlocker *f = new cmIfFunctionBlocker();
|
|
||||||
f->m_Define = args[0];
|
|
||||||
m_Makefile->AddFunctionBlocker(f);
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
if (args.size() == 2 && (args[0] == "NOT"))
|
||||||
|
{
|
||||||
|
def = m_Makefile->GetDefinition(args[1].c_str());
|
||||||
|
if(cmSystemTools::IsOff(def))
|
||||||
{
|
{
|
||||||
// remove any function blockers for this define
|
f = new cmIfFunctionBlocker();
|
||||||
m_Makefile->RemoveFunctionBlocker("ENDIF",args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.size() == 3 && (args[1] == "AND"))
|
||||||
|
{
|
||||||
|
def = m_Makefile->GetDefinition(args[0].c_str());
|
||||||
|
def2 = m_Makefile->GetDefinition(args[2].c_str());
|
||||||
|
if(cmSystemTools::IsOff(def) || cmSystemTools::IsOff(def2))
|
||||||
|
{
|
||||||
|
f = new cmIfFunctionBlocker();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() == 3 && (args[1] == "OR"))
|
||||||
|
{
|
||||||
|
def = m_Makefile->GetDefinition(args[0].c_str());
|
||||||
|
def2 = m_Makefile->GetDefinition(args[2].c_str());
|
||||||
|
if(cmSystemTools::IsOff(def) && cmSystemTools::IsOff(def2))
|
||||||
|
{
|
||||||
|
f = new cmIfFunctionBlocker();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() == 3 && (args[1] == "MATCHES"))
|
||||||
|
{
|
||||||
|
def = m_Makefile->GetDefinition(args[0].c_str());
|
||||||
|
cmRegularExpression regEntry(args[2].c_str());
|
||||||
|
|
||||||
|
// check for black line or comment
|
||||||
|
if (!regEntry.find(def))
|
||||||
|
{
|
||||||
|
f = new cmIfFunctionBlocker();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we created a function blocker then set its args
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
for(std::vector<std::string>::iterator j = args.begin();
|
||||||
|
j != args.end(); ++j)
|
||||||
|
{
|
||||||
|
f->m_Args.push_back(*j);
|
||||||
|
}
|
||||||
|
m_Makefile->AddFunctionBlocker(f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// remove any function blockers for this define
|
||||||
|
m_Makefile->RemoveFunctionBlocker("ENDIF",args);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ public:
|
||||||
virtual const char* GetFullDocumentation()
|
virtual const char* GetFullDocumentation()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"ELSE(define)";
|
"ELSE(args), Note that the args for the ELSE clause must match those of the IF clause. See the IF command for more information.";
|
||||||
}
|
}
|
||||||
|
|
||||||
cmTypeMacro(cmElseCommand, cmCommand);
|
cmTypeMacro(cmElseCommand, cmCommand);
|
||||||
|
|
|
@ -47,13 +47,7 @@ IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
|
||||||
{
|
{
|
||||||
if (!strcmp(name,"ELSE") || !strcmp(name,"ENDIF"))
|
if (!strcmp(name,"ELSE") || !strcmp(name,"ENDIF"))
|
||||||
{
|
{
|
||||||
if (m_Not && (args.size() == 2) && !strcmp(args[0].c_str(),"NOT") &&
|
if (args == m_Args)
|
||||||
!strcmp(args[1].c_str(),m_Define.c_str()))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!m_Not && (args.size() == 1) &&
|
|
||||||
!strcmp(args[0].c_str(),m_Define.c_str()))
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -72,9 +66,7 @@ void cmIfFunctionBlocker::
|
||||||
ScopeEnded(cmMakefile &mf)
|
ScopeEnded(cmMakefile &mf)
|
||||||
{
|
{
|
||||||
cmSystemTools::Error("The end of a CMakeLists file was reached with an IF statement that was not closed properly. Within the directory: ",
|
cmSystemTools::Error("The end of a CMakeLists file was reached with an IF statement that was not closed properly. Within the directory: ",
|
||||||
mf.GetCurrentDirectory(),
|
mf.GetCurrentDirectory());
|
||||||
(m_Not ? " The arguments to the if were: NOT " : " The arguments to the if were: "),
|
|
||||||
m_Define.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmIfCommand::InitialPass(std::vector<std::string>& args)
|
bool cmIfCommand::InitialPass(std::vector<std::string>& args)
|
||||||
|
@ -85,39 +77,73 @@ bool cmIfCommand::InitialPass(std::vector<std::string>& args)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for the NOT value
|
// create a function blocker
|
||||||
|
cmIfFunctionBlocker *f = NULL;
|
||||||
|
|
||||||
|
// check for the different signatures
|
||||||
const char *def;
|
const char *def;
|
||||||
|
const char *def2;
|
||||||
|
|
||||||
|
if (args.size() == 1)
|
||||||
|
{
|
||||||
|
def = m_Makefile->GetDefinition(args[0].c_str());
|
||||||
|
if(cmSystemTools::IsOff(def))
|
||||||
|
{
|
||||||
|
f = new cmIfFunctionBlocker();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args.size() == 2 && (args[0] == "NOT"))
|
if (args.size() == 2 && (args[0] == "NOT"))
|
||||||
{
|
{
|
||||||
def = m_Makefile->GetDefinition(args[1].c_str());
|
def = m_Makefile->GetDefinition(args[1].c_str());
|
||||||
if(!cmSystemTools::IsOff(def))
|
if(!cmSystemTools::IsOff(def))
|
||||||
{
|
{
|
||||||
// create a function blocker
|
f = new cmIfFunctionBlocker();
|
||||||
cmIfFunctionBlocker *f = new cmIfFunctionBlocker();
|
|
||||||
f->m_Define = args[1];
|
|
||||||
f->m_Not = true;
|
|
||||||
m_Makefile->AddFunctionBlocker(f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (args.size() == 3 && (args[1] == "AND"))
|
||||||
{
|
{
|
||||||
def = m_Makefile->GetDefinition(args[0].c_str());
|
def = m_Makefile->GetDefinition(args[0].c_str());
|
||||||
if(!cmSystemTools::IsOff(def))
|
def2 = m_Makefile->GetDefinition(args[2].c_str());
|
||||||
|
if(!cmSystemTools::IsOff(def) && !cmSystemTools::IsOff(def2))
|
||||||
{
|
{
|
||||||
// do nothing
|
f = new cmIfFunctionBlocker();
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
if (args.size() == 3 && (args[1] == "OR"))
|
||||||
|
{
|
||||||
|
def = m_Makefile->GetDefinition(args[0].c_str());
|
||||||
|
def2 = m_Makefile->GetDefinition(args[2].c_str());
|
||||||
|
if(!cmSystemTools::IsOff(def) || !cmSystemTools::IsOff(def2))
|
||||||
{
|
{
|
||||||
// create a function blocker
|
f = new cmIfFunctionBlocker();
|
||||||
cmIfFunctionBlocker *f = new cmIfFunctionBlocker();
|
|
||||||
f->m_Define = args[0];
|
|
||||||
m_Makefile->AddFunctionBlocker(f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.size() == 3 && (args[1] == "MATCHES"))
|
||||||
|
{
|
||||||
|
def = m_Makefile->GetDefinition(args[0].c_str());
|
||||||
|
cmRegularExpression regEntry(args[2].c_str());
|
||||||
|
|
||||||
|
// check for black line or comment
|
||||||
|
if (regEntry.find(def))
|
||||||
|
{
|
||||||
|
f = new cmIfFunctionBlocker();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we created a function blocker then set its args
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
for(std::vector<std::string>::iterator j = args.begin();
|
||||||
|
j != args.end(); ++j)
|
||||||
|
{
|
||||||
|
f->m_Args.push_back(*j);
|
||||||
|
}
|
||||||
|
m_Makefile->AddFunctionBlocker(f);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
class cmIfFunctionBlocker : public cmFunctionBlocker
|
class cmIfFunctionBlocker : public cmFunctionBlocker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cmIfFunctionBlocker() {m_Not = false;}
|
cmIfFunctionBlocker() {}
|
||||||
virtual ~cmIfFunctionBlocker() {}
|
virtual ~cmIfFunctionBlocker() {}
|
||||||
virtual bool IsFunctionBlocked(const char *name,
|
virtual bool IsFunctionBlocked(const char *name,
|
||||||
const std::vector<std::string> &args,
|
const std::vector<std::string> &args,
|
||||||
|
@ -63,8 +63,7 @@ public:
|
||||||
cmMakefile &mf);
|
cmMakefile &mf);
|
||||||
virtual void ScopeEnded(cmMakefile &mf);
|
virtual void ScopeEnded(cmMakefile &mf);
|
||||||
|
|
||||||
std::string m_Define;
|
std::vector<std::string> m_Args;
|
||||||
bool m_Not;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \class cmIfCommand
|
/** \class cmIfCommand
|
||||||
|
@ -114,8 +113,9 @@ public:
|
||||||
virtual const char* GetFullDocumentation()
|
virtual const char* GetFullDocumentation()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"IF (define) Starts an if block. Optionally there it can be invoked as\n"
|
"IF (define) Starts an if block. Optionally it can be invoked "
|
||||||
"IF (NOT Define) the matching ELSE and ENDIF require the NOT as well.";
|
"using (NOT define) (def AND def2) (def OR def2) (def MATCHES def2) "
|
||||||
|
"MATCHES checks if def matches the regular expression def2 ";
|
||||||
}
|
}
|
||||||
|
|
||||||
cmTypeMacro(cmIfCommand, cmCommand);
|
cmTypeMacro(cmIfCommand, cmCommand);
|
||||||
|
|
Loading…
Reference in New Issue