build(cmake): use CMAKE_COLOR_DIAGNOSTICS for colored output

- Set CMAKE_COLOR_DIAGNOSTICS instead of adding -fdiagnostics-color to
  CMAKE_CXX_FLAGS and setting CMAKE_COLOR_MAKEFILE
- CMake adds the correct flag for each compiler
- Keep a CMAKE_COLOR_DIAGNOSTICS value given by the user, except with
  DISABLE_COLOR=ON
- The color flag is no longer part of FairMQ_CXX_FLAGS in the package

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-09 23:03:44 +00:00
committed by Dennis Klein
parent 13739445e8
commit 08d371b1d4
2 changed files with 6 additions and 6 deletions

View File

@@ -120,12 +120,12 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g ${_warnings} -DNDEBUG ${_sanitizers}"
unset(_warnings)
unset(_sanitizers)
# Colored compiler diagnostics and build output. CMake adds the right compiler
# flag for each compiler. A value given by the user wins over the default.
if(DISABLE_COLOR)
set(CMAKE_COLOR_MAKEFILE OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=never")
else()
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
set(CMAKE_COLOR_DIAGNOSTICS OFF)
elseif(NOT DEFINED CMAKE_COLOR_DIAGNOSTICS)
set(CMAKE_COLOR_DIAGNOSTICS ON)
endif()
if(NOT DEFINED PROJECT_VERSION_TWEAK)

View File

@@ -118,7 +118,7 @@ FairMQ sets the compiler flags of each build type:
| `RelWithDebInfo` | `-O3 -g -DNDEBUG`, the warnings, the sanitizers |
| `Release` | `-O3 -DNDEBUG` |
The warnings are `-Wshadow -Wall -Wextra -Wpedantic`. The sanitizers are the flags of the [sanitizer options](#sanitizers). FairMQ also adds `-fdiagnostics-color=always` to `CMAKE_CXX_FLAGS`, or `-fdiagnostics-color=never` with `DISABLE_COLOR`.
The warnings are `-Wshadow -Wall -Wextra -Wpedantic`. The sanitizers are the flags of the [sanitizer options](#sanitizers). FairMQ sets `CMAKE_COLOR_DIAGNOSTICS` to `ON`, or to `OFF` with `DISABLE_COLOR`. CMake then adds the color flag of the compiler, for example `-fdiagnostics-color=always` for GCC. If you set `CMAKE_COLOR_DIAGNOSTICS`, FairMQ keeps your value, but `DISABLE_COLOR=ON` always sets `OFF`.
FairMQ sets the variables `CMAKE_CXX_FLAGS_<CONFIG>` as normal variables. Thus a value from `-DCMAKE_CXX_FLAGS_RELEASE=…` has no effect. Give additional flags in `CMAKE_CXX_FLAGS`.