86b6f25df839bd0a944aa43429cef9576c9476d5
[platform/upstream/cmake.git] / Source / cmGeneratorExpression.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12
13 #ifndef cmGeneratorExpression_h
14 #define cmGeneratorExpression_h
15
16 #include "cmStandardIncludes.h"
17 #include "cmListFileCache.h"
18
19 #include <stack>
20
21 #include <cmsys/RegularExpression.hxx>
22 #include <cmsys/auto_ptr.hxx>
23
24 class cmTarget;
25 class cmMakefile;
26 class cmListFileBacktrace;
27
28 struct cmGeneratorExpressionEvaluator;
29 struct cmGeneratorExpressionDAGChecker;
30
31 class cmCompiledGeneratorExpression;
32
33 /** \class cmGeneratorExpression
34  * \brief Evaluate generate-time query expression syntax.
35  *
36  * cmGeneratorExpression instances are used by build system generator
37  * implementations to evaluate the $<> generator expression syntax.
38  * Generator expressions are evaluated just before the generate step
39  * writes strings into the build system.  They have knowledge of the
40  * build configuration which is not available at configure time.
41  */
42 class cmGeneratorExpression
43 {
44 public:
45   /** Construct. */
46   cmGeneratorExpression(cmListFileBacktrace const& backtrace);
47   ~cmGeneratorExpression();
48
49   cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(
50                                                 std::string const& input);
51   cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(const char* input);
52
53   enum PreprocessContext {
54     StripAllGeneratorExpressions,
55     BuildInterface,
56     InstallInterface
57   };
58
59   static std::string Preprocess(const std::string &input,
60                                 PreprocessContext context);
61
62   static void Split(const std::string &input,
63                     std::vector<std::string> &output);
64
65   static std::string::size_type Find(const std::string &input);
66
67   static bool IsValidTargetName(const std::string &input);
68
69   static std::string StripEmptyListElements(const std::string &input);
70 private:
71   cmGeneratorExpression(const cmGeneratorExpression &);
72   void operator=(const cmGeneratorExpression &);
73
74   cmListFileBacktrace const& Backtrace;
75 };
76
77 class cmCompiledGeneratorExpression
78 {
79 public:
80   const char* Evaluate(cmMakefile* mf, const char* config,
81                        bool quiet = false,
82                        cmTarget *headTarget = 0,
83                        cmTarget *currentTarget = 0,
84                        cmGeneratorExpressionDAGChecker *dagChecker = 0) const;
85   const char* Evaluate(cmMakefile* mf, const char* config,
86                        bool quiet,
87                        cmTarget *headTarget,
88                        cmGeneratorExpressionDAGChecker *dagChecker) const;
89
90   /** Get set of targets found during evaluations.  */
91   std::set<cmTarget*> const& GetTargets() const
92     { return this->DependTargets; }
93
94   std::set<cmStdString> const& GetSeenTargetProperties() const
95     { return this->SeenTargetProperties; }
96
97   std::set<cmTarget*> const& GetAllTargetsSeen() const
98     { return this->AllTargetsSeen; }
99
100   ~cmCompiledGeneratorExpression();
101
102   std::string GetInput() const
103   {
104     return this->Input;
105   }
106
107   cmListFileBacktrace GetBacktrace() const
108   {
109     return this->Backtrace;
110   }
111   bool GetHadContextSensitiveCondition() const
112   {
113     return this->HadContextSensitiveCondition;
114   }
115
116 private:
117   cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
118               const char *input);
119
120   friend class cmGeneratorExpression;
121
122   cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
123   void operator=(const cmCompiledGeneratorExpression &);
124
125   cmListFileBacktrace Backtrace;
126   std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
127   const std::string Input;
128   bool NeedsParsing;
129
130   mutable std::set<cmTarget*> DependTargets;
131   mutable std::set<cmTarget*> AllTargetsSeen;
132   mutable std::set<cmStdString> SeenTargetProperties;
133   mutable std::string Output;
134   mutable bool HadContextSensitiveCondition;
135 };
136
137 #endif