Has nobody else notice this particular language inconsistency?<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 27, 2012 at 1:12 PM, James Bigler <span dir="ltr"><<a href="mailto:jamesbigler@gmail.com" target="_blank">jamesbigler@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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.<div>
<br></div><div><font face="courier new, monospace"><span style="background-color:rgb(255,242,204)"><span style="font-size:13px">If you want to </span><span style="font-size:13px">convert</span><span style="font-size:13px"> a string to a </span><span style="font-size:13px">list</span><span style="font-size:13px"> you can do it like this:</span><br style="font-size:13px">
<br style="font-size:13px"><span style="font-size:13px">set(</span><span style="font-size:13px">list</span><span style="font-size:13px"> ${string})</span><br style="font-size:13px"><br style="font-size:13px"><span style="font-size:13px">That will make the space separated </span><span style="font-size:13px">list</span><span style="font-size:13px"> string into a ; separated </span><span style="font-size:13px">list</span><span style="font-size:13px">. If you want to keep string a string you need quotes:</span><br style="font-size:13px">
<span style="font-size:13px">set(newstring "${string}").</span></span><br style="font-size:13px"></font></div><div><br></div><div>It doesn't seem to work that way though, so perhaps I'm missing something.</div>
<div><br></div><div>Here's my test program:</div><div><br></div><div><div><font face="courier new, monospace">function(print_list name)</font></div><div><font face="courier new, monospace"> list(LENGTH ${name} length_of_list)</font></div>
<div><font face="courier new, monospace"> message("${name} has ${length_of_list} items")</font></div><div><font face="courier new, monospace"> set(count 0)</font></div><div><font face="courier new, monospace"> foreach(i ${${name}})</font></div>
<div><font face="courier new, monospace"> message("${name}[${count}] = ${i}")</font></div><div><font face="courier new, monospace"> math(EXPR count "${count} + 1")</font></div><div><font face="courier new, monospace"> endforeach()</font></div>
<div><font face="courier new, monospace">endfunction()</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">set(mylist a b c)</font></div><div><font face="courier new, monospace">set(mystring "a b c")</font></div>
<div><font face="courier new, monospace">set(mylist_from_string ${mystring})</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">print_list(mylist)</font></div><div>
<font face="courier new, monospace">print_list(mystring)</font></div><div><font face="courier new, monospace">print_list(mylist_from_string)</font></div></div><div><br></div><div>And here's what I get when I run it:</div>
<div><br></div><div><font face="courier new, monospace">cmake -P list-from-string.cmake</font></div><div><font face="courier new, monospace"><br></font></div><div><div><font face="courier new, monospace">mylist has 3 items</font></div>
<div><font face="courier new, monospace">mylist[0] = a</font></div><div><font face="courier new, monospace">mylist[1] = b</font></div><div><font face="courier new, monospace">mylist[2] = c</font></div><div><font face="courier new, monospace">mystring has 1 items</font></div>
<div><font face="courier new, monospace">mystring[0] = a b c</font></div><div><font face="courier new, monospace">mylist_from_string has 1 items</font></div><div><font face="courier new, monospace">mylist_from_string[0] = a b c</font></div>
</div><div><br></div>
</blockquote></div><br></div>