diff --git a/CMakeLists.txt b/CMakeLists.txt index a83311cf78a..32d2f361884 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -862,8 +862,15 @@ if(NOT MSVC) append_cxx_flag_if_supported("-Qunused-arguments" CMAKE_CXX_FLAGS) if(${USE_COLORIZE_OUTPUT}) - append_cxx_flag_if_supported("-fcolor-diagnostics" CMAKE_CXX_FLAGS) - append_cxx_flag_if_supported("-fdiagnostics-color=always" CMAKE_CXX_FLAGS) + # Why compiler checks are necessary even when `try_compile` is used + # Because of the bug in ccache that can incorrectly identify `-fcolor-diagnostics` + # As supported by GCC, see https://github.com/ccache/ccache/issues/740 (for older ccache) + # and https://github.com/ccache/ccache/issues/1275 (for newer ones) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + append_cxx_flag_if_supported("-fdiagnostics-color=always" CMAKE_CXX_FLAGS) + else() + append_cxx_flag_if_supported("-fcolor-diagnostics" CMAKE_CXX_FLAGS) + endif() endif() append_cxx_flag_if_supported("-faligned-new" CMAKE_CXX_FLAGS)