From 74b5fae52d24e6fcfacee33441ae9fae2efbfaf7 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 19 Oct 2023 16:55:41 +0200 Subject: Clang: Use -fno-ansi-escape-codes for color diagnostics on Windows -fno-ansi-escape-codes is used only on Windows by Clang. Without the flag color diagnostics are displayed only if clang.exe is executed directly. Build tools like ninja and mingw32-make will not display colored diagnostics. Using -fno-ansi-escape-codes will make the build tools pass the colored diagnostics to the calling application e.g IDE. Fixes: #24235 --- Modules/Compiler/Clang.cmake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake index e5683c2..4c033ca 100644 --- a/Modules/Compiler/Clang.cmake +++ b/Modules/Compiler/Clang.cmake @@ -117,8 +117,14 @@ else() # '-fcolor-diagnostics' introduced since Clang 2.6 if(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 2.6) - set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS "-fcolor-diagnostics") - set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF "-fno-color-diagnostics") + # -fansi-escape-codes mentioned at https://releases.llvm.org/3.7.0/tools/clang/docs/UsersManual.html + if (CMAKE_HOST_WIN32 AND CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 3.7) + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS -fansi-escape-codes -fcolor-diagnostics) + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF -fno-ansi-escape-codes -fno-color-diagnostics) + else() + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS -fcolor-diagnostics) + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF -fno-color-diagnostics) + endif() endif() endmacro() endif() -- cgit v0.12