mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-09 23:59:53 -05:00
cmTarget*: Port away from cmCommand
This commit is contained in:
committed by
Brad King
parent
dcc117b944
commit
9d1a1bc495
+11
-16
@@ -246,26 +246,22 @@ void GetProjectCommands(cmState* state)
|
||||
state->AddBuiltinCommand("set_tests_properties",
|
||||
cmSetTestsPropertiesCommand);
|
||||
state->AddBuiltinCommand("subdirs", cmSubdirCommand);
|
||||
state->AddBuiltinCommand(
|
||||
"target_compile_definitions",
|
||||
cm::make_unique<cmTargetCompileDefinitionsCommand>());
|
||||
state->AddBuiltinCommand("target_compile_definitions",
|
||||
cmTargetCompileDefinitionsCommand);
|
||||
state->AddBuiltinCommand("target_compile_features",
|
||||
cm::make_unique<cmTargetCompileFeaturesCommand>());
|
||||
cmTargetCompileFeaturesCommand);
|
||||
state->AddBuiltinCommand("target_compile_options",
|
||||
cm::make_unique<cmTargetCompileOptionsCommand>());
|
||||
state->AddBuiltinCommand(
|
||||
"target_include_directories",
|
||||
cm::make_unique<cmTargetIncludeDirectoriesCommand>());
|
||||
cmTargetCompileOptionsCommand);
|
||||
state->AddBuiltinCommand("target_include_directories",
|
||||
cmTargetIncludeDirectoriesCommand);
|
||||
state->AddBuiltinCommand("target_link_libraries",
|
||||
cmTargetLinkLibrariesCommand);
|
||||
state->AddBuiltinCommand("target_sources",
|
||||
cm::make_unique<cmTargetSourcesCommand>());
|
||||
state->AddBuiltinCommand("target_sources", cmTargetSourcesCommand);
|
||||
state->AddBuiltinCommand("try_compile",
|
||||
cm::make_unique<cmTryCompileCommand>());
|
||||
state->AddBuiltinCommand("try_run", cm::make_unique<cmTryRunCommand>());
|
||||
state->AddBuiltinCommand(
|
||||
"target_precompile_headers",
|
||||
cm::make_unique<cmTargetPrecompileHeadersCommand>());
|
||||
state->AddBuiltinCommand("target_precompile_headers",
|
||||
cmTargetPrecompileHeadersCommand);
|
||||
|
||||
#if !defined(CMAKE_BOOTSTRAP)
|
||||
state->AddBuiltinCommand("add_compile_definitions",
|
||||
@@ -280,10 +276,9 @@ void GetProjectCommands(cmState* state)
|
||||
state->AddBuiltinCommand("install_programs", cmInstallProgramsCommand);
|
||||
state->AddBuiltinCommand("add_link_options", cmAddLinkOptionsCommand);
|
||||
state->AddBuiltinCommand("link_libraries", cmLinkLibrariesCommand);
|
||||
state->AddBuiltinCommand("target_link_options",
|
||||
cm::make_unique<cmTargetLinkOptionsCommand>());
|
||||
state->AddBuiltinCommand("target_link_options", cmTargetLinkOptionsCommand);
|
||||
state->AddBuiltinCommand("target_link_directories",
|
||||
cm::make_unique<cmTargetLinkDirectoriesCommand>());
|
||||
cmTargetLinkDirectoriesCommand);
|
||||
state->AddBuiltinCommand("load_cache", cmLoadCacheCommand);
|
||||
state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand);
|
||||
state->AddBuiltinCommand("qt_wrap_ui", cmQTWrapUICommand);
|
||||
|
||||
@@ -6,43 +6,53 @@
|
||||
#include "cmMessageType.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
namespace {
|
||||
|
||||
bool cmTargetCompileDefinitionsCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
class TargetCompileDefinitionsImpl : public cmTargetPropCommandBase
|
||||
{
|
||||
return this->HandleArguments(args, "COMPILE_DEFINITIONS");
|
||||
}
|
||||
public:
|
||||
using cmTargetPropCommandBase::cmTargetPropCommandBase;
|
||||
|
||||
void cmTargetCompileDefinitionsCommand::HandleMissingTarget(
|
||||
const std::string& name)
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify compile definitions for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
|
||||
std::string cmTargetCompileDefinitionsCommand::Join(
|
||||
const std::vector<std::string>& content)
|
||||
{
|
||||
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 = ";";
|
||||
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."));
|
||||
}
|
||||
return defs;
|
||||
}
|
||||
|
||||
bool cmTargetCompileDefinitionsCommand::HandleDirectContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool /*prepend*/, bool /*system*/) override
|
||||
{
|
||||
tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
|
||||
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 = ";";
|
||||
}
|
||||
return defs;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool cmTargetCompileDefinitionsCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
|
||||
return true; // Successfully handled.
|
||||
return TargetCompileDefinitionsImpl(status).HandleArguments(
|
||||
args, "COMPILE_DEFINITIONS");
|
||||
}
|
||||
|
||||
@@ -8,39 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCommand.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmTarget;
|
||||
|
||||
class cmTargetCompileDefinitionsCommand : public cmTargetPropCommandBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This is a virtual constructor for the command.
|
||||
*/
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmTargetCompileDefinitionsCommand>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the CMakeLists.txt file.
|
||||
*/
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override;
|
||||
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
};
|
||||
bool cmTargetCompileDefinitionsCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,40 +5,51 @@
|
||||
#include "cmMakefile.h"
|
||||
#include "cmMessageType.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmTarget;
|
||||
|
||||
bool cmTargetCompileFeaturesCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
{
|
||||
return this->HandleArguments(args, "COMPILE_FEATURES", NO_FLAGS);
|
||||
}
|
||||
namespace {
|
||||
|
||||
void cmTargetCompileFeaturesCommand::HandleMissingTarget(
|
||||
const std::string& name)
|
||||
class TargetCompileFeaturesImpl : public cmTargetPropCommandBase
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify compile features for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
public:
|
||||
using cmTargetPropCommandBase::cmTargetPropCommandBase;
|
||||
|
||||
std::string cmTargetCompileFeaturesCommand::Join(
|
||||
const std::vector<std::string>& content)
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
|
||||
bool cmTargetCompileFeaturesCommand::HandleDirectContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
|
||||
{
|
||||
for (std::string const& it : content) {
|
||||
std::string error;
|
||||
if (!this->Makefile->AddRequiredTargetFeature(tgt, it, &error)) {
|
||||
this->SetError(error);
|
||||
return false; // Not (successfully) handled.
|
||||
}
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify compile features for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
return true; // Successfully handled.
|
||||
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool /*prepend*/, bool /*system*/) override
|
||||
{
|
||||
for (std::string const& it : content) {
|
||||
std::string error;
|
||||
if (!this->Makefile->AddRequiredTargetFeature(tgt, it, &error)) {
|
||||
this->SetError(error);
|
||||
return false; // Not (successfully) handled.
|
||||
}
|
||||
}
|
||||
return true; // Successfully handled.
|
||||
}
|
||||
|
||||
std::string Join(const std::vector<std::string>& content) override
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool cmTargetCompileFeaturesCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
return TargetCompileFeaturesImpl(status).HandleArguments(args,
|
||||
"COMPILE_FEATURES");
|
||||
}
|
||||
|
||||
@@ -8,31 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCommand.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmTarget;
|
||||
|
||||
class cmTargetCompileFeaturesCommand : public cmTargetPropCommandBase
|
||||
{
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmTargetCompileFeaturesCommand>();
|
||||
}
|
||||
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override;
|
||||
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
};
|
||||
bool cmTargetCompileFeaturesCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,34 +7,44 @@
|
||||
#include "cmMessageType.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
namespace {
|
||||
|
||||
bool cmTargetCompileOptionsCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
class TargetCompileOptionsImpl : public cmTargetPropCommandBase
|
||||
{
|
||||
return this->HandleArguments(args, "COMPILE_OPTIONS", PROCESS_BEFORE);
|
||||
}
|
||||
public:
|
||||
using cmTargetPropCommandBase::cmTargetPropCommandBase;
|
||||
|
||||
void cmTargetCompileOptionsCommand::HandleMissingTarget(
|
||||
const std::string& name)
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify compile options for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
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."));
|
||||
}
|
||||
|
||||
std::string cmTargetCompileOptionsCommand::Join(
|
||||
const std::vector<std::string>& content)
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool /*prepend*/, bool /*system*/) override
|
||||
{
|
||||
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
|
||||
tgt->InsertCompileOption(this->Join(content), lfbt);
|
||||
return true; // Successfully handled.
|
||||
}
|
||||
|
||||
bool cmTargetCompileOptionsCommand::HandleDirectContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
|
||||
std::string Join(const std::vector<std::string>& content) override
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool cmTargetCompileOptionsCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
|
||||
tgt->InsertCompileOption(this->Join(content), lfbt);
|
||||
return true; // Successfully handled.
|
||||
return TargetCompileOptionsImpl(status).HandleArguments(
|
||||
args, "COMPILE_OPTIONS", TargetCompileOptionsImpl::PROCESS_BEFORE);
|
||||
}
|
||||
|
||||
@@ -8,39 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCommand.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmTarget;
|
||||
|
||||
class cmTargetCompileOptionsCommand : public cmTargetPropCommandBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This is a virtual constructor for the command.
|
||||
*/
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmTargetCompileOptionsCommand>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the CMakeLists.txt file.
|
||||
*/
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override;
|
||||
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
};
|
||||
bool cmTargetCompileOptionsCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,26 +11,36 @@
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
namespace {
|
||||
|
||||
bool cmTargetIncludeDirectoriesCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
class TargetIncludeDirectoriesImpl : public cmTargetPropCommandBase
|
||||
{
|
||||
return this->HandleArguments(args, "INCLUDE_DIRECTORIES",
|
||||
ArgumentFlags(PROCESS_BEFORE | PROCESS_SYSTEM));
|
||||
}
|
||||
public:
|
||||
using cmTargetPropCommandBase::cmTargetPropCommandBase;
|
||||
|
||||
void cmTargetIncludeDirectoriesCommand::HandleMissingTarget(
|
||||
const std::string& name)
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify include directories for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify include directories for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
|
||||
std::string cmTargetIncludeDirectoriesCommand::Join(
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
|
||||
void HandleInterfaceContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
};
|
||||
|
||||
std::string TargetIncludeDirectoriesImpl::Join(
|
||||
const std::vector<std::string>& content)
|
||||
{
|
||||
std::string dirs;
|
||||
@@ -48,7 +58,7 @@ std::string cmTargetIncludeDirectoriesCommand::Join(
|
||||
return dirs;
|
||||
}
|
||||
|
||||
bool cmTargetIncludeDirectoriesCommand::HandleDirectContent(
|
||||
bool TargetIncludeDirectoriesImpl::HandleDirectContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
|
||||
bool system)
|
||||
{
|
||||
@@ -70,16 +80,27 @@ bool cmTargetIncludeDirectoriesCommand::HandleDirectContent(
|
||||
return true; // Successfully handled.
|
||||
}
|
||||
|
||||
void cmTargetIncludeDirectoriesCommand::HandleInterfaceContent(
|
||||
void TargetIncludeDirectoriesImpl::HandleInterfaceContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
|
||||
bool system)
|
||||
{
|
||||
cmTargetPropCommandBase::HandleInterfaceContent(tgt, content, prepend,
|
||||
system);
|
||||
|
||||
if (system) {
|
||||
std::string joined = this->Join(content);
|
||||
tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES",
|
||||
joined.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool cmTargetIncludeDirectoriesCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
return TargetIncludeDirectoriesImpl(status).HandleArguments(
|
||||
args, "INCLUDE_DIRECTORIES",
|
||||
TargetIncludeDirectoriesImpl::ArgumentFlags(
|
||||
TargetIncludeDirectoriesImpl::PROCESS_BEFORE |
|
||||
TargetIncludeDirectoriesImpl::PROCESS_SYSTEM));
|
||||
}
|
||||
|
||||
@@ -8,43 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCommand.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmTarget;
|
||||
|
||||
class cmTargetIncludeDirectoriesCommand : public cmTargetPropCommandBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This is a virtual constructor for the command.
|
||||
*/
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmTargetIncludeDirectoriesCommand>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the CMakeLists.txt file.
|
||||
*/
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override;
|
||||
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
void HandleInterfaceContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
};
|
||||
bool cmTargetIncludeDirectoriesCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,25 +9,37 @@
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
namespace {
|
||||
|
||||
bool cmTargetLinkDirectoriesCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
class TargetLinkDirectoriesImpl : public cmTargetPropCommandBase
|
||||
{
|
||||
return this->HandleArguments(args, "LINK_DIRECTORIES", PROCESS_BEFORE);
|
||||
}
|
||||
public:
|
||||
using cmTargetPropCommandBase::cmTargetPropCommandBase;
|
||||
|
||||
void cmTargetLinkDirectoriesCommand::HandleMissingTarget(
|
||||
const std::string& name)
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify link directories for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify link directories for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
|
||||
std::string cmTargetLinkDirectoriesCommand::Join(
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool /*system*/) override
|
||||
{
|
||||
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
|
||||
tgt->InsertLinkDirectory(this->Join(content), lfbt, prepend);
|
||||
return true; // Successfully handled.
|
||||
}
|
||||
};
|
||||
|
||||
std::string TargetLinkDirectoriesImpl::Join(
|
||||
const std::vector<std::string>& content)
|
||||
{
|
||||
std::vector<std::string> directories;
|
||||
@@ -48,12 +60,11 @@ std::string cmTargetLinkDirectoriesCommand::Join(
|
||||
return cmJoin(directories, ";");
|
||||
}
|
||||
|
||||
bool cmTargetLinkDirectoriesCommand::HandleDirectContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool)
|
||||
} // namespace
|
||||
|
||||
bool cmTargetLinkDirectoriesCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
|
||||
|
||||
tgt->InsertLinkDirectory(this->Join(content), lfbt, prepend);
|
||||
|
||||
return true; // Successfully handled.
|
||||
return TargetLinkDirectoriesImpl(status).HandleArguments(
|
||||
args, "LINK_DIRECTORIES", TargetLinkDirectoriesImpl::PROCESS_BEFORE);
|
||||
}
|
||||
|
||||
@@ -8,39 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCommand.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmTarget;
|
||||
|
||||
class cmTargetLinkDirectoriesCommand : public cmTargetPropCommandBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This is a virtual constructor for the command.
|
||||
*/
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmTargetLinkDirectoriesCommand>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the CMakeLists.txt file.
|
||||
*/
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override;
|
||||
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
};
|
||||
bool cmTargetLinkDirectoriesCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,33 +7,44 @@
|
||||
#include "cmMessageType.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
namespace {
|
||||
|
||||
bool cmTargetLinkOptionsCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
class TargetLinkOptionsImpl : public cmTargetPropCommandBase
|
||||
{
|
||||
return this->HandleArguments(args, "LINK_OPTIONS", PROCESS_BEFORE);
|
||||
}
|
||||
public:
|
||||
using cmTargetPropCommandBase::cmTargetPropCommandBase;
|
||||
|
||||
void cmTargetLinkOptionsCommand::HandleMissingTarget(const std::string& name)
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify link options for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify link options for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
|
||||
std::string cmTargetLinkOptionsCommand::Join(
|
||||
const std::vector<std::string>& content)
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool /*system*/) override
|
||||
{
|
||||
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
|
||||
tgt->InsertLinkOption(this->Join(content), lfbt, prepend);
|
||||
return true; // Successfully handled.
|
||||
}
|
||||
|
||||
bool cmTargetLinkOptionsCommand::HandleDirectContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool)
|
||||
std::string Join(const std::vector<std::string>& content) override
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool cmTargetLinkOptionsCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
|
||||
tgt->InsertLinkOption(this->Join(content), lfbt, prepend);
|
||||
return true; // Successfully handled.
|
||||
return TargetLinkOptionsImpl(status).HandleArguments(
|
||||
args, "LINK_OPTIONS", TargetLinkOptionsImpl::PROCESS_BEFORE);
|
||||
}
|
||||
|
||||
@@ -8,39 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCommand.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmTarget;
|
||||
|
||||
class cmTargetLinkOptionsCommand : public cmTargetPropCommandBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This is a virtual constructor for the command.
|
||||
*/
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmTargetLinkOptionsCommand>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the CMakeLists.txt file.
|
||||
*/
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override;
|
||||
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
};
|
||||
bool cmTargetLinkOptionsCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,51 +8,14 @@
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
bool cmTargetPrecompileHeadersCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
{
|
||||
return this->HandleArguments(args, "PRECOMPILE_HEADERS", PROCESS_REUSE_FROM);
|
||||
}
|
||||
namespace {
|
||||
|
||||
void cmTargetPrecompileHeadersCommand::HandleInterfaceContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
|
||||
bool system)
|
||||
{
|
||||
cmTargetPropCommandBase::HandleInterfaceContent(
|
||||
tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system);
|
||||
}
|
||||
|
||||
void cmTargetPrecompileHeadersCommand::HandleMissingTarget(
|
||||
const std::string& name)
|
||||
{
|
||||
const std::string e =
|
||||
cmStrCat("Cannot specify precompile headers for target \"", name,
|
||||
"\" which is not built by this project.");
|
||||
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
|
||||
}
|
||||
|
||||
std::string cmTargetPrecompileHeadersCommand::Join(
|
||||
const std::vector<std::string>& content)
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
|
||||
bool cmTargetPrecompileHeadersCommand::HandleDirectContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
|
||||
{
|
||||
tgt->AppendProperty(
|
||||
"PRECOMPILE_HEADERS",
|
||||
this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
cmTargetPrecompileHeadersCommand::ConvertToAbsoluteContent(
|
||||
cmTarget* /*tgt*/, const std::vector<std::string>& content,
|
||||
bool /*isInterfaceContent*/)
|
||||
std::vector<std::string> ConvertToAbsoluteContent(
|
||||
const std::vector<std::string>& content, std::string const& baseDir)
|
||||
{
|
||||
std::vector<std::string> absoluteContent;
|
||||
absoluteContent.reserve(content.size());
|
||||
@@ -66,10 +29,59 @@ cmTargetPrecompileHeadersCommand::ConvertToAbsoluteContent(
|
||||
cmGeneratorExpression::Find(src) == 0) {
|
||||
absoluteSrc = src;
|
||||
} else {
|
||||
absoluteSrc =
|
||||
cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/', src);
|
||||
absoluteSrc = cmStrCat(baseDir, '/', src);
|
||||
}
|
||||
absoluteContent.emplace_back(std::move(absoluteSrc));
|
||||
}
|
||||
return absoluteContent;
|
||||
}
|
||||
|
||||
class TargetPrecompileHeadersImpl : public cmTargetPropCommandBase
|
||||
{
|
||||
public:
|
||||
using cmTargetPropCommandBase::cmTargetPropCommandBase;
|
||||
|
||||
private:
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool /*prepend*/, bool /*system*/) override
|
||||
{
|
||||
std::string const& base = this->Makefile->GetCurrentSourceDirectory();
|
||||
tgt->AppendProperty(
|
||||
"PRECOMPILE_HEADERS",
|
||||
this->Join(ConvertToAbsoluteContent(content, base)).c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void HandleInterfaceContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override
|
||||
{
|
||||
std::string const& base = this->Makefile->GetCurrentSourceDirectory();
|
||||
cmTargetPropCommandBase::HandleInterfaceContent(
|
||||
tgt, ConvertToAbsoluteContent(content, base), prepend, system);
|
||||
}
|
||||
|
||||
void HandleMissingTarget(const std::string& name) override
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify precompile headers for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
|
||||
std::string Join(const std::vector<std::string>& content) override
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool cmTargetPrecompileHeadersCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
return TargetPrecompileHeadersImpl(status).HandleArguments(
|
||||
args, "PRECOMPILE_HEADERS",
|
||||
TargetPrecompileHeadersImpl::PROCESS_REUSE_FROM);
|
||||
}
|
||||
|
||||
@@ -8,43 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCommand.h"
|
||||
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmTarget;
|
||||
|
||||
class cmTargetPrecompileHeadersCommand : public cmTargetPropCommandBase
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmTargetPrecompileHeadersCommand>();
|
||||
}
|
||||
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
protected:
|
||||
void HandleInterfaceContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override;
|
||||
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
|
||||
std::vector<std::string> ConvertToAbsoluteContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content,
|
||||
bool isInterfaceContent);
|
||||
};
|
||||
bool cmTargetPrecompileHeadersCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,12 +2,24 @@
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
#include "cmExecutionStatus.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmStateTypes.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmake.h"
|
||||
|
||||
cmTargetPropCommandBase::cmTargetPropCommandBase(cmExecutionStatus& status)
|
||||
: Makefile(&status.GetMakefile())
|
||||
, Status(status)
|
||||
{
|
||||
}
|
||||
|
||||
void cmTargetPropCommandBase::SetError(std::string const& e)
|
||||
{
|
||||
this->Status.SetError(e);
|
||||
}
|
||||
|
||||
bool cmTargetPropCommandBase::HandleArguments(
|
||||
std::vector<std::string> const& args, const std::string& prop,
|
||||
ArgumentFlags flags)
|
||||
|
||||
@@ -8,13 +8,18 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cmCommand.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmMakefile;
|
||||
class cmTarget;
|
||||
|
||||
class cmTargetPropCommandBase : public cmCommand
|
||||
class cmTargetPropCommandBase
|
||||
{
|
||||
public:
|
||||
cmTargetPropCommandBase(cmExecutionStatus& status);
|
||||
virtual ~cmTargetPropCommandBase() = default;
|
||||
|
||||
void SetError(std::string const& e);
|
||||
|
||||
enum ArgumentFlags
|
||||
{
|
||||
NO_FLAGS = 0x0,
|
||||
@@ -30,6 +35,7 @@ public:
|
||||
protected:
|
||||
std::string Property;
|
||||
cmTarget* Target = nullptr;
|
||||
cmMakefile* Makefile;
|
||||
|
||||
virtual void HandleInterfaceContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
@@ -49,6 +55,8 @@ private:
|
||||
bool PopulateTargetProperies(const std::string& scope,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system);
|
||||
|
||||
cmExecutionStatus& Status;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,47 +11,54 @@
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
namespace {
|
||||
|
||||
bool cmTargetSourcesCommand::InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus&)
|
||||
class TargetSourcesImpl : public cmTargetPropCommandBase
|
||||
{
|
||||
return this->HandleArguments(args, "SOURCES");
|
||||
}
|
||||
public:
|
||||
using cmTargetPropCommandBase::cmTargetPropCommandBase;
|
||||
|
||||
void cmTargetSourcesCommand::HandleInterfaceContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
|
||||
bool system)
|
||||
{
|
||||
cmTargetPropCommandBase::HandleInterfaceContent(
|
||||
tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system);
|
||||
}
|
||||
protected:
|
||||
void HandleInterfaceContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override
|
||||
{
|
||||
cmTargetPropCommandBase::HandleInterfaceContent(
|
||||
tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system);
|
||||
}
|
||||
|
||||
void cmTargetSourcesCommand::HandleMissingTarget(const std::string& name)
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify sources for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override
|
||||
{
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Cannot specify sources for target \"", name,
|
||||
"\" which is not built by this project."));
|
||||
}
|
||||
|
||||
std::string cmTargetSourcesCommand::Join(
|
||||
const std::vector<std::string>& content)
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool /*prepend*/, bool /*system*/) override
|
||||
{
|
||||
tgt->AppendProperty(
|
||||
"SOURCES",
|
||||
this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str());
|
||||
return true; // Successfully handled.
|
||||
}
|
||||
|
||||
bool cmTargetSourcesCommand::HandleDirectContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
|
||||
{
|
||||
tgt->AppendProperty(
|
||||
"SOURCES",
|
||||
this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str());
|
||||
return true; // Successfully handled.
|
||||
}
|
||||
std::string Join(const std::vector<std::string>& content) override
|
||||
{
|
||||
return cmJoin(content, ";");
|
||||
}
|
||||
|
||||
std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent(
|
||||
std::vector<std::string> ConvertToAbsoluteContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content,
|
||||
bool isInterfaceContent);
|
||||
};
|
||||
|
||||
std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content,
|
||||
bool isInterfaceContent)
|
||||
{
|
||||
@@ -120,3 +127,11 @@ std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent(
|
||||
|
||||
return useAbsoluteContent ? absoluteContent : content;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool cmTargetSourcesCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
return TargetSourcesImpl(status).HandleArguments(args, "SOURCES");
|
||||
}
|
||||
|
||||
@@ -8,49 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCommand.h"
|
||||
#include "cmTargetPropCommandBase.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmTarget;
|
||||
|
||||
class cmTargetSourcesCommand : public cmTargetPropCommandBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This is a virtual constructor for the command.
|
||||
*/
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmTargetSourcesCommand>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the CMakeLists.txt file.
|
||||
*/
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
protected:
|
||||
void HandleInterfaceContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
|
||||
private:
|
||||
void HandleMissingTarget(const std::string& name) override;
|
||||
|
||||
bool HandleDirectContent(cmTarget* tgt,
|
||||
const std::vector<std::string>& content,
|
||||
bool prepend, bool system) override;
|
||||
|
||||
std::string Join(const std::vector<std::string>& content) override;
|
||||
|
||||
std::vector<std::string> ConvertToAbsoluteContent(
|
||||
cmTarget* tgt, const std::vector<std::string>& content,
|
||||
bool isInterfaceContent);
|
||||
};
|
||||
bool cmTargetSourcesCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user