gcc.cmake: Add option for coloured gcc output

Setting the environment variable GCC_COLORS or CMake option
FORCE_COLORED_OUTPUT will cause GCC's colour messages to be outputted.
This commit is contained in:
Kent McLeod 2019-11-22 12:25:37 +11:00
parent 60ffdb1f0a
commit 4d21d40b1e

View file

@ -85,3 +85,20 @@ if(NOT ("${CCACHE}" STREQUAL CCACHE-NOTFOUND))
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
endif()
mark_as_advanced(CCACHE)
# GCC color options:
# Ninja and ccache cause gcc to not emit colored output when -fdiagnostics-color=auto.
# We upgrade this to -fdiagnostics-color=always if FORCE_COLORED_OUTPUT is set
# We default FORCE_COLORED_OUTPUT=ON if GCC_COLORS is set in the environment
# otherwise FORCE_COLORED_OUTPUT is left off.
if ($ENV{GCC_COLORS})
set(coloured_output ON)
else()
set(coloured_output OFF)
endif()
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output." ${coloured_output})
mark_as_advanced(FORCE_COLORED_OUTPUT)
if (${FORCE_COLORED_OUTPUT})
include_guard(GLOBAL)
add_compile_options(-fdiagnostics-color=always)
endif ()