cmake: enable CMAKE_COLOR_DIAGNOSTICS by default

Related to https://github.com/espressif/esp-idf/issues/4162

Setting this option informs CMake that it should pass
-fcolor-diagnostics flag to the compiler.

(Colorized build system output, like from GNU Make, is produced even
without this flag.)

Note that if the build is done using Ninja and the build output is
redirected (not a TTY), Ninja will still strip the escape codes from
the output. For the case of idf.py, this is handled in the next
commit.
This commit is contained in:
Ivan Grokhotkov 2022-08-01 20:18:28 +02:00
parent e40b83c16f
commit 1ffbee27e7
No known key found for this signature in database
GPG Key ID: 1E050E141B280628

View File

@ -344,6 +344,12 @@ macro(project project_name)
# Generate compile_commands.json (needs to come after project call).
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# If CMAKE_COLOR_DIAGNOSTICS not set in project CMakeLists.txt or in the environment,
# enable it by default.
if(NOT DEFINED CMAKE_COLOR_DIAGNOSTICS AND NOT DEFINED ENV{CMAKE_COLOR_DIAGNOSTICS})
set(CMAKE_COLOR_DIAGNOSTICS ON)
endif()
# Since components can import third-party libraries, the original definition of project() should be restored
# before the call to add components to the build.
function(project)