[CMake] ARGC != list(LENGTH ARGV) and ARGV0 != list(GET ARGV 0)
Johannes Zarl
johannes.zarl at jku.at
Mon Oct 14 04:50:57 EDT 2013
> CMake will not expand a string into a list when passed as arguments. It
> would do when using a variable:
While this is true, it's also not the whole truth (and I guess is that this is
bothering Clark). Consider the following two function calls:
foo1("a;b;c")
foo2("a;b" c)
Of course cmake recognises foo1 as having one parameter, and foo2 as having 2
parameters. And if you do use names arguments in your function, or access the
function arguments by their positional arguments, it works as expected:
function(foo2)
message("Arg0: ${arg0}") # "Arg0: a;b"
message("${ARGC} arguments.") # "2 Arguments."
endfunction()
If, however you try to access the argument list as a whole, you fall in the
"list of lists trap". CMake can not have lists as elements of other lists.
Trying to use the ARGV or ARGN lists in the above example will not achieve
what you are trying to do, because when cmake assembles the list of arguments,
the (for lack of a better word) "list property" is lost:
set(mylist)
list(ADD mylist "a;b")
list(LENGTH mylist n)
message( "length is ${n}") # "length is 2"
Cheers,
Johannes
More information about the CMake
mailing list