cmCommand.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <memory>
  7. #include <string>
  8. #include <vector>
  9. class cmExecutionStatus;
  10. class cmMakefile;
  11. struct cmListFileArgument;
  12. /** \class cmCommand
  13. * \brief Superclass for all commands in CMake.
  14. *
  15. * cmCommand is the base class for all commands in CMake. A command
  16. * manifests as an entry in CMakeLists.txt and produces one or
  17. * more makefile rules. Commands are associated with a particular
  18. * makefile. This base class cmCommand defines the API for commands
  19. * to support such features as enable/disable, inheritance,
  20. * documentation, and construction.
  21. */
  22. class cmCommand
  23. {
  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. cmCommand(cmCommand const&) = delete;
  34. cmCommand& operator=(cmCommand const&) = delete;
  35. /**
  36. * Specify the makefile.
  37. */
  38. cmMakefile* GetMakefile() { return this->Makefile; }
  39. void SetExecutionStatus(cmExecutionStatus* s);
  40. cmExecutionStatus* GetExecutionStatus() { return this->Status; };
  41. /**
  42. * This is called by the cmMakefile when the command is first
  43. * encountered in the CMakeLists.txt file. It expands the command's
  44. * arguments and then invokes the InitialPass.
  45. */
  46. bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
  47. cmExecutionStatus& status);
  48. /**
  49. * This is called when the command is first encountered in
  50. * the CMakeLists.txt file.
  51. */
  52. virtual bool InitialPass(std::vector<std::string> const& args,
  53. cmExecutionStatus&) = 0;
  54. /**
  55. * This is a virtual constructor for the command.
  56. */
  57. virtual std::unique_ptr<cmCommand> Clone() = 0;
  58. /**
  59. * Set the error message
  60. */
  61. void SetError(const std::string& e);
  62. protected:
  63. cmMakefile* Makefile = nullptr;
  64. private:
  65. cmExecutionStatus* Status = nullptr;
  66. };
  67. class cmLegacyCommandWrapper
  68. {
  69. public:
  70. explicit cmLegacyCommandWrapper(std::unique_ptr<cmCommand> cmd);
  71. cmLegacyCommandWrapper(cmLegacyCommandWrapper const& other);
  72. cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper const& other);
  73. cmLegacyCommandWrapper(cmLegacyCommandWrapper&&) = default;
  74. cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper&&) = default;
  75. bool operator()(std::vector<cmListFileArgument> const& args,
  76. cmExecutionStatus& status) const;
  77. private:
  78. std::unique_ptr<cmCommand> Command;
  79. };
  80. #endif