[CMake] Concatenating lists back to string

Domen Vrankar domen.vrankar at gmail.com
Thu Oct 23 09:49:49 EDT 2014


Hi,

I am trying to convert string to list and back with string(REPLACE) and it
doesn't work as expected (tested with cmake 2.8.12 on Ubuntu 14.04 and main
branch in git on Ubuntu 14.10).

cmake_minimum_required( VERSION 2.8.12 )
project(test_list)

set(str_1 "abc.def.ghi")
message("str_1: ${str_1}")
string(REPLACE "." ";" list_1 ${str_1})
message("list_1: ${list_1}")
string(REPLACE ";" "." str_2 ${list_1})
message("str_2: ${str_2}")


When I run cmake I get the following output:
str_1: abc.def.ghi
list_1: abc;def;ghi
str_2: abcdefghi

what I expected was that str_2 would be the same as str_1.

In case that semicolons are not used everything works as expected:

cmake_minimum_required( VERSION 2.8.12 )
project(test_list)

set(str_1 "abc.def.ghi")
message("str_1: ${str_1}")
string(REPLACE "." "'" list_1 ${str_1})
message("list_1: ${list_1}")
string(REPLACE "'" "." str_2 ${list_1})
message("str_2: ${str_2}")

Output:
str_1: abc.def.ghi
list_1: abc'def'ghi
str_2: abc.def.ghi

Is this a bug or is there a reason that ; is treated differently since it
represents lists?
Is there any other simpler option than to run foreach on the list and
convert it back to a string?

Thanks,
Domen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141023/701e37a3/attachment.html>


More information about the CMake mailing list