[CMake] Strangeness with ARGVn variables

Brad King brad.king at kitware.com
Thu Jan 26 11:43:36 EST 2006


Zachary Pincus wrote:
> I'm having some strange issues using the ARGVn variables in macros.  
> Specifically, even when one of those variables has a value, they seem  
> to fail IF tests (and similar).
> 
> Perhaps this is best illustrated with an example:
> #----------
> MACRO(foo)
>   IF(ARGV0)
>     MESSAGE("ONE ARGUMENT")
>   ELSE(ARGV0)
>     MESSAGE("NO ARGUMENTS")
>   ENDIF(ARGV0)
> ENDMACRO(foo)

The ARGV* variables in macros are handled differently from other 
variables.  When the macro is invoked "${ARGV0}" is replaced by the 
argument passed to the macro.  The resulting macro body is then 
executed.  Try this:

MACRO(foo)
   IF("${ARGV0}")
     MESSAGE("ONE ARGUMENT")
   ELSE("${ARGV0}")
     MESSAGE("NO ARGUMENTS")
   ENDIF("${ARGV0}")
ENDMACRO(foo)

-Brad


More information about the CMake mailing list