1

On Linux I can build a C++ project with cmake like:

$ mkdir build
$ cd build
$ cmake ../myproject
$ make
[  ] Building CXX object ...

Is there a way to pass an option to cmake or make so that it will print the full command-lines (and all the options) it is passing to the C++ compiler to compile each object file?

(I tried:

$ make V=1

but it doesn't seem to work. I guess the cmake-generated Makefile doesn't work with that option?)

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319

2 Answers2

2

As per this link There are three options (+1 extra found in the answer of HolyBlackCat):

1

If you can / want to modify the CMakeLists.txt, you can just add

set(CMAKE_VERBOSE_MAKEFILE ON)

This has to be done in every CMakeLists.txt file in your project though, so it might be a bit cumbersome, if you want to enable it for the entire project.

2

To write the verbose changes directly to the makefile, you can run the cmake command which generates the make file with an additional flag:

cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ./path

And, you guessed it, to disable it, you need to run it again:

cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=OFF ./path

3

Finally, if you build your project by calling make and do not use the cmake --build ./path or cmake --build ./path --target target commands, you can pass it as an option to make directly:

make VERBOSE=1;

Although I would not recommend it, because they whole point of cmake is to not have to use make anymore (although it's still called behind the scenes).

infinitezero
  • 1,610
  • 3
  • 14
  • 29
1

Use either make VERBOSE=1, or cmake --build <path> --verbose which automatically invokes the right command for the generator you used.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207