diff options
author | Regina Pfeifer <regina@mailbox.org> | 2019-09-10 21:41:44 +0200 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-09-26 13:27:55 -0400 |
commit | 9d1a1bc495be41b035f61f9b707df8006da54160 (patch) | |
tree | a1b41bb5a94b7ca5c8fdae2a1258581c59a62eb6 | |
parent | dcc117b9446cfc3d6c8bf191545aac8d1519abca (diff) | |
download | cmake-9d1a1bc495be41b035f61f9b707df8006da54160.tar.gz |
cmTarget*: Port away from cmCommand
-rw-r--r-- | Source/cmCommands.cxx | 27 | ||||
-rw-r--r-- | Source/cmTargetCompileDefinitionsCommand.cxx | 70 | ||||
-rw-r--r-- | Source/cmTargetCompileDefinitionsCommand.h | 34 | ||||
-rw-r--r-- | Source/cmTargetCompileFeaturesCommand.cxx | 65 | ||||
-rw-r--r-- | Source/cmTargetCompileFeaturesCommand.h | 26 | ||||
-rw-r--r-- | Source/cmTargetCompileOptionsCommand.cxx | 56 | ||||
-rw-r--r-- | Source/cmTargetCompileOptionsCommand.h | 34 | ||||
-rw-r--r-- | Source/cmTargetIncludeDirectoriesCommand.cxx | 57 | ||||
-rw-r--r-- | Source/cmTargetIncludeDirectoriesCommand.h | 38 | ||||
-rw-r--r-- | Source/cmTargetLinkDirectoriesCommand.cxx | 53 | ||||
-rw-r--r-- | Source/cmTargetLinkDirectoriesCommand.h | 34 | ||||
-rw-r--r-- | Source/cmTargetLinkOptionsCommand.cxx | 55 | ||||
-rw-r--r-- | Source/cmTargetLinkOptionsCommand.h | 34 | ||||
-rw-r--r-- | Source/cmTargetPrecompileHeadersCommand.cxx | 98 | ||||
-rw-r--r-- | Source/cmTargetPrecompileHeadersCommand.h | 38 | ||||
-rw-r--r-- | Source/cmTargetPropCommandBase.cxx | 12 | ||||
-rw-r--r-- | Source/cmTargetPropCommandBase.h | 14 | ||||
-rw-r--r-- | Source/cmTargetSourcesCommand.cxx | 81 | ||||
-rw-r--r-- | Source/cmTargetSourcesCommand.h | 44 |
19 files changed, 368 insertions, 502 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 88d17f11ba..b1f7db7435 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -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); diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx index 94e249f22b..edee167004 100644 --- a/Source/cmTargetCompileDefinitionsCommand.cxx +++ b/Source/cmTargetCompileDefinitionsCommand.cxx @@ -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.")); -} +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.")); + } -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; + 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 = ";"; } - sep = ";"; + return defs; } - return defs; -} +}; + +} // namespace -bool cmTargetCompileDefinitionsCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool, bool) +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"); } diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h index f85dc0a9c5..05ff092e87 100644 --- a/Source/cmTargetCompileDefinitionsCommand.h +++ b/Source/cmTargetCompileDefinitionsCommand.h @@ -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 diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx index a22b94b100..06be4f0ddd 100644 --- a/Source/cmTargetCompileFeaturesCommand.cxx +++ b/Source/cmTargetCompileFeaturesCommand.cxx @@ -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, ";"); -} +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.")); + } -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. + 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, ";"); } - return true; // Successfully handled. +}; + +} // namespace + +bool cmTargetCompileFeaturesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return TargetCompileFeaturesImpl(status).HandleArguments(args, + "COMPILE_FEATURES"); } diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h index 39597ca22f..db0c04b7e5 100644 --- a/Source/cmTargetCompileFeaturesCommand.h +++ b/Source/cmTargetCompileFeaturesCommand.h @@ -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 diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx index ccc215ab6e..e39b726705 100644 --- a/Source/cmTargetCompileOptionsCommand.cxx +++ b/Source/cmTargetCompileOptionsCommand.cxx @@ -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. + } + + std::string Join(const std::vector<std::string>& content) override + { + return cmJoin(content, ";"); + } +}; + +} // namespace -bool cmTargetCompileOptionsCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool, bool) +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); } diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h index b328ba2f09..3ab1a89c56 100644 --- a/Source/cmTargetCompileOptionsCommand.h +++ b/Source/cmTargetCompileOptionsCommand.h @@ -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 diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx index 7801ee8c3e..95b69f3998 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.cxx +++ b/Source/cmTargetIncludeDirectoriesCommand.cxx @@ -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.")); + } + + 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 cmTargetIncludeDirectoriesCommand::Join( + 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)); +} diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h index f6481dbf12..9958f419a3 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.h +++ b/Source/cmTargetIncludeDirectoriesCommand.h @@ -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 diff --git a/Source/cmTargetLinkDirectoriesCommand.cxx b/Source/cmTargetLinkDirectoriesCommand.cxx index c2ef6c1340..0c68d604c8 100644 --- a/Source/cmTargetLinkDirectoriesCommand.cxx +++ b/Source/cmTargetLinkDirectoriesCommand.cxx @@ -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 Join(const std::vector<std::string>& content) override; -std::string cmTargetLinkDirectoriesCommand::Join( + 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) -{ - cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); +} // namespace - tgt->InsertLinkDirectory(this->Join(content), lfbt, prepend); - - return true; // Successfully handled. +bool cmTargetLinkDirectoriesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return TargetLinkDirectoriesImpl(status).HandleArguments( + args, "LINK_DIRECTORIES", TargetLinkDirectoriesImpl::PROCESS_BEFORE); } diff --git a/Source/cmTargetLinkDirectoriesCommand.h b/Source/cmTargetLinkDirectoriesCommand.h index a651d73f4f..3724d6cf82 100644 --- a/Source/cmTargetLinkDirectoriesCommand.h +++ b/Source/cmTargetLinkDirectoriesCommand.h @@ -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 diff --git a/Source/cmTargetLinkOptionsCommand.cxx b/Source/cmTargetLinkOptionsCommand.cxx index dbd7bfee96..df9416fad3 100644 --- a/Source/cmTargetLinkOptionsCommand.cxx +++ b/Source/cmTargetLinkOptionsCommand.cxx @@ -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. + } + + std::string Join(const std::vector<std::string>& content) override + { + return cmJoin(content, ";"); + } +}; + +} // namespace -bool cmTargetLinkOptionsCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool) +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); } diff --git a/Source/cmTargetLinkOptionsCommand.h b/Source/cmTargetLinkOptionsCommand.h index 918a8d7a8a..13fb40cb69 100644 --- a/Source/cmTargetLinkOptionsCommand.h +++ b/Source/cmTargetLinkOptionsCommand.h @@ -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 diff --git a/Source/cmTargetPrecompileHeadersCommand.cxx b/Source/cmTargetPrecompileHeadersCommand.cxx index 5751fffa19..887d9738cf 100644 --- a/Source/cmTargetPrecompileHeadersCommand.cxx +++ b/Source/cmTargetPrecompileHeadersCommand.cxx @@ -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); -} - -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; -} +namespace { -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); +} diff --git a/Source/cmTargetPrecompileHeadersCommand.h b/Source/cmTargetPrecompileHeadersCommand.h index 00dc9285c0..8b0ac97777 100644 --- a/Source/cmTargetPrecompileHeadersCommand.h +++ b/Source/cmTargetPrecompileHeadersCommand.h @@ -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 diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index 4bc3125478..bbc1e16f76 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -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) diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h index b2444172b8..601ad01132 100644 --- a/Source/cmTargetPropCommandBase.h +++ b/Source/cmTargetPropCommandBase.h @@ -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 diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index 7c9d03c539..c2e0b28fe1 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -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> ConvertToAbsoluteContent( + cmTarget* tgt, const std::vector<std::string>& content, + bool isInterfaceContent); +}; -std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent( +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"); +} diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h index 1cff8c3361..5eecf3454e 100644 --- a/Source/cmTargetSourcesCommand.h +++ b/Source/cmTargetSourcesCommand.h @@ -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 |