[CMake] How to write a correct wrapper of MESSAGE()?

Johannes Zarl johannes.zarl at jku.at
Tue Oct 15 08:12:36 EDT 2013


On Monday, 14. October 2013, 19:07:06, Matthew Woehlke wrote:
> > The "IN LISTS" signature of foreach seems to do additional list
> > splitting, leading to ("foo;bar" "baz") appearing as 3 elements.
> > Accessing the ARGV array by the positional indices (e.g. ${ARGV0})
> > prevents the splitting.
> 
> Really? That... is surprising. I thought the whole point of 'IN LISTS'
> was to take a variable that already contains a list and NOT do
> additional splitting (the way 'foreach(NAME ${LIST})' would)...

While the behaviour here is hardly what one would expect, the list is not 
really split.

What happens, is the following:
 1) Function info gets two parameters: "foo;bar" and "baz"
 2) The ARGV list is created by adding the parameters to the list:
    set(ARGV)
    list(ADD ARGV "foo;bar") # here the "foo;bar" list is flattened
    list(ADD ARGV "baz")
 Since a list cannot contain another list, we get a flattened representation
 of  the arguments: ARGV == "foo;bar;baz"
 3) foreach(name IN LISTS ARGV) only gets to see the flattened representation
 contained in ARGV.

  Johannes


More information about the CMake mailing list