CMake: colorised through test -t doesn't work

This commit is contained in:
Adriaan de Groot 2017-08-02 11:27:14 -04:00
parent 46636bdf65
commit f711d6e39c

View File

@ -1,8 +1,13 @@
if(NOT WIN32)
# [ -t 2 ] tests whether stderr is interactive.
# The negation '!' is because for POSIX shells, 0 is true and 1 is false.
execute_process(COMMAND test ! -t 2 RESULT_VARIABLE IS_STDERR_INTERACTIVE)
if(IS_STDERR_INTERACTIVE)
set(_use_color ON)
if("0" STREQUAL "$ENV{CLICOLOR}")
set(_use_color OFF)
endif()
if("0" STREQUAL "$ENV{CLICOLOR_FORCE}")
set(_use_color OFF)
endif()
if(_use_color)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(ColorBold "${Esc}[1m")
@ -20,5 +25,5 @@ if(NOT WIN32)
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif(IS_STDERR_INTERACTIVE)
endif()
endif()