resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmGetTargetPropertyCommand.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #include "cmGetTargetPropertyCommand.h"
4
5 #include <sstream>
6
7 #include "cmExecutionStatus.h"
8 #include "cmGlobalGenerator.h"
9 #include "cmMakefile.h"
10 #include "cmMessageType.h"
11 #include "cmPolicies.h"
12 #include "cmTarget.h"
13 #include "cmValue.h"
14
15 bool cmGetTargetPropertyCommand(std::vector<std::string> const& args,
16                                 cmExecutionStatus& status)
17 {
18   if (args.size() != 3) {
19     status.SetError("called with incorrect number of arguments");
20     return false;
21   }
22   std::string const& var = args[0];
23   std::string const& targetName = args[1];
24   std::string prop;
25   bool prop_exists = false;
26   cmMakefile& mf = status.GetMakefile();
27
28   if (cmTarget* tgt = mf.FindTargetToUse(targetName)) {
29     if (args[2] == "ALIASED_TARGET" || args[2] == "ALIAS_GLOBAL") {
30       if (mf.IsAlias(targetName)) {
31         prop_exists = true;
32         if (args[2] == "ALIASED_TARGET") {
33
34           prop = tgt->GetName();
35         }
36         if (args[2] == "ALIAS_GLOBAL") {
37           prop =
38             mf.GetGlobalGenerator()->IsAlias(targetName) ? "TRUE" : "FALSE";
39         }
40       }
41     } else if (!args[2].empty()) {
42       cmValue prop_cstr = nullptr;
43       prop_cstr = tgt->GetComputedProperty(args[2], mf);
44       if (!prop_cstr) {
45         prop_cstr = tgt->GetProperty(args[2]);
46       }
47       if (prop_cstr) {
48         prop = *prop_cstr;
49         prop_exists = true;
50       }
51     }
52   } else {
53     bool issueMessage = false;
54     std::ostringstream e;
55     MessageType messageType = MessageType::AUTHOR_WARNING;
56     switch (mf.GetPolicyStatus(cmPolicies::CMP0045)) {
57       case cmPolicies::WARN:
58         issueMessage = true;
59         e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0045) << "\n";
60         CM_FALLTHROUGH;
61       case cmPolicies::OLD:
62         break;
63       case cmPolicies::REQUIRED_IF_USED:
64       case cmPolicies::REQUIRED_ALWAYS:
65       case cmPolicies::NEW:
66         issueMessage = true;
67         messageType = MessageType::FATAL_ERROR;
68         break;
69     }
70     if (issueMessage) {
71       e << "get_target_property() called with non-existent target \""
72         << targetName << "\".";
73       mf.IssueMessage(messageType, e.str());
74       if (messageType == MessageType::FATAL_ERROR) {
75         return false;
76       }
77     }
78   }
79   if (prop_exists) {
80     mf.AddDefinition(var, prop);
81     return true;
82   }
83   mf.AddDefinition(var, var + "-NOTFOUND");
84   return true;
85 }