diff options
author | Regina Pfeifer <regina@mailbox.org> | 2019-09-10 19:41:44 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-09-26 17:27:55 (GMT) |
commit | 9d1a1bc495be41b035f61f9b707df8006da54160 (patch) | |
tree | a1b41bb5a94b7ca5c8fdae2a1258581c59a62eb6 /Source/cmTargetPrecompileHeadersCommand.cxx | |
parent | dcc117b9446cfc3d6c8bf191545aac8d1519abca (diff) | |
download | CMake-9d1a1bc495be41b035f61f9b707df8006da54160.zip CMake-9d1a1bc495be41b035f61f9b707df8006da54160.tar.gz CMake-9d1a1bc495be41b035f61f9b707df8006da54160.tar.bz2 |
cmTarget*: Port away from cmCommand
Diffstat (limited to 'Source/cmTargetPrecompileHeadersCommand.cxx')
-rw-r--r-- | Source/cmTargetPrecompileHeadersCommand.cxx | 98 |
1 files changed, 55 insertions, 43 deletions
diff --git a/Source/cmTargetPrecompileHeadersCommand.cxx b/Source/cmTargetPrecompileHeadersCommand.cxx index 5751fff..887d973 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); +} |