diff options
Diffstat (limited to 'Source/cmTargetCompileDefinitionsCommand.cxx')
-rw-r--r-- | Source/cmTargetCompileDefinitionsCommand.cxx | 75 |
1 files changed, 41 insertions, 34 deletions
diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx index c4dc8383b..edee16700 100644 --- a/Source/cmTargetCompileDefinitionsCommand.cxx +++ b/Source/cmTargetCompileDefinitionsCommand.cxx @@ -2,50 +2,57 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmTargetCompileDefinitionsCommand.h" -#include <sstream> - -#include "cmAlgorithms.h" #include "cmMakefile.h" #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) -{ - std::ostringstream e; - e << "Cannot specify compile definitions for target \"" << name - << "\" " - "which is not built by this project."; - this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); -} +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"); } |