[Cmake-commits] [cmake-commits] martink committed cmIfCommand.cxx 1.94 1.95 cmIfCommand.h 1.54 1.55 cmPolicies.cxx 1.35 1.36 cmPolicies.h 1.22 1.23 cmWhileCommand.cxx 1.17 1.18
cmake-commits at cmake.org
cmake-commits at cmake.org
Fri Jun 12 10:07:07 EDT 2009
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv14449/Source
Modified Files:
cmIfCommand.cxx cmIfCommand.h cmPolicies.cxx cmPolicies.h
cmWhileCommand.cxx
Log Message:
ENH: modified the if command to address bug 9123 some
Index: cmWhileCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmWhileCommand.cxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -C 2 -d -r1.17 -r1.18
*** cmWhileCommand.cxx 13 May 2009 15:08:29 -0000 1.17
--- cmWhileCommand.cxx 12 Jun 2009 14:07:05 -0000 1.18
***************
*** 42,50 ****
std::vector<std::string> expandedArguments;
mf.ExpandArguments(this->Args, expandedArguments);
bool isTrue =
! cmIfCommand::IsTrue(expandedArguments,errorString,&mf);
while (isTrue)
{
// Invoke all the functions that were collected in the block.
for(unsigned int c = 0; c < this->Functions.size(); ++c)
--- 42,74 ----
std::vector<std::string> expandedArguments;
mf.ExpandArguments(this->Args, expandedArguments);
+ cmake::MessageType messageType;
bool isTrue =
! cmIfCommand::IsTrue(expandedArguments,errorString,
! &mf, messageType);
while (isTrue)
{
+ if (errorString.size())
+ {
+ std::string err = "had incorrect arguments: ";
+ unsigned int i;
+ for(i =0; i < this->Args.size(); ++i)
+ {
+ err += (this->Args[i].Quoted?"\"":"");
+ err += this->Args[i].Value;
+ err += (this->Args[i].Quoted?"\"":"");
+ err += " ";
+ }
+ err += "(";
+ err += errorString;
+ err += ").";
+ mf.IssueMessage(messageType, err);
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+ }
+
// Invoke all the functions that were collected in the block.
for(unsigned int c = 0; c < this->Functions.size(); ++c)
***************
*** 69,73 ****
mf.ExpandArguments(this->Args, expandedArguments);
isTrue =
! cmIfCommand::IsTrue(expandedArguments,errorString,&mf);
}
return true;
--- 93,98 ----
mf.ExpandArguments(this->Args, expandedArguments);
isTrue =
! cmIfCommand::IsTrue(expandedArguments,errorString,
! &mf, messageType);
}
return true;
Index: cmPolicies.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmPolicies.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C 2 -d -r1.22 -r1.23
*** cmPolicies.h 23 Jan 2009 17:20:09 -0000 1.22
--- cmPolicies.h 12 Jun 2009 14:07:05 -0000 1.23
***************
*** 53,56 ****
--- 53,57 ----
CMP0010, // Bad variable reference syntax is an error
CMP0011, // Strong policy scope for include and find_package
+ CMP0012, // Strong handling of boolean constants
// Always the last entry. Useful mostly to avoid adding a comma
Index: cmPolicies.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmPolicies.cxx,v
retrieving revision 1.35
retrieving revision 1.36
diff -C 2 -d -r1.35 -r1.36
*** cmPolicies.cxx 22 Jan 2009 18:18:39 -0000 1.35
--- cmPolicies.cxx 12 Jun 2009 14:07:05 -0000 1.36
***************
*** 356,359 ****
--- 356,372 ----
"default cmake_policy PUSH and POP.",
2,6,3, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0012, "CMP0012",
+ "In CMake versions prior to 2.6.5 the only boolean constants were 0 and 1. "
+ "Other boolean constants such as true, false, yes, no, "
+ "on, off, y, n, notfound, ignore were recognized in some cases but not all. "
+ "In later versions of cmake these values are treated as boolean constants "
+ "more consistently and should not be used as variable names. "
+ "Please do not use them as variable names.",
+ "The OLD behavior for this policy is to allow variables to have names such as "
+ "true and to dereference them. "
+ "The NEW behavior for this policy is to treat strings like true as a boolean constant.",
+ 2,6,5, cmPolicies::WARN);
}
Index: cmIfCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmIfCommand.cxx,v
retrieving revision 1.94
retrieving revision 1.95
diff -C 2 -d -r1.94 -r1.95
*** cmIfCommand.cxx 21 Jan 2009 14:49:00 -0000 1.94
--- cmIfCommand.cxx 12 Jun 2009 14:07:03 -0000 1.95
***************
*** 10,15 ****
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
! This software is distributed WITHOUT ANY WARRANTY; without even
! the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
--- 10,15 ----
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
! This software is distributed WITHOUT ANY WARRANTY; without even
! the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
***************
*** 24,28 ****
//=========================================================================
bool cmIfFunctionBlocker::
! IsFunctionBlocked(const cmListFileFunction& lff,
cmMakefile &mf,
cmExecutionStatus &inStatus)
--- 24,28 ----
//=========================================================================
bool cmIfFunctionBlocker::
! IsFunctionBlocked(const cmListFileFunction& lff,
cmMakefile &mf,
cmExecutionStatus &inStatus)
***************
*** 37,41 ****
this->ScopeDepth--;
// if this is the endif for this if statement, then start executing
! if (!this->ScopeDepth)
{
// Remove the function blocker for this scope or bail.
--- 37,41 ----
this->ScopeDepth--;
// if this is the endif for this if statement, then start executing
! if (!this->ScopeDepth)
{
// Remove the function blocker for this scope or bail.
***************
*** 79,89 ****
std::string errorString;
!
std::vector<std::string> expandedArguments;
! mf.ExpandArguments(this->Functions[c].Arguments,
expandedArguments);
! bool isTrue =
! cmIfCommand::IsTrue(expandedArguments,errorString,&mf);
!
if (errorString.size())
{
--- 79,92 ----
std::string errorString;
!
std::vector<std::string> expandedArguments;
! mf.ExpandArguments(this->Functions[c].Arguments,
expandedArguments);
!
! cmake::MessageType status;
! bool isTrue =
! cmIfCommand::IsTrue(expandedArguments, errorString,
! &mf, status);
!
if (errorString.size())
{
***************
*** 100,108 ****
err += errorString;
err += ").";
! mf.IssueMessage(cmake::FATAL_ERROR, err);
! cmSystemTools::SetFatalErrorOccured();
! return true;
}
!
if (isTrue)
{
--- 103,114 ----
err += errorString;
err += ").";
! mf.IssueMessage(status, err);
! if (status == cmake::FATAL_ERROR)
! {
! cmSystemTools::SetFatalErrorOccured();
! return true;
! }
}
!
if (isTrue)
{
***************
*** 112,116 ****
}
}
!
// should we execute?
else if (!this->IsBlocking)
--- 118,122 ----
}
}
!
// should we execute?
else if (!this->IsBlocking)
***************
*** 133,140 ****
}
}
!
// record the command
this->Functions.push_back(lff);
!
// always return true
return true;
--- 139,146 ----
}
}
!
// record the command
this->Functions.push_back(lff);
!
// always return true
return true;
***************
*** 161,174 ****
//=========================================================================
bool cmIfCommand
! ::InvokeInitialPass(const std::vector<cmListFileArgument>& args,
cmExecutionStatus &)
{
std::string errorString;
!
std::vector<std::string> expandedArguments;
this->Makefile->ExpandArguments(args, expandedArguments);
! bool isTrue =
! cmIfCommand::IsTrue(expandedArguments,errorString,this->Makefile);
!
if (errorString.size())
{
--- 167,183 ----
//=========================================================================
bool cmIfCommand
! ::InvokeInitialPass(const std::vector<cmListFileArgument>& args,
cmExecutionStatus &)
{
std::string errorString;
!
std::vector<std::string> expandedArguments;
this->Makefile->ExpandArguments(args, expandedArguments);
!
! cmake::MessageType status;
! bool isTrue =
! cmIfCommand::IsTrue(expandedArguments,errorString,
! this->Makefile, status);
!
if (errorString.size())
{
***************
*** 185,193 ****
err += errorString;
err += ").";
! this->SetError(err.c_str());
! cmSystemTools::SetFatalErrorOccured();
! return false;
}
!
cmIfFunctionBlocker *f = new cmIfFunctionBlocker();
// if is isn't true block the commands
--- 194,209 ----
err += errorString;
err += ").";
! if (status == cmake::FATAL_ERROR)
! {
! this->SetError(err.c_str());
! cmSystemTools::SetFatalErrorOccured();
! return false;
! }
! else
! {
! this->Makefile->IssueMessage(status, err);
! }
}
!
cmIfFunctionBlocker *f = new cmIfFunctionBlocker();
// if is isn't true block the commands
***************
*** 200,210 ****
f->Args = args;
this->Makefile->AddFunctionBlocker(f);
!
return true;
}
! namespace
{
! //=========================================================================
void IncrementArguments(std::list<std::string> &newArgs,
std::list<std::string>::iterator &argP1,
--- 216,328 ----
f->Args = args;
this->Makefile->AddFunctionBlocker(f);
!
return true;
}
! namespace
{
! //=========================================================================
! // returns true if succesfull, the resulting bool parsed is stored in result
! bool GetBooleanValue(std::string &newArg,
! cmMakefile *makefile,
! bool &result,
! std::string &errorString,
! cmPolicies::PolicyStatus Policy12Status,
! cmake::MessageType &status)
! {
! if (Policy12Status != cmPolicies::OLD &&
! Policy12Status != cmPolicies::WARN)
! {
! // please note IsOn(var) does not always equal !IsOff(var)
! // that is why each is called
! if (cmSystemTools::IsOn(newArg.c_str()))
! {
! result = true;
! return true;
! }
! if (cmSystemTools::IsOff(newArg.c_str()))
! {
! result = false;
! return true;
! }
! return false;
! }
!
! // Old policy is more complex...
! // 0 and 1 are very common, test for them first quickly
! if (newArg == "0")
! {
! result = false;
! return true;
! }
! if (newArg == "1")
! {
! result = true;
! return true;
! }
!
! // old behavior is to dereference the var
! if (Policy12Status == cmPolicies::OLD)
! {
! return false;
! }
!
! // now test for values that may be the name of a variable
! // warn if used
! if (cmSystemTools::IsOn(newArg.c_str()))
! {
! // only warn if the value would change
! const char *def = makefile->GetDefinition(newArg.c_str());
! if (cmSystemTools::IsOff(def))
! {
! cmPolicies* policies = makefile->GetPolicies();
! errorString = "You have used a variable or argument named \""
! + newArg
! + "\" in a conditional statement. Please be aware of issues "
! + "related to policy CMP0012. "
! + policies->GetPolicyWarning(cmPolicies::CMP0012);
! status = cmake::AUTHOR_WARNING;
! }
! return false;
! }
! if (cmSystemTools::IsOff(newArg.c_str()))
! {
! // only warn if the value would change
! const char *def = makefile->GetDefinition(newArg.c_str());
! if (!cmSystemTools::IsOff(def))
! {
! cmPolicies* policies = makefile->GetPolicies();
! errorString = "You have used a variable or argument named \""
! + newArg
! + "\" in a conditional statement. Please be aware of issues "
! + "related to policy CMP0012. "
! + policies->GetPolicyWarning(cmPolicies::CMP0012);
! status = cmake::AUTHOR_WARNING;
! }
! return false;
! }
! return false;
! }
!
! //=========================================================================
! // returns the resulting boolean value
! bool GetBooleanValueWithAutoDereference(
! std::string &newArg,
! cmMakefile *makefile,
! std::string &errorString,
! cmPolicies::PolicyStatus Policy12Status,
! cmake::MessageType &status)
! {
! bool result = false;
! if (GetBooleanValue(newArg, makefile, result,
! errorString, Policy12Status, status))
! {
! return result;
! }
! const char *def = makefile->GetDefinition(newArg.c_str());
! return !cmSystemTools::IsOff(def);
! }
!
! //=========================================================================
void IncrementArguments(std::list<std::string> &newArgs,
std::list<std::string>::iterator &argP1,
***************
*** 234,238 ****
*arg = "1";
}
! else
{
*arg = "0";
--- 352,356 ----
*arg = "1";
}
! else
{
*arg = "0";
***************
*** 256,260 ****
*arg = "1";
}
! else
{
*arg = "0";
--- 374,378 ----
*arg = "1";
}
! else
{
*arg = "0";
***************
*** 299,303 ****
bool HandleLevel0(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &errorString)
{
int reducible;
--- 417,422 ----
bool HandleLevel0(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &errorString,
! cmake::MessageType &status)
{
int reducible;
***************
*** 330,333 ****
--- 449,453 ----
{
errorString = "mismatched parenthesis in condition";
+ status = cmake::FATAL_ERROR;
return false;
}
***************
*** 339,343 ****
argP1++;
for(; argP1 != argClose; argP1++)
! {
newArgs2.push_back(*argP1);
}
--- 459,463 ----
argP1++;
for(; argP1 != argClose; argP1++)
! {
newArgs2.push_back(*argP1);
}
***************
*** 345,355 ****
// now recursively invoke IsTrue to handle the values inside the
// parenthetical expression
! bool value =
! cmIfCommand::IsTrue(newArgs2, errorString, makefile);
if(value)
{
*arg = "1";
}
! else
{
*arg = "0";
--- 465,475 ----
// now recursively invoke IsTrue to handle the values inside the
// parenthetical expression
! bool value =
! cmIfCommand::IsTrue(newArgs2, errorString, makefile, status);
if(value)
{
*arg = "1";
}
! else
{
*arg = "0";
***************
*** 358,362 ****
argP1++;
// remove the now evaluated parenthetical expression
! newArgs.erase(argP1,argClose);
}
++arg;
--- 478,482 ----
argP1++;
// remove the now evaluated parenthetical expression
! newArgs.erase(argP1,argClose);
}
++arg;
***************
*** 366,375 ****
return true;
}
!
//=========================================================================
// level one handles most predicates except for NOT
bool HandleLevel1(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &)
{
int reducible;
--- 486,495 ----
return true;
}
!
//=========================================================================
// level one handles most predicates except for NOT
bool HandleLevel1(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &, cmake::MessageType &)
{
int reducible;
***************
*** 455,459 ****
bool HandleLevel2(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &errorString)
{
int reducible;
--- 575,580 ----
bool HandleLevel2(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &errorString,
! cmake::MessageType &status)
{
int reducible;
***************
*** 471,475 ****
IncrementArguments(newArgs,argP1,argP2);
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
! *(argP1) == "MATCHES")
{
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
--- 592,596 ----
IncrementArguments(newArgs,argP1,argP2);
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
! *(argP1) == "MATCHES")
{
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
***************
*** 482,485 ****
--- 603,607 ----
error << "Regular expression \"" << rex << "\" cannot compile";
errorString = error.str();
+ status = cmake::FATAL_ERROR;
return false;
}
***************
*** 500,504 ****
}
! if (argP1 != newArgs.end() && *arg == "MATCHES")
{
*arg = "0";
--- 622,626 ----
}
! if (argP1 != newArgs.end() && *arg == "MATCHES")
{
*arg = "0";
***************
*** 510,515 ****
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
! (*(argP1) == "LESS" || *(argP1) == "GREATER" ||
! *(argP1) == "EQUAL"))
{
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
--- 632,637 ----
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
! (*(argP1) == "LESS" || *(argP1) == "GREATER" ||
! *(argP1) == "EQUAL"))
{
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
***************
*** 530,538 ****
{
result = (lhs > rhs);
! }
else
{
result = (lhs == rhs);
! }
HandleBinaryOp(result,
reducible, arg, newArgs, argP1, argP2);
--- 652,660 ----
{
result = (lhs > rhs);
! }
else
{
result = (lhs == rhs);
! }
HandleBinaryOp(result,
reducible, arg, newArgs, argP1, argP2);
***************
*** 540,546 ****
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
! (*(argP1) == "STRLESS" ||
! *(argP1) == "STREQUAL" ||
! *(argP1) == "STRGREATER"))
{
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
--- 662,668 ----
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
! (*(argP1) == "STRLESS" ||
! *(argP1) == "STREQUAL" ||
! *(argP1) == "STRGREATER"))
{
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
***************
*** 608,615 ****
bool HandleLevel3(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &)
{
int reducible;
- const char *def;
do
{
--- 730,738 ----
bool HandleLevel3(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &errorString,
! cmPolicies::PolicyStatus Policy12Status,
! cmake::MessageType &status)
{
int reducible;
do
{
***************
*** 624,630 ****
if (argP1 != newArgs.end() && *arg == "NOT")
{
! def = cmIfCommand::GetVariableOrNumber((argP1)->c_str(), makefile);
! HandlePredicate(cmSystemTools::IsOff(def),
! reducible, arg, newArgs, argP1, argP2);
}
++arg;
--- 747,755 ----
if (argP1 != newArgs.end() && *arg == "NOT")
{
! bool rhs = GetBooleanValueWithAutoDereference(*argP1, makefile,
! errorString,
! Policy12Status,
! status);
! HandlePredicate(!rhs, reducible, arg, newArgs, argP1, argP2);
}
++arg;
***************
*** 639,647 ****
bool HandleLevel4(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &)
{
int reducible;
! const char *def;
! const char *def2;
do
{
--- 764,774 ----
bool HandleLevel4(std::list<std::string> &newArgs,
cmMakefile *makefile,
! std::string &errorString,
! cmPolicies::PolicyStatus Policy12Status,
! cmake::MessageType &status)
{
int reducible;
! bool lhs;
! bool rhs;
do
{
***************
*** 654,674 ****
argP1 = arg;
IncrementArguments(newArgs,argP1,argP2);
! if (argP1 != newArgs.end() && *(argP1) == "AND" &&
argP2 != newArgs.end())
{
! def = cmIfCommand::GetVariableOrNumber(arg->c_str(), makefile);
! def2 = cmIfCommand::GetVariableOrNumber((argP2)->c_str(), makefile);
! HandleBinaryOp(
! !(cmSystemTools::IsOff(def) || cmSystemTools::IsOff(def2)),
reducible, arg, newArgs, argP1, argP2);
}
! if (argP1 != newArgs.end() && *(argP1) == "OR" &&
argP2 != newArgs.end())
{
! def = cmIfCommand::GetVariableOrNumber(arg->c_str(), makefile);
! def2 = cmIfCommand::GetVariableOrNumber((argP2)->c_str(), makefile);
! HandleBinaryOp(
! !(cmSystemTools::IsOff(def) && cmSystemTools::IsOff(def2)),
reducible, arg, newArgs, argP1, argP2);
}
--- 781,811 ----
argP1 = arg;
IncrementArguments(newArgs,argP1,argP2);
! if (argP1 != newArgs.end() && *(argP1) == "AND" &&
argP2 != newArgs.end())
{
! lhs = GetBooleanValueWithAutoDereference(*arg, makefile,
! errorString,
! Policy12Status,
! status);
! rhs = GetBooleanValueWithAutoDereference(*argP2, makefile,
! errorString,
! Policy12Status,
! status);
! HandleBinaryOp((lhs && rhs),
reducible, arg, newArgs, argP1, argP2);
}
! if (argP1 != newArgs.end() && *(argP1) == "OR" &&
argP2 != newArgs.end())
{
! lhs = GetBooleanValueWithAutoDereference(*arg, makefile,
! errorString,
! Policy12Status,
! status);
! rhs = GetBooleanValueWithAutoDereference(*argP2, makefile,
! errorString,
! Policy12Status,
! status);
! HandleBinaryOp((lhs || rhs),
reducible, arg, newArgs, argP1, argP2);
}
***************
*** 684,690 ****
//=========================================================================
// order of operations,
! // 1. ( ) -- parenthetical groups
! // 2. IS_DIRECTORY EXISTS COMMAND DEFINED etc predicates
! // 3. MATCHES LESS GREATER EQUAL STRLESS STRGREATER STREQUAL etc binary ops
// 4. NOT
// 5. AND OR
--- 821,827 ----
//=========================================================================
// order of operations,
! // 1. ( ) -- parenthetical groups
! // 2. IS_DIRECTORY EXISTS COMMAND DEFINED etc predicates
! // 3. MATCHES LESS GREATER EQUAL STRLESS STRGREATER STREQUAL etc binary ops
// 4. NOT
// 5. AND OR
***************
*** 700,706 ****
bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
! std::string &errorString, cmMakefile *makefile)
{
- const char *def;
errorString = "";
--- 837,843 ----
bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
! std::string &errorString, cmMakefile *makefile,
! cmake::MessageType &status)
{
errorString = "";
***************
*** 716,720 ****
// copy to the list structure
for(unsigned int i = 0; i < args.size(); ++i)
! {
newArgs.push_back(args[i]);
}
--- 853,857 ----
// copy to the list structure
for(unsigned int i = 0; i < args.size(); ++i)
! {
newArgs.push_back(args[i]);
}
***************
*** 722,742 ****
// now loop through the arguments and see if we can reduce any of them
// we do this multiple times. Once for each level of precedence
! if (!HandleLevel0(newArgs, makefile, errorString)) // parens
{
return false;
}
! if (!HandleLevel1(newArgs, makefile, errorString)) //predicates
{
return false;
}
! if (!HandleLevel2(newArgs, makefile, errorString)) // binary ops
{
return false;
}
! if (!HandleLevel3(newArgs, makefile, errorString)) // NOT
{
return false;
}
! if (!HandleLevel4(newArgs, makefile, errorString)) // AND OR
{
return false;
--- 859,891 ----
// now loop through the arguments and see if we can reduce any of them
// we do this multiple times. Once for each level of precedence
! // parens
! if (!HandleLevel0(newArgs, makefile, errorString, status))
{
return false;
}
! //predicates
! if (!HandleLevel1(newArgs, makefile, errorString, status))
{
return false;
}
! // binary ops
! if (!HandleLevel2(newArgs, makefile, errorString, status))
{
return false;
}
!
! // used to store the value of policy CMP0012 for performance
! cmPolicies::PolicyStatus Policy12Status =
! makefile->GetPolicyStatus(cmPolicies::CMP0012);
!
! // NOT
! if (!HandleLevel3(newArgs, makefile, errorString,
! Policy12Status, status))
{
return false;
}
! // AND OR
! if (!HandleLevel4(newArgs, makefile, errorString,
! Policy12Status, status))
{
return false;
***************
*** 744,770 ****
// now at the end there should only be one argument left
! if (newArgs.size() == 1)
! {
! if (*newArgs.begin() == "0")
! {
! return false;
! }
! if (*newArgs.begin() == "1")
! {
! return true;
! }
! def = makefile->GetDefinition(args[0].c_str());
! if(cmSystemTools::IsOff(def))
! {
! return false;
! }
! }
! else
{
errorString = "Unknown arguments specified";
return false;
}
!
! return true;
}
--- 893,907 ----
// now at the end there should only be one argument left
! if (newArgs.size() != 1)
{
errorString = "Unknown arguments specified";
return false;
}
!
! return GetBooleanValueWithAutoDereference(*(newArgs.begin()),
! makefile,
! errorString,
! Policy12Status,
! status);
}
***************
*** 780,796 ****
return def;
}
-
- //=========================================================================
- const char* cmIfCommand::GetVariableOrNumber(const char* str,
- const cmMakefile* mf)
- {
- const char* def = mf->GetDefinition(str);
- if(!def)
- {
- if (atoi(str))
- {
- def = str;
- }
- }
- return def;
- }
--- 917,918 ----
Index: cmIfCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmIfCommand.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -C 2 -d -r1.54 -r1.55
*** cmIfCommand.h 16 Feb 2009 18:56:04 -0000 1.54
--- cmIfCommand.h 12 Jun 2009 14:07:05 -0000 1.55
***************
*** 192,195 ****
--- 192,260 ----
"evaluated as part of evaluating the expression "
"that contains them."
+ "\n"
+
+ "The if statement was written fairly early in CMake's history "
+ "and it has some convenience features that may be confusing for "
+ "new users. The if statement reduces operations until there is "
+ "a single remaining value, at that point if the case "
+ "insensitive value is: ON, 1, YES, TRUE, Y it returns true, if "
+ "it is OFF, 0, NO, FALSE, N, NOTFOUND, *-NOTFOUND, IGNORE it "
+ "will return false. \n"
+
+ "This is fairly reasonable. The convenience feature that makes "
+ "it more confusing is how CMake handles values that do not "
+ "match the true or false list. Those values are treated as "
+ "variables and are dereferenced even though they do not have "
+ "the required ${} syntax. This means that if you write\n"
+
+ " if (boobah)\n"
+
+ "CMake will treat it as if you wrote \n"
+
+ " if (${boobah})\n"
+
+ "likewise if you write \n"
+
+ " if (fubar AND sol)\n"
+
+ "CMake will conveniently treat it as \n"
+
+ " if (\"${fubar}\" AND \"${sol}\")\n"
+
+ "The later is really the correct way to write it, but the "
+ "former will work as well. Only some operations in the if "
+ "statement have this special handling of arguments. The "
+ "specific details follow: \n"
+
+ "1) The left hand argument to MATCHES is first checked to see "
+ "if it is a defined variable, if so the variable's value is "
+ "used, otherwise the original value is used. \n"
+
+ "2) If the left hand argument to MATCHES is missing it returns "
+ "false without error \n"
+
+ "3) Both left and right hand arguments to LESS GREATER EQUAL "
+ "are independently tested to see if they are defined variables, "
+ "if so their defined values are used otherwise the original "
+ "value is used. \n"
+
+ "4) Both left and right hand arguments to STRLESS STREQUAL "
+ "STRGREATER are independently tested to see if they are defined "
+ "variables, if so their defined values are used otherwise the "
+ "original value is used. \n"
+
+ "5) Both left and right hand argumemnts to VERSION_LESS "
+ "VERSION_EQUAL VERSION_GREATER are independently tested to see "
+ "if they are defined variables, if so their defined values are "
+ "used otherwise the original value is used. \n"
+
+ "6) The right hand argument to NOT is tested to see if it is a "
+ "boolean constant, if so the value is used, otherwise it is "
+ "assumed to be a variable and it is dereferenced. \n"
+
+ "7) The left and right hand arguments to AND OR are "
+ "independently tested to see if they are boolean constants, if "
+ "so they are used as such, otherwise they are assumed to be "
+ "variables and are dereferenced. \n"
;
}
***************
*** 199,203 ****
// an error, the errorString will be set.
static bool IsTrue(const std::vector<std::string> &args,
! std::string &errorString, cmMakefile *mf);
// Get a definition from the makefile. If it doesn't exist,
--- 264,269 ----
// an error, the errorString will be set.
static bool IsTrue(const std::vector<std::string> &args,
! std::string &errorString, cmMakefile *mf,
! cmake::MessageType &status);
// Get a definition from the makefile. If it doesn't exist,
***************
*** 205,211 ****
static const char* GetVariableOrString(const char* str,
const cmMakefile* mf);
- static const char* GetVariableOrNumber(const char* str,
- const cmMakefile* mf);
-
cmTypeMacro(cmIfCommand, cmCommand);
--- 271,274 ----
More information about the Cmake-commits
mailing list