Add PREPEND sub-command to string command

This commit is contained in:
Sylvain Joubert
2017-08-11 13:26:33 +02:00
parent f8a61c578b
commit d8ecc25457
9 changed files with 108 additions and 0 deletions

View File

@@ -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) {