Add this line after the list LENGTH call:math(EXPR list_max_index ${list_count}-1)
and then use list_max_index instead of list_count in the foreach loop. 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... HTH, David On Fri, Sep 12, 2008 at 5:56 AM, Nicolas Desprès <[EMAIL PROTECTED]>wrote: > Hi, > > I'm using cmake 2.6.0. > > I'm trying the foreach(loop_var RANGE total) syntax and I find its > behavior quiet surprising since it is something equivalent to: > > for (int loop_var = 0; loop_var <= total; ++loop_var) > ; > > Most of the time (specially when you iterate over a list) you want to > test for 'loop_var < total'. > > For instance you can't write code like that: > > list(LENGTH list list_count) > > foreach(i RANGE ${list_count}) > > list(GET list ${i} x) > > endforeach(i) > > list(GET always fail on the last iteration. > > Cheers, > > -- > Nicolas Desprès > _______________________________________________ > CMake mailing list > CMake@cmake.org > http://www.cmake.org/mailman/listinfo/cmake >
_______________________________________________ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake