cmGeneratorExpression.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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(
  37. cmListFileBacktrace const& backtrace = cmListFileBacktrace());
  38. ~cmGeneratorExpression();
  39. cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(
  40. std::string const& input);
  41. cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(const char* input);
  42. enum PreprocessContext {
  43. StripAllGeneratorExpressions,
  44. BuildInterface,
  45. InstallInterface
  46. };
  47. static std::string Preprocess(const std::string &input,
  48. PreprocessContext context,
  49. bool resolveRelative = false);
  50. static void Split(const std::string &input,
  51. std::vector<std::string> &output);
  52. static std::string::size_type Find(const std::string &input);
  53. static bool IsValidTargetName(const std::string &input);
  54. static std::string StripEmptyListElements(const std::string &input);
  55. private:
  56. cmGeneratorExpression(const cmGeneratorExpression &);
  57. void operator=(const cmGeneratorExpression &);
  58. cmListFileBacktrace Backtrace;
  59. };
  60. class cmCompiledGeneratorExpression
  61. {
  62. public:
  63. const char* Evaluate(cmMakefile* mf, const std::string& config,
  64. bool quiet = false,
  65. cmTarget const* headTarget = 0,
  66. cmTarget const* currentTarget = 0,
  67. cmGeneratorExpressionDAGChecker *dagChecker = 0,
  68. std::string const& language = std::string()) const;
  69. const char* Evaluate(cmMakefile* mf, const std::string& config,
  70. bool quiet,
  71. cmTarget const* headTarget,
  72. cmGeneratorExpressionDAGChecker *dagChecker,
  73. std::string const& language = std::string()) const;
  74. /** Get set of targets found during evaluations. */
  75. std::set<cmTarget*> const& GetTargets() const
  76. { return this->DependTargets; }
  77. std::set<std::string> const& GetSeenTargetProperties() const
  78. { return this->SeenTargetProperties; }
  79. std::set<cmTarget const*> const& GetAllTargetsSeen() const
  80. { return this->AllTargetsSeen; }
  81. ~cmCompiledGeneratorExpression();
  82. std::string const& GetInput() const
  83. {
  84. return this->Input;
  85. }
  86. cmListFileBacktrace GetBacktrace() const
  87. {
  88. return this->Backtrace;
  89. }
  90. bool GetHadContextSensitiveCondition() const
  91. {
  92. return this->HadContextSensitiveCondition;
  93. }
  94. bool GetHadHeadSensitiveCondition() const
  95. {
  96. return this->HadHeadSensitiveCondition;
  97. }
  98. std::set<cmTarget const*> GetSourceSensitiveTargets() const
  99. {
  100. return this->SourceSensitiveTargets;
  101. }
  102. void SetEvaluateForBuildsystem(bool eval)
  103. {
  104. this->EvaluateForBuildsystem = eval;
  105. }
  106. void GetMaxLanguageStandard(cmTarget const* tgt,
  107. std::map<std::string, std::string>& mapping);
  108. private:
  109. const char* EvaluateWithContext(cmGeneratorExpressionContext& context,
  110. cmGeneratorExpressionDAGChecker *dagChecker) const;
  111. cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
  112. const std::string& input);
  113. friend class cmGeneratorExpression;
  114. cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
  115. void operator=(const cmCompiledGeneratorExpression &);
  116. cmListFileBacktrace Backtrace;
  117. std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
  118. const std::string Input;
  119. bool NeedsEvaluation;
  120. mutable std::set<cmTarget*> DependTargets;
  121. mutable std::set<cmTarget const*> AllTargetsSeen;
  122. mutable std::set<std::string> SeenTargetProperties;
  123. mutable std::map<cmTarget const*, std::map<std::string, std::string> >
  124. MaxLanguageStandard;
  125. mutable std::string Output;
  126. mutable bool HadContextSensitiveCondition;
  127. mutable bool HadHeadSensitiveCondition;
  128. mutable std::set<cmTarget const*> SourceSensitiveTargets;
  129. bool EvaluateForBuildsystem;
  130. };
  131. #endif