Merge topic 'string-CONCAT-command'

4e184a2 string: Add CONCAT sub-command
This commit is contained in:
Brad King 2013-10-22 09:08:15 -04:00 committed by CMake Topic Stage
commit 7809adb814
10 changed files with 63 additions and 0 deletions

View File

@ -15,6 +15,7 @@ String operations.
string(REPLACE <match_string> string(REPLACE <match_string>
<replace_string> <output variable> <replace_string> <output variable>
<input> [<input>...]) <input> [<input>...])
string(CONCAT <output variable> [<input>...])
string(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512> string(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512>
<output variable> <input>) <output variable> <input>)
string(COMPARE EQUAL <string1> <string2> <output variable>) string(COMPARE EQUAL <string1> <string2> <output variable>)
@ -51,6 +52,9 @@ through argument parsing.
REPLACE will replace all occurrences of match_string in the input with REPLACE will replace all occurrences of match_string in the input with
replace_string and store the result in the output. replace_string and store the result in the output.
CONCAT will concatenate all the input arguments together and store
the result in the named output variable.
MD5, SHA1, SHA224, SHA256, SHA384, and SHA512 will compute a MD5, SHA1, SHA224, SHA256, SHA384, and SHA512 will compute a
cryptographic hash of the input string. cryptographic hash of the input string.

View File

@ -73,6 +73,10 @@ bool cmStringCommand
{ {
return this->HandleLengthCommand(args); return this->HandleLengthCommand(args);
} }
else if(subCommand == "CONCAT")
{
return this->HandleConcatCommand(args);
}
else if(subCommand == "SUBSTRING") else if(subCommand == "SUBSTRING")
{ {
return this->HandleSubstringCommand(args); return this->HandleSubstringCommand(args);
@ -766,6 +770,27 @@ bool cmStringCommand
return true; return true;
} }
//----------------------------------------------------------------------------
bool cmStringCommand
::HandleConcatCommand(std::vector<std::string> const& args)
{
if(args.size() < 2)
{
this->SetError("sub-command CONCAT requires at least one argument.");
return false;
}
std::string const& variableName = args[1];
std::string value;
for(unsigned int i = 2; i < args.size(); ++i)
{
value += args[i];
}
this->Makefile->AddDefinition(variableName.c_str(), value.c_str());
return true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmStringCommand bool cmStringCommand
::HandleMakeCIdentifierCommand(std::vector<std::string> const& args) ::HandleMakeCIdentifierCommand(std::vector<std::string> const& args)

View File

@ -69,6 +69,7 @@ protected:
bool HandleReplaceCommand(std::vector<std::string> const& args); bool HandleReplaceCommand(std::vector<std::string> const& args);
bool HandleLengthCommand(std::vector<std::string> const& args); bool HandleLengthCommand(std::vector<std::string> const& args);
bool HandleSubstringCommand(std::vector<std::string> const& args); bool HandleSubstringCommand(std::vector<std::string> const& args);
bool HandleConcatCommand(std::vector<std::string> const& args);
bool HandleStripCommand(std::vector<std::string> const& args); bool HandleStripCommand(std::vector<std::string> const& args);
bool HandleRandomCommand(std::vector<std::string> const& args); bool HandleRandomCommand(std::vector<std::string> const& args);
bool HandleFindCommand(std::vector<std::string> const& args); bool HandleFindCommand(std::vector<std::string> const& args);

View File

@ -99,6 +99,7 @@ add_RunCMake_test(include)
add_RunCMake_test(include_directories) add_RunCMake_test(include_directories)
add_RunCMake_test(list) add_RunCMake_test(list)
add_RunCMake_test(message) add_RunCMake_test(message)
add_RunCMake_test(string)
add_RunCMake_test(try_compile) add_RunCMake_test(try_compile)
add_RunCMake_test(variable_watch) add_RunCMake_test(variable_watch)
add_RunCMake_test(CMP0004) add_RunCMake_test(CMP0004)

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 2.8.4)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@ -0,0 +1,19 @@
set(b b)
set(out x)
string(CONCAT out)
if(NOT out STREQUAL "")
message(FATAL_ERROR "\"string(CONCAT out)\" set out to \"${out}\"")
endif()
string(CONCAT out a)
if(NOT out STREQUAL "a")
message(FATAL_ERROR "\"string(CONCAT out a)\" set out to \"${out}\"")
endif()
string(CONCAT out a "b")
if(NOT out STREQUAL "ab")
message(FATAL_ERROR "\"string(CONCAT out a \"b\")\" set out to \"${out}\"")
endif()
string(CONCAT out a "${b}" [[
${c}]])
if(NOT out STREQUAL "ab\${c}")
message(FATAL_ERROR "\"string(CONCAT out a \"\${b}\" [[\${c}]])\" set out to \"${out}\"")
endif()

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
CMake Error at ConcatNoArgs.cmake:1 \(string\):
string sub-command CONCAT requires at least one argument.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1 @@
string(CONCAT)

View File

@ -0,0 +1,4 @@
include(RunCMake)
run_cmake(Concat)
run_cmake(ConcatNoArgs)