cmake/Source/cmTargetCompileDefinitionsCommand.cxx

55 lines
1.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. */
2013-03-16 19:13:01 +02:00
#include "cmTargetCompileDefinitionsCommand.h"
2015-08-17 11:37:30 +02:00
#include "cmAlgorithms.h"
2016-07-09 11:21:54 +02:00
bool cmTargetCompileDefinitionsCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
2013-03-16 19:13:01 +02:00
{
return this->HandleArguments(args, "COMPILE_DEFINITIONS");
}
2016-07-09 11:21:54 +02:00
void cmTargetCompileDefinitionsCommand::HandleImportedTarget(
const std::string& tgt)
2013-03-16 19:13:01 +02:00
{
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2016-07-09 11:21:54 +02:00
e << "Cannot specify compile definitions for imported target \"" << tgt
<< "\".";
2013-03-16 19:13:01 +02:00
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
}
2016-07-09 11:21:54 +02:00
void cmTargetCompileDefinitionsCommand::HandleMissingTarget(
const std::string& name)
2013-03-16 19:13:01 +02:00
{
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2016-07-09 11:21:54 +02:00
e << "Cannot specify compile definitions for target \"" << name
<< "\" "
2013-03-16 19:13:01 +02:00
"which is not built by this project.";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
}
2016-07-09 11:21:54 +02:00
std::string cmTargetCompileDefinitionsCommand::Join(
const std::vector<std::string>& content)
2013-03-16 19:13:01 +02:00
{
std::string defs;
std::string sep;
2016-07-09 11:21:54 +02:00
for (std::vector<std::string>::const_iterator it = content.begin();
it != content.end(); ++it) {
if (cmHasLiteralPrefix(it->c_str(), "-D")) {
2013-03-16 19:13:01 +02:00
defs += sep + it->substr(2);
2016-07-09 11:21:54 +02:00
} else {
2013-03-16 19:13:01 +02:00
defs += sep + *it;
}
2016-07-09 11:21:54 +02:00
sep = ";";
}
2013-03-16 19:13:01 +02:00
return defs;
}
2016-07-09 11:21:54 +02:00
bool cmTargetCompileDefinitionsCommand::HandleDirectContent(
cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
2013-03-16 19:13:01 +02:00
{
tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
2015-04-27 22:25:09 +02:00
return true;
2013-03-16 19:13:01 +02:00
}