2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2013-01-01 22:20:04 +00:00
|
|
|
#include "cmTargetPropCommandBase.h"
|
|
|
|
|
|
|
|
#include "cmGlobalGenerator.h"
|
2016-10-25 18:35:04 +00:00
|
|
|
#include "cmMakefile.h"
|
2016-11-05 20:40:14 +00:00
|
|
|
#include "cmStateTypes.h"
|
|
|
|
#include "cmTarget.h"
|
|
|
|
#include "cmake.h"
|
2013-01-01 22:20:04 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmTargetPropCommandBase::HandleArguments(
|
|
|
|
std::vector<std::string> const& args, const std::string& prop,
|
|
|
|
ArgumentFlags flags)
|
2013-01-01 22:20:04 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() < 2) {
|
2013-01-01 22:20:04 +00:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-01 22:20:04 +00:00
|
|
|
|
|
|
|
// Lookup the target for which libraries are specified.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->Makefile->IsAlias(args[0])) {
|
2013-07-12 07:14:31 +00:00
|
|
|
this->SetError("can not be used on an ALIAS target.");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-01 22:20:04 +00:00
|
|
|
this->Target =
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Makefile->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(
|
|
|
|
args[0]);
|
|
|
|
if (!this->Target) {
|
2014-01-15 22:56:38 +00:00
|
|
|
this->Target = this->Makefile->FindTargetToUse(args[0]);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!this->Target) {
|
2013-01-01 22:20:04 +00:00
|
|
|
this->HandleMissingTarget(args[0]);
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2016-10-18 19:28:46 +00:00
|
|
|
if ((this->Target->GetType() != cmStateEnums::SHARED_LIBRARY) &&
|
|
|
|
(this->Target->GetType() != cmStateEnums::STATIC_LIBRARY) &&
|
|
|
|
(this->Target->GetType() != cmStateEnums::OBJECT_LIBRARY) &&
|
|
|
|
(this->Target->GetType() != cmStateEnums::MODULE_LIBRARY) &&
|
|
|
|
(this->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) &&
|
|
|
|
(this->Target->GetType() != cmStateEnums::EXECUTABLE)) {
|
2013-02-08 18:12:45 +00:00
|
|
|
this->SetError("called with non-compilable target type");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-01 22:20:04 +00:00
|
|
|
|
2013-01-20 13:04:13 +00:00
|
|
|
bool system = false;
|
2013-01-01 22:20:04 +00:00
|
|
|
unsigned int argIndex = 1;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if ((flags & PROCESS_SYSTEM) && args[argIndex] == "SYSTEM") {
|
|
|
|
if (args.size() < 3) {
|
2013-01-20 13:04:13 +00:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-20 13:04:13 +00:00
|
|
|
system = true;
|
|
|
|
++argIndex;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-20 13:04:13 +00:00
|
|
|
|
2013-01-01 22:20:04 +00:00
|
|
|
bool prepend = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE") {
|
|
|
|
if (args.size() < 3) {
|
2013-01-01 22:20:04 +00:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-01 22:20:04 +00:00
|
|
|
prepend = true;
|
|
|
|
++argIndex;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-01 22:20:04 +00:00
|
|
|
|
|
|
|
this->Property = prop;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
while (argIndex < args.size()) {
|
|
|
|
if (!this->ProcessContentArgs(args, argIndex, prepend, system)) {
|
2013-01-01 22:20:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-01 22:20:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmTargetPropCommandBase::ProcessContentArgs(
|
|
|
|
std::vector<std::string> const& args, unsigned int& argIndex, bool prepend,
|
|
|
|
bool system)
|
2013-01-01 22:20:04 +00:00
|
|
|
{
|
|
|
|
const std::string scope = args[argIndex];
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (scope != "PUBLIC" && scope != "PRIVATE" && scope != "INTERFACE") {
|
2013-01-01 22:20:04 +00:00
|
|
|
this->SetError("called with invalid arguments");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-01 22:20:04 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->Target->IsImported()) {
|
2013-01-21 11:28:27 +00:00
|
|
|
this->HandleImportedTarget(args[0]);
|
2013-01-01 22:20:04 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-01-01 22:20:04 +00:00
|
|
|
|
2016-10-18 19:28:46 +00:00
|
|
|
if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY &&
|
2016-05-16 14:34:04 +00:00
|
|
|
scope != "INTERFACE") {
|
2012-11-02 14:47:40 +00:00
|
|
|
this->SetError("may only be set INTERFACE properties on INTERFACE "
|
2016-05-16 14:34:04 +00:00
|
|
|
"targets");
|
2012-11-02 14:47:40 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-11-02 14:47:40 +00:00
|
|
|
|
2013-01-01 22:20:04 +00:00
|
|
|
++argIndex;
|
|
|
|
|
2013-01-29 16:23:31 +00:00
|
|
|
std::vector<std::string> content;
|
2013-01-01 22:20:04 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (unsigned int i = argIndex; i < args.size(); ++i, ++argIndex) {
|
|
|
|
if (args[i] == "PUBLIC" || args[i] == "PRIVATE" ||
|
|
|
|
args[i] == "INTERFACE") {
|
2013-11-08 23:18:35 +00:00
|
|
|
return this->PopulateTargetProperies(scope, content, prepend, system);
|
2013-01-01 22:20:04 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
content.push_back(args[i]);
|
|
|
|
}
|
2013-11-08 23:18:35 +00:00
|
|
|
return this->PopulateTargetProperies(scope, content, prepend, system);
|
2013-01-01 22:20:04 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmTargetPropCommandBase::PopulateTargetProperies(
|
|
|
|
const std::string& scope, const std::vector<std::string>& content,
|
|
|
|
bool prepend, bool system)
|
2013-01-01 22:20:04 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (scope == "PRIVATE" || scope == "PUBLIC") {
|
|
|
|
if (!this->HandleDirectContent(this->Target, content, prepend, system)) {
|
2013-11-08 23:18:35 +00:00
|
|
|
return false;
|
2013-01-01 22:20:04 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (scope == "INTERFACE" || scope == "PUBLIC") {
|
2013-01-20 13:04:13 +00:00
|
|
|
this->HandleInterfaceContent(this->Target, content, prepend, system);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-11-08 23:18:35 +00:00
|
|
|
return true;
|
2013-07-01 21:19:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmTargetPropCommandBase::HandleInterfaceContent(
|
|
|
|
cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool)
|
2013-07-01 21:19:25 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (prepend) {
|
2013-07-01 21:19:25 +00:00
|
|
|
const std::string propName = std::string("INTERFACE_") + this->Property;
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* propValue = tgt->GetProperty(propName);
|
|
|
|
const std::string totalContent = this->Join(content) +
|
|
|
|
(propValue ? std::string(";") + propValue : std::string());
|
2014-03-10 23:04:11 +00:00
|
|
|
tgt->SetProperty(propName, totalContent.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2014-03-10 23:04:11 +00:00
|
|
|
tgt->AppendProperty("INTERFACE_" + this->Property,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Join(content).c_str());
|
|
|
|
}
|
2013-01-01 22:20:04 +00:00
|
|
|
}
|