When repeatedly building a project, when there are warnings but no errors in a translation unit, the main source file is typically not recompiled.
This can make it difficult to work through errors and warnings to attempt to get the project to build with no warnings. Typically one must keep iteratively building until all errors are taken care of, then do a full clean and build to ensure that there are no warnings (as well as to ensure that the previously-completed build wasn't a "fluke" caused by leftover build artifacts).
Is there any way with CMake (or some other utility such as a Bash script) to parse build output for warnings, save them in a text file somewhere, and then re-display them on subsequent builds?
For bonus points, since I'm colorizing my compiler output, can warnings be saved with the color control-characters and re-displayed with the same colorization?
(If it matters, at the moment I'm only compiling C++, and I'm typically using GCC to do so. My build generator of choice is Ninja, and I have some Bash scripts I've written that wrap all my calls to CMake and Ninja.)
I'm not a
bash
expert - so the following code can certainly be improved - but here is a working example withCMake
/bash
/gcc
/ninja
that should give the basic idea I had:stderr
<object file name>.warnings
CMakeLists.txt
capture_warnings.sh.in
build.sh
I thought collecting the files to be deleted in
remove_obj_with_warnings.sh
would be faster than grepping for the.warnings
files. The disadvantage would be that it could contain files that are already deleted or not-yet-existing (covered by givingrm -f
).Especially true if you make the
remove_obj_with_warnings.sh
call optional.References used: