[cmake-developers] Weird behaviour of arguments in macro

Daniele E. Domenichelli daniele.domenichelli at gmail.com
Fri Nov 15 03:27:07 EST 2013


On 14/11/13 20:39, Brad King wrote:
> On 11/14/2013 12:09 PM, Daniele E. Domenichelli wrote:
>> Is this a wanted behaviour? If it is, perhaps it should be documented in
>> macro() command documentation.
> 
> The "macro" command documentation says:
> 
>  http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:macro
>  Note that the parameters to a macro ... are not variables
> 
> The "if" command documentation says:
> 
>  http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:if
>  Note macro arguments are not variables.


Ok there is some documentation, but perhaps it is not very clear what
you cannot do with a macro parameter:

* it's not a variable but it isn't either a list (the list()
documentation says "A list in cmake is a ; separated group of strings",
and doesn't mention macro arguments). Therefore you cannot use the
list() command.
* foreach(IN LISTS), does not mention that it won't work with macro
parameters.
* The if() command mentions that in the documentation of the if(var)
form, but not in the if(DEFINED var).

Also the problem that gave me more issues is that I was using ARGN like
this:

  macro(_BAR)
    foreach(arg IN LISTS ARGN)
      [...]
    endforeach()
  endmacro()

  function(_FOO)
    _bar(x y z)
  endfunction()

  _foo(a b c)

And it took a lot of time to realize that I was using the list from the
current scope, not from the macro.

So I believe that some more documentation would be helpful... If you
agree, I can write it...



Cheers,
 Daniele



More information about the cmake-developers mailing list