【问题标题】:CMake get a cache variables list from inside a CMakeLists.txt scriptCMake 从 CMakeLists.txt 脚本中获取缓存变量列表
【发布时间】:2021-11-05 22:38:27
【问题描述】:

我想知道是否有办法从 CMakeLists.txt 脚本中获取缓存变量列表。我的意思是,有这样的东西:

cmake -S . -B build -DMY_VAR1=hello -DMY_VAR2=there 

并且,在我的 CMakeLists.txt 中

option(MY_VAR3 "a cache setting" ON)

有没有办法从 CMakeLists.txt 脚本本身中获取包含 MY_VAR1、MY_VAR2 和 MY_VAR3 以及所有其他缓存变量的列表 var MY_CACHE_LIST?

谢谢

【问题讨论】:

    标签: cmake cmake-language cmakelists-options


    【解决方案1】:

    缓存变量列表包含在目录的CACHE_VARIABLES 属性中。可以这样提取:

    get_directory_property(cache_vars CACHE_VARIABLES)
    message(STATUS "List of CACHE variables: ${cache_vars}")
    

    除了打印这些变量的列表之外,通过使用每个变量的名称,还可以提取其值并提取Properties on Cache Entries 下列出的其他属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-29
      • 2013-06-15
      • 1970-01-01
      • 2015-09-27
      • 1970-01-01
      相关资源
      最近更新 更多