[CMake] Passing a var to a macro

Adiel Mittmann adiel at inf.ufsc.br
Sun Mar 30 14:39:16 EDT 2008


Hi!

On Sun, Mar 30, 2008 at 08:13:27PM +0200, Leopold Palomo Avellaneda wrote:
> but if I do:
> 
> file(GLOB plugin_STR  *.c *.cpp *.cxx *.h *.hpp)
> PRINT_VALUES(${plugin_STR})
> 
> where:
> 
> macro(PRINT_VALUES  list)
> 	message (STATUS "Files to process in the macro PRINT_VALUES ${list}")
> endmacro(CREATE_FILE_LIST)

A minor correction here: it should be endmacro(PRINT_VALUES).

> then I get _only_  the first value of the list. 

This is because each item of the list stored in your variable plugin_STR gets
assigned to a different argument in your macro. This should fix it:

macro(PRINT_VALUES  list)
  FOREACH(arg ${ARGV})
    message("File: ${arg}")
  ENDFOREACH(arg ${ARGV})
endmacro(PRINT_VALUES)

> Or, what do I have to do to pass a list of values in a macro?

You could do that by specifying the variable NAME instead of its VALUE:

macro(PRINT_VALUES  list)
  message (STATUS "Files to process in the macro PRINT_VALUES ${${list}}")
endmacro(PRINT_VALUES)

file(GLOB plugin_STR  *.c *.cpp *.cxx *.h *.hpp)
PRINT_VALUES(plugin_STR)

-- 
Adiel Mittmann


More information about the CMake mailing list