Ever wanted to get more information out of a build process controlled by CMake
?
We sure did and this is how we did it:
Option 1 – Change your CMakeLists.txt files
As our first option, we present updating your CMakeLists.txt
file to include the following configuration line:
set(CMAKE_VERBOSE_MAKEFILE ON)
This option by itself is enough to enable verbosity.
A caveat with this option is that the configuration is not passed on to other CMakeLists.txt
files that are included to the build using the command add_subdirectory ()
from the master CMakeLists.txt
file.
Thus, you need to copy the configuration file to each CMakeLists.txt
file you want to be verbose.
Option 2 – Add the variable VERBOSE=1 to your make command
Assuming you are using a terminal and you are in the folder where you want to build your project.
After you execute the command
cmake $path_to_project_source;
execute your make command using the VERBOSE=1
variable as follows
make VERBOSE=1;
The caveat of this solution is that EVERYTHING becomes verbose, so you could have too many output data.
Option 3 – Add the variable -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to your cmake command
Adding the option -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
to the cmake
command, it will enable verbosity on all generated Makefiles
permanently.
So, assuming you are in the folder where you want to make the build, execute the following to generate the Makefiles
:
cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON $path_to_project_source;
and then just issue make
to perform the build with verbose output.
Please note, you cannot disable verbose output using make VERBOSE=0
after you enable it through cmake
, you need to execute the cmake
command again without the -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
option.
Bonus
To remove the ‘building’ and ‘linking’ lines from the output
e.g.
[ 10%] Building C object libs/segmentation/CMakeFiles/segments.dir/list_helpers.c.o and [ 30%] Linking C static library libsegments.a
add the option -DCMAKE_RULE_MESSAGES:BOOL=OFF
to your cmake
command to disable them.
e.g.
cmake -DCMAKE_RULE_MESSAGES:BOOL=OFF $path_to_project_source;
To remove the ‘Entering directory’ and ‘Leaving directory’ lines from the output
e.g.
make[2]: Leaving directory '/home/george/Projects/3rd Party/segments222bit/cmake-build-debug' and make[2]: Entering directory '/home/george/Projects/3rd Party/segments222bit/cmake-build-debug'
add the option --no-print-directory
to your make
command to disable them.
e.g.
make --no-print-directory;
This post is also available in: Greek
Pingback: [cmake] CMakeLists.txt 파일을 어떻게 디버깅합니까? - 리뷰나라