Passing a list to a CMake macro

前端 未结 4 1832
我寻月下人不归
我寻月下人不归 2020-12-03 02:39

I am trying to write a macro which goes through a given list of libraries. However the message call in the macro prints only the first item of the list. What am I doing wron

4条回答
  •  無奈伤痛
    2020-12-03 03:03

    Your macro should look like this:

    macro(FindLibs list_var_name)            
        message( "inside ${${list_var_name}}" )
    endmacro()
    

    and call the macro like this:

    FindLibs(LIBRARY_NAMES_LIST)
    

    So inside the macro: ${list_var_name} = LIBRARY_NAMES_LIST, ${${list_var_name}} = ${LIBRARY_NAMES_LIST} = your list.

    Another solution could be (somewhat more obscure):

    macro(FindLibs)            
        message( "inside ${ARGN}" )
    endmacro()
    
    FindLibs(${LIBRARY_NAMES_LIST})
    

    In the first solution you pass only the name of the list-variable to the macro (one argument). In the second solution you expand the list before calling the macro and pass N parameters (N = length of the list).

提交回复
热议问题