diff options
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); +} |