cmake/Source/cmGetTargetPropertyCommand.cxx

89 lines
2.6 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGetTargetPropertyCommand.h"
2017-04-14 19:02:05 +02:00
#include <sstream>
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2020-08-30 11:54:41 +02:00
#include "cmGlobalGenerator.h"
2017-04-14 19:02:05 +02:00
#include "cmListFileCache.h"
#include "cmMakefile.h"
2019-11-11 23:01:05 +01:00
#include "cmMessageType.h"
2017-04-14 19:02:05 +02:00
#include "cmPolicies.h"
2020-08-30 11:54:41 +02:00
#include "cmProperty.h"
2017-04-14 19:02:05 +02:00
#include "cmTarget.h"
class cmMessenger;
2020-02-01 23:06:01 +01:00
bool cmGetTargetPropertyCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-07-09 11:21:54 +02:00
if (args.size() != 3) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
std::string const& var = args[0];
std::string const& targetName = args[1];
2015-04-27 22:25:09 +02:00
std::string prop;
bool prop_exists = false;
2020-02-01 23:06:01 +01:00
cmMakefile& mf = status.GetMakefile();
2020-02-01 23:06:01 +01:00
if (cmTarget* tgt = mf.FindTargetToUse(targetName)) {
2020-08-30 11:54:41 +02:00
if (args[2] == "ALIASED_TARGET" || args[2] == "ALIAS_GLOBAL") {
2020-02-01 23:06:01 +01:00
if (mf.IsAlias(targetName)) {
2016-10-30 18:24:19 +01:00
prop_exists = true;
2020-08-30 11:54:41 +02:00
if (args[2] == "ALIASED_TARGET") {
prop = tgt->GetName();
}
if (args[2] == "ALIAS_GLOBAL") {
prop =
mf.GetGlobalGenerator()->IsAlias(targetName) ? "TRUE" : "FALSE";
}
2016-10-30 18:24:19 +01:00
}
} else if (!args[2].empty()) {
2020-08-30 11:54:41 +02:00
cmProp prop_cstr = nullptr;
2020-02-01 23:06:01 +01:00
cmListFileBacktrace bt = mf.GetBacktrace();
cmMessenger* messenger = mf.GetMessenger();
2021-09-14 00:13:48 +02:00
prop_cstr = tgt->GetComputedProperty(args[2], messenger, bt);
if (!prop_cstr) {
prop_cstr = tgt->GetProperty(args[2]);
2017-04-14 19:02:05 +02:00
}
2016-10-30 18:24:19 +01:00
if (prop_cstr) {
2020-08-30 11:54:41 +02:00
prop = *prop_cstr;
2015-04-27 22:25:09 +02:00
prop_exists = true;
}
2014-08-03 19:52:23 +02:00
}
2016-07-09 11:21:54 +02:00
} else {
2014-08-03 19:52:23 +02:00
bool issueMessage = false;
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2019-11-11 23:01:05 +01:00
MessageType messageType = MessageType::AUTHOR_WARNING;
2020-02-01 23:06:01 +01:00
switch (mf.GetPolicyStatus(cmPolicies::CMP0045)) {
2014-08-03 19:52:23 +02:00
case cmPolicies::WARN:
issueMessage = true;
2015-08-17 11:37:30 +02:00
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0045) << "\n";
2014-08-03 19:52:23 +02:00
case cmPolicies::OLD:
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
issueMessage = true;
2019-11-11 23:01:05 +01:00
messageType = MessageType::FATAL_ERROR;
2016-07-09 11:21:54 +02:00
}
if (issueMessage) {
2014-08-03 19:52:23 +02:00
e << "get_target_property() called with non-existent target \""
2016-07-09 11:21:54 +02:00
<< targetName << "\".";
2020-02-01 23:06:01 +01:00
mf.IssueMessage(messageType, e.str());
2019-11-11 23:01:05 +01:00
if (messageType == MessageType::FATAL_ERROR) {
2014-08-03 19:52:23 +02:00
return false;
}
2013-11-03 12:27:13 +02:00
}
2016-07-09 11:21:54 +02:00
}
if (prop_exists) {
2020-02-01 23:06:01 +01:00
mf.AddDefinition(var, prop);
2013-11-03 12:27:13 +02:00
return true;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
mf.AddDefinition(var, var + "-NOTFOUND");
return true;
}