[CMake] Cmake coloring gcc output on errror

Michael Hertling mhertling at online.de
Wed Jan 11 07:44:51 EST 2012


On 01/10/2012 07:17 PM, vivek goel wrote:
> Is there a way to color warning/error of gcc with cmake ?

AFAIK, no, but you might remember the power of *nix, feed the output
of "make VERBOSE=1 2>&1" into sed/awk/perl/<your-favorite-here> and
use ANSI Control Sequence Initiators:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(P C)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){Return 0;}\n")
SET_SOURCE_FILES_PROPERTIES(main.c PROPERTIES COMPILE_FLAGS "-Wall")
ADD_EXECUTABLE(main main.c)

% cmake <srcdir>
...
% make VERBOSE=1 2>&1 | sed \
-e 's%^.*: error: .*$%\x1b[37;41m&\x1b[m%' \
-e 's%^.*: warning: .*$%\x1b[30;43m&\x1b[m%'

Regards,

Michael


More information about the CMake mailing list