From bdb13d2c7cf22236d7fb9d4f0a0fa46dd08d128a Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 11 Jan 2017 22:55:35 +0000 Subject: [PATCH] Add -Wl,-color-diagnostics if a linker supports the option. Differential Revision: https://reviews.llvm.org/D28046 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291719 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/modules/CheckLinkerFlag.cmake | 8 ++++++++ cmake/modules/HandleLLVMOptions.cmake | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 cmake/modules/CheckLinkerFlag.cmake diff --git a/cmake/modules/CheckLinkerFlag.cmake b/cmake/modules/CheckLinkerFlag.cmake new file mode 100644 index 00000000000..e96d35e7721 --- /dev/null +++ b/cmake/modules/CheckLinkerFlag.cmake @@ -0,0 +1,8 @@ +include(CheckCXXCompilerFlag) + +function(check_linker_flag flag out_var) + set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") + check_cxx_compiler_flag("" ${out_var}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +endfunction() diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 89d90befc81..4ce7f57403c 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -597,6 +597,14 @@ if (UNIX AND append("-fcolor-diagnostics" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif() +# lld doesn't print colored diagnostics when invoked from Ninja +if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja") + include(CheckLinkerFlag) + check_linker_flag("-Wl,-color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS) + append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,-color-diagnostics" + CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) +endif() + # Add flags for add_dead_strip(). # FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF? # But MinSizeRel seems to add that automatically, so maybe disable these -- 2.50.1