CMake change color in makefile

拜拜、爱过 提交于 2021-01-27 06:58:02

问题


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.


回答1:


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.




回答2:


CMake 3.18 started to provide a variable called CCMAKE_COLORS that changes the output colors. Citing the documentation:

Determines what colors are used by the CMake curses interface [..]. The syntax follows the same conventions as LS_COLORS; that is, a list of key/value pairs separated by :.

[..]

For example:

CCMAKE_COLORS='s=39:p=220:c=207:n=196:y=46'

With s a string, p a file path and so on. Source: https://cmake.org/cmake/help/latest/envvar/CCMAKE_COLORS.html



来源:https://stackoverflow.com/questions/24607094/cmake-change-color-in-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!