From f711d6e39cb777f1e156743e5a92cafe15b81ba1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 2 Aug 2017 11:27:14 -0400 Subject: [PATCH] CMake: colorised through test -t doesn't work --- CMakeModules/CMakeColors.cmake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeModules/CMakeColors.cmake b/CMakeModules/CMakeColors.cmake index 4b96ac8a8..7a9a13e1d 100644 --- a/CMakeModules/CMakeColors.cmake +++ b/CMakeModules/CMakeColors.cmake @@ -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()