cmCommand.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmCommand_h
  4. #define cmCommand_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. #include <vector>
  8. class cmExecutionStatus;
  9. class cmMakefile;
  10. struct cmListFileArgument;
  11. /** \class cmCommand
  12. * \brief Superclass for all commands in CMake.
  13. *
  14. * cmCommand is the base class for all commands in CMake. A command
  15. * manifests as an entry in CMakeLists.txt and produces one or
  16. * more makefile rules. Commands are associated with a particular
  17. * makefile. This base class cmCommand defines the API for commands
  18. * to support such features as enable/disable, inheritance,
  19. * documentation, and construction.
  20. */
  21. class cmCommand
  22. {
  23. CM_DISABLE_COPY(cmCommand)
  24. public:
  25. /**
  26. * Construct the command. By default it has no makefile.
  27. */
  28. cmCommand() = default;
  29. /**
  30. * Need virtual destructor to destroy real command type.
  31. */
  32. virtual ~cmCommand() = default;
  33. /**
  34. * Specify the makefile.
  35. */
  36. void SetMakefile(cmMakefile* m) { this->Makefile = m; }
  37. cmMakefile* GetMakefile() { return this->Makefile; }
  38. /**
  39. * This is called by the cmMakefile when the command is first
  40. * encountered in the CMakeLists.txt file. It expands the command's
  41. * arguments and then invokes the InitialPass.
  42. */
  43. virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
  44. cmExecutionStatus& status);
  45. /**
  46. * This is called when the command is first encountered in
  47. * the CMakeLists.txt file.
  48. */
  49. virtual bool InitialPass(std::vector<std::string> const& args,
  50. cmExecutionStatus&) = 0;
  51. /**
  52. * This is called at the end after all the information
  53. * specified by the command is accumulated. Most commands do
  54. * not implement this method. At this point, reading and
  55. * writing to the cache can be done.
  56. */
  57. virtual void FinalPass() {}
  58. /**
  59. * Does this command have a final pass? Query after InitialPass.
  60. */
  61. virtual bool HasFinalPass() const { return false; }
  62. /**
  63. * This is a virtual constructor for the command.
  64. */
  65. virtual cmCommand* Clone() = 0;
  66. /**
  67. * Return the last error string.
  68. */
  69. const char* GetError();
  70. /**
  71. * Set the error message
  72. */
  73. void SetError(const std::string& e);
  74. protected:
  75. cmMakefile* Makefile = nullptr;
  76. private:
  77. std::string Error;
  78. };
  79. #endif