Search code examples
cmakemakefileninja

Report target failure in addition to translation unit compilation failure


Suppose I have hundreds of targets and some of them are not critical for the build to succeed (and for example I am using --keep-going on make or -k 9000 on ninja) and I need to figure out which cmake targets failed.

With add_custom_command() a post-build command can be added to a cmake target that prints its name like this:

success: myTarget.dll

But what about failures?

If linking fails then I can parse the verbose output of whatever I am using (ninja/make/msbuild) and see which target has failed.

However if compilation of a translation unit fails the only error I get is that a particular source file does not compile and figuring out which cmake target exactly has failed is harder.

The only thing I have come up with is running this after the build has failed: ninja -nv which will make a verbose dry run and I can intercept the link commands and parse the cmake targets that have failed that way...

Any other ideas?


Solution

  • I ended up using dry runs of make/ninja and parsing their output