summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-08-07 08:47:36 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-08-07 08:47:36 +0000
commitf7364d5833f700eefd7919326bfa5724da1461c3 (patch)
tree1cff97a630c09c8545fc850c474f1152f5f0d8b2 /cmake
parentf76e118cf879a90145aebbdc39fdd7feb9bf3e51 (diff)
downloadllvm-f7364d5833f700eefd7919326bfa5724da1461c3.tar.gz
llvm-f7364d5833f700eefd7919326bfa5724da1461c3.tar.bz2
llvm-f7364d5833f700eefd7919326bfa5724da1461c3.tar.xz
Add support for linking against a curses library when available and
using it to detect whether or not a terminal supports colors. This replaces a particularly egregious hack that merely compared the TERM environment variable to "dumb". That doesn't really translate to a reasonable experience for users that have actually ensured their terminal's capabilities are accurately reflected. This makes testing a terminal for color support somewhat more expensive, but it is called very rarely anyways. The important fast path when the output is being piped somewhere is already in place. The global lock may seem excessive, but the spec for calling into curses is *terrible*. The whole library is terrible, and I spent quite a bit of time looking for a better way of doing this before convincing myself that this was the fundamentally correct way to behave. The damage of the curses library is very narrowly confined, and we continue to use raw escape codes for actually manipulating the colors which is a much sane system than directly using curses here (IMO). If this causes trouble for folks, please let me know. I've tested it on Linux and will watch the bots carefully. I've also worked to account for the variances of curses interfaces that I could finde documentation for, but that may not have been sufficient. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187874 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rwxr-xr-xcmake/config-ix.cmake19
-rw-r--r--cmake/modules/LLVM-Config.cmake9
-rw-r--r--cmake/modules/LLVMConfig.cmake.in2
3 files changed, 30 insertions, 0 deletions
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 85c4d81255..0567820b33 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -74,6 +74,12 @@ check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
check_include_file(mach/mach.h HAVE_MACH_MACH_H)
check_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
+check_include_file(curses.h HAVE_CURSES_H)
+check_include_file(ncurses.h HAVE_NCURSES_H)
+check_include_file(ncursesw.h HAVE_NCURSESW_H)
+check_include_file(ncurses/curses.h HAVE_NCURSES_CURSES_H)
+check_include_file(ncursesw/curses.h HAVE_NCURSESW_CURSES_H)
+
# library checks
if( NOT PURE_WINDOWS )
check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
@@ -97,6 +103,19 @@ if( NOT PURE_WINDOWS )
else()
set(HAVE_LIBZ 0)
endif()
+ if(LLVM_ENABLE_CURSES)
+ check_library_exists(curses has_colors "" HAVE_CURSES)
+ if(NOT HAVE_CURSES)
+ check_library_exists(ncurses has_colors "" HAVE_NCURSES)
+ set(HAVE_CURSES ${HAVE_NCURSES})
+ if(NOT HAVE_CURSES)
+ check_library_exists(ncursesw has_colors "" HAVE_NCURSESW)
+ set(HAVE_CURSES ${HAVE_NCURSESW})
+ endif()
+ endif()
+ else()
+ set(HAVE_CURSES 0)
+ endif()
endif()
# function checks
diff --git a/cmake/modules/LLVM-Config.cmake b/cmake/modules/LLVM-Config.cmake
index 2ddc0b2bf8..3e2447a046 100644
--- a/cmake/modules/LLVM-Config.cmake
+++ b/cmake/modules/LLVM-Config.cmake
@@ -10,6 +10,15 @@ function(get_system_libs return_var)
if( HAVE_LIBDL )
set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
endif()
+ if(LLVM_ENABLE_CURSES)
+ if(HAVE_NCURSESW)
+ set(system_libs ${system_libs} ncursesw)
+ elseif(HAVE_NCURSES)
+ set(system_libs ${system_libs} ncurses)
+ elseif(HAVE_CURSES)
+ set(system_libs ${system_libs} curses)
+ endif()
+ endif()
if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
set(system_libs ${system_libs} pthread)
endif()
diff --git a/cmake/modules/LLVMConfig.cmake.in b/cmake/modules/LLVMConfig.cmake.in
index f0b8c14ec3..ae2bc596aa 100644
--- a/cmake/modules/LLVMConfig.cmake.in
+++ b/cmake/modules/LLVMConfig.cmake.in
@@ -20,6 +20,8 @@ set(TARGET_TRIPLE "@TARGET_TRIPLE@")
set(LLVM_TOOLS_BINARY_DIR @LLVM_TOOLS_BINARY_DIR@)
+set(LLVM_ENABLE_CURSES @LLVM_ENABLE_CURSES@)
+
set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@)
set(LLVM_ENABLE_ZLIB @LLVM_ENABLE_ZLIB@)