How to view CMake cache variables

Running CMake for a project creates many variables that are required for its own operation and for the project being built. If you use the CMake GUI, then these are the variables which you see populated after you perform Configure and then Generate. When you want to diagnose a CMake build problem at the shell, it is useful to be able to view these variables.

  • To perform a CMake build and then print the cache variables:
$ cmake -L ..

Note that in the above command, I am in the build directory and the CMakeLists.txt is in the parent directory. This command builds as usual and at the end prints the CMake variables and their values.

  • To perform a CMake build and list all the cache variables, including advanced variables:
$ cmake -LA ..

Note that the number of variables that are printed can be quite high for big projects. I have seen it run into the hundreds.

  • To perform a CMake build and list all the cache variables and print the help documentation about each variable too:
$ cmake -LAH ..
  • If you have already done a CMake build and just need to print out the cache variables, add the -N option:
$ cmake -L -N

This command assumes that the current directory is the build directory containing the cache files, so no directory needs to be specified. This command is quick because it does not do a CMake build. Additionally, you can also add the -AH options as before if you want.

Tried with: CMake 2.8.12.2 and Ubuntu 16.04

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s