Make use of CMake gccfilter

GCCFilter is a neat perl script that allows you to colorize GCC output and thus makes debugging much more fun and, more importantly, faster.

You can use GCCFilter with CMake generated Makefile by calling

gccfilter -a -c make


However, this approach has some drawbacks: delayed output of CMake status information, lack of color in CMake commands is most obvious.

The question is: is there a way to write some CMake module that looks gccfilter

if the compiler is equal gcc

, checks if it is installed, for example COLOR_CXX

(quite easily) and then tells CMake to replace all calls gcc

with gccfilter -a -c gcc


CMake offers a variable CMAKE_CXX_COMPILER

, but changing that setting will prevent CMake from finding the correct include paths, etc. Is there some variable that we can change after the command project()

, which is prefixed before each call gcc



source to share

1 answer

You can use CMake by setting the RULE_LAUNCH_COMPILEgccfilter

property to a shell script that calls with the options you want.gccfilter

Create an executable shell script named gccfilter_wrap

in the furthest CMake project directory with the following content:

exec gccfilter -a -c "$@"


Make sure to set the executable bit of the file. Then in CMakeLists.txt

set the directory property RULE_LAUNCH_COMPILE

before adding targets:

project (HelloWorld)

set_directory_properties(PROPERTIES RULE_LAUNCH_COMPILE

add_executable(HelloWorld HelloWorld.cpp)


The generated makefile rules are then prefixed with each call to the compiler with a gccfilter_wrap

script. Alternatively, the property RULE_LAUNCH_COMPILE

can also be set as a target property or a global property.


only works for Makefile-based CMake generators.

Edit Thilo

This is how I finally solved the problem - basically a paraphrased version of that solution:

# GCCFilter, if appliciable
  option(COLOR_GCC "Use GCCFilter to color compiler output messages" ON)
  set(COLOR_GCC_OPTIONS "-c -r -w" CACHE STRING "Arguments that are passed to gccfilter when output coloring is switchend on. Defaults to -c -r -w.")




All Articles