Aar*_* B. 26
要简单地打印一个值,您可以执行以下操作:
message(STATUS "foo include dir: ${foo_INCLUDE}")
Run Code Online (Sandbox Code Playgroud)
${foo_INCLUDE}您希望打印的值在哪里。
注意:我使用的是 cmake > 3.14
Phi*_*hil 14
您问:(1)是否有一种简单的方法来显示这些变量而无需在CMakeLists.txt文件上运行cmake,以及(2)无需手动检查config.cmake文件?
我可以给你一个肯定的回答(2)但它确实要求你(重新)运行cmake.但是,由于您只需cmake .在构建目录中执行即可重新运行cmake configure步骤,因此重新运行cmake不会阻止您尝试此方法.我在这个答案中给出了答案,并使用了get_cmake_property命令.这是封装到cmake宏中的代码print_all_variables,所以我可以在调试我的cmake脚本时使用它.
macro(print_all_variables)
message(STATUS "print_all_variables------------------------------------------{")
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
message(STATUS "print_all_variables------------------------------------------}")
endmacro()
Run Code Online (Sandbox Code Playgroud)
使用与cmake函数相同的语法调用宏:
print_all_variables()
Run Code Online (Sandbox Code Playgroud)
运行 CMake 并使用 GUI 工具查看缓存ccmake。然后你就会得到所有的变量。
或者运行 CMake, -LH然后您将在配置后打印所有变量。
所以我认为不运行 CMake 就不可能获取变量。
这些变量通常被硬编码到 FindFoo.cmake 中,因此如果不先运行该函数就无法提取它们。请注意,有时 Foo_LIBRARIES 的值取决于系统配置,在运行 find_package(Foo) 之前这是未知的。
| 归档时间: |
|
| 查看次数: |
35193 次 |
| 最近记录: |