cmake/Source/cmTargetCompileDefinitionsCommand.cxx

61 lines
1.7 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"
2022-11-16 20:14:03 +01:00
#include "cmListFileCache.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
2019-11-11 23:01:05 +01:00
#include "cmMessageType.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
#include "cmTarget.h"
2020-02-01 23:06:01 +01:00
#include "cmTargetPropCommandBase.h"
2017-04-14 19:02:05 +02:00
2020-02-01 23:06:01 +01:00
namespace {
2015-08-17 11:37:30 +02:00
2020-02-01 23:06:01 +01:00
class TargetCompileDefinitionsImpl : public cmTargetPropCommandBase
2013-03-16 19:13:01 +02:00
{
2020-02-01 23:06:01 +01:00
public:
using cmTargetPropCommandBase::cmTargetPropCommandBase;
2013-03-16 19:13:01 +02:00
2020-02-01 23:06:01 +01:00
private:
void HandleMissingTarget(const std::string& name) override
{
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("Cannot specify compile definitions for target \"", name,
"\" which is not built by this project."));
}
2013-03-16 19:13:01 +02:00
2020-02-01 23:06:01 +01:00
bool HandleDirectContent(cmTarget* tgt,
const std::vector<std::string>& content,
bool /*prepend*/, bool /*system*/) override
{
2022-11-16 20:14:03 +01:00
tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content),
this->Makefile->GetBacktrace());
2020-02-01 23:06:01 +01:00
return true; // Successfully handled.
}
std::string Join(const std::vector<std::string>& content) override
{
std::string defs;
std::string sep;
for (std::string const& it : content) {
if (cmHasLiteralPrefix(it, "-D")) {
defs += sep + it.substr(2);
} else {
defs += sep + it;
}
sep = ";";
2013-03-16 19:13:01 +02:00
}
2020-02-01 23:06:01 +01:00
return defs;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
};
} // namespace
2013-03-16 19:13:01 +02:00
2020-02-01 23:06:01 +01:00
bool cmTargetCompileDefinitionsCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
2013-03-16 19:13:01 +02:00
{
2020-02-01 23:06:01 +01:00
return TargetCompileDefinitionsImpl(status).HandleArguments(
args, "COMPILE_DEFINITIONS");
2013-03-16 19:13:01 +02:00
}