<div dir="ltr">Add this line after the list LENGTH call:<div>math(EXPR list_max_index ${list_count}-1)<br><br></div><div>and then use list_max_index instead of list_count in the foreach loop.</div><div><br></div><div>The documentation (cmake --help-command foreach) is quite clear that the one arg form of the range command loops from 0 to total including total...</div>
<div><br></div><div><br></div><div>HTH,</div><div>David</div><div><br></div><div><br><div class="gmail_quote">On Fri, Sep 12, 2008 at 5:56 AM, Nicolas Desprès <span dir="ltr"><<a href="mailto:nicolas.despres@gmail.com">nicolas.despres@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi,<br>
<br>
I'm using cmake <a href="http://2.6.0." target="_blank">2.6.0.</a><br>
<br>
I'm trying the foreach(loop_var RANGE total) syntax and I find its<br>
behavior quiet surprising since it is something equivalent to:<br>
<br>
for (int loop_var = 0; loop_var <= total; ++loop_var)<br>
;<br>
<br>
Most of the time (specially when you iterate over a list) you want to<br>
test for 'loop_var < total'.<br>
<br>
For instance you can't write code like that:<br>
<br>
list(LENGTH list list_count)<br>
<br>
foreach(i RANGE ${list_count})<br>
<br>
list(GET list ${i} x)<br>
<br>
endforeach(i)<br>
<br>
list(GET always fail on the last iteration.<br>
<br>
Cheers,<br>
<font color="#888888"><br>
--<br>
Nicolas Desprès<br>
_______________________________________________<br>
CMake mailing list<br>
<a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</font></blockquote></div><br></div></div>