From 47c1144a3cbcffde1f92af2f07357daf91af16fc Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 2 Nov 2018 12:26:27 +0100 Subject: [PATCH] cmake: Enable colors with ninja Unfortunately this needs a bit of a hack, as the compiler uses isatty(), and ninja uses a pipe. --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 563a21868..e3251903f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,15 @@ IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) SET(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}") ENDIF() +# Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support. +# Rationale in https://github.com/ninja-build/ninja/issues/814 +if (CMAKE_GENERATOR STREQUAL "Ninja" AND + ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") +endif() + # Disable exception handling. ADD_COMPILE_OPTIONS(-fno-exceptions)