cmCustomCommand.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <string>
  6. #include <utility>
  7. #include <vector>
  8. #include "cmCustomCommandLines.h"
  9. #include "cmListFileCache.h"
  10. #include "cmPolicies.h"
  11. class cmImplicitDependsList
  12. : public std::vector<std::pair<std::string, std::string>>
  13. {
  14. };
  15. class cmStateSnapshot;
  16. /** \class cmCustomCommand
  17. * \brief A class to encapsulate a custom command
  18. *
  19. * cmCustomCommand encapsulates the properties of a custom command
  20. */
  21. class cmCustomCommand
  22. {
  23. public:
  24. /** Get the output file produced by the command. */
  25. const std::vector<std::string>& GetOutputs() const;
  26. void SetOutputs(std::vector<std::string> outputs);
  27. void SetOutputs(std::string output);
  28. /** Get the extra files produced by the command. */
  29. const std::vector<std::string>& GetByproducts() const;
  30. void SetByproducts(std::vector<std::string> byproducts);
  31. /** Get the vector that holds the list of dependencies. */
  32. const std::vector<std::string>& GetDepends() const;
  33. void SetDepends(std::vector<std::string> depends);
  34. bool HasMainDependency() const { return this->HasMainDependency_; }
  35. const std::string& GetMainDependency() const;
  36. void SetMainDependency(std::string main_dependency);
  37. /** Get the working directory. */
  38. std::string const& GetWorkingDirectory() const
  39. {
  40. return this->WorkingDirectory;
  41. }
  42. void SetWorkingDirectory(const char* workingDirectory)
  43. {
  44. this->WorkingDirectory = (workingDirectory ? workingDirectory : "");
  45. }
  46. /** Get the list of command lines. */
  47. const cmCustomCommandLines& GetCommandLines() const;
  48. void SetCommandLines(cmCustomCommandLines commandLines);
  49. /** Get the comment string for the command. */
  50. const char* GetComment() const;
  51. void SetComment(const char* comment);
  52. /** Get a value indicating if the command uses UTF-8 output pipes. */
  53. bool GetStdPipesUTF8() const { return this->StdPipesUTF8; }
  54. void SetStdPipesUTF8(bool stdPipesUTF8)
  55. {
  56. this->StdPipesUTF8 = stdPipesUTF8;
  57. }
  58. /** Append to the list of command lines. */
  59. void AppendCommands(const cmCustomCommandLines& commandLines);
  60. /** Append to the list of dependencies. */
  61. void AppendDepends(const std::vector<std::string>& depends);
  62. /** Set/Get whether old-style escaping should be used. */
  63. bool GetEscapeOldStyle() const;
  64. void SetEscapeOldStyle(bool b);
  65. /** Set/Get whether the build tool can replace variables in
  66. arguments to the command. */
  67. bool GetEscapeAllowMakeVars() const;
  68. void SetEscapeAllowMakeVars(bool b);
  69. /** Backtrace of the command that created this custom command. */
  70. cmListFileBacktrace const& GetBacktrace() const;
  71. void SetBacktrace(cmListFileBacktrace lfbt);
  72. void SetImplicitDepends(cmImplicitDependsList const&);
  73. void AppendImplicitDepends(cmImplicitDependsList const&);
  74. cmImplicitDependsList const& GetImplicitDepends() const;
  75. /** Set/Get whether this custom command should be given access to the
  76. real console (if possible). */
  77. bool GetUsesTerminal() const;
  78. void SetUsesTerminal(bool b);
  79. /** Set/Get whether lists in command lines should be expanded. */
  80. bool GetCommandExpandLists() const;
  81. void SetCommandExpandLists(bool b);
  82. /** Set/Get whether to use additional dependencies coming from
  83. users of OUTPUT of the custom command. */
  84. bool GetDependsExplicitOnly() const;
  85. void SetDependsExplicitOnly(bool b);
  86. /** Set/Get the depfile (used by the Ninja generator) */
  87. const std::string& GetDepfile() const;
  88. void SetDepfile(const std::string& depfile);
  89. /** Set/Get the job_pool (used by the Ninja generator) */
  90. const std::string& GetJobPool() const;
  91. void SetJobPool(const std::string& job_pool);
  92. /** Set/Get whether this custom command should be given access to the
  93. jobserver (if possible). */
  94. bool GetJobserverAware() const;
  95. void SetJobserverAware(bool b);
  96. #define DECLARE_CC_POLICY_ACCESSOR(P) \
  97. cmPolicies::PolicyStatus Get##P##Status() const;
  98. CM_FOR_EACH_CUSTOM_COMMAND_POLICY(DECLARE_CC_POLICY_ACCESSOR)
  99. #undef DECLARE_CC_POLICY_ACCESSOR
  100. /** Record policy values from state snapshot */
  101. void RecordPolicyValues(const cmStateSnapshot& snapshot);
  102. /** Set/Get the associated target */
  103. const std::string& GetTarget() const;
  104. void SetTarget(const std::string& target);
  105. private:
  106. std::vector<std::string> Outputs;
  107. std::vector<std::string> Byproducts;
  108. std::vector<std::string> Depends;
  109. cmCustomCommandLines CommandLines;
  110. cmListFileBacktrace Backtrace;
  111. cmImplicitDependsList ImplicitDepends;
  112. std::string Target;
  113. std::string Comment;
  114. std::string WorkingDirectory;
  115. std::string Depfile;
  116. std::string JobPool;
  117. bool JobserverAware = false;
  118. bool HaveComment = false;
  119. bool EscapeAllowMakeVars = false;
  120. bool EscapeOldStyle = true;
  121. bool UsesTerminal = false;
  122. bool CommandExpandLists = false;
  123. bool StdPipesUTF8 = false;
  124. bool HasMainDependency_ = false;
  125. bool DependsExplicitOnly = false;
  126. // Policies are NEW for synthesized custom commands, and set by cmMakefile for
  127. // user-created custom commands.
  128. #define DECLARE_CC_POLICY_FIELD(P) \
  129. cmPolicies::PolicyStatus P##Status = cmPolicies::NEW;
  130. CM_FOR_EACH_CUSTOM_COMMAND_POLICY(DECLARE_CC_POLICY_FIELD)
  131. #undef DECLARE_CC_POLICY_FIELD
  132. };