diff options
author | Sylvain Joubert <joubert.sy@gmail.com> | 2017-08-11 11:26:33 (GMT) |
---|---|---|
committer | Sylvain Joubert <joubert.sy@gmail.com> | 2017-08-11 11:26:33 (GMT) |
commit | d8ecc2545798c77ec5bf22bb420a3343d4843ef6 (patch) | |
tree | de0ac663a00cb494ec78452811ca1f0aac3f551d /Source | |
parent | f8a61c578badb0015423580b38341bc00a3c7fd4 (diff) | |
download | CMake-d8ecc2545798c77ec5bf22bb420a3343d4843ef6.zip CMake-d8ecc2545798c77ec5bf22bb420a3343d4843ef6.tar.gz CMake-d8ecc2545798c77ec5bf22bb420a3343d4843ef6.tar.bz2 |
Add PREPEND sub-command to string command
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); |