cmGeneratorExpression.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <stack>
  15. #include <cmsys/RegularExpression.hxx>
  16. #include <cmsys/auto_ptr.hxx>
  17. class cmTarget;
  18. class cmMakefile;
  19. class cmListFileBacktrace;
  20. struct cmGeneratorExpressionEvaluator;
  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);
  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 char* config,
  63. bool quiet = false,
  64. cmTarget *headTarget = 0,
  65. cmTarget *currentTarget = 0,
  66. cmGeneratorExpressionDAGChecker *dagChecker = 0) const;
  67. const char* Evaluate(cmMakefile* mf, const char* config,
  68. bool quiet,
  69. cmTarget *headTarget,
  70. cmGeneratorExpressionDAGChecker *dagChecker) const;
  71. /** Get set of targets found during evaluations. */
  72. std::set<cmTarget*> const& GetTargets() const
  73. { return this->DependTargets; }
  74. std::set<cmStdString> const& GetSeenTargetProperties() const
  75. { return this->SeenTargetProperties; }
  76. std::set<cmTarget*> const& GetAllTargetsSeen() const
  77. { return this->AllTargetsSeen; }
  78. ~cmCompiledGeneratorExpression();
  79. std::string GetInput() const
  80. {
  81. return this->Input;
  82. }
  83. cmListFileBacktrace GetBacktrace() const
  84. {
  85. return this->Backtrace;
  86. }
  87. bool GetHadContextSensitiveCondition() const
  88. {
  89. return this->HadContextSensitiveCondition;
  90. }
  91. private:
  92. cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
  93. const char *input);
  94. friend class cmGeneratorExpression;
  95. cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
  96. void operator=(const cmCompiledGeneratorExpression &);
  97. cmListFileBacktrace Backtrace;
  98. std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
  99. const std::string Input;
  100. bool NeedsParsing;
  101. mutable std::set<cmTarget*> DependTargets;
  102. mutable std::set<cmTarget*> AllTargetsSeen;
  103. mutable std::set<cmStdString> SeenTargetProperties;
  104. mutable std::string Output;
  105. mutable bool HadContextSensitiveCondition;
  106. };
  107. #endif