[CMake] foreach(loop_var RANGE total)

Nicolas Desprès nicolas.despres at gmail.com
Fri Sep 12 05:56:39 EDT 2008


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


More information about the CMake mailing list