[CMake] Expansion of variables

Brad King brad.king at kitware.com
Thu Jun 9 16:55:45 EDT 2005


Axel Wachtler wrote:
>> > For C compiler the expansion is correct:
>> > -this --that --someother -many -more --of -this -nasty -settings
>> >
>> > In the MACRO() I get
>> > -this\ --that\ --someother\ -many\ -more\ --of\ -this\ -nasty\ 
>> -settings
>>
>> What is the definition of the macro?
>         ADD_CUSTOM_COMMAND(
>             OUTPUT ${asm_obj}
>             DEPENDS ${asm_file}
>             COMMAND ${CMAKE_C_COMPILER}
>             ARGS -x assembler-with-cpp -o ${asm_obj} ${CMAKE_C_FLAGS}\
>                 $(INCLUDE_FLAGS) -c ${asm_file}

The problem is not in the MACRO.  Any ADD_CUSTOM_COMMAND will behave the 
same way.  The problem is that CMAKE_C_FLAGS is a string representing 
the set of flags to be put on the command line for the C compiler. 
Since command lines use spaces for separation, the string value uses 
spaces too.  When you pass it to ADD_CUSTOM_COMMAND it is treated as a 
CMake language argument, which uses semicolons for separation.  The 
command then gets all the arguments in a single string and thinks it is 
supposed to reproduce that string as a single argument on the command line.

You need to use the SEPARATE_ARGUMENTS command to convert the 
space-separated list to a semicolon-separated list for use as a CMake 
language argument list.

-Brad


More information about the CMake mailing list