[CMake] foreach() bug?
Brad King
brad.king at kitware.com
Wed May 6 13:05:07 EDT 2009
Alexandre.Feblot at thomsonreuters.com wrote:
> foreach(arg ${list})
[snip]
> The empty element has been discarded by foreach(). Is this the wanted
> behaviour? If it is, how can I manage empty elements when I need them?
The foreach command never even sees the empty arguments. By the time
${list} is evaluated the empty elements are gone. This is for language
consistency. No one would want
add_executable(myexe ${srcs})
to try to add "" as a source file if srcs has an empty element.
In CMake HEAD from CVS there is an "IN" mode for foreach that supports
explicitly named lists:
set(my_list "a;b;;c;d")
foreach(arg IN LISTS my_list)
...
endforeach()
For now you need to use the list() command. You can iterate over
a range of the list size with foreach(arg RANGE ...).
-Brad
More information about the CMake
mailing list