Get warning/error count

Hi All,

I have a CMake project that attempts to catch a huge number of errors in the configuration stage. This works quite well, and the output is normally no more than a hundred or so lines. However, even with such sparse output it can sometimes be difficult to pick out errors and warnings. If there have been errors and warnings, I would like to run a macro right at the end of configuration that tells the user if there have been any errors and warnings in a really obvious way.

My current solution is to override message(), and for the SEND_ERROR and WARNING cases I add one to a counter and pass the message on to _message(). This works, but it feels a bit hacky. Is there a more “official” way to do it? Something like CMAKE_NUMBER_OF_WARNINGS and CMAKE_NUMBER_OF_ERRORS variables - my understanding is that you don’t have to count FATAL_ERROR, because there can only ever be one of those.

If something like these variables doesn’t exist yet, might this ticket become a feature request?

Thanks,
Tom

1 Like

I don’t think there’s anything like that today. A feature request could be made, but that’s no guarantee that it will ever get implemented. I think usually CTest is used to “count” them, but it does it by regex capture on the output I believe.

Thanks Ben - would you mind expanding on what you mean by using CTest to count the number of CMake errors? We don’t use CTest internally, so I’m not familiar with the tool!

CTest is used in CI scripts and is shipped with CMake to help run test suites. It has logic for counting errors and warnings. It does this via regex scraping the output.

There’s already this proposal which would allow you to post-process the output to do what you want. There’s no-one driving it now though (I can’t put time into it myself in the foreseeable future).

Ah, now we’re talking - that would actually be useful for us on a number of levels.

At the moment we provide a little shim that makes our new CMake system look a lot like our legacy system, to keep the senior engineers happy. We have to pass some information from CMake back to this shim, and so far the best way has been to have CMake write a sourceable file for the shim to interpret. This might be a little more elegant.

We’ve also overridden the message() command in order to have some home comforts (Remove the “–” and indent for decorative text, colours when appropriate, etc…), but it’s a bit primitive. Again, there are features in that ticket that I’d definitely like to see.