/src/CMake/Source/cmGeneratorTarget_TargetPropertyEntry.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 | | /* clang-format off */ |
4 | | #include "cmGeneratorTarget.h" |
5 | | /* clang-format on */ |
6 | | |
7 | | #include <map> |
8 | | #include <string> |
9 | | #include <utility> |
10 | | #include <vector> |
11 | | |
12 | | #include <cm/memory> |
13 | | |
14 | | #include "cmFileSet.h" |
15 | | #include "cmGeneratorExpression.h" |
16 | | #include "cmLinkItem.h" |
17 | | #include "cmList.h" |
18 | | #include "cmListFileCache.h" |
19 | | |
20 | | class cmake; |
21 | | |
22 | | cmLinkItem cmGeneratorTarget::TargetPropertyEntry::NoLinkItem; |
23 | | |
24 | | class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry |
25 | | { |
26 | | public: |
27 | | TargetPropertyEntryString(BT<std::string> propertyValue, |
28 | | cmLinkItem const& item = NoLinkItem) |
29 | 0 | : cmGeneratorTarget::TargetPropertyEntry(item) |
30 | 0 | , PropertyValue(std::move(propertyValue)) |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | std::string const& Evaluate(cm::GenEx::Context const&, |
35 | | cmGeneratorTarget const*, |
36 | | cmGeneratorExpressionDAGChecker*) const override |
37 | 0 | { |
38 | 0 | return this->PropertyValue.Value; |
39 | 0 | } |
40 | | |
41 | | cmListFileBacktrace GetBacktrace() const override |
42 | 0 | { |
43 | 0 | return this->PropertyValue.Backtrace; |
44 | 0 | } |
45 | | std::string const& GetInput() const override |
46 | 0 | { |
47 | 0 | return this->PropertyValue.Value; |
48 | 0 | } |
49 | | |
50 | | private: |
51 | | BT<std::string> PropertyValue; |
52 | | }; |
53 | | |
54 | | class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry |
55 | | { |
56 | | public: |
57 | | TargetPropertyEntryGenex(std::unique_ptr<cmCompiledGeneratorExpression> cge, |
58 | | cmLinkItem const& item = NoLinkItem) |
59 | 0 | : cmGeneratorTarget::TargetPropertyEntry(item) |
60 | 0 | , ge(std::move(cge)) |
61 | 0 | { |
62 | 0 | } |
63 | | |
64 | | std::string const& Evaluate( |
65 | | cm::GenEx::Context const& context, cmGeneratorTarget const* headTarget, |
66 | | cmGeneratorExpressionDAGChecker* dagChecker) const override |
67 | 0 | { |
68 | 0 | return this->ge->Evaluate(context, dagChecker, headTarget); |
69 | 0 | } |
70 | | |
71 | | cmListFileBacktrace GetBacktrace() const override |
72 | 0 | { |
73 | 0 | return this->ge->GetBacktrace(); |
74 | 0 | } |
75 | | |
76 | 0 | std::string const& GetInput() const override { return this->ge->GetInput(); } |
77 | | |
78 | | bool GetHadContextSensitiveCondition() const override |
79 | 0 | { |
80 | 0 | return this->ge->GetHadContextSensitiveCondition(); |
81 | 0 | } |
82 | | |
83 | | private: |
84 | | std::unique_ptr<cmCompiledGeneratorExpression> const ge; |
85 | | }; |
86 | | |
87 | | class TargetPropertyEntryFileSet |
88 | | : public cmGeneratorTarget::TargetPropertyEntry |
89 | | { |
90 | | public: |
91 | | TargetPropertyEntryFileSet( |
92 | | std::vector<std::string> dirs, bool contextSensitiveDirs, |
93 | | std::unique_ptr<cmCompiledGeneratorExpression> entryCge, |
94 | | cmFileSet const* fileSet, cmLinkItem const& item = NoLinkItem) |
95 | 0 | : cmGeneratorTarget::TargetPropertyEntry(item) |
96 | 0 | , BaseDirs(std::move(dirs)) |
97 | 0 | , ContextSensitiveDirs(contextSensitiveDirs) |
98 | 0 | , EntryCge(std::move(entryCge)) |
99 | 0 | , FileSet(fileSet) |
100 | 0 | { |
101 | 0 | } |
102 | | |
103 | | std::string const& Evaluate( |
104 | | cm::GenEx::Context const& context, cmGeneratorTarget const* headTarget, |
105 | | cmGeneratorExpressionDAGChecker* dagChecker) const override |
106 | 0 | { |
107 | 0 | std::map<std::string, std::vector<std::string>> filesPerDir; |
108 | 0 | this->FileSet->EvaluateFileEntry(this->BaseDirs, filesPerDir, |
109 | 0 | this->EntryCge, context, headTarget, |
110 | 0 | dagChecker); |
111 | |
|
112 | 0 | std::vector<std::string> files; |
113 | 0 | for (auto const& it : filesPerDir) { |
114 | 0 | files.insert(files.end(), it.second.begin(), it.second.end()); |
115 | 0 | } |
116 | |
|
117 | 0 | static std::string filesStr; |
118 | 0 | filesStr = cmList::to_string(files); |
119 | 0 | return filesStr; |
120 | 0 | } |
121 | | |
122 | | cmListFileBacktrace GetBacktrace() const override |
123 | 0 | { |
124 | 0 | return this->EntryCge->GetBacktrace(); |
125 | 0 | } |
126 | | |
127 | | std::string const& GetInput() const override |
128 | 0 | { |
129 | 0 | return this->EntryCge->GetInput(); |
130 | 0 | } |
131 | | |
132 | | bool GetHadContextSensitiveCondition() const override |
133 | 0 | { |
134 | 0 | return this->ContextSensitiveDirs || |
135 | 0 | this->EntryCge->GetHadContextSensitiveCondition(); |
136 | 0 | } |
137 | | |
138 | | private: |
139 | | std::vector<std::string> const BaseDirs; |
140 | | bool const ContextSensitiveDirs; |
141 | | std::unique_ptr<cmCompiledGeneratorExpression> const EntryCge; |
142 | | cmFileSet const* FileSet; |
143 | | }; |
144 | | |
145 | | std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry> |
146 | | cmGeneratorTarget::TargetPropertyEntry::Create( |
147 | | cmake& cmakeInstance, const BT<std::string>& propertyValue, |
148 | | bool evaluateForBuildsystem) |
149 | 0 | { |
150 | 0 | if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) { |
151 | 0 | cmGeneratorExpression ge(cmakeInstance, propertyValue.Backtrace); |
152 | 0 | std::unique_ptr<cmCompiledGeneratorExpression> cge = |
153 | 0 | ge.Parse(propertyValue.Value); |
154 | 0 | cge->SetEvaluateForBuildsystem(evaluateForBuildsystem); |
155 | 0 | return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>( |
156 | 0 | cm::make_unique<TargetPropertyEntryGenex>(std::move(cge))); |
157 | 0 | } |
158 | | |
159 | 0 | return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>( |
160 | 0 | cm::make_unique<TargetPropertyEntryString>(propertyValue)); |
161 | 0 | } |
162 | | |
163 | | std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry> |
164 | | cmGeneratorTarget::TargetPropertyEntry::CreateFileSet( |
165 | | std::vector<std::string> dirs, bool contextSensitiveDirs, |
166 | | std::unique_ptr<cmCompiledGeneratorExpression> entryCge, |
167 | | cmFileSet const* fileSet, cmLinkItem const& item) |
168 | 0 | { |
169 | 0 | return cm::make_unique<TargetPropertyEntryFileSet>( |
170 | 0 | std::move(dirs), contextSensitiveDirs, std::move(entryCge), fileSet, item); |
171 | 0 | } |
172 | | |
173 | | cmGeneratorTarget::TargetPropertyEntry::TargetPropertyEntry( |
174 | | cmLinkItem const& item) |
175 | 0 | : LinkItem(item) |
176 | 0 | { |
177 | 0 | } |
178 | | |
179 | | bool cmGeneratorTarget::TargetPropertyEntry::GetHadContextSensitiveCondition() |
180 | | const |
181 | 0 | { |
182 | 0 | return false; |
183 | 0 | } |