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"
7 #include "cmExecutionStatus.h"
8 #include "cmGlobalGenerator.h"
9 #include "cmMakefile.h"
10 #include "cmMessageType.h"
11 #include "cmPolicies.h"
15 bool cmGetTargetPropertyCommand(std::vector<std::string> const& args,
16 cmExecutionStatus& status)
18 if (args.size() != 3) {
19 status.SetError("called with incorrect number of arguments");
22 std::string const& var = args[0];
23 std::string const& targetName = args[1];
25 bool prop_exists = false;
26 cmMakefile& mf = status.GetMakefile();
28 if (cmTarget* tgt = mf.FindTargetToUse(targetName)) {
29 if (args[2] == "ALIASED_TARGET" || args[2] == "ALIAS_GLOBAL") {
30 if (mf.IsAlias(targetName)) {
32 if (args[2] == "ALIASED_TARGET") {
34 prop = tgt->GetName();
36 if (args[2] == "ALIAS_GLOBAL") {
38 mf.GetGlobalGenerator()->IsAlias(targetName) ? "TRUE" : "FALSE";
41 } else if (!args[2].empty()) {
42 cmValue prop_cstr = nullptr;
43 prop_cstr = tgt->GetComputedProperty(args[2], mf);
45 prop_cstr = tgt->GetProperty(args[2]);
53 bool issueMessage = false;
55 MessageType messageType = MessageType::AUTHOR_WARNING;
56 switch (mf.GetPolicyStatus(cmPolicies::CMP0045)) {
57 case cmPolicies::WARN:
59 e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0045) << "\n";
63 case cmPolicies::REQUIRED_IF_USED:
64 case cmPolicies::REQUIRED_ALWAYS:
67 messageType = MessageType::FATAL_ERROR;
71 e << "get_target_property() called with non-existent target \""
72 << targetName << "\".";
73 mf.IssueMessage(messageType, e.str());
74 if (messageType == MessageType::FATAL_ERROR) {
80 mf.AddDefinition(var, prop);
83 mf.AddDefinition(var, var + "-NOTFOUND");