cmGeneratorExpression.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 cmGeneratorExpression_h
  4. #define cmGeneratorExpression_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmListFileCache.h"
  7. #include "cm_auto_ptr.hxx"
  8. #include <map>
  9. #include <set>
  10. #include <string>
  11. #include <vector>
  12. class cmCompiledGeneratorExpression;
  13. class cmGeneratorTarget;
  14. class cmLocalGenerator;
  15. struct cmGeneratorExpressionContext;
  16. struct cmGeneratorExpressionDAGChecker;
  17. struct cmGeneratorExpressionEvaluator;
  18. /** \class cmGeneratorExpression
  19. * \brief Evaluate generate-time query expression syntax.
  20. *
  21. * cmGeneratorExpression instances are used by build system generator
  22. * implementations to evaluate the $<> generator expression syntax.
  23. * Generator expressions are evaluated just before the generate step
  24. * writes strings into the build system. They have knowledge of the
  25. * build configuration which is not available at configure time.
  26. */
  27. class cmGeneratorExpression
  28. {
  29. CM_DISABLE_COPY(cmGeneratorExpression)
  30. public:
  31. /** Construct. */
  32. cmGeneratorExpression(
  33. cmListFileBacktrace const& backtrace = cmListFileBacktrace());
  34. ~cmGeneratorExpression();
  35. CM_AUTO_PTR<cmCompiledGeneratorExpression> Parse(std::string const& input);
  36. CM_AUTO_PTR<cmCompiledGeneratorExpression> Parse(const char* input);
  37. enum PreprocessContext
  38. {
  39. StripAllGeneratorExpressions,
  40. BuildInterface,
  41. InstallInterface
  42. };
  43. static std::string Preprocess(const std::string& input,
  44. PreprocessContext context,
  45. bool resolveRelative = false);
  46. static void Split(const std::string& input,
  47. std::vector<std::string>& output);
  48. static std::string::size_type Find(const std::string& input);
  49. static bool IsValidTargetName(const std::string& input);
  50. static std::string StripEmptyListElements(const std::string& input);
  51. private:
  52. cmListFileBacktrace Backtrace;
  53. };
  54. class cmCompiledGeneratorExpression
  55. {
  56. CM_DISABLE_COPY(cmCompiledGeneratorExpression)
  57. public:
  58. const char* Evaluate(cmLocalGenerator* lg, const std::string& config,
  59. bool quiet = false,
  60. cmGeneratorTarget const* headTarget = nullptr,
  61. cmGeneratorTarget const* currentTarget = nullptr,
  62. cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
  63. std::string const& language = std::string()) const;
  64. const char* Evaluate(cmLocalGenerator* lg, const std::string& config,
  65. bool quiet, cmGeneratorTarget const* headTarget,
  66. cmGeneratorExpressionDAGChecker* dagChecker,
  67. std::string const& language = std::string()) const;
  68. /** Get set of targets found during evaluations. */
  69. std::set<cmGeneratorTarget*> const& GetTargets() const
  70. {
  71. return this->DependTargets;
  72. }
  73. std::set<std::string> const& GetSeenTargetProperties() const
  74. {
  75. return this->SeenTargetProperties;
  76. }
  77. std::set<cmGeneratorTarget const*> const& GetAllTargetsSeen() const
  78. {
  79. return this->AllTargetsSeen;
  80. }
  81. ~cmCompiledGeneratorExpression();
  82. std::string const& GetInput() const { return this->Input; }
  83. cmListFileBacktrace GetBacktrace() const { return this->Backtrace; }
  84. bool GetHadContextSensitiveCondition() const
  85. {
  86. return this->HadContextSensitiveCondition;
  87. }
  88. bool GetHadHeadSensitiveCondition() const
  89. {
  90. return this->HadHeadSensitiveCondition;
  91. }
  92. std::set<cmGeneratorTarget const*> GetSourceSensitiveTargets() const
  93. {
  94. return this->SourceSensitiveTargets;
  95. }
  96. void SetEvaluateForBuildsystem(bool eval)
  97. {
  98. this->EvaluateForBuildsystem = eval;
  99. }
  100. void GetMaxLanguageStandard(cmGeneratorTarget const* tgt,
  101. std::map<std::string, std::string>& mapping);
  102. private:
  103. const char* EvaluateWithContext(
  104. cmGeneratorExpressionContext& context,
  105. cmGeneratorExpressionDAGChecker* dagChecker) const;
  106. cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
  107. const std::string& input);
  108. friend class cmGeneratorExpression;
  109. cmListFileBacktrace Backtrace;
  110. std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
  111. const std::string Input;
  112. bool NeedsEvaluation;
  113. mutable std::set<cmGeneratorTarget*> DependTargets;
  114. mutable std::set<cmGeneratorTarget const*> AllTargetsSeen;
  115. mutable std::set<std::string> SeenTargetProperties;
  116. mutable std::map<cmGeneratorTarget const*,
  117. std::map<std::string, std::string>>
  118. MaxLanguageStandard;
  119. mutable std::string Output;
  120. mutable bool HadContextSensitiveCondition;
  121. mutable bool HadHeadSensitiveCondition;
  122. mutable std::set<cmGeneratorTarget const*> SourceSensitiveTargets;
  123. bool EvaluateForBuildsystem;
  124. };
  125. #endif