Make colors the output fine by default, nice. My default configuration with Make/Clang colors my output just fine. But if I simply change my generator to Ninja, the pretty coloring is.
Hi, How can I enable color output when using the Ninja generator? I have set CMAKE_COLOR_DIAGNOSTICS to ON and also tried adding the -fdiagnostics-color=always compiler option, but still, no color is displayed. Another cause is that if Ninja itself doesn't see a terminal, such as when you pipe it into Less, it removes color codes from its buffered subprocess output. The way Ninja supports disabling this is with an environment variable.
For GCC or Clang put -fdiagnostics-color=always in the CMAKE_CXX_FLAGS and CMAKE_C_FLAGS variable. That works quite well with Ninja and Makefiles generators. With CMAKE_COLOR_MAKEFILE (default to ON) CMake creates target descriptions with colors.
This is great for human readability. However, with the Ninja generator there is no such option, and CMake doesn't emit any color: the output is much harder to read by a human. Would it be possible to add a CMAKE_COLOR_NINJA equivalent to CMAKE_COLOR_MAKEFILE, but for the Ninja generator? To enable colored diagnostic outputs when using GCC or Clang with Ninja builds, you need to ensure that the compilers are configured to output colors by using the right flags.
On POSIX, terminal color can be modified through ANSI escape codes, and if you put ANSI escape codes in your command's description, ninja will write it through to the terminal unmodified. That way, you can have colored descriptions. This build.ninja produces colored output: $ less build.ninja.
As this link and Oliv highlighted out, one needs to force Ninja to use colors (via -fdiagnostics-color on GCC>=4.9 or -fcolor-diagnostics for Clang) This will force Ninja to format the specific output elements with the format defined in the GCC_COLORS environment variable. FYI: If this variable is an empty string, then there is no coloring at all. With color (using ANSI escape sequences) in NINJA_STATUS, implicit include detection gets confused.
It might be worth setting CLICOLOR_FORCE=0 and/or TERM=dumb in the environment for. The problem comes from ninja's output handling (Ninja must interfere with the output to avoid that concurrent processes mix their outputs). While gcc/clang even in the gitlab-CI issue colored output, ninja determines if the output goes to a usual user terminal or a logfile and removes the colors.