CMAKE: Print out all accessible variables in a scr

2019-01-05 07:48发布

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?

标签: cmake
3条回答
萌系小妹纸
2楼-- · 2019-01-05 08:01

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

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

To print environment variables use cmake's command mode:

execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment")
查看更多
3楼-- · 2019-01-05 08:03

Another way is to simply use:

cmake -LAH

From the manpage:

-L[A][H]

List non-advanced cached variables.

List cache variables will run CMake and list all the variables from the CMake cache that are not marked as INTERNAL or ADVANCED. This will effectively display current CMake settings [...].

If A is specified, then it will display also advanced variables.

If H is specified, it will also display help for each variable.

查看更多
走好不送
4楼-- · 2019-01-05 08:05

ccmake is a good interactive option to interactively inspect cached variables (option( or set( CACHE:

sudo apt-get install cmake-curses-gui
mkdir build
cd build
cmake ..
ccmake ..

查看更多
登录 后发表回答