[cmake-developers] Fwd: List from strings (CMAKE_CXX_FLAGS and friends)

James Bigler jamesbigler at gmail.com
Tue Dec 4 19:31:13 EST 2012


Is this a bug or is what I'm trying to do impossible?

Thanks,
James

---------- Forwarded message ----------
From: James Bigler <jamesbigler at gmail.com>
Date: Mon, Dec 3, 2012 at 3:22 PM
Subject: Re: List from strings (CMAKE_CXX_FLAGS and friends)
To: "cmake at cmake.org" <cmake at cmake.org>


Has nobody else notice this particular language inconsistency?


On Tue, Nov 27, 2012 at 1:12 PM, James Bigler <jamesbigler at gmail.com> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20121204/f7b82793/attachment.html>


More information about the cmake-developers mailing list