[CMake] Post-process compiler output

Michael Hertling mhertling at online.de
Tue Jun 14 10:36:48 EDT 2011


On 06/14/2011 11:46 AM, Michael Wild wrote:
> On 06/14/2011 11:36 AM, Sebastian Schaetz wrote:
>> Hi,
>>
>> I'm using CMake to generate makefiles to build my C++ projects with g++. When
>> developing code I find it useful to "post-process" g++ output. In particular I
>> like to feed the output through gSTLFilt.pl [0] and a custom version of colorgcc
>> [1].
>>
>> Currently I have a wrapper around make (I call xmake.sh) that pipes the entire
>> output of make through those two tools [2]. But this is not optimal since I lose
>> the colorful output CMake puts into the makefiles.
>>
>> So my question is: is there a way to append stuff to the g++ command line such
>> as "2>&1 | perl colorize.pl 2>&1 | perl gSTLFilt.pl"?
>>
>> Thanks in advance,
>> Sebastian
>>
>> [0] http://www.bdsoft.com/tools/stlfilt.html
>> [1] http://schlueters.de/colorgcc.html
>> [2] https://github.com/sschaetz/colorgcc/tree/filter
> 
> I don't think that this is possible directly. But you can write a
> wrapper shell script which does the above and then pass that script as
> the compiler to cmake. Something like this:
> 
> #!/bin/sh
> /usr/bin/g++ $@ 2>&1 | perl colorize.pl 2>&1 | perl gSTLFilt.pl
> 
> HTH
> 
> Michael

Alternatively, you might use the RULE_LAUNCH_COMPILE properties to
introduce a wrapper script for the compilations. In this way, you do
not have to remember to configure the project with the wrapper script
as compiler, and the script can't make any trouble during the initial
CMake run when the toolchain is examined.

However, when using a wrapper script in lieu of the compiler, be aware
of the rules w.r.t. the return values of pipelines; Make is especially
sensitive in this regard. E.g., just grepping GCC's output certainly
wouldn't work, and the above-noted line means that the last Perl
script's return value would be taken on trust. Refer to Bash's
pipefail option for more information.

Regards,

Michael


More information about the CMake mailing list