cmake/Source/cmGetTargetPropertyCommand.cxx

84 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>
#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmPolicies.h"
#include "cmTarget.h"
#include "cmTargetPropertyComputer.h"
#include "cmake.h"
class cmExecutionStatus;
class cmMessenger;
// cmSetTargetPropertyCommand
2016-07-09 11:21:54 +02:00
bool cmGetTargetPropertyCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
2016-07-09 11:21:54 +02:00
if (args.size() != 3) {
this->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;
2016-10-30 18:24:19 +01:00
if (cmTarget* tgt = this->Makefile->FindTargetToUse(targetName)) {
if (args[2] == "ALIASED_TARGET") {
if (this->Makefile->IsAlias(targetName)) {
prop = tgt->GetName();
prop_exists = true;
}
} else if (!args[2].empty()) {
2018-01-26 17:06:56 +01:00
const char* prop_cstr = nullptr;
2017-04-14 19:02:05 +02:00
cmListFileBacktrace bt = this->Makefile->GetBacktrace();
cmMessenger* messenger = this->Makefile->GetMessenger();
if (cmTargetPropertyComputer::PassesWhitelist(tgt->GetType(), args[2],
messenger, bt)) {
prop_cstr = tgt->GetComputedProperty(args[2], messenger, bt);
if (!prop_cstr) {
prop_cstr = tgt->GetProperty(args[2]);
}
}
2016-10-30 18:24:19 +01:00
if (prop_cstr) {
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;
2014-08-03 19:52:23 +02:00
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
2016-07-09 11:21:54 +02:00
switch (this->Makefile->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;
messageType = cmake::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 << "\".";
2015-04-27 22:25:09 +02:00
this->Makefile->IssueMessage(messageType, e.str());
2016-07-09 11:21:54 +02:00
if (messageType == cmake::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) {
2015-04-27 22:25:09 +02:00
this->Makefile->AddDefinition(var, prop.c_str());
2013-11-03 12:27:13 +02:00
return true;
2016-07-09 11:21:54 +02:00
}
this->Makefile->AddDefinition(var, (var + "-NOTFOUND").c_str());
return true;
}