diff options
author | Brad King <brad.king@kitware.com> | 2017-08-16 14:50:34 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2017-08-16 14:50:38 (GMT) |
commit | d817bbb8dfda07e94850c73811b7a520cb65c6f0 (patch) | |
tree | a4e8a335a66244e1fce7cb41301dce8df171a14b /Source | |
parent | 75b3866a8ebfbb2823611ebc7e7febeea2bd91c1 (diff) | |
parent | d8ecc2545798c77ec5bf22bb420a3343d4843ef6 (diff) | |
download | CMake-d817bbb8dfda07e94850c73811b7a520cb65c6f0.zip CMake-d817bbb8dfda07e94850c73811b7a520cb65c6f0.tar.gz CMake-d817bbb8dfda07e94850c73811b7a520cb65c6f0.tar.bz2 |
Merge topic 'string_prepend'
d8ecc254 Add PREPEND sub-command to string command
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1129
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmStringCommand.cxx | 27 | ||||
-rw-r--r-- | Source/cmStringCommand.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 5a6cf48..b07eae1 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -62,6 +62,9 @@ bool cmStringCommand::InitialPass(std::vector<std::string> const& args, if (subCommand == "APPEND") { return this->HandleAppendCommand(args); } + if (subCommand == "PREPEND") { + return this->HandlePrependCommand(args); + } if (subCommand == "CONCAT") { return this->HandleConcatCommand(args); } @@ -643,6 +646,30 @@ bool cmStringCommand::HandleAppendCommand(std::vector<std::string> const& args) return true; } +bool cmStringCommand::HandlePrependCommand( + std::vector<std::string> const& args) +{ + if (args.size() < 2) { + this->SetError("sub-command PREPEND requires at least one argument."); + return false; + } + + // Skip if nothing to prepend. + if (args.size() < 3) { + return true; + } + + const std::string& variable = args[1]; + + std::string value = cmJoin(cmMakeRange(args).advance(2), std::string()); + const char* oldValue = this->Makefile->GetDefinition(variable); + if (oldValue) { + value += oldValue; + } + this->Makefile->AddDefinition(variable, value.c_str()); + return true; +} + bool cmStringCommand::HandleConcatCommand(std::vector<std::string> const& args) { if (args.size() < 2) { diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index 88015ad..0dded15 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -46,6 +46,7 @@ protected: bool HandleLengthCommand(std::vector<std::string> const& args); bool HandleSubstringCommand(std::vector<std::string> const& args); bool HandleAppendCommand(std::vector<std::string> const& args); + bool HandlePrependCommand(std::vector<std::string> const& args); bool HandleConcatCommand(std::vector<std::string> const& args); bool HandleStripCommand(std::vector<std::string> const& args); bool HandleRandomCommand(std::vector<std::string> const& args); |