/src/CMake/Source/cmGetPropertyCommand.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 "cmGetPropertyCommand.h" |
4 | | |
5 | | #include "cmDirectoryPropertyHelper.h" |
6 | | #include "cmExecutionStatus.h" |
7 | | #include "cmFileSet.h" |
8 | | #include "cmInstalledFile.h" |
9 | | #include "cmMakefile.h" |
10 | | #include "cmProperty.h" |
11 | | #include "cmPropertyDefinition.h" |
12 | | #include "cmRule.h" |
13 | | #include "cmSetPropertyCommand.h" |
14 | | #include "cmSourceFilePropertyHelper.h" |
15 | | #include "cmState.h" |
16 | | #include "cmStringAlgorithms.h" |
17 | | #include "cmTarget.h" |
18 | | #include "cmTargetPropertyHelper.h" |
19 | | #include "cmTestPropertyHelper.h" |
20 | | #include "cmValue.h" |
21 | | #include "cmake.h" |
22 | | |
23 | | namespace { |
24 | | enum OutType |
25 | | { |
26 | | OutValue, |
27 | | OutDefined, |
28 | | OutBriefDoc, |
29 | | OutFullDoc, |
30 | | OutSet |
31 | | }; |
32 | | |
33 | | // Implementation of each property type. |
34 | | bool HandleGlobalMode(cmExecutionStatus& status, std::string const& name, |
35 | | OutType infoType, std::string const& variable, |
36 | | std::string const& propertyName); |
37 | | bool HandleDirectoryMode(cmExecutionStatus& status, std::string const& name, |
38 | | OutType infoType, std::string const& variable, |
39 | | std::string const& propertyName); |
40 | | bool HandleRuleMode(cmExecutionStatus& status, std::string const& name, |
41 | | OutType infoType, std::string const& variable, |
42 | | std::string const& propertyName); |
43 | | bool HandleTargetMode(cmExecutionStatus& status, std::string const& name, |
44 | | OutType infoType, std::string const& variable, |
45 | | std::string const& propertyName); |
46 | | bool HandleFileSetMode(cmExecutionStatus& status, std::string const& name, |
47 | | OutType infoType, std::string const& variable, |
48 | | std::string const& propertyName, cmTarget* target); |
49 | | bool HandleSourceMode(cmExecutionStatus& status, std::string const& name, |
50 | | OutType infoType, std::string const& variable, |
51 | | std::string const& propertyName, |
52 | | bool sourceFileDirectoryOptionEnabled, |
53 | | bool sourceFileTargetOptionEnabled, |
54 | | std::vector<std::string>& sourceFileDirectories, |
55 | | std::vector<std::string>& sourceFileTargetDirectories); |
56 | | bool HandleTestMode(cmExecutionStatus& status, std::string const& name, |
57 | | OutType infoType, std::string const& variable, |
58 | | std::string const& propertyName, |
59 | | bool testDirectoryOptionEnabled, |
60 | | std::string& testDirectory); |
61 | | bool HandleVariableMode(cmExecutionStatus& status, std::string const& name, |
62 | | OutType infoType, std::string const& variable, |
63 | | std::string const& propertyName); |
64 | | bool HandleCacheMode(cmExecutionStatus& status, std::string const& name, |
65 | | OutType infoType, std::string const& variable, |
66 | | std::string const& propertyName); |
67 | | bool HandleInstallMode(cmExecutionStatus& status, std::string const& name, |
68 | | OutType infoType, std::string const& variable, |
69 | | std::string const& propertyName); |
70 | | } |
71 | | |
72 | | bool cmGetPropertyCommand(std::vector<std::string> const& args, |
73 | | cmExecutionStatus& status) |
74 | 0 | { |
75 | 0 | OutType infoType = OutValue; |
76 | 0 | if (args.size() < 3) { |
77 | 0 | status.SetError("called with incorrect number of arguments"); |
78 | 0 | return false; |
79 | 0 | } |
80 | | |
81 | | // The cmake variable in which to store the result. |
82 | 0 | std::string const& variable = args[0]; |
83 | |
|
84 | 0 | std::string name; |
85 | 0 | std::string propertyName; |
86 | |
|
87 | 0 | std::string file_set_target_name; |
88 | 0 | bool file_set_target_option_enabled = false; |
89 | |
|
90 | 0 | std::vector<std::string> source_file_directories; |
91 | 0 | std::vector<std::string> source_file_target_directories; |
92 | 0 | bool source_file_directory_option_enabled = false; |
93 | 0 | bool source_file_target_option_enabled = false; |
94 | |
|
95 | 0 | std::string test_directory; |
96 | 0 | bool test_directory_option_enabled = false; |
97 | | |
98 | | // Get the scope from which to get the property. |
99 | 0 | cmProperty::ScopeType scope; |
100 | 0 | if (args[1] == "GLOBAL") { |
101 | 0 | scope = cmProperty::GLOBAL; |
102 | 0 | } else if (args[1] == "DIRECTORY") { |
103 | 0 | scope = cmProperty::DIRECTORY; |
104 | 0 | } else if (args[1] == "RULE") { |
105 | 0 | scope = cmProperty::RULE; |
106 | 0 | } else if (args[1] == "TARGET") { |
107 | 0 | scope = cmProperty::TARGET; |
108 | 0 | } else if (args[1] == "FILE_SET") { |
109 | 0 | scope = cmProperty::FILE_SET; |
110 | 0 | } else if (args[1] == "SOURCE") { |
111 | 0 | scope = cmProperty::SOURCE_FILE; |
112 | 0 | } else if (args[1] == "TEST") { |
113 | 0 | scope = cmProperty::TEST; |
114 | 0 | } else if (args[1] == "VARIABLE") { |
115 | 0 | scope = cmProperty::VARIABLE; |
116 | 0 | } else if (args[1] == "CACHE") { |
117 | 0 | scope = cmProperty::CACHE; |
118 | 0 | } else if (args[1] == "INSTALL") { |
119 | 0 | scope = cmProperty::INSTALL; |
120 | 0 | } else { |
121 | 0 | status.SetError( |
122 | 0 | cmStrCat("given invalid scope ", args[1], |
123 | 0 | ". Valid scopes are GLOBAL, DIRECTORY, RULE, TARGET, " |
124 | 0 | "FILE_SET, SOURCE, TEST, VARIABLE, CACHE, INSTALL.")); |
125 | 0 | return false; |
126 | 0 | } |
127 | | |
128 | | // Parse remaining arguments. |
129 | 0 | enum Doing |
130 | 0 | { |
131 | 0 | DoingNone, |
132 | 0 | DoingName, |
133 | 0 | DoingProperty, |
134 | 0 | DoingType, |
135 | 0 | DoingFileSetTarget, |
136 | 0 | DoingSourceDirectory, |
137 | 0 | DoingSourceTargetDirectory, |
138 | 0 | DoingTestDirectory, |
139 | 0 | }; |
140 | 0 | Doing doing = DoingName; |
141 | 0 | for (unsigned int i = 2; i < args.size(); ++i) { |
142 | 0 | if (args[i] == "PROPERTY") { |
143 | 0 | doing = DoingProperty; |
144 | 0 | } else if (args[i] == "BRIEF_DOCS") { |
145 | 0 | doing = DoingNone; |
146 | 0 | infoType = OutBriefDoc; |
147 | 0 | } else if (args[i] == "FULL_DOCS") { |
148 | 0 | doing = DoingNone; |
149 | 0 | infoType = OutFullDoc; |
150 | 0 | } else if (args[i] == "SET") { |
151 | 0 | doing = DoingNone; |
152 | 0 | infoType = OutSet; |
153 | 0 | } else if (args[i] == "DEFINED") { |
154 | 0 | doing = DoingNone; |
155 | 0 | infoType = OutDefined; |
156 | 0 | } else if (doing == DoingName) { |
157 | 0 | doing = DoingNone; |
158 | 0 | name = args[i]; |
159 | 0 | } else if (doing == DoingNone && scope == cmProperty::FILE_SET && |
160 | 0 | args[i] == "TARGET") { |
161 | 0 | doing = DoingFileSetTarget; |
162 | 0 | file_set_target_option_enabled = true; |
163 | 0 | } else if (doing == DoingNone && scope == cmProperty::SOURCE_FILE && |
164 | 0 | args[i] == "DIRECTORY") { |
165 | 0 | doing = DoingSourceDirectory; |
166 | 0 | source_file_directory_option_enabled = true; |
167 | 0 | } else if (doing == DoingNone && scope == cmProperty::SOURCE_FILE && |
168 | 0 | args[i] == "TARGET_DIRECTORY") { |
169 | 0 | doing = DoingSourceTargetDirectory; |
170 | 0 | source_file_target_option_enabled = true; |
171 | 0 | } else if (doing == DoingNone && scope == cmProperty::TEST && |
172 | 0 | args[i] == "DIRECTORY") { |
173 | 0 | doing = DoingTestDirectory; |
174 | 0 | test_directory_option_enabled = true; |
175 | 0 | } else if (doing == DoingFileSetTarget) { |
176 | 0 | file_set_target_name = args[i]; |
177 | 0 | doing = DoingNone; |
178 | 0 | } else if (doing == DoingSourceDirectory) { |
179 | 0 | source_file_directories.push_back(args[i]); |
180 | 0 | doing = DoingNone; |
181 | 0 | } else if (doing == DoingSourceTargetDirectory) { |
182 | 0 | source_file_target_directories.push_back(args[i]); |
183 | 0 | doing = DoingNone; |
184 | 0 | } else if (doing == DoingTestDirectory) { |
185 | 0 | test_directory = args[i]; |
186 | 0 | doing = DoingNone; |
187 | 0 | } else if (doing == DoingProperty) { |
188 | 0 | doing = DoingNone; |
189 | 0 | propertyName = args[i]; |
190 | 0 | } else { |
191 | 0 | status.SetError(cmStrCat("given invalid argument \"", args[i], "\".")); |
192 | 0 | return false; |
193 | 0 | } |
194 | 0 | } |
195 | | |
196 | | // Make sure a property name was found. |
197 | 0 | if (propertyName.empty()) { |
198 | 0 | status.SetError("not given a PROPERTY <name> argument."); |
199 | 0 | return false; |
200 | 0 | } |
201 | | |
202 | | // Compute requested output. |
203 | 0 | if (infoType == OutBriefDoc) { |
204 | | // Lookup brief documentation. |
205 | 0 | std::string output; |
206 | 0 | if (cmPropertyDefinition const* def = |
207 | 0 | status.GetMakefile().GetState()->GetPropertyDefinition(propertyName, |
208 | 0 | scope)) { |
209 | 0 | output = def->GetShortDescription(); |
210 | 0 | } |
211 | 0 | if (output.empty()) { |
212 | 0 | output = "NOTFOUND"; |
213 | 0 | } |
214 | 0 | status.GetMakefile().AddDefinition(variable, output); |
215 | 0 | } else if (infoType == OutFullDoc) { |
216 | | // Lookup full documentation. |
217 | 0 | std::string output; |
218 | 0 | if (cmPropertyDefinition const* def = |
219 | 0 | status.GetMakefile().GetState()->GetPropertyDefinition(propertyName, |
220 | 0 | scope)) { |
221 | 0 | output = def->GetFullDescription(); |
222 | 0 | } |
223 | 0 | if (output.empty()) { |
224 | 0 | output = "NOTFOUND"; |
225 | 0 | } |
226 | 0 | status.GetMakefile().AddDefinition(variable, output); |
227 | 0 | } else if (infoType == OutDefined) { |
228 | | // Lookup if the property is defined |
229 | 0 | if (status.GetMakefile().GetState()->GetPropertyDefinition(propertyName, |
230 | 0 | scope)) { |
231 | 0 | status.GetMakefile().AddDefinition(variable, "1"); |
232 | 0 | } else { |
233 | 0 | status.GetMakefile().AddDefinition(variable, "0"); |
234 | 0 | } |
235 | 0 | } else { |
236 | | // Dispatch property getting. |
237 | 0 | switch (scope) { |
238 | 0 | case cmProperty::GLOBAL: |
239 | 0 | return HandleGlobalMode(status, name, infoType, variable, |
240 | 0 | propertyName); |
241 | 0 | case cmProperty::DIRECTORY: |
242 | 0 | return HandleDirectoryMode(status, name, infoType, variable, |
243 | 0 | propertyName); |
244 | 0 | case cmProperty::RULE: |
245 | 0 | return HandleRuleMode(status, name, infoType, variable, propertyName); |
246 | 0 | case cmProperty::TARGET: |
247 | 0 | return HandleTargetMode(status, name, infoType, variable, |
248 | 0 | propertyName); |
249 | 0 | case cmProperty::FILE_SET: { |
250 | 0 | cmTarget* file_set_target; |
251 | 0 | if (!SetPropertyCommand::HandleAndValidateFileSetTargetScopes( |
252 | 0 | status, file_set_target_option_enabled, file_set_target_name, |
253 | 0 | file_set_target)) { |
254 | 0 | return false; |
255 | 0 | } |
256 | 0 | return HandleFileSetMode(status, name, infoType, variable, |
257 | 0 | propertyName, file_set_target); |
258 | 0 | } |
259 | 0 | case cmProperty::SOURCE_FILE: |
260 | 0 | return HandleSourceMode(status, name, infoType, variable, propertyName, |
261 | 0 | source_file_directory_option_enabled, |
262 | 0 | source_file_target_option_enabled, |
263 | 0 | source_file_directories, |
264 | 0 | source_file_target_directories); |
265 | 0 | case cmProperty::TEST: |
266 | 0 | return HandleTestMode(status, name, infoType, variable, propertyName, |
267 | 0 | test_directory_option_enabled, test_directory); |
268 | 0 | case cmProperty::VARIABLE: |
269 | 0 | return HandleVariableMode(status, name, infoType, variable, |
270 | 0 | propertyName); |
271 | 0 | case cmProperty::CACHE: |
272 | 0 | return HandleCacheMode(status, name, infoType, variable, propertyName); |
273 | 0 | case cmProperty::INSTALL: |
274 | 0 | return HandleInstallMode(status, name, infoType, variable, |
275 | 0 | propertyName); |
276 | | |
277 | 0 | case cmProperty::CACHED_VARIABLE: |
278 | 0 | break; // should never happen |
279 | 0 | } |
280 | 0 | } |
281 | | |
282 | 0 | return true; |
283 | 0 | } |
284 | | |
285 | | namespace { |
286 | | |
287 | | // Implementation of result storage. |
288 | | template <typename ValueType> |
289 | | bool StoreResult(OutType infoType, cmMakefile& makefile, |
290 | | std::string const& variable, ValueType value) |
291 | 0 | { |
292 | 0 | if (infoType == OutSet) { |
293 | 0 | makefile.AddDefinition(variable, value ? "1" : "0"); |
294 | 0 | } else // if(infoType == OutValue) |
295 | 0 | { |
296 | 0 | if (value) { |
297 | 0 | makefile.AddDefinition(variable, value); |
298 | 0 | } else { |
299 | 0 | makefile.RemoveDefinition(variable); |
300 | 0 | } |
301 | 0 | } |
302 | 0 | return true; |
303 | 0 | } Unexecuted instantiation: cmGetPropertyCommand.cxx:bool (anonymous namespace)::StoreResult<cmValue>((anonymous namespace)::OutType, cmMakefile&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmValue) Unexecuted instantiation: cmGetPropertyCommand.cxx:bool (anonymous namespace)::StoreResult<char const*>((anonymous namespace)::OutType, cmMakefile&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) |
304 | | |
305 | | bool HandleGlobalMode(cmExecutionStatus& status, std::string const& name, |
306 | | OutType infoType, std::string const& variable, |
307 | | std::string const& propertyName) |
308 | 0 | { |
309 | 0 | if (!name.empty()) { |
310 | 0 | status.SetError("given name for GLOBAL scope."); |
311 | 0 | return false; |
312 | 0 | } |
313 | | |
314 | | // Get the property. |
315 | 0 | cmake* cm = status.GetMakefile().GetCMakeInstance(); |
316 | 0 | return StoreResult(infoType, status.GetMakefile(), variable, |
317 | 0 | cm->GetState()->GetGlobalProperty(propertyName)); |
318 | 0 | } |
319 | | |
320 | | bool HandleDirectoryMode(cmExecutionStatus& status, std::string const& name, |
321 | | OutType infoType, std::string const& variable, |
322 | | std::string const& propertyName) |
323 | 0 | { |
324 | 0 | cmValue prop; |
325 | 0 | if (!GetPropertyCommand::LookupDirectoryProperty(status, name, propertyName, |
326 | 0 | prop)) { |
327 | 0 | return false; |
328 | 0 | } |
329 | 0 | return StoreResult(infoType, status.GetMakefile(), variable, prop); |
330 | 0 | } |
331 | | |
332 | | bool HandleRuleMode(cmExecutionStatus& status, std::string const& name, |
333 | | OutType infoType, std::string const& variable, |
334 | | std::string const& propertyName) |
335 | 0 | { |
336 | 0 | if (name.empty()) { |
337 | 0 | status.SetError("not given name for RULE scope."); |
338 | 0 | return false; |
339 | 0 | } |
340 | | |
341 | 0 | if (cmRule* rule = status.GetMakefile().FindRuleToUse(name)) { |
342 | 0 | cmValue prop = rule->GetProperty(propertyName); |
343 | 0 | return StoreResult(infoType, status.GetMakefile(), variable, prop); |
344 | 0 | } |
345 | 0 | status.SetError(cmStrCat("could not find RULE ", name, |
346 | 0 | ". Perhaps it has not yet been created.")); |
347 | 0 | return false; |
348 | 0 | } |
349 | | |
350 | | bool HandleTargetMode(cmExecutionStatus& status, std::string const& name, |
351 | | OutType infoType, std::string const& variable, |
352 | | std::string const& propertyName) |
353 | 0 | { |
354 | 0 | cmValue prop; |
355 | 0 | if (!GetPropertyCommand::LookupTargetProperty(status, name, propertyName, |
356 | 0 | prop)) { |
357 | 0 | return false; |
358 | 0 | } |
359 | 0 | return StoreResult(infoType, status.GetMakefile(), variable, prop); |
360 | 0 | } |
361 | | |
362 | | bool HandleFileSetMode(cmExecutionStatus& status, std::string const& name, |
363 | | OutType infoType, std::string const& variable, |
364 | | std::string const& propertyName, cmTarget* target) |
365 | 0 | { |
366 | 0 | if (name.empty()) { |
367 | 0 | status.SetError("not given name for FILE_SET scope."); |
368 | 0 | return false; |
369 | 0 | } |
370 | | |
371 | 0 | if (cmFileSet* fileSet = target->GetFileSet(name)) { |
372 | 0 | cmValue prop = fileSet->GetProperty(propertyName); |
373 | 0 | return StoreResult(infoType, status.GetMakefile(), variable, prop); |
374 | 0 | } |
375 | 0 | status.SetError(cmStrCat("could not find FILE_SET ", name, " for TARGET ", |
376 | 0 | target->GetName(), |
377 | 0 | ". Perhaps it has not yet been created.")); |
378 | 0 | return false; |
379 | 0 | } |
380 | | |
381 | | bool HandleSourceMode(cmExecutionStatus& status, std::string const& name, |
382 | | OutType infoType, std::string const& variable, |
383 | | std::string const& propertyName, |
384 | | bool sourceFileDirectoryOptionEnabled, |
385 | | bool sourceFileTargetOptionEnabled, |
386 | | std::vector<std::string>& sourceFileDirectories, |
387 | | std::vector<std::string>& sourceFileTargetDirectories) |
388 | 0 | { |
389 | 0 | cmValue prop; |
390 | 0 | if (!GetPropertyCommand::LookupSourceProperty( |
391 | 0 | status, name, propertyName, sourceFileDirectoryOptionEnabled, |
392 | 0 | sourceFileTargetOptionEnabled, sourceFileDirectories, |
393 | 0 | sourceFileTargetDirectories, prop)) { |
394 | 0 | return false; |
395 | 0 | } |
396 | 0 | return StoreResult(infoType, status.GetMakefile(), variable, prop); |
397 | 0 | } |
398 | | |
399 | | bool HandleTestMode(cmExecutionStatus& status, std::string const& name, |
400 | | OutType infoType, std::string const& variable, |
401 | | std::string const& propertyName, |
402 | | bool testDirectoryOptionEnabled, |
403 | | std::string& testDirectory) |
404 | 0 | { |
405 | 0 | cmValue prop; |
406 | 0 | if (!GetPropertyCommand::LookupTestProperty(status, name, propertyName, |
407 | 0 | testDirectoryOptionEnabled, |
408 | 0 | testDirectory, prop)) { |
409 | 0 | return false; |
410 | 0 | } |
411 | 0 | return StoreResult(infoType, status.GetMakefile(), variable, prop); |
412 | 0 | } |
413 | | |
414 | | bool HandleVariableMode(cmExecutionStatus& status, std::string const& name, |
415 | | OutType infoType, std::string const& variable, |
416 | | std::string const& propertyName) |
417 | 0 | { |
418 | 0 | if (!name.empty()) { |
419 | 0 | status.SetError("given name for VARIABLE scope."); |
420 | 0 | return false; |
421 | 0 | } |
422 | | |
423 | 0 | return StoreResult(infoType, status.GetMakefile(), variable, |
424 | 0 | status.GetMakefile().GetDefinition(propertyName)); |
425 | 0 | } |
426 | | |
427 | | bool HandleCacheMode(cmExecutionStatus& status, std::string const& name, |
428 | | OutType infoType, std::string const& variable, |
429 | | std::string const& propertyName) |
430 | 0 | { |
431 | 0 | cmValue value; |
432 | 0 | if (!GetPropertyCommand::LookupCacheProperty(status, name, propertyName, |
433 | 0 | value)) { |
434 | 0 | return false; |
435 | 0 | } |
436 | 0 | StoreResult(infoType, status.GetMakefile(), variable, value); |
437 | 0 | return true; |
438 | 0 | } |
439 | | |
440 | | bool HandleInstallMode(cmExecutionStatus& status, std::string const& name, |
441 | | OutType infoType, std::string const& variable, |
442 | | std::string const& propertyName) |
443 | 0 | { |
444 | 0 | if (name.empty()) { |
445 | 0 | status.SetError("not given name for INSTALL scope."); |
446 | 0 | return false; |
447 | 0 | } |
448 | | |
449 | | // Get the installed file. |
450 | 0 | cmake* cm = status.GetMakefile().GetCMakeInstance(); |
451 | |
|
452 | 0 | if (cmInstalledFile* file = |
453 | 0 | cm->GetOrCreateInstalledFile(&status.GetMakefile(), name)) { |
454 | 0 | std::string value; |
455 | 0 | bool isSet = file->GetProperty(propertyName, value); |
456 | |
|
457 | 0 | return StoreResult(infoType, status.GetMakefile(), variable, |
458 | 0 | isSet ? value.c_str() : nullptr); |
459 | 0 | } |
460 | 0 | status.SetError( |
461 | 0 | cmStrCat("given INSTALL name that could not be found or created: ", name)); |
462 | 0 | return false; |
463 | 0 | } |
464 | | } |
465 | | |
466 | | namespace GetPropertyCommand { |
467 | | |
468 | | bool LookupTargetProperty(cmExecutionStatus& status, std::string const& name, |
469 | | std::string const& propertyName, cmValue& out) |
470 | 0 | { |
471 | 0 | if (name.empty()) { |
472 | 0 | status.SetError("not given name for TARGET scope."); |
473 | 0 | return false; |
474 | 0 | } |
475 | | |
476 | 0 | auto result = |
477 | 0 | cmGetTargetProperty(name, propertyName, status.GetMakefile(), out); |
478 | 0 | if (result == cmGetTargetPropertyResult::Success) { |
479 | 0 | return true; |
480 | 0 | } |
481 | 0 | if (result == cmGetTargetPropertyResult::TargetNotFound) { |
482 | 0 | status.SetError(cmStrCat("could not find TARGET ", name, |
483 | 0 | ". Perhaps it has not yet been created.")); |
484 | 0 | } |
485 | 0 | return false; |
486 | 0 | } |
487 | | |
488 | | bool LookupDirectoryProperty(cmExecutionStatus& status, |
489 | | std::string const& name, |
490 | | std::string const& propertyName, cmValue& out) |
491 | 0 | { |
492 | 0 | auto result = |
493 | 0 | cmGetDirectoryProperty(name, propertyName, status.GetMakefile(), out); |
494 | 0 | if (result == cmGetDirectoryPropertyResult::Success) { |
495 | 0 | return true; |
496 | 0 | } |
497 | 0 | if (result == cmGetDirectoryPropertyResult::DirectoryNotFound) { |
498 | 0 | status.SetError( |
499 | 0 | "DIRECTORY scope provided but requested directory was not found. " |
500 | 0 | "This could be because the directory argument was invalid or, " |
501 | 0 | "it is valid but has not been processed yet."); |
502 | 0 | } |
503 | 0 | return false; |
504 | 0 | } |
505 | | |
506 | | bool LookupSourceProperty( |
507 | | cmExecutionStatus& status, std::string const& name, |
508 | | std::string const& propertyName, bool sourceFileDirectoryOptionEnabled, |
509 | | bool sourceFileTargetOptionEnabled, |
510 | | std::vector<std::string>& sourceFileDirectories, |
511 | | std::vector<std::string>& sourceFileTargetDirectories, cmValue& out) |
512 | 0 | { |
513 | 0 | if (name.empty()) { |
514 | 0 | status.SetError("not given name for SOURCE scope."); |
515 | 0 | return false; |
516 | 0 | } |
517 | | |
518 | 0 | auto result = cmGetSourceFileProperty( |
519 | 0 | name, propertyName, status, sourceFileDirectoryOptionEnabled, |
520 | 0 | sourceFileTargetOptionEnabled, sourceFileDirectories, |
521 | 0 | sourceFileTargetDirectories, out, /*alwaysCreateSource=*/true); |
522 | 0 | if (result == cmGetSourceFilePropertyResult::Success) { |
523 | 0 | return true; |
524 | 0 | } |
525 | 0 | if (result == cmGetSourceFilePropertyResult::Error || |
526 | 0 | result == cmGetSourceFilePropertyResult::SourceNotFound) { |
527 | 0 | status.SetError(cmStrCat( |
528 | 0 | "given SOURCE name that could not be found or created: ", name)); |
529 | 0 | } |
530 | 0 | return false; |
531 | 0 | } |
532 | | |
533 | | bool LookupSourceProperty(cmExecutionStatus& status, std::string const& name, |
534 | | std::string const& propertyName, cmValue& out) |
535 | 0 | { |
536 | 0 | std::vector<std::string> noDirectories; |
537 | 0 | std::vector<std::string> noTargetDirectories; |
538 | 0 | return LookupSourceProperty(status, name, propertyName, |
539 | 0 | /*sourceFileDirectoryOptionEnabled=*/false, |
540 | 0 | /*sourceFileTargetOptionEnabled=*/false, |
541 | 0 | noDirectories, noTargetDirectories, out); |
542 | 0 | } |
543 | | |
544 | | bool LookupTestProperty(cmExecutionStatus& status, std::string const& name, |
545 | | std::string const& propertyName, |
546 | | bool testDirectoryOptionEnabled, |
547 | | std::string& testDirectory, cmValue& out) |
548 | 0 | { |
549 | 0 | if (name.empty()) { |
550 | 0 | status.SetError("not given name for TEST scope."); |
551 | 0 | return false; |
552 | 0 | } |
553 | | |
554 | 0 | auto result = |
555 | 0 | cmGetTestProperty(name, propertyName, status, testDirectoryOptionEnabled, |
556 | 0 | testDirectory, out); |
557 | 0 | if (result == cmGetTestPropertyResult::Success) { |
558 | 0 | return true; |
559 | 0 | } |
560 | 0 | if (result == cmGetTestPropertyResult::TestNotFound) { |
561 | 0 | status.SetError(cmStrCat("given TEST name that does not exist: ", name)); |
562 | 0 | } |
563 | 0 | return false; |
564 | 0 | } |
565 | | |
566 | | bool LookupTestProperty(cmExecutionStatus& status, std::string const& name, |
567 | | std::string const& propertyName, cmValue& out) |
568 | 0 | { |
569 | 0 | std::string noDirectory; |
570 | 0 | return LookupTestProperty(status, name, propertyName, |
571 | 0 | /*testDirectoryOptionEnabled=*/false, noDirectory, |
572 | 0 | out); |
573 | 0 | } |
574 | | |
575 | | bool LookupCacheProperty(cmExecutionStatus& status, std::string const& name, |
576 | | std::string const& propertyName, cmValue& out) |
577 | 0 | { |
578 | 0 | if (name.empty()) { |
579 | 0 | status.SetError("not given name for CACHE scope."); |
580 | 0 | return false; |
581 | 0 | } |
582 | | |
583 | 0 | out = nullptr; |
584 | 0 | if (status.GetMakefile().GetState()->GetCacheEntryValue(name)) { |
585 | 0 | out = status.GetMakefile().GetState()->GetCacheEntryProperty(name, |
586 | 0 | propertyName); |
587 | 0 | } |
588 | 0 | return true; |
589 | 0 | } |
590 | | |
591 | | } |