cmake: Enable colors with ninja

Unfortunately this needs a bit of a hack, as the compiler uses isatty(),
and ninja uses a pipe.
This commit is contained in:
Fabian Homborg 2018-11-02 12:26:27 +01:00
parent 1836e704c4
commit 47c1144a3c

View file

@ -21,6 +21,15 @@ IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
SET(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}") SET(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
ENDIF() 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. # Disable exception handling.
ADD_COMPILE_OPTIONS(-fno-exceptions) ADD_COMPILE_OPTIONS(-fno-exceptions)