[CMake] FOREACH loop control variable scope bug
Ken Martin
ken.martin at kitware.com
Wed Jun 22 13:16:58 EDT 2005
Currently FOREACH and MACRO do not actually use variables in their
implementation. They do their own string replacement on the "variable" prior
to passing the command to the main parser. (this was because they tend to
use nested variables ${FU${BAR}} which wasn't supported in CMake 2.0 or
earlier). With CMake 2.2 the parser fully supports nested variables so we
can convert these commands to use variables instead. In fact Andy added an
item on my whiteboard to do just that a couple weeks ago. I'll put that on
my todo list. Having said that a quick workaround is to just add a set
command
# top level CMakeLists.txt
SET(var "this is var")
FOREACH(LCV one two three)
MESSAGE("var: ${var} LCV: ${LCV}")
SET(LCV_SUB ${LCV})
ADD_SUBDIRECTORY(foo)
ENDFOREACH(LCV)
# foo dir CMakeLists.txt
MESSAGE("In Directory var: ${var} LCV: ${LCV_SUB}")
Thanks
Ken
More information about the CMake
mailing list