cmGeneratorExpression.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. 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. private:
  53. cmGeneratorExpression(const cmGeneratorExpression &);
  54. void operator=(const cmGeneratorExpression &);
  55. cmListFileBacktrace const& Backtrace;
  56. };
  57. class cmCompiledGeneratorExpression
  58. {
  59. public:
  60. const char* Evaluate(cmMakefile* mf, const char* config,
  61. bool quiet = false,
  62. cmTarget *headTarget = 0,
  63. cmTarget *currentTarget = 0,
  64. cmGeneratorExpressionDAGChecker *dagChecker = 0) const;
  65. const char* Evaluate(cmMakefile* mf, const char* config,
  66. bool quiet,
  67. cmTarget *headTarget,
  68. cmGeneratorExpressionDAGChecker *dagChecker) const;
  69. /** Get set of targets found during evaluations. */
  70. std::set<cmTarget*> const& GetTargets() const
  71. { return this->Targets; }
  72. std::set<cmStdString> const& GetSeenTargetProperties() const
  73. { return this->SeenTargetProperties; }
  74. ~cmCompiledGeneratorExpression();
  75. std::string GetInput() const
  76. {
  77. return this->Input;
  78. }
  79. cmListFileBacktrace GetBacktrace() const
  80. {
  81. return this->Backtrace;
  82. }
  83. bool GetHadContextSensitiveCondition() const
  84. {
  85. return this->HadContextSensitiveCondition;
  86. }
  87. private:
  88. cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
  89. const char *input);
  90. friend class cmGeneratorExpression;
  91. cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
  92. void operator=(const cmCompiledGeneratorExpression &);
  93. cmListFileBacktrace Backtrace;
  94. std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
  95. const std::string Input;
  96. bool NeedsParsing;
  97. mutable std::set<cmTarget*> Targets;
  98. mutable std::set<cmStdString> SeenTargetProperties;
  99. mutable std::string Output;
  100. mutable bool HadContextSensitiveCondition;
  101. };
  102. #endif