2013-01-02 02:20:04 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2013 Stephen Kelly <steveire@gmail.com>
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
|
|
|
|
#include "cmTargetPropCommandBase.h"
|
|
|
|
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmTargetPropCommandBase
|
2013-09-03 00:27:32 +04:00
|
|
|
::HandleArguments(std::vector<std::string> const& args,
|
|
|
|
const std::string& prop,
|
|
|
|
ArgumentFlags flags)
|
2013-01-02 02:20:04 +04:00
|
|
|
{
|
2013-07-31 18:02:07 +04:00
|
|
|
if(args.size() < 2)
|
2013-01-02 02:20:04 +04:00
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup the target for which libraries are specified.
|
2014-01-16 02:56:38 +04:00
|
|
|
if (this->Makefile->IsAlias(args[0]))
|
2013-07-12 11:14:31 +04:00
|
|
|
{
|
|
|
|
this->SetError("can not be used on an ALIAS target.");
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-02 02:20:04 +04:00
|
|
|
this->Target =
|
|
|
|
this->Makefile->GetCMakeInstance()
|
|
|
|
->GetGlobalGenerator()->FindTarget(0, args[0].c_str());
|
|
|
|
if(!this->Target)
|
|
|
|
{
|
2014-01-16 02:56:38 +04:00
|
|
|
this->Target = this->Makefile->FindTargetToUse(args[0]);
|
2013-01-02 02:20:04 +04:00
|
|
|
}
|
|
|
|
if(!this->Target)
|
|
|
|
{
|
|
|
|
this->HandleMissingTarget(args[0]);
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-08 22:12:45 +04:00
|
|
|
if ((this->Target->GetType() != cmTarget::SHARED_LIBRARY)
|
|
|
|
&& (this->Target->GetType() != cmTarget::STATIC_LIBRARY)
|
|
|
|
&& (this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
|
|
|
|
&& (this->Target->GetType() != cmTarget::MODULE_LIBRARY)
|
2012-11-02 18:47:40 +04:00
|
|
|
&& (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
|
2013-02-08 22:12:45 +04:00
|
|
|
&& (this->Target->GetType() != cmTarget::EXECUTABLE))
|
|
|
|
{
|
|
|
|
this->SetError("called with non-compilable target type");
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-02 02:20:04 +04:00
|
|
|
|
2013-01-20 17:04:13 +04:00
|
|
|
bool system = false;
|
2013-01-02 02:20:04 +04:00
|
|
|
unsigned int argIndex = 1;
|
|
|
|
|
2013-01-20 17:04:13 +04:00
|
|
|
if ((flags & PROCESS_SYSTEM) && args[argIndex] == "SYSTEM")
|
|
|
|
{
|
2013-07-31 18:02:07 +04:00
|
|
|
if (args.size() < 3)
|
2013-01-20 17:04:13 +04:00
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
system = true;
|
|
|
|
++argIndex;
|
|
|
|
}
|
|
|
|
|
2013-01-02 02:20:04 +04:00
|
|
|
bool prepend = false;
|
|
|
|
if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE")
|
|
|
|
{
|
2013-07-31 18:02:07 +04:00
|
|
|
if (args.size() < 3)
|
2013-01-02 02:20:04 +04:00
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
prepend = true;
|
|
|
|
++argIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->Property = prop;
|
|
|
|
|
|
|
|
while (argIndex < args.size())
|
|
|
|
{
|
2013-01-20 17:04:13 +04:00
|
|
|
if (!this->ProcessContentArgs(args, argIndex, prepend, system))
|
2013-01-02 02:20:04 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmTargetPropCommandBase
|
|
|
|
::ProcessContentArgs(std::vector<std::string> const& args,
|
2013-01-20 17:04:13 +04:00
|
|
|
unsigned int &argIndex, bool prepend, bool system)
|
2013-01-02 02:20:04 +04:00
|
|
|
{
|
|
|
|
const std::string scope = args[argIndex];
|
|
|
|
|
|
|
|
if(scope != "PUBLIC"
|
|
|
|
&& scope != "PRIVATE"
|
|
|
|
&& scope != "INTERFACE" )
|
|
|
|
{
|
|
|
|
this->SetError("called with invalid arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-21 15:28:27 +04:00
|
|
|
if(this->Target->IsImported())
|
2013-01-02 02:20:04 +04:00
|
|
|
{
|
2013-01-21 15:28:27 +04:00
|
|
|
this->HandleImportedTarget(args[0]);
|
2013-01-02 02:20:04 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-02 18:47:40 +04:00
|
|
|
if (this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
|
|
|
|
&& scope != "INTERFACE")
|
|
|
|
{
|
|
|
|
this->SetError("may only be set INTERFACE properties on INTERFACE "
|
|
|
|
"targets");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-02 02:20:04 +04:00
|
|
|
++argIndex;
|
|
|
|
|
2013-01-29 20:23:31 +04:00
|
|
|
std::vector<std::string> content;
|
2013-01-02 02:20:04 +04:00
|
|
|
|
|
|
|
for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
|
|
|
|
{
|
|
|
|
if(args[i] == "PUBLIC"
|
|
|
|
|| args[i] == "PRIVATE"
|
|
|
|
|| args[i] == "INTERFACE" )
|
|
|
|
{
|
2013-01-20 17:04:13 +04:00
|
|
|
this->PopulateTargetProperies(scope, content, prepend, system);
|
2013-01-02 02:20:04 +04:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-29 20:23:31 +04:00
|
|
|
content.push_back(args[i]);
|
2013-01-02 02:20:04 +04:00
|
|
|
}
|
2013-01-20 17:04:13 +04:00
|
|
|
this->PopulateTargetProperies(scope, content, prepend, system);
|
2013-01-02 02:20:04 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmTargetPropCommandBase
|
|
|
|
::PopulateTargetProperies(const std::string &scope,
|
2013-01-29 20:23:31 +04:00
|
|
|
const std::vector<std::string> &content,
|
2013-01-20 17:04:13 +04:00
|
|
|
bool prepend, bool system)
|
2013-01-02 02:20:04 +04:00
|
|
|
{
|
|
|
|
if (scope == "PRIVATE" || scope == "PUBLIC")
|
|
|
|
{
|
2013-01-20 17:04:13 +04:00
|
|
|
this->HandleDirectContent(this->Target, content, prepend, system);
|
2013-01-02 02:20:04 +04:00
|
|
|
}
|
|
|
|
if (scope == "INTERFACE" || scope == "PUBLIC")
|
|
|
|
{
|
2013-01-20 17:04:13 +04:00
|
|
|
this->HandleInterfaceContent(this->Target, content, prepend, system);
|
2013-07-02 01:19:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmTargetPropCommandBase::HandleInterfaceContent(cmTarget *tgt,
|
|
|
|
const std::vector<std::string> &content,
|
2013-01-20 17:04:13 +04:00
|
|
|
bool prepend, bool)
|
2013-07-02 01:19:25 +04:00
|
|
|
{
|
|
|
|
if (prepend)
|
|
|
|
{
|
|
|
|
const std::string propName = std::string("INTERFACE_") + this->Property;
|
|
|
|
const char *propValue = tgt->GetProperty(propName.c_str());
|
|
|
|
const std::string totalContent = this->Join(content) + (propValue
|
|
|
|
? std::string(";") + propValue
|
|
|
|
: std::string());
|
|
|
|
tgt->SetProperty(propName.c_str(), totalContent.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tgt->AppendProperty(("INTERFACE_" + this->Property).c_str(),
|
|
|
|
this->Join(content).c_str());
|
2013-01-02 02:20:04 +04:00
|
|
|
}
|
|
|
|
}
|