Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake change color in makefile

The make files generated by CMake have a colorful output for improved readability.

Is it possible to change the color? I have a green terminal font so I kind of loose the color for the messages indicating that objects are built.

like image 243
usr1234567 Avatar asked Jul 07 '14 09:07

usr1234567


2 Answers

I assume you are talking about the cmake added messages from the make output (and not the normal make output itself) in which case it looks like those lines are hard-coded into the generated makefiles with arguments to the cmake cmake_echo_color command that include literal color names as arguments. So there don't appear to be any variables to override or anything of the sort that would let you change that.

So, no, it looks like you cannot control the colors that cmake uses for its various messages. At all.

It doesn't even get the values it uses to control the colors from your terminal's termcap/terminfo it has hard-coded escape sequences in the source code from what I can tell.

The only think you can do is change your terminal's color definitions.

Edit: While discussing this with a colleague we came up with a fairly obvious and unsophisticated workaround for this. Create a cmake wrapper script, assign the path to it to the $(CMAKE) variable (the only variable in use on that generated make line) and then your wrapper needs to scan for the -E cmake_echo_color command sequence and replace whatever color the command was going to be using with the appropriate argument for the color you want to use.

The only problem with this approach is that there is nothing in the command line that indicates any category or any of the sort other than the message itself so to do this in anything resembling a coherent fashion is going to require a filtering on (potentially random) message texts.

like image 130
Etan Reisner Avatar answered Sep 21 '22 09:09

Etan Reisner


As of 2022, it still isn't possible to change the colors.

I've filed two bugs about this with Kitware:

  • https://gitlab.kitware.com/cmake/cmake/-/issues/23277
  • https://gitlab.kitware.com/cmake/cmake/-/issues/23279

So maybe things will improve like they have for ccmake.

like image 34
einpoklum Avatar answered Sep 21 '22 09:09

einpoklum