cmGeneratorExpression.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmGeneratorExpression_h
  11. #define cmGeneratorExpression_h
  12. #include <cmConfigure.h>
  13. #include "cmListFileCache.h"
  14. #include <cm_auto_ptr.hxx>
  15. #include <map>
  16. #include <set>
  17. #include <string>
  18. #include <vector>
  19. class cmCompiledGeneratorExpression;
  20. class cmGeneratorTarget;
  21. class cmLocalGenerator;
  22. struct cmGeneratorExpressionContext;
  23. struct cmGeneratorExpressionDAGChecker;
  24. struct cmGeneratorExpressionEvaluator;
  25. /** \class cmGeneratorExpression
  26. * \brief Evaluate generate-time query expression syntax.
  27. *
  28. * cmGeneratorExpression instances are used by build system generator
  29. * implementations to evaluate the $<> generator expression syntax.
  30. * Generator expressions are evaluated just before the generate step
  31. * writes strings into the build system. They have knowledge of the
  32. * build configuration which is not available at configure time.
  33. */
  34. class cmGeneratorExpression
  35. {
  36. public:
  37. /** Construct. */
  38. cmGeneratorExpression(
  39. cmListFileBacktrace const& backtrace = cmListFileBacktrace());
  40. ~cmGeneratorExpression();
  41. CM_AUTO_PTR<cmCompiledGeneratorExpression> Parse(std::string const& input);
  42. CM_AUTO_PTR<cmCompiledGeneratorExpression> Parse(const char* input);
  43. enum PreprocessContext
  44. {
  45. StripAllGeneratorExpressions,
  46. BuildInterface,
  47. InstallInterface
  48. };
  49. static std::string Preprocess(const std::string& input,
  50. PreprocessContext context,
  51. bool resolveRelative = false);
  52. static void Split(const std::string& input,
  53. std::vector<std::string>& output);
  54. static std::string::size_type Find(const std::string& input);
  55. static bool IsValidTargetName(const std::string& input);
  56. static std::string StripEmptyListElements(const std::string& input);
  57. private:
  58. cmGeneratorExpression(const cmGeneratorExpression&);
  59. void operator=(const cmGeneratorExpression&);
  60. cmListFileBacktrace Backtrace;
  61. };
  62. class cmCompiledGeneratorExpression
  63. {
  64. public:
  65. const char* Evaluate(
  66. cmLocalGenerator* lg, const std::string& config, bool quiet = false,
  67. cmGeneratorTarget const* headTarget = CM_NULLPTR,
  68. cmGeneratorTarget const* currentTarget = CM_NULLPTR,
  69. cmGeneratorExpressionDAGChecker* dagChecker = CM_NULLPTR,
  70. std::string const& language = std::string()) const;
  71. const char* Evaluate(cmLocalGenerator* lg, const std::string& config,
  72. bool quiet, cmGeneratorTarget const* headTarget,
  73. cmGeneratorExpressionDAGChecker* dagChecker,
  74. std::string const& language = std::string()) const;
  75. /** Get set of targets found during evaluations. */
  76. std::set<cmGeneratorTarget*> const& GetTargets() const
  77. {
  78. return this->DependTargets;
  79. }
  80. std::set<std::string> const& GetSeenTargetProperties() const
  81. {
  82. return this->SeenTargetProperties;
  83. }
  84. std::set<cmGeneratorTarget const*> const& GetAllTargetsSeen() const
  85. {
  86. return this->AllTargetsSeen;
  87. }
  88. ~cmCompiledGeneratorExpression();
  89. std::string const& GetInput() const { return this->Input; }
  90. cmListFileBacktrace GetBacktrace() const { return this->Backtrace; }
  91. bool GetHadContextSensitiveCondition() const
  92. {
  93. return this->HadContextSensitiveCondition;
  94. }
  95. bool GetHadHeadSensitiveCondition() const
  96. {
  97. return this->HadHeadSensitiveCondition;
  98. }
  99. std::set<cmGeneratorTarget const*> GetSourceSensitiveTargets() const
  100. {
  101. return this->SourceSensitiveTargets;
  102. }
  103. void SetEvaluateForBuildsystem(bool eval)
  104. {
  105. this->EvaluateForBuildsystem = eval;
  106. }
  107. void GetMaxLanguageStandard(cmGeneratorTarget const* tgt,
  108. std::map<std::string, std::string>& mapping);
  109. private:
  110. const char* EvaluateWithContext(
  111. cmGeneratorExpressionContext& context,
  112. cmGeneratorExpressionDAGChecker* dagChecker) const;
  113. cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
  114. const std::string& input);
  115. friend class cmGeneratorExpression;
  116. cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression&);
  117. void operator=(const cmCompiledGeneratorExpression&);
  118. cmListFileBacktrace Backtrace;
  119. std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
  120. const std::string Input;
  121. bool NeedsEvaluation;
  122. mutable std::set<cmGeneratorTarget*> DependTargets;
  123. mutable std::set<cmGeneratorTarget const*> AllTargetsSeen;
  124. mutable std::set<std::string> SeenTargetProperties;
  125. mutable std::map<cmGeneratorTarget const*,
  126. std::map<std::string, std::string> >
  127. MaxLanguageStandard;
  128. mutable std::string Output;
  129. mutable bool HadContextSensitiveCondition;
  130. mutable bool HadHeadSensitiveCondition;
  131. mutable std::set<cmGeneratorTarget const*> SourceSensitiveTargets;
  132. bool EvaluateForBuildsystem;
  133. };
  134. #endif