packaging: Initial packaging
[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                                 bool resolveRelative = false);
62
63   static void Split(const std::string &input,
64                     std::vector<std::string> &output);
65
66   static std::string::size_type Find(const std::string &input);
67
68   static bool IsValidTargetName(const std::string &input);
69
70   static std::string StripEmptyListElements(const std::string &input);
71 private:
72   cmGeneratorExpression(const cmGeneratorExpression &);
73   void operator=(const cmGeneratorExpression &);
74
75   cmListFileBacktrace const& Backtrace;
76 };
77
78 class cmCompiledGeneratorExpression
79 {
80 public:
81   const char* Evaluate(cmMakefile* mf, const char* config,
82                        bool quiet = false,
83                        cmTarget *headTarget = 0,
84                        cmTarget *currentTarget = 0,
85                        cmGeneratorExpressionDAGChecker *dagChecker = 0) const;
86   const char* Evaluate(cmMakefile* mf, const char* config,
87                        bool quiet,
88                        cmTarget *headTarget,
89                        cmGeneratorExpressionDAGChecker *dagChecker) const;
90
91   /** Get set of targets found during evaluations.  */
92   std::set<cmTarget*> const& GetTargets() const
93     { return this->DependTargets; }
94
95   std::set<cmStdString> const& GetSeenTargetProperties() const
96     { return this->SeenTargetProperties; }
97
98   std::set<cmTarget*> const& GetAllTargetsSeen() const
99     { return this->AllTargetsSeen; }
100
101   ~cmCompiledGeneratorExpression();
102
103   std::string GetInput() const
104   {
105     return this->Input;
106   }
107
108   cmListFileBacktrace GetBacktrace() const
109   {
110     return this->Backtrace;
111   }
112   bool GetHadContextSensitiveCondition() const
113   {
114     return this->HadContextSensitiveCondition;
115   }
116
117 private:
118   cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
119               const char *input);
120
121   friend class cmGeneratorExpression;
122
123   cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
124   void operator=(const cmCompiledGeneratorExpression &);
125
126   cmListFileBacktrace Backtrace;
127   std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
128   const std::string Input;
129   bool NeedsParsing;
130
131   mutable std::set<cmTarget*> DependTargets;
132   mutable std::set<cmTarget*> AllTargetsSeen;
133   mutable std::set<cmStdString> SeenTargetProperties;
134   mutable std::string Output;
135   mutable bool HadContextSensitiveCondition;
136 };
137
138 #endif