cmGeneratorExpression.h 5.3 KB

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