/src/CMake/Source/cmGetTargetPropertyCommand.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 "cmGetTargetPropertyCommand.h" |
4 | | |
5 | | #include "cmExecutionStatus.h" |
6 | | #include "cmGlobalGenerator.h" |
7 | | #include "cmMakefile.h" |
8 | | #include "cmMessageType.h" |
9 | | #include "cmStringAlgorithms.h" |
10 | | #include "cmTarget.h" |
11 | | #include "cmValue.h" |
12 | | |
13 | | bool cmGetTargetPropertyCommand(std::vector<std::string> const& args, |
14 | | cmExecutionStatus& status) |
15 | 0 | { |
16 | 0 | if (args.size() != 3) { |
17 | 0 | status.SetError("called with incorrect number of arguments"); |
18 | 0 | return false; |
19 | 0 | } |
20 | 0 | std::string const& var = args[0]; |
21 | 0 | std::string const& targetName = args[1]; |
22 | 0 | std::string prop; |
23 | 0 | bool prop_exists = false; |
24 | 0 | cmMakefile& mf = status.GetMakefile(); |
25 | |
|
26 | 0 | if (cmTarget* tgt = mf.FindTargetToUse(targetName)) { |
27 | 0 | if (args[2] == "ALIASED_TARGET" || args[2] == "ALIAS_GLOBAL") { |
28 | 0 | if (mf.IsAlias(targetName)) { |
29 | 0 | prop_exists = true; |
30 | 0 | if (args[2] == "ALIASED_TARGET") { |
31 | |
|
32 | 0 | prop = tgt->GetName(); |
33 | 0 | } |
34 | 0 | if (args[2] == "ALIAS_GLOBAL") { |
35 | 0 | prop = |
36 | 0 | mf.GetGlobalGenerator()->IsAlias(targetName) ? "TRUE" : "FALSE"; |
37 | 0 | } |
38 | 0 | } |
39 | 0 | } else if (!args[2].empty()) { |
40 | 0 | cmValue prop_cstr = nullptr; |
41 | 0 | prop_cstr = tgt->GetComputedProperty(args[2], mf); |
42 | 0 | if (!prop_cstr) { |
43 | 0 | prop_cstr = tgt->GetProperty(args[2]); |
44 | 0 | } |
45 | 0 | if (prop_cstr) { |
46 | 0 | prop = *prop_cstr; |
47 | 0 | prop_exists = true; |
48 | 0 | } |
49 | 0 | } |
50 | 0 | } else { |
51 | 0 | mf.IssueMessage( |
52 | 0 | MessageType::FATAL_ERROR, |
53 | 0 | cmStrCat("get_target_property() called with non-existent target \"", |
54 | 0 | targetName, "\".")); |
55 | 0 | return false; |
56 | 0 | } |
57 | 0 | if (prop_exists) { |
58 | 0 | mf.AddDefinition(var, prop); |
59 | 0 | return true; |
60 | 0 | } |
61 | 0 | mf.AddDefinition(var, var + "-NOTFOUND"); |
62 | 0 | return true; |
63 | 0 | } |