[CMake] Weird behaviour of functions with list arguments

Johannes Zarl johannes.zarl at jku.at
Sat Dec 11 15:17:01 EST 2010


Hello,

I noticed that when defining a function, one can access lists as 
arguments using named arguments or ARGV0..ARGVn, but not using ARGV and 
ARGN.

To elaborate, assuming the function list_as_args defined as follows:
function(list_as_arg)
  message(STATUS "${ARGC} arguments, ARGV: ${ARGV}")
  message(STATUS "First argument: ${ARGV0}")
  foreach(_arg ${ARGN})
    message(STATUS "Parsing argument ${_arg}")
  endforeach(_arg)
endfunction(list_as_arg)

... and called with 2 arguments:
list_as_arg("list1a;list1b" "list2a;list2b")

...prints the following:
-- 2 arguments, ARGV: list1a;list1b;list2a;list2b
-- First argument: list1a;list1b
-- Parsing argument list1a
-- Parsing argument list1b
-- Parsing argument list2a
-- Parsing argument list2b

So ARGV0 is not the same as the first argument of ARGV. Why? Is it that 
the ARGV and ARGN lists get flattened, but the ARGVx are assigned before 
that?

How can I safely access the values of ARGN, if they might contain lists?

Thanks,
  Johannes


More information about the CMake mailing list