There is no such function, but creating one is not so hard. Here is the one possible implementation:
#the function to reverse the string
function (string_reverse INPUT_STRING OUTPUT_VAR)
string(LENGTH ${INPUT_STRING} len)
set(out "")
foreach(indx RANGE ${len})
string(SUBSTRING ${INPUT_STRING} ${indx} 1 char)
string(PREPEND out ${char})
endforeach()
set(${OUTPUT_VAR} ${out} PARENT_SCOPE)
endfunction()
The usage of the function reverse_string
would be as follows. Please note that the code expects the function definition to be available now.
# prepare the string to be reversed
set(ORIGINAL_STRING "123 45 67 890 a b c d e fgh I J K LMNO PQ")
# call the function to reverse the string
string_reverse(${ORIGINAL_STRING} REVERSED_STRING)
# debugging output
message ("ORIGINAL_STRING: ${ORIGINAL_STRING}")
message ("REVERSED_STRING: ${REVERSED_STRING}")
Note that the variable REVERSED_STRING
will be created and initialized within the function, so it is unnecessary to do it explicitly.
After running this code, the output would be as follows:
ORIGINAL_STRING: 123 45 67 890 a b c d e fgh I J K LMNO PQ
REVERSED_STRING: QP ONML K J I hgf e d c b a 098 76 54 321
BTW, what are you trying to achieve? i.e., why do you need string reversal within cmake?