Browse Source

color: Add CMAKE_COLOR_DIAGNOSTICS environment variable

Semyon Kolton 3 years ago
parent
commit
78adb1b952

+ 9 - 0
Help/envvar/CMAKE_COLOR_DIAGNOSTICS.rst

@@ -0,0 +1,9 @@
+CMAKE_COLOR_DIAGNOSTICS
+-----------------------
+
+.. versionadded:: 3.24
+
+.. include:: ENV_VAR.txt
+
+Specifies a default value for the :variable:`CMAKE_COLOR_DIAGNOSTICS` variable
+when there is no explicit value given on the first run.

+ 1 - 0
Help/manual/cmake-env-variables.7.rst

@@ -31,6 +31,7 @@ Environment Variables that Control the Build
    /envvar/CMAKE_APPLE_SILICON_PROCESSOR
    /envvar/CMAKE_BUILD_PARALLEL_LEVEL
    /envvar/CMAKE_BUILD_TYPE
+   /envvar/CMAKE_COLOR_DIAGNOSTICS
    /envvar/CMAKE_CONFIGURATION_TYPES
    /envvar/CMAKE_CONFIG_TYPE
    /envvar/CMAKE_EXPORT_COMPILE_COMMANDS

+ 3 - 0
Help/release/dev/color-diagnostics.rst

@@ -5,3 +5,6 @@ color-diagnostics
   color diagnostics generated by compilers.  This variable also controls
   color buildsystem messages with :ref:`Makefile Generators`, replacing
   :variable:`CMAKE_COLOR_MAKEFILE`.
+
+  The :envvar:`CMAKE_COLOR_DIAGNOSTICS` environment was added to set
+  a default value for :variable:`CMAKE_COLOR_DIAGNOSTICS`.

+ 3 - 1
Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst

@@ -32,4 +32,6 @@ When ``OFF``:
 * GNU/Clang compilers are invoked with a flag disabling color diagnostics
   (``-fno-color-diagnostics``).
 
-``CMAKE_COLOR_DIAGNOSTICS`` is not defined by default.
+If the :envvar:`CMAKE_COLOR_DIAGNOSTICS` environment variable is set, its
+value is used.  Otherwise, ``CMAKE_COLOR_DIAGNOSTICS`` is not defined by
+default.

+ 4 - 0
Modules/CMakeGenericSystem.cmake

@@ -47,6 +47,10 @@ set (CMAKE_SKIP_INSTALL_RPATH "NO" CACHE BOOL
 
 set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make.  This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.")
 
+if(DEFINED ENV{CMAKE_COLOR_DIAGNOSTICS} AND NOT DEFINED CACHE{CMAKE_COLOR_DIAGNOSTICS})
+  set(CMAKE_COLOR_DIAGNOSTICS $ENV{CMAKE_COLOR_DIAGNOSTICS} CACHE BOOL "Enable colored diagnostics throughout.")
+endif()
+
 if(CMAKE_GENERATOR MATCHES "Make")
   if(NOT DEFINED CMAKE_COLOR_DIAGNOSTICS)
     set(CMAKE_COLOR_MAKEFILE ON CACHE BOOL "Enable/Disable color output during build.")