debuggingmakefilecmakeoutput

How to produce a make build that is verbose only on failure


There are many ways to produce a verbose make command with cmake. This has been described in many places. (basically cmake; make VERBOSE=1 or set the CMAKE_VERBOSE_MAKEFILE variable).

Verbose here refers to showing the invoked commands and other information on the steps taken by make.

This seems to be an all or nothing setting. Either you see all the commands or none of the commands, regardless of the whether the command succeed or not.

A related tool, ctest (for testing) has a very useful options --output-on-failure for which verbosity depends on the particular test being successful; only showing the screen out for failing tests.

The question is whether cmake has a similar feature regarding giving details only on failure. That is, for the most part I don't want to see make compilation commands, but when it fails I would like to see what is the exact command that failed with all the options on display.

That is, the question is if there is some setting or command-line option for make or cmake that, in the build step, will print the full issued command (and output) only for commands that failed.

The reason of course is that it gives the opportunity to see the actual compilation flags for the failing step and allows to reproduce the exact command interactively sometimes.

(I use C++, but the question is general I think)


Solution

  • Sometimes, when I am too desperate and I cannot understand the error messages I do this:

    make -j 10 || make VERBOSE=1
    

    So it will compile fast, and if it fails it runs again serially in verbose mode. It is very likely that the first compilation is the one failing.