cmConditionEvaluator.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2014 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmConditionEvaluator.h"
  11. cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile):
  12. Makefile(makefile),
  13. Policy12Status(makefile.GetPolicyStatus(cmPolicies::CMP0012)),
  14. Policy54Status(makefile.GetPolicyStatus(cmPolicies::CMP0054))
  15. {
  16. }
  17. //=========================================================================
  18. // order of operations,
  19. // 1. ( ) -- parenthetical groups
  20. // 2. IS_DIRECTORY EXISTS COMMAND DEFINED etc predicates
  21. // 3. MATCHES LESS GREATER EQUAL STRLESS STRGREATER STREQUAL etc binary ops
  22. // 4. NOT
  23. // 5. AND OR
  24. //
  25. // There is an issue on whether the arguments should be values of references,
  26. // for example IF (FOO AND BAR) should that compare the strings FOO and BAR
  27. // or should it really do IF (${FOO} AND ${BAR}) Currently IS_DIRECTORY
  28. // EXISTS COMMAND and DEFINED all take values. EQUAL, LESS and GREATER can
  29. // take numeric values or variable names. STRLESS and STRGREATER take
  30. // variable names but if the variable name is not found it will use the name
  31. // directly. AND OR take variables or the values 0 or 1.
  32. bool cmConditionEvaluator::IsTrue(
  33. const std::vector<cmExpandedCommandArgument> &args,
  34. std::string &errorString,
  35. cmake::MessageType &status)
  36. {
  37. errorString = "";
  38. // handle empty invocation
  39. if (args.size() < 1)
  40. {
  41. return false;
  42. }
  43. // store the reduced args in this vector
  44. cmArgumentList newArgs;
  45. // copy to the list structure
  46. for(unsigned int i = 0; i < args.size(); ++i)
  47. {
  48. newArgs.push_back(args[i]);
  49. }
  50. // now loop through the arguments and see if we can reduce any of them
  51. // we do this multiple times. Once for each level of precedence
  52. // parens
  53. if (!this->HandleLevel0(newArgs, errorString, status))
  54. {
  55. return false;
  56. }
  57. //predicates
  58. if (!this->HandleLevel1(newArgs, errorString, status))
  59. {
  60. return false;
  61. }
  62. // binary ops
  63. if (!this->HandleLevel2(newArgs, errorString, status))
  64. {
  65. return false;
  66. }
  67. // NOT
  68. if (!this->HandleLevel3(newArgs, errorString, status))
  69. {
  70. return false;
  71. }
  72. // AND OR
  73. if (!this->HandleLevel4(newArgs, errorString, status))
  74. {
  75. return false;
  76. }
  77. // now at the end there should only be one argument left
  78. if (newArgs.size() != 1)
  79. {
  80. errorString = "Unknown arguments specified";
  81. status = cmake::FATAL_ERROR;
  82. return false;
  83. }
  84. return this->GetBooleanValueWithAutoDereference(*(newArgs.begin()),
  85. errorString, status, true);
  86. }
  87. //=========================================================================
  88. const char* cmConditionEvaluator::GetDefinitionIfUnquoted(
  89. cmExpandedCommandArgument const& argument) const
  90. {
  91. if((this->Policy54Status != cmPolicies::WARN &&
  92. this->Policy54Status != cmPolicies::OLD) &&
  93. argument.WasQuoted())
  94. {
  95. return 0;
  96. }
  97. const char* def = this->Makefile.GetDefinition(argument.GetValue());
  98. if(def && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN)
  99. {
  100. bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported(
  101. this->Makefile.GetBacktrace()[0]);
  102. if(!hasBeenReported)
  103. {
  104. cmOStringStream e;
  105. e << (this->Makefile.GetPolicies()->GetPolicyWarning(
  106. cmPolicies::CMP0054)) << "\n";
  107. e << "Quoted variables like \"" << argument.GetValue() <<
  108. "\" will no longer be dereferenced "
  109. "when the policy is set to NEW. "
  110. "Since the policy is not set the OLD behavior will be used.";
  111. this->Makefile.IssueMessage(cmake::AUTHOR_WARNING, e.str());
  112. }
  113. }
  114. return def;
  115. }
  116. //=========================================================================
  117. const char* cmConditionEvaluator::GetVariableOrString(
  118. const cmExpandedCommandArgument& argument) const
  119. {
  120. const char* def = this->GetDefinitionIfUnquoted(argument);
  121. if(!def)
  122. {
  123. def = argument.c_str();
  124. }
  125. return def;
  126. }
  127. //=========================================================================
  128. bool cmConditionEvaluator::IsKeyword(std::string const& keyword,
  129. cmExpandedCommandArgument& argument) const
  130. {
  131. if((this->Policy54Status != cmPolicies::WARN &&
  132. this->Policy54Status != cmPolicies::OLD) &&
  133. argument.WasQuoted())
  134. {
  135. return false;
  136. }
  137. bool isKeyword = argument.GetValue() == keyword;
  138. if(isKeyword && argument.WasQuoted() &&
  139. this->Policy54Status == cmPolicies::WARN)
  140. {
  141. bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported(
  142. this->Makefile.GetBacktrace()[0]);
  143. if(!hasBeenReported)
  144. {
  145. cmOStringStream e;
  146. e << (this->Makefile.GetPolicies()->GetPolicyWarning(
  147. cmPolicies::CMP0054)) << "\n";
  148. e << "Quoted keywords like \"" << argument.GetValue() <<
  149. "\" will no longer be interpreted as keywords "
  150. "when the policy is set to NEW. "
  151. "Since the policy is not set the OLD behavior will be used.";
  152. this->Makefile.IssueMessage(cmake::AUTHOR_WARNING, e.str());
  153. }
  154. }
  155. return isKeyword;
  156. }
  157. //=========================================================================
  158. bool cmConditionEvaluator::GetBooleanValue(
  159. cmExpandedCommandArgument& arg) const
  160. {
  161. // Check basic constants.
  162. if (arg == "0")
  163. {
  164. return false;
  165. }
  166. if (arg == "1")
  167. {
  168. return true;
  169. }
  170. // Check named constants.
  171. if (cmSystemTools::IsOn(arg.c_str()))
  172. {
  173. return true;
  174. }
  175. if (cmSystemTools::IsOff(arg.c_str()))
  176. {
  177. return false;
  178. }
  179. // Check for numbers.
  180. if(!arg.empty())
  181. {
  182. char* end;
  183. double d = strtod(arg.c_str(), &end);
  184. if(*end == '\0')
  185. {
  186. // The whole string is a number. Use C conversion to bool.
  187. return d? true:false;
  188. }
  189. }
  190. // Check definition.
  191. const char* def = this->GetDefinitionIfUnquoted(arg);
  192. return !cmSystemTools::IsOff(def);
  193. }
  194. //=========================================================================
  195. // Boolean value behavior from CMake 2.6.4 and below.
  196. bool cmConditionEvaluator::GetBooleanValueOld(
  197. cmExpandedCommandArgument const& arg, bool one) const
  198. {
  199. if(one)
  200. {
  201. // Old IsTrue behavior for single argument.
  202. if(arg == "0")
  203. { return false; }
  204. else if(arg == "1")
  205. { return true; }
  206. else
  207. {
  208. const char* def = this->GetDefinitionIfUnquoted(arg);
  209. return !cmSystemTools::IsOff(def);
  210. }
  211. }
  212. else
  213. {
  214. // Old GetVariableOrNumber behavior.
  215. const char* def = this->GetDefinitionIfUnquoted(arg);
  216. if(!def && atoi(arg.c_str()))
  217. {
  218. def = arg.c_str();
  219. }
  220. return !cmSystemTools::IsOff(def);
  221. }
  222. }
  223. //=========================================================================
  224. // returns the resulting boolean value
  225. bool cmConditionEvaluator::GetBooleanValueWithAutoDereference(
  226. cmExpandedCommandArgument &newArg,
  227. std::string &errorString,
  228. cmake::MessageType &status,
  229. bool oneArg) const
  230. {
  231. // Use the policy if it is set.
  232. if (this->Policy12Status == cmPolicies::NEW)
  233. {
  234. return GetBooleanValue(newArg);
  235. }
  236. else if (this->Policy12Status == cmPolicies::OLD)
  237. {
  238. return GetBooleanValueOld(newArg, oneArg);
  239. }
  240. // Check policy only if old and new results differ.
  241. bool newResult = this->GetBooleanValue(newArg);
  242. bool oldResult = this->GetBooleanValueOld(newArg, oneArg);
  243. if(newResult != oldResult)
  244. {
  245. switch(this->Policy12Status)
  246. {
  247. case cmPolicies::WARN:
  248. {
  249. cmPolicies* policies = this->Makefile.GetPolicies();
  250. errorString = "An argument named \"" + newArg.GetValue()
  251. + "\" appears in a conditional statement. "
  252. + policies->GetPolicyWarning(cmPolicies::CMP0012);
  253. status = cmake::AUTHOR_WARNING;
  254. }
  255. case cmPolicies::OLD:
  256. return oldResult;
  257. case cmPolicies::REQUIRED_IF_USED:
  258. case cmPolicies::REQUIRED_ALWAYS:
  259. {
  260. cmPolicies* policies = this->Makefile.GetPolicies();
  261. errorString = "An argument named \"" + newArg.GetValue()
  262. + "\" appears in a conditional statement. "
  263. + policies->GetRequiredPolicyError(cmPolicies::CMP0012);
  264. status = cmake::FATAL_ERROR;
  265. }
  266. case cmPolicies::NEW:
  267. break;
  268. }
  269. }
  270. return newResult;
  271. }
  272. //=========================================================================
  273. void cmConditionEvaluator::IncrementArguments(cmArgumentList &newArgs,
  274. cmArgumentList::iterator &argP1,
  275. cmArgumentList::iterator &argP2) const
  276. {
  277. if (argP1 != newArgs.end())
  278. {
  279. argP1++;
  280. argP2 = argP1;
  281. if (argP1 != newArgs.end())
  282. {
  283. argP2++;
  284. }
  285. }
  286. }
  287. //=========================================================================
  288. // helper function to reduce code duplication
  289. void cmConditionEvaluator::HandlePredicate(bool value, int &reducible,
  290. cmArgumentList::iterator &arg,
  291. cmArgumentList &newArgs,
  292. cmArgumentList::iterator &argP1,
  293. cmArgumentList::iterator &argP2) const
  294. {
  295. if(value)
  296. {
  297. *arg = cmExpandedCommandArgument("1", true);
  298. }
  299. else
  300. {
  301. *arg = cmExpandedCommandArgument("0", true);
  302. }
  303. newArgs.erase(argP1);
  304. argP1 = arg;
  305. this->IncrementArguments(newArgs,argP1,argP2);
  306. reducible = 1;
  307. }
  308. //=========================================================================
  309. // helper function to reduce code duplication
  310. void cmConditionEvaluator::HandleBinaryOp(bool value, int &reducible,
  311. cmArgumentList::iterator &arg,
  312. cmArgumentList &newArgs,
  313. cmArgumentList::iterator &argP1,
  314. cmArgumentList::iterator &argP2)
  315. {
  316. if(value)
  317. {
  318. *arg = cmExpandedCommandArgument("1", true);
  319. }
  320. else
  321. {
  322. *arg = cmExpandedCommandArgument("0", true);
  323. }
  324. newArgs.erase(argP2);
  325. newArgs.erase(argP1);
  326. argP1 = arg;
  327. this->IncrementArguments(newArgs,argP1,argP2);
  328. reducible = 1;
  329. }
  330. //=========================================================================
  331. // level 0 processes parenthetical expressions
  332. bool cmConditionEvaluator::HandleLevel0(cmArgumentList &newArgs,
  333. std::string &errorString,
  334. cmake::MessageType &status)
  335. {
  336. int reducible;
  337. do
  338. {
  339. reducible = 0;
  340. cmArgumentList::iterator arg = newArgs.begin();
  341. while (arg != newArgs.end())
  342. {
  343. if (IsKeyword("(", *arg))
  344. {
  345. // search for the closing paren for this opening one
  346. cmArgumentList::iterator argClose;
  347. argClose = arg;
  348. argClose++;
  349. unsigned int depth = 1;
  350. while (argClose != newArgs.end() && depth)
  351. {
  352. if (this->IsKeyword("(", *argClose))
  353. {
  354. depth++;
  355. }
  356. if (this->IsKeyword(")", *argClose))
  357. {
  358. depth--;
  359. }
  360. argClose++;
  361. }
  362. if (depth)
  363. {
  364. errorString = "mismatched parenthesis in condition";
  365. status = cmake::FATAL_ERROR;
  366. return false;
  367. }
  368. // store the reduced args in this vector
  369. std::vector<cmExpandedCommandArgument> newArgs2;
  370. // copy to the list structure
  371. cmArgumentList::iterator argP1 = arg;
  372. argP1++;
  373. for(; argP1 != argClose; argP1++)
  374. {
  375. newArgs2.push_back(*argP1);
  376. }
  377. newArgs2.pop_back();
  378. // now recursively invoke IsTrue to handle the values inside the
  379. // parenthetical expression
  380. bool value =
  381. this->IsTrue(newArgs2, errorString, status);
  382. if(value)
  383. {
  384. *arg = cmExpandedCommandArgument("1", true);
  385. }
  386. else
  387. {
  388. *arg = cmExpandedCommandArgument("0", true);
  389. }
  390. argP1 = arg;
  391. argP1++;
  392. // remove the now evaluated parenthetical expression
  393. newArgs.erase(argP1,argClose);
  394. }
  395. ++arg;
  396. }
  397. }
  398. while (reducible);
  399. return true;
  400. }
  401. //=========================================================================
  402. // level one handles most predicates except for NOT
  403. bool cmConditionEvaluator::HandleLevel1(cmArgumentList &newArgs,
  404. std::string &, cmake::MessageType &)
  405. {
  406. int reducible;
  407. do
  408. {
  409. reducible = 0;
  410. cmArgumentList::iterator arg = newArgs.begin();
  411. cmArgumentList::iterator argP1;
  412. cmArgumentList::iterator argP2;
  413. while (arg != newArgs.end())
  414. {
  415. argP1 = arg;
  416. this->IncrementArguments(newArgs,argP1,argP2);
  417. // does a file exist
  418. if (this->IsKeyword("EXISTS", *arg) && argP1 != newArgs.end())
  419. {
  420. this->HandlePredicate(
  421. cmSystemTools::FileExists(argP1->c_str()),
  422. reducible, arg, newArgs, argP1, argP2);
  423. }
  424. // does a directory with this name exist
  425. if (this->IsKeyword("IS_DIRECTORY", *arg) && argP1 != newArgs.end())
  426. {
  427. this->HandlePredicate(
  428. cmSystemTools::FileIsDirectory(argP1->c_str()),
  429. reducible, arg, newArgs, argP1, argP2);
  430. }
  431. // does a symlink with this name exist
  432. if (this->IsKeyword("IS_SYMLINK", *arg) && argP1 != newArgs.end())
  433. {
  434. this->HandlePredicate(
  435. cmSystemTools::FileIsSymlink(argP1->c_str()),
  436. reducible, arg, newArgs, argP1, argP2);
  437. }
  438. // is the given path an absolute path ?
  439. if (this->IsKeyword("IS_ABSOLUTE", *arg) && argP1 != newArgs.end())
  440. {
  441. this->HandlePredicate(
  442. cmSystemTools::FileIsFullPath(argP1->c_str()),
  443. reducible, arg, newArgs, argP1, argP2);
  444. }
  445. // does a command exist
  446. if (this->IsKeyword("COMMAND", *arg) && argP1 != newArgs.end())
  447. {
  448. this->HandlePredicate(
  449. this->Makefile.CommandExists(argP1->c_str()),
  450. reducible, arg, newArgs, argP1, argP2);
  451. }
  452. // does a policy exist
  453. if (this->IsKeyword("POLICY", *arg) && argP1 != newArgs.end())
  454. {
  455. cmPolicies::PolicyID pid;
  456. this->HandlePredicate(
  457. this->Makefile.GetPolicies()->GetPolicyID(
  458. argP1->c_str(), pid),
  459. reducible, arg, newArgs, argP1, argP2);
  460. }
  461. // does a target exist
  462. if (this->IsKeyword("TARGET", *arg) && argP1 != newArgs.end())
  463. {
  464. this->HandlePredicate(
  465. this->Makefile.FindTargetToUse(argP1->GetValue())?true:false,
  466. reducible, arg, newArgs, argP1, argP2);
  467. }
  468. // is a variable defined
  469. if (this->IsKeyword("DEFINED", *arg) && argP1 != newArgs.end())
  470. {
  471. size_t argP1len = argP1->GetValue().size();
  472. bool bdef = false;
  473. if(argP1len > 4 && argP1->GetValue().substr(0, 4) == "ENV{" &&
  474. argP1->GetValue().operator[](argP1len-1) == '}')
  475. {
  476. std::string env = argP1->GetValue().substr(4, argP1len-5);
  477. bdef = cmSystemTools::GetEnv(env.c_str())?true:false;
  478. }
  479. else
  480. {
  481. bdef = this->Makefile.IsDefinitionSet(argP1->GetValue());
  482. }
  483. this->HandlePredicate(bdef, reducible, arg, newArgs, argP1, argP2);
  484. }
  485. ++arg;
  486. }
  487. }
  488. while (reducible);
  489. return true;
  490. }
  491. //=========================================================================
  492. // level two handles most binary operations except for AND OR
  493. bool cmConditionEvaluator::HandleLevel2(cmArgumentList &newArgs,
  494. std::string &errorString,
  495. cmake::MessageType &status)
  496. {
  497. int reducible;
  498. const char *def;
  499. const char *def2;
  500. do
  501. {
  502. reducible = 0;
  503. cmArgumentList::iterator arg = newArgs.begin();
  504. cmArgumentList::iterator argP1;
  505. cmArgumentList::iterator argP2;
  506. while (arg != newArgs.end())
  507. {
  508. argP1 = arg;
  509. this->IncrementArguments(newArgs,argP1,argP2);
  510. if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
  511. IsKeyword("MATCHES", *argP1))
  512. {
  513. def = this->GetVariableOrString(*arg);
  514. const char* rex = argP2->c_str();
  515. this->Makefile.ClearMatches();
  516. cmsys::RegularExpression regEntry;
  517. if ( !regEntry.compile(rex) )
  518. {
  519. cmOStringStream error;
  520. error << "Regular expression \"" << rex << "\" cannot compile";
  521. errorString = error.str();
  522. status = cmake::FATAL_ERROR;
  523. return false;
  524. }
  525. if (regEntry.find(def))
  526. {
  527. this->Makefile.StoreMatches(regEntry);
  528. *arg = cmExpandedCommandArgument("1", true);
  529. }
  530. else
  531. {
  532. *arg = cmExpandedCommandArgument("0", true);
  533. }
  534. newArgs.erase(argP2);
  535. newArgs.erase(argP1);
  536. argP1 = arg;
  537. this->IncrementArguments(newArgs,argP1,argP2);
  538. reducible = 1;
  539. }
  540. if (argP1 != newArgs.end() && this->IsKeyword("MATCHES", *arg))
  541. {
  542. *arg = cmExpandedCommandArgument("0", true);
  543. newArgs.erase(argP1);
  544. argP1 = arg;
  545. this->IncrementArguments(newArgs,argP1,argP2);
  546. reducible = 1;
  547. }
  548. if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
  549. (this->IsKeyword("LESS", *argP1) ||
  550. this->IsKeyword("GREATER", *argP1) ||
  551. this->IsKeyword("EQUAL", *argP1)))
  552. {
  553. def = this->GetVariableOrString(*arg);
  554. def2 = this->GetVariableOrString(*argP2);
  555. double lhs;
  556. double rhs;
  557. bool result;
  558. if(sscanf(def, "%lg", &lhs) != 1 ||
  559. sscanf(def2, "%lg", &rhs) != 1)
  560. {
  561. result = false;
  562. }
  563. else if (*(argP1) == "LESS")
  564. {
  565. result = (lhs < rhs);
  566. }
  567. else if (*(argP1) == "GREATER")
  568. {
  569. result = (lhs > rhs);
  570. }
  571. else
  572. {
  573. result = (lhs == rhs);
  574. }
  575. this->HandleBinaryOp(result,
  576. reducible, arg, newArgs, argP1, argP2);
  577. }
  578. if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
  579. (this->IsKeyword("STRLESS", *argP1) ||
  580. this->IsKeyword("STREQUAL", *argP1) ||
  581. this->IsKeyword("STRGREATER", *argP1)))
  582. {
  583. def = this->GetVariableOrString(*arg);
  584. def2 = this->GetVariableOrString(*argP2);
  585. int val = strcmp(def,def2);
  586. bool result;
  587. if (*(argP1) == "STRLESS")
  588. {
  589. result = (val < 0);
  590. }
  591. else if (*(argP1) == "STRGREATER")
  592. {
  593. result = (val > 0);
  594. }
  595. else // strequal
  596. {
  597. result = (val == 0);
  598. }
  599. this->HandleBinaryOp(result,
  600. reducible, arg, newArgs, argP1, argP2);
  601. }
  602. if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
  603. (this->IsKeyword("VERSION_LESS", *argP1) ||
  604. this->IsKeyword("VERSION_GREATER", *argP1) ||
  605. this->IsKeyword("VERSION_EQUAL", *argP1)))
  606. {
  607. def = this->GetVariableOrString(*arg);
  608. def2 = this->GetVariableOrString(*argP2);
  609. cmSystemTools::CompareOp op = cmSystemTools::OP_EQUAL;
  610. if(*argP1 == "VERSION_LESS")
  611. {
  612. op = cmSystemTools::OP_LESS;
  613. }
  614. else if(*argP1 == "VERSION_GREATER")
  615. {
  616. op = cmSystemTools::OP_GREATER;
  617. }
  618. bool result = cmSystemTools::VersionCompare(op, def, def2);
  619. this->HandleBinaryOp(result,
  620. reducible, arg, newArgs, argP1, argP2);
  621. }
  622. // is file A newer than file B
  623. if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
  624. this->IsKeyword("IS_NEWER_THAN", *argP1))
  625. {
  626. int fileIsNewer=0;
  627. bool success=cmSystemTools::FileTimeCompare(arg->GetValue(),
  628. (argP2)->GetValue(),
  629. &fileIsNewer);
  630. this->HandleBinaryOp(
  631. (success==false || fileIsNewer==1 || fileIsNewer==0),
  632. reducible, arg, newArgs, argP1, argP2);
  633. }
  634. ++arg;
  635. }
  636. }
  637. while (reducible);
  638. return true;
  639. }
  640. //=========================================================================
  641. // level 3 handles NOT
  642. bool cmConditionEvaluator::HandleLevel3(cmArgumentList &newArgs,
  643. std::string &errorString,
  644. cmake::MessageType &status)
  645. {
  646. int reducible;
  647. do
  648. {
  649. reducible = 0;
  650. cmArgumentList::iterator arg = newArgs.begin();
  651. cmArgumentList::iterator argP1;
  652. cmArgumentList::iterator argP2;
  653. while (arg != newArgs.end())
  654. {
  655. argP1 = arg;
  656. IncrementArguments(newArgs,argP1,argP2);
  657. if (argP1 != newArgs.end() && IsKeyword("NOT", *arg))
  658. {
  659. bool rhs = this->GetBooleanValueWithAutoDereference(*argP1,
  660. errorString,
  661. status);
  662. this->HandlePredicate(!rhs, reducible, arg, newArgs, argP1, argP2);
  663. }
  664. ++arg;
  665. }
  666. }
  667. while (reducible);
  668. return true;
  669. }
  670. //=========================================================================
  671. // level 4 handles AND OR
  672. bool cmConditionEvaluator::HandleLevel4(cmArgumentList &newArgs,
  673. std::string &errorString,
  674. cmake::MessageType &status)
  675. {
  676. int reducible;
  677. bool lhs;
  678. bool rhs;
  679. do
  680. {
  681. reducible = 0;
  682. cmArgumentList::iterator arg = newArgs.begin();
  683. cmArgumentList::iterator argP1;
  684. cmArgumentList::iterator argP2;
  685. while (arg != newArgs.end())
  686. {
  687. argP1 = arg;
  688. IncrementArguments(newArgs,argP1,argP2);
  689. if (argP1 != newArgs.end() && IsKeyword("AND", *argP1) &&
  690. argP2 != newArgs.end())
  691. {
  692. lhs = this->GetBooleanValueWithAutoDereference(*arg,
  693. errorString,
  694. status);
  695. rhs = this->GetBooleanValueWithAutoDereference(*argP2,
  696. errorString,
  697. status);
  698. this->HandleBinaryOp((lhs && rhs),
  699. reducible, arg, newArgs, argP1, argP2);
  700. }
  701. if (argP1 != newArgs.end() && this->IsKeyword("OR", *argP1) &&
  702. argP2 != newArgs.end())
  703. {
  704. lhs = this->GetBooleanValueWithAutoDereference(*arg,
  705. errorString,
  706. status);
  707. rhs = this->GetBooleanValueWithAutoDereference(*argP2,
  708. errorString,
  709. status);
  710. this->HandleBinaryOp((lhs || rhs),
  711. reducible, arg, newArgs, argP1, argP2);
  712. }
  713. ++arg;
  714. }
  715. }
  716. while (reducible);
  717. return true;
  718. }