From 6af248261295977d882f2cc66cc294026b66725c Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 24 May 2019 09:12:27 -0700 Subject: [PATCH] Leave it as an option for whether to colorize output during build (#20771) Summary: Currently PyTorch forces color output due to #20662. But users should be left an option to turn it off because redirection of the output to a file would be messed if color output is forced. Pull Request resolved: https://github.com/pytorch/pytorch/pull/20771 Differential Revision: D15495677 Pulled By: ezyang fbshipit-source-id: 9d89bbed40d0b67368554305394763a54c5ff6f5 --- CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 172b2d3b7296..f10585855787 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,7 @@ option(BUILD_TEST "Build C++ test binaries (need gtest and gbenchmark)" OFF) cmake_dependent_option( INSTALL_TEST "Install test binaries if BUILD_TEST is on" ON "BUILD_TEST" OFF) +option(COLORIZE_OUTPUT "Colorize output during compilation" ON) option(USE_ASAN "Use Address Sanitizer" OFF) option(USE_CUDA "Use CUDA" ON) option(USE_ROCM "Use ROCm" ON) @@ -322,10 +323,14 @@ if(NOT MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-constexpr-not-const") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics") + if (${COLORIZE_OUTPUT}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics") + endif() endif() if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") + if (${COLORIZE_OUTPUT}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") + endif() endif() if ((APPLE AND (NOT ("${CLANG_VERSION_STRING}" VERSION_LESS "9.0"))) OR (CMAKE_COMPILER_IS_GNUCXX