cmGeneratorExpressionDAGChecker.h 3.57 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3 4 5
#ifndef cmGeneratorExpressionDAGChecker_h
#define cmGeneratorExpressionDAGChecker_h

6
#include "cmConfigure.h" // IWYU pragma: keep
7

8
#include "cmListFileCache.h"
9

10 11 12 13 14 15
#include <map>
#include <set>
#include <string>

struct GeneratorExpressionContent;
struct cmGeneratorExpressionContext;
16
class cmGeneratorTarget;
17

18
#define CM_SELECT_BOTH(F, A1, A2) F(A1, A2)
19 20 21
#define CM_SELECT_FIRST(F, A1, A2) F(A1)
#define CM_SELECT_SECOND(F, A1, A2) F(A2)

22 23 24 25 26 27 28
#define CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, SELECT)                       \
  SELECT(F, EvaluatingIncludeDirectories, INCLUDE_DIRECTORIES)                \
  SELECT(F, EvaluatingSystemIncludeDirectories, SYSTEM_INCLUDE_DIRECTORIES)   \
  SELECT(F, EvaluatingCompileDefinitions, COMPILE_DEFINITIONS)                \
  SELECT(F, EvaluatingCompileOptions, COMPILE_OPTIONS)                        \
  SELECT(F, EvaluatingAutoUicOptions, AUTOUIC_OPTIONS)                        \
  SELECT(F, EvaluatingSources, SOURCES)                                       \
29
  SELECT(F, EvaluatingCompileFeatures, COMPILE_FEATURES)                      \
30
  SELECT(F, EvaluatingLinkOptions, LINK_OPTIONS)                              \
31
  SELECT(F, EvaluatingLinkDirectories, LINK_DIRECTORIES)                      \
32
  SELECT(F, EvaluatingLinkDepends, LINK_DEPENDS)
33 34

#define CM_FOR_EACH_TRANSITIVE_PROPERTY(F)                                    \
35 36
  CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_BOTH)

37
#define CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(F)                             \
38
  CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_FIRST)
39

40
#define CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(F)                               \
41
  CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_SECOND)
42

43 44
struct cmGeneratorExpressionDAGChecker
{
wahikihiki's avatar
wahikihiki committed
45
  cmGeneratorExpressionDAGChecker(cmListFileBacktrace backtrace,
46
                                  cmGeneratorTarget const* target,
wahikihiki's avatar
wahikihiki committed
47
                                  std::string property,
48 49
                                  const GeneratorExpressionContent* content,
                                  cmGeneratorExpressionDAGChecker* parent);
50
  cmGeneratorExpressionDAGChecker(cmGeneratorTarget const* target,
wahikihiki's avatar
wahikihiki committed
51
                                  std::string property,
52 53 54 55 56
                                  const GeneratorExpressionContent* content,
                                  cmGeneratorExpressionDAGChecker* parent);

  enum Result
  {
57 58
    DAG,
    SELF_REFERENCE,
59 60
    CYCLIC_REFERENCE,
    ALREADY_SEEN
61 62
  };

63
  Result Check() const;
64

65 66
  void ReportError(cmGeneratorExpressionContext* context,
                   const std::string& expr);
67

68
  bool EvaluatingGenexExpression();
69
  bool EvaluatingPICExpression();
70
  bool EvaluatingLinkLibraries(cmGeneratorTarget const* tgt = nullptr);
71

72
#define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) bool METHOD() const;
73

74 75 76
  CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(DECLARE_TRANSITIVE_PROPERTY_METHOD)

#undef DECLARE_TRANSITIVE_PROPERTY_METHOD
77

78
  bool GetTransitivePropertiesOnly();
79
  void SetTransitivePropertiesOnly() { this->TransitivePropertiesOnly = true; }
80

81
  cmGeneratorTarget const* TopTarget() const;
82

83
private:
84
  Result CheckGraph() const;
85
  void Initialize();
86 87

private:
88
  const cmGeneratorExpressionDAGChecker* const Parent;
89
  cmGeneratorTarget const* Target;
90
  const std::string Property;
91
  mutable std::map<cmGeneratorTarget const*, std::set<std::string>> Seen;
92
  const GeneratorExpressionContent* const Content;
93
  const cmListFileBacktrace Backtrace;
94
  Result CheckResult;
95
  bool TransitivePropertiesOnly;
96 97 98
};

#endif