From 15a7e4670a8f580545c95e14101f852c9d947998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Sun, 20 Sep 2020 10:50:44 +0200 Subject: [PATCH] Add a global option to force colored output from compiler. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Taken from https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949 Signed-off-by: Slávek Banko (cherry picked from commit 0459cbaf3eaf2b123a07d125623db0fc82baa6aa) --- modules/TDEMacros.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake index 6e61d4a..8f1110c 100644 --- a/modules/TDEMacros.cmake +++ b/modules/TDEMacros.cmake @@ -41,6 +41,19 @@ if( NOT TDE_CMAKE_ROOT ) CACHE FILEPATH "TDE CMake templates" ) endif() + + + option( FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." FALSE ) + if( ${FORCE_COLORED_OUTPUT} ) + if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) + if( NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.9" ) + add_compile_options (-fdiagnostics-color=always) + endif() + elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" ) + add_compile_options (-fcolor-diagnostics) + endif() + endif() + endif()