mirror of
https://github.com/reactos/CMake.git
synced 2024-12-02 16:46:36 +00:00
Merge topic 'string_prepend'
d8ecc254
Add PREPEND sub-command to string command
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1129
This commit is contained in:
commit
d817bbb8df
@ -132,6 +132,15 @@ APPEND
|
||||
|
||||
Append all the input arguments to the string.
|
||||
|
||||
PREPEND
|
||||
"""""""
|
||||
|
||||
::
|
||||
|
||||
string(PREPEND <string variable> [<input>...])
|
||||
|
||||
Prepend all the input arguments to the string.
|
||||
|
||||
CONCAT
|
||||
""""""
|
||||
|
||||
|
4
Help/release/dev/string_prepend.rst
Normal file
4
Help/release/dev/string_prepend.rst
Normal file
@ -0,0 +1,4 @@
|
||||
string_prepend
|
||||
--------------
|
||||
|
||||
* The :command:`string` command learned a new ``PREPEND`` subcommand.
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
58
Tests/RunCMake/string/Prepend.cmake
Normal file
58
Tests/RunCMake/string/Prepend.cmake
Normal file
@ -0,0 +1,58 @@
|
||||
set(out)
|
||||
string(PREPEND out)
|
||||
if(DEFINED out)
|
||||
message(FATAL_ERROR "\"string(PREPEND out)\" set out to \"${out}\"")
|
||||
endif()
|
||||
|
||||
set(out "")
|
||||
string(PREPEND out)
|
||||
if(NOT out STREQUAL "")
|
||||
message(FATAL_ERROR "\"string(PREPEND out)\" set out to \"${out}\"")
|
||||
endif()
|
||||
|
||||
set(out x)
|
||||
string(PREPEND out)
|
||||
if(NOT out STREQUAL "x")
|
||||
message(FATAL_ERROR "\"string(PREPEND out)\" set out to \"${out}\"")
|
||||
endif()
|
||||
|
||||
|
||||
set(out)
|
||||
string(PREPEND out a)
|
||||
if(NOT out STREQUAL "a")
|
||||
message(FATAL_ERROR "\"string(PREPEND out a)\" set out to \"${out}\"")
|
||||
endif()
|
||||
|
||||
set(out "")
|
||||
string(PREPEND out a)
|
||||
if(NOT out STREQUAL "a")
|
||||
message(FATAL_ERROR "\"string(PREPEND out a)\" set out to \"${out}\"")
|
||||
endif()
|
||||
|
||||
set(out x)
|
||||
string(PREPEND out a)
|
||||
if(NOT out STREQUAL "ax")
|
||||
message(FATAL_ERROR "\"string(PREPEND out a)\" set out to \"${out}\"")
|
||||
endif()
|
||||
|
||||
|
||||
set(out x)
|
||||
string(PREPEND out a "b")
|
||||
if(NOT out STREQUAL "abx")
|
||||
message(FATAL_ERROR "\"string(PREPEND out a \"b\")\" set out to \"${out}\"")
|
||||
endif()
|
||||
|
||||
set(b)
|
||||
set(out x)
|
||||
string(PREPEND out ${b})
|
||||
if(NOT out STREQUAL "x")
|
||||
message(FATAL_ERROR "\"string(PREPEND out \${b})\" set out to \"${out}\"")
|
||||
endif()
|
||||
|
||||
set(b b)
|
||||
set(out x)
|
||||
string(PREPEND out a "${b}" [[
|
||||
${c}]])
|
||||
if(NOT out STREQUAL "ab\${c}x")
|
||||
message(FATAL_ERROR "\"string(PREPEND out a \"\${b}\" [[\${c}]])\" set out to \"${out}\"")
|
||||
endif()
|
1
Tests/RunCMake/string/PrependNoArgs-result.txt
Normal file
1
Tests/RunCMake/string/PrependNoArgs-result.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
Tests/RunCMake/string/PrependNoArgs-stderr.txt
Normal file
4
Tests/RunCMake/string/PrependNoArgs-stderr.txt
Normal file
@ -0,0 +1,4 @@
|
||||
CMake Error at PrependNoArgs.cmake:1 \(string\):
|
||||
string sub-command PREPEND requires at least one argument.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
1
Tests/RunCMake/string/PrependNoArgs.cmake
Normal file
1
Tests/RunCMake/string/PrependNoArgs.cmake
Normal file
@ -0,0 +1 @@
|
||||
string(PREPEND)
|
@ -3,6 +3,9 @@ include(RunCMake)
|
||||
run_cmake(Append)
|
||||
run_cmake(AppendNoArgs)
|
||||
|
||||
run_cmake(Prepend)
|
||||
run_cmake(PrependNoArgs)
|
||||
|
||||
run_cmake(Concat)
|
||||
run_cmake(ConcatNoArgs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user