cmIfCommand.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmIfCommand_h
  14. #define cmIfCommand_h
  15. #include "cmStandardIncludes.h"
  16. #include "cmCommand.h"
  17. #include "cmFunctionBlocker.h"
  18. /** \class cmIfFunctionBlocker
  19. * \brief subclass of function blocker
  20. *
  21. *
  22. */
  23. class cmIfFunctionBlocker : public cmFunctionBlocker
  24. {
  25. public:
  26. cmIfFunctionBlocker() {}
  27. virtual ~cmIfFunctionBlocker() {}
  28. virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
  29. cmMakefile &mf);
  30. virtual bool ShouldRemove(const cmListFileFunction& lff,
  31. cmMakefile &mf);
  32. virtual void ScopeEnded(cmMakefile &mf);
  33. std::vector<cmListFileArgument> m_Args;
  34. bool m_IsBlocking;
  35. };
  36. /** \class cmIfCommand
  37. * \brief starts an if block
  38. *
  39. * cmIfCommand starts an if block
  40. */
  41. class cmIfCommand : public cmCommand
  42. {
  43. public:
  44. /**
  45. * This is a virtual constructor for the command.
  46. */
  47. virtual cmCommand* Clone()
  48. {
  49. return new cmIfCommand;
  50. }
  51. /**
  52. * This overrides the default InvokeInitialPass implementation.
  53. * It records the arguments before expansion.
  54. */
  55. virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args);
  56. /**
  57. * This is called when the command is first encountered in
  58. * the CMakeLists.txt file.
  59. */
  60. virtual bool InitialPass(std::vector<std::string> const&) { return false; }
  61. /**
  62. * The name of the command as specified in CMakeList.txt.
  63. */
  64. virtual const char* GetName() { return "IF";}
  65. /**
  66. * Succinct documentation.
  67. */
  68. virtual const char* GetTerseDocumentation()
  69. {
  70. return "Conditionally execute a group of commands.";
  71. }
  72. /**
  73. * This determines if the command gets propagated down
  74. * to makefiles located in subdirectories.
  75. */
  76. virtual bool IsInherited() {return true;}
  77. /**
  78. * More documentation.
  79. */
  80. virtual const char* GetFullDocumentation()
  81. {
  82. return
  83. " IF(expression)\n"
  84. " # THEN section.\n"
  85. " COMMAND1(ARGS ...)\n"
  86. " COMMAND2(ARGS ...)\n"
  87. " ...\n"
  88. " ELSE(expression)\n"
  89. " # ELSE section.\n"
  90. " COMMAND1(ARGS ...)\n"
  91. " COMMAND2(ARGS ...)\n"
  92. " ...\n"
  93. " ENDIF(expression)\n"
  94. "Evaluates the given expression. If the result is true, the commands "
  95. "in the THEN section are invoked. Otherwise, the commands in the "
  96. "ELSE section are invoked. The ELSE section is optional. Note that "
  97. "the same expression must be given to IF, ELSE, and ENDIF. Possible "
  98. "expressions are:\n"
  99. " IF(variable)\n"
  100. "True if the variable's value is not empty, 0, FALSE, OFF, or NOTFOUND.\n"
  101. " IF(NOT variable)\n"
  102. "True if the variable's value is empty, 0, FALSE, OFF, or NOTFOUND.\n"
  103. " IF(variable1 AND variable2)\n"
  104. "True if both variables would be considered true individually. Only "
  105. "one AND is allowed to keep expressions short.\n"
  106. " IF(variable1 OR variable2)\n"
  107. "True if either variable would be considered true individually. Only "
  108. "one OR is allowed to keep expressions short.\n"
  109. " IF(COMMAND command-name)\n"
  110. "True if the given name is a command that can be invoked.\n"
  111. " IF(EXISTS file-name)\n"
  112. " IF(EXISTS directory-name)\n"
  113. "True if the named file or directory exists.\n"
  114. " IF(variable MATCHES regex)\n"
  115. " IF(string MATCHES regex)\n"
  116. "True if the given string or variable's value matches the given "
  117. "regular expression.\n"
  118. " IF(variable LESS number)\n"
  119. " IF(string LESS number)\n"
  120. " IF(variable GREATER number)\n"
  121. " IF(string GREATER number)\n"
  122. "True if the given string or variable's value is a valid number and "
  123. "the inequality is true.\n"
  124. " IF(variable STRLESS string)\n"
  125. " IF(string STRLESS string)\n"
  126. " IF(variable STRGREATER string)\n"
  127. " IF(string STRGREATER string)\n"
  128. "True if the given string or variable's value is lexicographically "
  129. "less (or greater) than the string on the right.";
  130. }
  131. // this is a shared function for both If and Else to determine if
  132. // the arguments were valid, and if so, was the response true
  133. static bool IsTrue(const std::vector<std::string> &args,
  134. bool &isValid, const cmMakefile *mf);
  135. // Get a definition from the makefile. If it doesn't exist,
  136. // return the original string.
  137. static const char* GetVariableOrString(const char* str,
  138. const cmMakefile* mf);
  139. cmTypeMacro(cmIfCommand, cmCommand);
  140. };
  141. #endif