cmGeneratorExpressionDAGChecker.h 3.39 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

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

21 22 23 24 25 26 27
#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)                                       \
28
  SELECT(F, EvaluatingCompileFeatures, COMPILE_FEATURES)                      \
29 30
  SELECT(F, EvaluatingLinkOptions, LINK_OPTIONS)                              \
  SELECT(F, EvaluatingLinkDepends, LINK_DEPENDS)
31 32

#define CM_FOR_EACH_TRANSITIVE_PROPERTY(F)                                    \
33 34
  CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_BOTH)

35
#define CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(F)                             \
36
  CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_FIRST)
37

38
#define CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(F)                               \
39
  CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_SECOND)
40

41 42
struct cmGeneratorExpressionDAGChecker
{
43 44 45 46 47 48 49 50 51 52 53 54
  cmGeneratorExpressionDAGChecker(const cmListFileBacktrace& backtrace,
                                  const std::string& target,
                                  const std::string& property,
                                  const GeneratorExpressionContent* content,
                                  cmGeneratorExpressionDAGChecker* parent);
  cmGeneratorExpressionDAGChecker(const std::string& target,
                                  const std::string& property,
                                  const GeneratorExpressionContent* content,
                                  cmGeneratorExpressionDAGChecker* parent);

  enum Result
  {
55 56
    DAG,
    SELF_REFERENCE,
57 58
    CYCLIC_REFERENCE,
    ALREADY_SEEN
59 60
  };

61
  Result Check() const;
62

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

66
  bool EvaluatingGenexExpression();
Daniel Pfeifer's avatar
Daniel Pfeifer committed
67
  bool EvaluatingLinkLibraries(const char* tgt = nullptr);
68

69
#define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) bool METHOD() const;
70

71 72 73
  CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(DECLARE_TRANSITIVE_PROPERTY_METHOD)

#undef DECLARE_TRANSITIVE_PROPERTY_METHOD
74

75
  bool GetTransitivePropertiesOnly();
76
  void SetTransitivePropertiesOnly() { this->TransitivePropertiesOnly = true; }
77

78 79
  std::string TopTarget() const;

80
private:
81
  Result CheckGraph() const;
82
  void Initialize();
83 84

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

#endif