Creating logs

I know this question has been asked before, but I still can’t quite figure it out. Regarding the toolchain, I am using CMake 3.27, ninja for the generator, and arm-none-eabi for the GCC compiler toolchain, where my host machine is Windows, and the target firmware is built against a Cortex-M.

After building, I would like to create a post-build step that parses the resulting log file and pulls out all the compiler warnings (there are a lot in this project I have inherited). The problem is that the log file Ninja creates has no compiler warnings; stdout is the only place I can see the compiler warnings.

Not that it matters, but I am using CMakePresets, so when I build, technically, I could do something like this:
cmake --build --preset foo >> build_log.txt

However, I have a group of devs, so each one would have to remember to type that exact command, or, I would have to wrap it in a script, but that adds another layer of complexity. Presets have been the norm for the team, but I can’t ask people to also create log files. Instead, I want to find a way to do this implicitly.

I *almost had things working in a hacky sort of way, by leveraging CMAKE_RULE_LAUNCH_COMPILE. I never did get it working, as it was kind of an abuse of functionality on my end, but it was worth a try.

Anyway, do you know of any hacks or workarounds that would let me write the compiler warnings to a file as part of the build? Maybe there are some different generators like Make that support logs? Or maybe there’s a flag I can pass to Ninja to show the compiler warnings in the log? I’ve searched all over, so this was my last hope.

Thanks!

Try builddriver, that may help

In addition to builddriver (I’ve never used it myself), you can use CMAKE_CXX_COMPILER_LAUNCHER to be a script that wraps up the “real” compiler to do your logging (synchronization in a parallel build may be an issue). Alternatively, you can use a CTest script to do ctest_build. CTest can parse out warning and error lines and puts them…somwhere under Testing/. You can also upload that to CDash for a web viewer into the warning/error state of the build.