cmake/Source/cmTargetCompileOptionsCommand.cxx

58 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-11-03 12:27:13 +02:00
#include "cmTargetCompileOptionsCommand.h"
2017-04-14 19:02:05 +02:00
#include "cmListFileCache.h"
#include "cmMakefile.h"
2019-11-11 23:01:05 +01:00
#include "cmMessageType.h"
2020-08-30 11:54:41 +02:00
#include "cmPolicies.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 TargetCompileOptionsImpl : public cmTargetPropCommandBase
2013-11-03 12:27:13 +02:00
{
2020-02-01 23:06:01 +01:00
public:
using cmTargetPropCommandBase::cmTargetPropCommandBase;
2013-11-03 12:27:13 +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 options for target \"", name,
"\" which is not built by this project."));
}
2013-11-03 12:27:13 +02:00
2020-02-01 23:06:01 +01:00
bool HandleDirectContent(cmTarget* tgt,
const std::vector<std::string>& content,
2020-08-30 11:54:41 +02:00
bool prepend, bool /*system*/) override
2020-02-01 23:06:01 +01:00
{
2020-08-30 11:54:41 +02:00
cmPolicies::PolicyStatus policyStatus =
this->Makefile->GetPolicyStatus(cmPolicies::CMP0101);
if (policyStatus == cmPolicies::OLD || policyStatus == cmPolicies::WARN) {
prepend = false;
}
2020-02-01 23:06:01 +01:00
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
2020-08-30 11:54:41 +02:00
tgt->InsertCompileOption(this->Join(content), lfbt, prepend);
2020-02-01 23:06:01 +01:00
return true; // Successfully handled.
}
std::string Join(const std::vector<std::string>& content) override
{
return cmJoin(content, ";");
}
};
} // namespace
2013-11-03 12:27:13 +02:00
2020-02-01 23:06:01 +01:00
bool cmTargetCompileOptionsCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
2013-11-03 12:27:13 +02:00
{
2020-02-01 23:06:01 +01:00
return TargetCompileOptionsImpl(status).HandleArguments(
args, "COMPILE_OPTIONS", TargetCompileOptionsImpl::PROCESS_BEFORE);
2013-11-03 12:27:13 +02:00
}