cmGeneratorExpression.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 cmGeneratorExpressionDAGChecker;
  21. class cmCompiledGeneratorExpression;
  22. /** \class cmGeneratorExpression
  23. * \brief Evaluate generate-time query expression syntax.
  24. *
  25. * cmGeneratorExpression instances are used by build system generator
  26. * implementations to evaluate the $<> generator expression syntax.
  27. * Generator expressions are evaluated just before the generate step
  28. * writes strings into the build system. They have knowledge of the
  29. * build configuration which is not available at configure time.
  30. */
  31. class cmGeneratorExpression
  32. {
  33. public:
  34. /** Construct. */
  35. cmGeneratorExpression(cmListFileBacktrace const& backtrace);
  36. ~cmGeneratorExpression();
  37. cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(
  38. std::string const& input);
  39. cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(const char* input);
  40. enum PreprocessContext {
  41. StripAllGeneratorExpressions,
  42. BuildInterface,
  43. InstallInterface
  44. };
  45. static std::string Preprocess(const std::string &input,
  46. PreprocessContext context,
  47. bool resolveRelative = false);
  48. static void Split(const std::string &input,
  49. std::vector<std::string> &output);
  50. static std::string::size_type Find(const std::string &input);
  51. static bool IsValidTargetName(const std::string &input);
  52. static std::string StripEmptyListElements(const std::string &input);
  53. private:
  54. cmGeneratorExpression(const cmGeneratorExpression &);
  55. void operator=(const cmGeneratorExpression &);
  56. cmListFileBacktrace const& Backtrace;
  57. };
  58. class cmCompiledGeneratorExpression
  59. {
  60. public:
  61. const char* Evaluate(cmMakefile* mf, const std::string& config,
  62. bool quiet = false,
  63. cmTarget const* headTarget = 0,
  64. cmTarget const* currentTarget = 0,
  65. cmGeneratorExpressionDAGChecker *dagChecker = 0) const;
  66. const char* Evaluate(cmMakefile* mf, const std::string& config,
  67. bool quiet,
  68. cmTarget const* headTarget,
  69. cmGeneratorExpressionDAGChecker *dagChecker) const;
  70. /** Get set of targets found during evaluations. */
  71. std::set<cmTarget*> const& GetTargets() const
  72. { return this->DependTargets; }
  73. std::set<std::string> const& GetSeenTargetProperties() const
  74. { return this->SeenTargetProperties; }
  75. std::set<cmTarget const*> const& GetAllTargetsSeen() const
  76. { return this->AllTargetsSeen; }
  77. ~cmCompiledGeneratorExpression();
  78. std::string const& GetInput() const
  79. {
  80. return this->Input;
  81. }
  82. cmListFileBacktrace GetBacktrace() const
  83. {
  84. return this->Backtrace;
  85. }
  86. bool GetHadContextSensitiveCondition() const
  87. {
  88. return this->HadContextSensitiveCondition;
  89. }
  90. private:
  91. cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
  92. const std::string& input);
  93. friend class cmGeneratorExpression;
  94. cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
  95. void operator=(const cmCompiledGeneratorExpression &);
  96. cmListFileBacktrace Backtrace;
  97. std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
  98. const std::string Input;
  99. bool NeedsEvaluation;
  100. mutable std::set<cmTarget*> DependTargets;
  101. mutable std::set<cmTarget const*> AllTargetsSeen;
  102. mutable std::set<std::string> SeenTargetProperties;
  103. mutable std::string Output;
  104. mutable bool HadContextSensitiveCondition;
  105. };
  106. #endif