How to enable color output with Ninja

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.

The color output works fine when I use the make generator. Is there a way to get colored output when using the Ninja generator?

Ninja buffers output, so tools are writing to a pipe, not directly to the terminal, so auto-detection may turn it off conservatively. Does make -Otarget still work (this does similar buffering)?

Yes, make -Otarget displays colored output when the project configured with Make.

So is it expected to get color with Ninja then?

I’m not sure…I’ve never used color diagnostics myself (NeoVim tends to re-color build output anyways AFAICT).