[Cmake] Quoting rules

Andy Cedilnik andy . cedilnik at kitware . com
26 Jun 2003 07:21:22 -0400


Hi Neil,

Works like this:

MYMACRO(A B) 

will work, because A and B are single arguments.

SET(A 1)
SET(B 2)
MYMACRO(${A} ${B}) 

will work, because ${A} expands into 1 and ${B} expands into 2, so still
single arguments.

SET(A foo bar)
SET(B X Y)
MYMACRO(${A} ${B}) 

will expand into:

MYMACRO(foo;bar X;Y)

which means it will be called with four arguments. The quotes combine
argument into a single argument:

SET(A foo bar)
SET(B X Y)
MYMACRO("${A}" "${B}") 

is expanded to:

MYMACRO("foo;bar" "X;Y")

which are two arguments and so you are ok.

On Wed, 2003-06-25 at 21:49, Neil Killeen wrote:
> I have just discovered the MACRO command, yippee !
> 
> MACRO (MYMACRO arg1 arg2)
>  MESSAGE ("arg1 = " ${arg1})
>  MESSAGE ("arg2 = " ${arg2})
> ENDMACRO(MYMACRO)
> 
> I tried to invoke it with
> 
> MYMACRO (${ARG1} ${ARG2})
> 
> where ARG1 and ARG2 are defined CMake variables.
> But that failed claiming wrong number of arguments.
> Eventually by poking about in ITK I discovered
> that I need to quote the arguments.
> 
> MYMACRO ("${ARG1}" "${ARG2}")
> 
> what exactly are the quoting rules in CMake ? I have always
> been a bit confused by this !
> 
> This could usefully go in the FAQ.

We probably should put it to FAQ.

			Andy