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

后端 未结 5 1662
庸人自扰
庸人自扰 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 19:52

    Another approach is to use global properties. Once you set it:

    set_property(GLOBAL PROPERTY source_list_property "${source_list}")
    

    you can read it from everywhere:

    get_property(source_list GLOBAL PROPERTY source_list_property)
    

    I used in examples above the different names for property (source_list_property) and for variable (source_list). Maybe it is better to use the same name. But point is to use a property as global variables, and not about naming.

    Such global properties aren't in cache.

提交回复
热议问题