How to set the global variable in a function for cmake?

后端 未结 5 1657
庸人自扰
庸人自扰 2020-12-15 19:14

I\'m writing a CMakeLists.txt to generate files and compile the generated files. I create a function to add some file path strings to a global list variable.

My CMak

5条回答
  •  醉话见心
    2020-12-15 20:12

    Building upon Maxim Suslov's answer, the following code worked for a similar problem I faced:

    set_property(GLOBAL PROPERTY source_list)
    function(add_source)
        get_property(tmp GLOBAL PROPERTY source_list)
        foreach(arg ${ARGV})
            set(tmp "${tmp} ${arg}")
        endforeach()
        set_property(GLOBAL PROPERTY source_list "${tmp}")
    endfunction(add_source)
    
    add_source(a_file)
    add_source(b_file c_file)
    
    get_property(local_prop GLOBAL PROPERTY source_list)
    message("list: ${local_prop}")
    

    Function add_source can be called from inside any sub-directory.

提交回复
热议问题