cmCommand.h 2.03 KB
Newer Older
1
2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3
4
#ifndef cmCommand_h
#define cmCommand_h
5

6
#include "cmConfigure.h"
7

8
9
10
11
12
13
#include <string>
#include <vector>

class cmExecutionStatus;
class cmMakefile;
struct cmListFileArgument;
14

15
16
/** \class cmCommand
 * \brief Superclass for all commands in CMake.
17
 *
18
19
20
 * cmCommand is the base class for all commands in CMake. A command
 * manifests as an entry in CMakeLists.txt and produces one or
 * more makefile rules. Commands are associated with a particular
21
22
 * makefile. This base class cmCommand defines the API for commands
 * to support such features as enable/disable, inheritance,
23
 * documentation, and construction.
24
 */
25
class cmCommand
26
{
Daniel Pfeifer's avatar
Daniel Pfeifer committed
27
28
  CM_DISABLE_COPY(cmCommand)

29
public:
30
  /**
31
   * Construct the command. By default it has no makefile.
32
   */
33
  cmCommand()
34
    : Makefile(CM_NULLPTR)
35
36
  {
  }
37

38
39
40
  /**
   * Need virtual destructor to destroy real command type.
   */
41
  virtual ~cmCommand() {}
42

43
44
45
  /**
   * Specify the makefile.
   */
46
  void SetMakefile(cmMakefile* m) { this->Makefile = m; }
Ken Martin's avatar
Ken Martin committed
47
  cmMakefile* GetMakefile() { return this->Makefile; }
48

49
50
51
52
53
  /**
   * This is called by the cmMakefile when the command is first
   * encountered in the CMakeLists.txt file.  It expands the command's
   * arguments and then invokes the InitialPass.
   */
54
  virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
55
                                 cmExecutionStatus& status);
56

57
  /**
58
   * This is called when the command is first encountered in
59
60
   * the CMakeLists.txt file.
   */
61
  virtual bool InitialPass(std::vector<std::string> const& args,
62
                           cmExecutionStatus&) = 0;
63
64

  /**
65
   * This is a virtual constructor for the command.
66
   */
67
  virtual cmCommand* Clone() = 0;
68

69
70
71
  /**
   * Return the last error string.
   */
72
  const char* GetError();
73

74
75
76
  /**
   * Set the error message
   */
77
  void SetError(const std::string& e);
78
79

protected:
Ken Martin's avatar
Ken Martin committed
80
  cmMakefile* Makefile;
81

82
private:
Ken Martin's avatar
Ken Martin committed
83
  std::string Error;
84
85
86
};

#endif