Skip to content

Introduce `CMAKE_COLOR_DIAGNOSTICS` and `CMAKE_COMPILER_COLOR_DIAGNOSTICS` variables

Semyon Kolton requested to merge semyon.kolton/cmake:colored_diagnostics into master

This merge request tries to solve the issue #15502 (closed). See #15502 (comment 1083527) It introduces 2 new CMake variables:

  • CMAKE_COMPILER_COLOR_DIAGNOSTICS. This variable controls whether CMake should enable colored compiler diagnostics via compiler flags. It has 3 states: ON/OFF/not defined. ON will force colored diagnostics (-fcolor-diagnostics). OFF will disable colored diagnostics (-fno-color-diagnostics). If the variable is not defined - then CMake will not pass anything and default behavior will be used. By default, this variable is ON for Ninja generators and not defined for other cases.
  • CMAKE_COLOR_DIAGNOSTICS. This variable controls all colored diagnostics in CMake. When ON it will force CMAKE_COMPILER_COLOR_DIAGNOSTICS and CMAKE_COLOR_MAKEFILE to ON. When OFF it does nothing. By default, it's OFF.

This MR consists of 2 commits. First introduce CMAKE_COMPILER_COLOR_DIAGNOSTICS and second introduces CMAKE_COLOR_DIAGNOSTICS. These are dependent commits, so I was unable to create separate MRs for each of them. However, I consider them as solving separate issues. Variable CMAKE_COMPILER_COLOR_DIAGNOSTICS solve actual issue at hand - no colored diagnostics for CMake. I consider this to be a more critical issue. While the second variable CMAKE_COLOR_DIAGNOSTICS is more of a quality of life variable needed for easier configuration for users.

Fixes: #15502 (closed)

Merge request reports