cmCommand.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 cmCommand_h
  14. #define cmCommand_h
  15. #include "cmObject.h"
  16. #include "cmListFileCache.h"
  17. #include "cmMakefile.h"
  18. /** \class cmCommand
  19. * \brief Superclass for all commands in CMake.
  20. *
  21. * cmCommand is the base class for all commands in CMake. A command
  22. * manifests as an entry in CMakeLists.txt and produces one or
  23. * more makefile rules. Commands are associated with a particular
  24. * makefile. This base class cmCommand defines the API for commands
  25. * to support such features as enable/disable, inheritance,
  26. * documentation, and construction.
  27. */
  28. class cmCommand : public cmObject
  29. {
  30. public:
  31. cmTypeMacro(cmCommand, cmObject);
  32. /**
  33. * Construct the command. By default it is enabled with no makefile.
  34. */
  35. cmCommand()
  36. {m_Makefile = 0; m_Enabled = true;}
  37. /**
  38. * Need virtual destructor to destroy real command type.
  39. */
  40. virtual ~cmCommand() {}
  41. /**
  42. * Specify the makefile.
  43. */
  44. void SetMakefile(cmMakefile*m)
  45. {m_Makefile = m; }
  46. cmMakefile* GetMakefile() { return m_Makefile; }
  47. /**
  48. * This is called by the cmMakefile when the command is first
  49. * encountered in the CMakeLists.txt file. It expands the command's
  50. * arguments and then invokes the InitialPass.
  51. */
  52. virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args)
  53. {
  54. std::vector<std::string> expandedArguments;
  55. m_Makefile->ExpandArguments(args, expandedArguments);
  56. return this->InitialPass(expandedArguments);
  57. }
  58. /**
  59. * This is called when the command is first encountered in
  60. * the CMakeLists.txt file.
  61. */
  62. virtual bool InitialPass(std::vector<std::string> const& args) = 0;
  63. /**
  64. * This is called at the end after all the information
  65. * specified by the command is accumulated. Most commands do
  66. * not implement this method. At this point, reading and
  67. * writing to the cache can be done.
  68. */
  69. virtual void FinalPass() {};
  70. /**
  71. * This is a virtual constructor for the command.
  72. */
  73. virtual cmCommand* Clone() = 0;
  74. /**
  75. * This determines if the command is invoked when in script mode.
  76. */
  77. virtual bool IsScriptable()
  78. {
  79. return false;
  80. }
  81. /**
  82. * This determines if the method is deprecated or not.
  83. */
  84. virtual bool IsDeprecated(int /*major*/, int /*minor*/)
  85. {
  86. return false;
  87. }
  88. /**
  89. * The name of the command as specified in CMakeList.txt.
  90. */
  91. virtual const char* GetName() = 0;
  92. /**
  93. * Succinct documentation.
  94. */
  95. virtual const char* GetTerseDocumentation() = 0;
  96. /**
  97. * More documentation.
  98. */
  99. virtual const char* GetFullDocumentation() = 0;
  100. /**
  101. * Enable the command.
  102. */
  103. void EnabledOn()
  104. {m_Enabled = true;}
  105. /**
  106. * Disable the command.
  107. */
  108. void EnabledOff()
  109. {m_Enabled = false;}
  110. /**
  111. * Query whether the command is enabled.
  112. */
  113. bool GetEnabled()
  114. {return m_Enabled;}
  115. /**
  116. * Disable or enable the command.
  117. */
  118. void SetEnabled(bool enabled)
  119. {m_Enabled = enabled;}
  120. /**
  121. * Return the last error string.
  122. */
  123. const char* GetError()
  124. {
  125. if(m_Error.length() == 0)
  126. {
  127. m_Error = this->GetName();
  128. m_Error += " unknown error.";
  129. }
  130. return m_Error.c_str();
  131. }
  132. /**
  133. * Set the error message
  134. */
  135. void SetError(const char* e)
  136. {
  137. m_Error = this->GetName();
  138. m_Error += " ";
  139. m_Error += e;
  140. }
  141. protected:
  142. cmMakefile* m_Makefile;
  143. private:
  144. bool m_Enabled;
  145. std::string m_Error;
  146. };
  147. #endif