Has nobody else notice this particular language inconsistency?

On Tue, Nov 27, 2012 at 1:12 PM, James Bigler <[email protected]> wrote:

> I'm running into this again, and I trawled through the mailing list, and
> according to Bill (4/11/2009 - managing lists with space separated
> elements), I should be able to get a list from a string with a single
> command.
>
> If you want to convert a string to a list you can do it like this:
>
> set(list ${string})
>
> That will make the space separated list string into a ; separated list.
>  If you want to keep string a string you need quotes:
> set(newstring "${string}").
>
> It doesn't seem to work that way though, so perhaps I'm missing something.
>
> Here's my test program:
>
> function(print_list name)
>   list(LENGTH ${name} length_of_list)
>   message("${name} has ${length_of_list} items")
>   set(count 0)
>   foreach(i ${${name}})
>     message("${name}[${count}] = ${i}")
>     math(EXPR count "${count} + 1")
>   endforeach()
> endfunction()
>
> set(mylist a b c)
> set(mystring "a b c")
> set(mylist_from_string ${mystring})
>
> print_list(mylist)
> print_list(mystring)
> print_list(mylist_from_string)
>
> And here's what I get when I run it:
>
> cmake -P list-from-string.cmake
>
> mylist has 3 items
> mylist[0] = a
> mylist[1] = b
> mylist[2] = c
> mystring has 1 items
> mystring[0] = a b c
> mylist_from_string has 1 items
> mylist_from_string[0] = a b c
>
>
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to