cmIfCommand.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 char *name,
  29. const std::vector<std::string> &args,
  30. cmMakefile &mf);
  31. virtual bool ShouldRemove(const char *name,
  32. const std::vector<std::string> &args,
  33. cmMakefile &mf);
  34. virtual void ScopeEnded(cmMakefile &mf);
  35. std::vector<std::string> m_Args;
  36. bool m_IsBlocking;
  37. };
  38. /** \class cmIfCommand
  39. * \brief starts an if block
  40. *
  41. * cmIfCommand starts an if block
  42. */
  43. class cmIfCommand : public cmCommand
  44. {
  45. public:
  46. /**
  47. * This is a virtual constructor for the command.
  48. */
  49. virtual cmCommand* Clone()
  50. {
  51. return new cmIfCommand;
  52. }
  53. /**
  54. * This is called when the command is first encountered in
  55. * the CMakeLists.txt file.
  56. */
  57. virtual bool InitialPass(std::vector<std::string> const& args);
  58. /**
  59. * The name of the command as specified in CMakeList.txt.
  60. */
  61. virtual const char* GetName() { return "IF";}
  62. /**
  63. * Succinct documentation.
  64. */
  65. virtual const char* GetTerseDocumentation()
  66. {
  67. return "start an if block";
  68. }
  69. /**
  70. * This determines if the command gets propagated down
  71. * to makefiles located in subdirectories.
  72. */
  73. virtual bool IsInherited() {return true;}
  74. /**
  75. * More documentation.
  76. */
  77. virtual const char* GetFullDocumentation()
  78. {
  79. return
  80. "IF (define) Starts an if block. Optionally it can be invoked "
  81. "using (NOT define) (def AND def2) (def OR def2) (def MATCHES def2) "
  82. "(COMMAND cmd) (EXISTS file) MATCHES checks if def matches the "
  83. "regular expression def2. COMMAND checks if the cmake command cmd "
  84. "is in this cmake executable. EXISTS file checks if file exists."
  85. "Additionally you can do comparisons using LESS GREATER STRLESS "
  86. "and STRGREATER. LESS and GREATER do numeric comparison while "
  87. "STRLESS and STRGREATER do string comparisons.";
  88. }
  89. // this is a shared function for both If and Else to determine if
  90. // the arguments were valid, and if so, was the response true
  91. static bool IsTrue(const std::vector<std::string> &args,
  92. bool &isValid, const cmMakefile *mf);
  93. // Get a definition from the makefile. If it doesn't exist,
  94. // return the original string.
  95. static const char* GetVariableOrString(const char* str,
  96. const cmMakefile* mf);
  97. cmTypeMacro(cmIfCommand, cmCommand);
  98. };
  99. #endif