cmake, lost in the concept of global variables (and PARENT_SCOPE or add_subdirectory alternatives)

前端 未结 2 421
走了就别回头了
走了就别回头了 2020-12-09 05:42

I have a cmake project in which I have some modules and I\'m using Find-*.cmake for including the shared modules in the application. For not taking in account every module t

2条回答
  •  旧时难觅i
    2020-12-09 06:17

    You can 'simulate' GLOBAL variable behavior, by using properties with GLOBAL scope :

    SET_PROPERTY(GLOBAL PROPERTY MyGlobalProperty "MyGlobalPropertyValue")
    

    Then you can extract your global property by using

    GET_PROPERTY(MyLocalVariable GLOBAL PROPERTY MyGlobalProperty)
    

    Then, MyLocalVariable contains "MyGlobalPropertyValue".

    Because PARENT_SCOPE extends variable definitions to the only parent directory (and not to its parents), there are cases it's not enough, for example if you have a deep source tree...

提交回复
热议问题