CMAKE:在脚本中打印出所有可访问的变量 [英] CMAKE: Print out all accessible variables in a script

查看:1176
本文介绍了CMAKE:在脚本中打印出所有可访问的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法打印出所有可访问的变量在CMAKE。我对CMAKE变量不感兴趣 - 如--help-variables选项。我说的是我定义的变量,或者包含脚本定义的变量。



我目前包含



INCLUDE($ {CMAKE_ROOT} CMakeBackwardCompatibilityCXX.cmake)



,希望我可以打印出所有的变量,而不是通过所有的文件和阅读什么是可用的 - 我可能会发现一些变量,我不知道这可能是有用的。这将是很好的帮助学习&发现。它是严格的调试/开发。



类似于打印Lua中当前范围可访问的所有局部变量但是对于cmake!



有没有人这样做?

解决方案

使用 get_cmake_property 函数,以下循环将打印出所有定义的CMake变量及其值:

  get_cmake_property(_variableNames VARIABLES)
foreach(_variableName $ {_ variableNames})
message(STATUS$ {_ variableName} = $ {$ {_ variableName} }要打印环境变量,请使用cmake的 https://cmake.org/cmake/help/v3.7/manual/cmake.1.html#command-line-tool-moderel =nofollow noreferrer>命令模式

  execute_process(COMMAND$ {CMAKE_COMMAND}-Eenvironment)
pre>

I'm wondering if there is a way to print out all accessible variables in CMAKE. I'm not interested in the CMAKE variables - as in the --help-variables option. I'm talking about my variables that I defined, or the variables defined by included scripts.

I'm currently including

INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityCXX.cmake)

and was hoping that I could just print out all the variables that are here, instead of having to go through all the files and read what was available - I may find some variables I didn't know about that may be useful. It would be good to aid learning & discovery. It is strictly for debugging/development.

similar to the question in Print all local variables accessible to the current scope in Lua but for cmake!

Has anyone done this?

解决方案

Using the get_cmake_property function the following loop will print out all CMake variables defined and their values:

get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
    message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

To print environment variables use cmake's command mode:

execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment")

这篇关于CMAKE:在脚本中打印出所有可访问的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆