[cmake-developers] [CMake] Forcing colorization of output from cmake

Brad King brad.king at kitware.com
Thu Oct 9 09:55:46 EDT 2014


On 10/08/2014 02:36 PM, Paul Smith wrote:
> Hi all.  Attached please find a proposed patch for the above.  I still
> think there's some slightly awkward redundancy between AssumeTTY and the
> new ForceTTY, but I'm not sure these can actually be combined into one
> flag... certainly not without reworking more of how AssumeTTY is
> interpreted and used than I felt confident with.

In this hunk:

> @@ -68,14 +68,16 @@ void kwsysTerminal_cfprintf(int color, FILE* stream, const char* format, ...)
>  #if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
>    CONSOLE_SCREEN_BUFFER_INFO hOutInfo;
>    HANDLE hOut = kwsysTerminalGetStreamHandle(stream);
> -  if(GetConsoleScreenBufferInfo(hOut, &hOutInfo))
> +  if(color & kwsysTerminal_Color_ForceTTY ||
> +     GetConsoleScreenBufferInfo(hOut, &hOutInfo))
>      {
>      pipeIsConsole = 1;
>      kwsysTerminalSetConsoleColor(hOut, &hOutInfo, stream, color);
>      }

we cannot enter the if() block unless GetConsoleScreenBufferInfo
returns true because otherwise the hOutInfo will not be initialized
correctly.  In the Windows console code path we really need a handle
to the console from the stream or it cannot work.  Also, once the
pipeIsConsole value is true, the kwsysTerminalSetVT100Color code
path should not be used, so we do not want to force the second code
path either.  Instead ForceTTY should just influence the return
value of kwsysTerminalStreamIsVT100.

The Source/kwsys part of the change actually belongs in a separate
KWSys upstream first.  I've added a modified version of your change
for upstream review and testing here:

 http://review.source.kitware.com/17578

Please try out that version with the rest of your changes.

> it's darn handy to have this "just work" without having to export
> COLOR='$(if $(MAKE_TERMOUT),FORCE)' in your ~/.bashrc or whatever.
> There's no "GNU Makefiles" generator, and I couldn't come up with a good
> way to implement this in the generic Unix Makefiles generator.

We already have a CMAKE_COLOR_MAKEFILE option.  Perhaps instead
of just ON or OFF values it could have a GNU value that enables
this behavior.  When initializing it in CMakeGenericSystem.cmake
perhaps it is possible to detect if CMAKE_MAKE_PROGRAM is a GNU
make tool and provide a good default.

Thanks,
-Brad




More information about the cmake-developers mailing list