Using CMake with GNU Make: How can I see the exact

2019-01-02 19:50发布

I use CMake with GNU Make and would like to see all commands exactly (for example how the compiler is executed, all the flags etc.).

GNU make has --debug, but it does not seem to be that helpful are there any other options? Does CMake provide additional flags in the generated Makefile for debugging purpose?

5条回答
萌妹纸的霸气范
2楼-- · 2019-01-02 19:55

When you run make, add VERBOSE=1 to see the full command output. For example:

cmake .
make VERBOSE=1

Or you can add -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to the cmake command for permanent verbose command output from the generated Makefiles.

cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make

To reduce some possibly less-interesting output you might like to use the following options. The option CMAKE_RULE_MESSAGES=OFF removes lines like [ 33%] Building C object..., while --no-print-directory tells make to not print out the current directory filtering out lines like make[1]: Entering directory and make[1]: Leaving directory.

cmake -DCMAKE_RULE_MESSAGES:BOOL=OFF -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make --no-print-directory
查看更多
宁负流年不负卿
3楼-- · 2019-01-02 19:58

It is convenient to set the option in the CMakeLists.txt file as:

set(CMAKE_VERBOSE_MAKEFILE ON)
查看更多
无色无味的生活
4楼-- · 2019-01-02 20:14

Or simply export VERBOSE environment variable on the shell like this: export VERBOSE=1

查看更多
泪湿衣
5楼-- · 2019-01-02 20:15

If you use the CMake GUI then swap to the advanced view and then the option is called CMAKE_VERBOSE_MAKEFILE.

查看更多
刘海飞了
6楼-- · 2019-01-02 20:15

I was trying something similar to ensure the -ggdb flag was present.

Call make in a clean directory and grep the flag you are looking for. Looking for debug rather than ggdb I would just write.

make VERBOSE=1 | grep debug

The -ggdb flag was obscure enough that only the compile commands popped up.

查看更多
登录 后发表回答