summaryrefslogtreecommitdiff
path: root/Source/cmGeneratorExpression.h
blob: 29d3f444f60b028fffc3f2e01099b4b270233bd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/

#ifndef cmGeneratorExpression_h
#define cmGeneratorExpression_h

#include "cmStandardIncludes.h"

#include <stack>

#include <cmsys/RegularExpression.hxx>

class cmTarget;
class cmGeneratorTarget;
class cmMakefile;
class cmListFileBacktrace;

struct cmGeneratorExpressionEvaluator;
struct cmGeneratorExpressionDAGChecker;

class cmCompiledGeneratorExpression;

/** \class cmGeneratorExpression
 * \brief Evaluate generate-time query expression syntax.
 *
 * cmGeneratorExpression instances are used by build system generator
 * implementations to evaluate the $<> generator expression syntax.
 * Generator expressions are evaluated just before the generate step
 * writes strings into the build system.  They have knowledge of the
 * build configuration which is not available at configure time.
 */
class cmGeneratorExpression
{
public:
  /** Construct. */
  cmGeneratorExpression(cmListFileBacktrace const& backtrace);
  ~cmGeneratorExpression();

  const cmCompiledGeneratorExpression& Parse(std::string const& input);
  const cmCompiledGeneratorExpression& Parse(const char* input);

  enum PreprocessContext {
    StripAllGeneratorExpressions
  };

  static std::string Preprocess(const std::string &input,
                                PreprocessContext context);

private:
  cmGeneratorExpression(const cmGeneratorExpression &);
  void operator=(const cmGeneratorExpression &);

  cmListFileBacktrace const& Backtrace;
  cmCompiledGeneratorExpression *CompiledExpression;
};

class cmCompiledGeneratorExpression
{
public:
  const char* Evaluate(cmMakefile* mf, const char* config,
                       bool quiet = false,
                       cmGeneratorTarget *target = 0,
                       cmGeneratorExpressionDAGChecker *dagChecker = 0) const;

  /** Get set of targets found during evaluations.  */
  std::set<cmTarget*> const& GetTargets() const
    { return this->Targets; }

  ~cmCompiledGeneratorExpression();

private:
  cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
              const std::vector<cmGeneratorExpressionEvaluator*> &evaluators,
              const char *input, bool needsParsing);

  friend class cmGeneratorExpression;

  cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
  void operator=(const cmCompiledGeneratorExpression &);

  cmListFileBacktrace const& Backtrace;
  const std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
  const char* const Input;
  const bool NeedsParsing;

  mutable std::set<cmTarget*> Targets;
  mutable std::string Output;
};

#endif