/src/CMake/Source/cmEvaluatedTargetProperty.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmEvaluatedTargetProperty.h" |
4 | | |
5 | | #include <unordered_map> |
6 | | #include <utility> |
7 | | |
8 | | #include "cmGenExContext.h" |
9 | | #include "cmGenExEvaluation.h" |
10 | | #include "cmGeneratorFileSets.h" |
11 | | #include "cmGeneratorTarget.h" |
12 | | #include "cmLinkItem.h" |
13 | | #include "cmList.h" |
14 | | #include "cmTargetPropertyEntry.h" |
15 | | |
16 | | struct cmGeneratorExpressionDAGChecker; |
17 | | |
18 | | namespace cm { |
19 | | EvaluatedTargetPropertyEntry::EvaluatedTargetPropertyEntry( |
20 | | cmLinkItem const& item, cmListFileBacktrace bt) |
21 | 0 | : LinkItem(item) |
22 | 0 | , Backtrace(std::move(bt)) |
23 | 0 | { |
24 | 0 | } |
25 | | |
26 | | EvaluatedTargetPropertyEntry EvaluateTargetPropertyEntry( |
27 | | cmGeneratorTarget const* thisTarget, cm::GenEx::Context const& context, |
28 | | cmGeneratorExpressionDAGChecker* dagChecker, cm::TargetPropertyEntry& entry) |
29 | 0 | { |
30 | 0 | EvaluatedTargetPropertyEntry ee(entry.LinkItem, entry.GetBacktrace()); |
31 | 0 | cmExpandList(entry.Evaluate(context, thisTarget, dagChecker), ee.Values); |
32 | 0 | if (entry.GetHadContextSensitiveCondition()) { |
33 | 0 | ee.ContextDependent = true; |
34 | 0 | } |
35 | 0 | return ee; |
36 | 0 | } |
37 | | |
38 | | EvaluatedTargetPropertyEntries EvaluateTargetPropertyEntries( |
39 | | cmGeneratorTarget const* thisTarget, cm::GenEx::Context const& context, |
40 | | cmGeneratorExpressionDAGChecker* dagChecker, |
41 | | std::vector<std::unique_ptr<cm::TargetPropertyEntry>> const& in) |
42 | 0 | { |
43 | 0 | EvaluatedTargetPropertyEntries out; |
44 | 0 | out.Entries.reserve(in.size()); |
45 | 0 | for (auto const& entry : in) { |
46 | 0 | out.Entries.emplace_back( |
47 | 0 | EvaluateTargetPropertyEntry(thisTarget, context, dagChecker, *entry)); |
48 | 0 | } |
49 | 0 | return out; |
50 | 0 | } |
51 | | |
52 | | namespace { |
53 | | void addInterfaceEntry(cmGeneratorTarget const* headTarget, |
54 | | std::string const& prop, |
55 | | cm::GenEx::Context const& context, |
56 | | cmGeneratorExpressionDAGChecker* dagChecker, |
57 | | EvaluatedTargetPropertyEntries& entries, |
58 | | cmGeneratorTarget::UseTo usage, |
59 | | std::vector<cmLinkItem> const& libraries) |
60 | 0 | { |
61 | 0 | for (cmLinkItem const& lib : libraries) { |
62 | 0 | if (lib.Target) { |
63 | 0 | EvaluatedTargetPropertyEntry ee(lib, lib.Backtrace); |
64 | | // Pretend $<TARGET_PROPERTY:lib.Target,prop> appeared in our |
65 | | // caller's property and hand-evaluate it as if it were compiled. |
66 | | // Create a context as cmCompiledGeneratorExpression::Evaluate does. |
67 | 0 | cm::GenEx::Evaluation eval(context, false, headTarget, headTarget, true, |
68 | 0 | lib.Backtrace); |
69 | 0 | cmExpandList( |
70 | 0 | lib.Target->EvaluateInterfaceProperty(prop, &eval, dagChecker, usage), |
71 | 0 | ee.Values); |
72 | 0 | ee.ContextDependent = eval.HadContextSensitiveCondition; |
73 | 0 | entries.Entries.emplace_back(std::move(ee)); |
74 | 0 | } |
75 | 0 | } |
76 | 0 | } |
77 | | |
78 | | void addInterfaceFileSetsEntry(cmGeneratorTarget const* headTarget, |
79 | | cm::string_view type, std::string const& prop, |
80 | | cm::GenEx::Context const& context, |
81 | | cmGeneratorExpressionDAGChecker* dagChecker, |
82 | | EvaluatedTargetPropertyEntries& entries, |
83 | | std::vector<cmLinkItem> const& libraries) |
84 | 0 | { |
85 | 0 | for (cmLinkItem const& lib : libraries) { |
86 | 0 | if (lib.Target) { |
87 | 0 | EvaluatedTargetPropertyEntry ee(lib, lib.Backtrace); |
88 | | // Pretend $<TARGET_PROPERTY:lib.Target,prop> appeared in our |
89 | | // caller's property and hand-evaluate it as if it were compiled. |
90 | | // Create a context as cmCompiledGeneratorExpression::Evaluate does. |
91 | 0 | cm::GenEx::Evaluation eval(context, false, headTarget, headTarget, true, |
92 | 0 | lib.Backtrace); |
93 | 0 | cmExpandList( |
94 | 0 | lib.Target->GetGeneratorFileSets()->EvaluateInterfaceProperty( |
95 | 0 | type, prop, &eval, dagChecker), |
96 | 0 | ee.Values); |
97 | 0 | ee.ContextDependent = eval.HadContextSensitiveCondition; |
98 | 0 | entries.Entries.emplace_back(std::move(ee)); |
99 | 0 | } |
100 | 0 | } |
101 | 0 | } |
102 | | } |
103 | | |
104 | | void AddInterfaceEntries(cmGeneratorTarget const* headTarget, |
105 | | std::string const& prop, |
106 | | cm::GenEx::Context const& context, |
107 | | cmGeneratorExpressionDAGChecker* dagChecker, |
108 | | EvaluatedTargetPropertyEntries& entries, |
109 | | IncludeRuntimeInterface searchRuntime, |
110 | | cmGeneratorTarget::UseTo usage) |
111 | 0 | { |
112 | 0 | if (searchRuntime == IncludeRuntimeInterface::Yes) { |
113 | 0 | if (cmLinkImplementation const* impl = |
114 | 0 | headTarget->GetLinkImplementation(context.Config, usage)) { |
115 | 0 | entries.HadContextSensitiveCondition = |
116 | 0 | impl->HadContextSensitiveCondition; |
117 | |
|
118 | 0 | auto runtimeLibIt = |
119 | 0 | impl->LanguageRuntimeLibraries.find(context.Language); |
120 | 0 | if (runtimeLibIt != impl->LanguageRuntimeLibraries.end()) { |
121 | 0 | addInterfaceEntry(headTarget, prop, context, dagChecker, entries, |
122 | 0 | usage, runtimeLibIt->second); |
123 | 0 | } |
124 | 0 | addInterfaceEntry(headTarget, prop, context, dagChecker, entries, usage, |
125 | 0 | impl->Libraries); |
126 | 0 | } |
127 | 0 | } else { |
128 | 0 | if (cmLinkImplementationLibraries const* impl = |
129 | 0 | headTarget->GetLinkImplementationLibraries(context.Config, usage)) { |
130 | 0 | entries.HadContextSensitiveCondition = |
131 | 0 | impl->HadContextSensitiveCondition; |
132 | 0 | addInterfaceEntry(headTarget, prop, context, dagChecker, entries, usage, |
133 | 0 | impl->Libraries); |
134 | 0 | } |
135 | 0 | } |
136 | 0 | } |
137 | | |
138 | | void AddInterfaceFileSetsEntries(cmGeneratorTarget const* headTarget, |
139 | | cm::string_view type, std::string const& prop, |
140 | | cm::GenEx::Context const& context, |
141 | | cmGeneratorExpressionDAGChecker* dagChecker, |
142 | | EvaluatedTargetPropertyEntries& entries) |
143 | 0 | { |
144 | 0 | if (cmLinkImplementationLibraries const* impl = |
145 | 0 | headTarget->GetLinkImplementationLibraries( |
146 | 0 | context.Config, cmGeneratorTarget::UseTo::Compile)) { |
147 | 0 | entries.HadContextSensitiveCondition = impl->HadContextSensitiveCondition; |
148 | 0 | addInterfaceFileSetsEntry(headTarget, type, prop, context, dagChecker, |
149 | 0 | entries, impl->Libraries); |
150 | 0 | } |
151 | 0 | } |
152 | | } |