21

I would like to know if there is any way to debug a cmake process that forcing the command to print mode details about how variables are getting some value. For example, I see

-- Boost version: 1.63.0
-- Boost version: 1.63.0
-- Found the following Boost libraries:
--   system
--   filesystem
--   timer
--   chrono

And I would like to know where does that version is checked and found.

I have added set(CMAKE_VERBOSE_MAKEFILE ON) in the first line of CMakeLists.txt prior to running cmake ... However, I don't see any verbose message.

I am looking for some thing like set -x in bash programming.

2 Answers 2

29

Cmake has command line options --trace, --trace-expand, and --trace-source=some_cmake_source

These will give you very verbose output, and if you start cmake like this:

$cmake --trace-expand source_dir

will output complete configure process, with all cmake variables replaced with their value. Since the amount of output is huge (literally) I usually redirect it into file, like this:

$cmake --trace-expand source_dir > trace.txt 2>&1

This will redirect complete output, including error messages, into the file trace.txt.

If you don't want output of complete configure, but one particular file, you should use --trace-source=some-source, like this:

$cmake --trace-source=FindBoost.cmake source_dir

will output execution of that particular file (in this case, it will show the process of searching for boost libraries)

Also, setting CMAKE_VERBOSE_MAKEFILE variable will not help you, since it controls verbosity during the build process, not configure.

at the end, here are references to cmake documentation:

cmake command line options

CMAKE_VERBOSE_MAKEFILE

Sign up to request clarification or add additional context in comments.

Comments

6

CMake provides --debug-output and --trace options that can be used when running from the command line:

cmake --debug-output ..

or

cmake --trace ..

The debug-output option provides some high-level insight into how CMake is traversing your CMakeLists.txt file structure; this can be set from the CMake GUI also (Options > Debug Output). The trace option dumps CMake's processing line-by-line (likely want to redirect this output to a file). The trace option also comes with trace-expand and trace-source=<file> flavors, to expand CMake variables and trace only a specific file, respectively.

If you use trace to find a CMake file and variable of interest (e.g. a BOOST variable), you can also make use of variable_watch() to help monitor changes to that variable, and print messages to the screen.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.