Skip to content

Commit a52173a

Browse files
haampieJDevlieghere
authored andcommitted
Use find_library for ncurses
Currently it is hard to avoid having LLVM link to the system install of ncurses, since it uses check_library_exists to find e.g. libtinfo and not find_library or find_package. With this change the ncurses lib is found with find_library, which also considers CMAKE_PREFIX_PATH. This solves an issue for the spack package manager, where we want to use the zlib installed by spack, and spack provides the CMAKE_PREFIX_PATH for it. This is a similar change as https://reviews.llvm.org/D79219, which just landed in master. Differential revision: https://reviews.llvm.org/D85820
1 parent c7ec3a7 commit a52173a

File tree

8 files changed

+30
-36
lines changed

8 files changed

+30
-36
lines changed

compiler-rt/cmake/config-ix.cmake

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,16 @@ check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
133133
check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO)
134134

135135
# Look for terminfo library, used in unittests that depend on LLVMSupport.
136-
if(LLVM_ENABLE_TERMINFO)
137-
foreach(library terminfo tinfo curses ncurses ncursesw)
138-
string(TOUPPER ${library} library_suffix)
139-
check_library_exists(
140-
${library} setupterm "" COMPILER_RT_HAS_TERMINFO_${library_suffix})
141-
if(COMPILER_RT_HAS_TERMINFO_${library_suffix})
142-
set(COMPILER_RT_HAS_TERMINFO TRUE)
143-
set(COMPILER_RT_TERMINFO_LIB "${library}")
144-
break()
145-
endif()
146-
endforeach()
136+
if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
137+
set(MAYBE_REQUIRED REQUIRED)
138+
else()
139+
set(MAYBE_REQUIRED)
140+
endif()
141+
find_library(COMPILER_RT_TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw ${MAYBE_REQUIRED})
142+
if(COMPILER_RT_TERMINFO_LIB)
143+
set(LLVM_ENABLE_TERMINFO 1)
144+
else()
145+
set(LLVM_ENABLE_TERMINFO 0)
147146
endif()
148147

149148
if (ANDROID AND COMPILER_RT_HAS_LIBDL)

compiler-rt/lib/xray/tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ set(XRAY_UNITTEST_LINK_FLAGS
5555
if (NOT APPLE)
5656
# Needed by LLVMSupport.
5757
append_list_if(
58-
COMPILER_RT_HAS_TERMINFO
58+
LLVM_ENABLE_TERMINFO
5959
-l${COMPILER_RT_TERMINFO_LIB} XRAY_UNITTEST_LINK_FLAGS)
6060

6161
if (COMPILER_RT_STANDALONE_BUILD)

lldb/source/Core/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ set(LLDB_LIBEDIT_LIBS)
1111

1212
if (LLDB_ENABLE_CURSES)
1313
list(APPEND LLDB_CURSES_LIBS ${CURSES_LIBRARIES} ${PANEL_LIBRARIES})
14-
if(LLVM_ENABLE_TERMINFO AND HAVE_TERMINFO)
15-
list(APPEND LLDB_CURSES_LIBS ${TERMINFO_LIBS})
14+
if(LLVM_ENABLE_TERMINFO)
15+
list(APPEND LLDB_CURSES_LIBS ${TERMINFO_LIB})
1616
endif()
1717
if (LLVM_BUILD_STATIC)
1818
list(APPEND LLDB_CURSES_LIBS gpm)

llvm/cmake/config-ix.cmake

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,16 @@ if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
147147
else()
148148
set(HAVE_LIBEDIT 0)
149149
endif()
150-
if(LLVM_ENABLE_TERMINFO)
151-
set(HAVE_TERMINFO 0)
152-
foreach(library terminfo tinfo curses ncurses ncursesw)
153-
string(TOUPPER ${library} library_suffix)
154-
check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix})
155-
if(HAVE_TERMINFO_${library_suffix})
156-
set(HAVE_TERMINFO 1)
157-
set(TERMINFO_LIBS "${library}")
158-
break()
159-
endif()
160-
endforeach()
150+
if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
151+
set(MAYBE_REQUIRED REQUIRED)
152+
else()
153+
set(MAYBE_REQUIRED)
154+
endif()
155+
find_library(TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw ${MAYBE_REQUIRED})
156+
if(TERMINFO_LIB)
157+
set(LLVM_ENABLE_TERMINFO 1)
161158
else()
162-
set(HAVE_TERMINFO 0)
159+
set(LLVM_ENABLE_TERMINFO 0)
163160
endif()
164161

165162
find_library(ICONV_LIBRARY_PATH NAMES iconv libiconv libiconv-2 c)

llvm/include/llvm/Config/config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
210210

211211
/* Define if the setupterm() function is supported this platform. */
212-
#cmakedefine HAVE_TERMINFO ${HAVE_TERMINFO}
212+
#cmakedefine LLVM_ENABLE_TERMINFO ${LLVM_ENABLE_TERMINFO}
213213

214214
/* Define if the xar_open() function is supported this platform. */
215215
#cmakedefine HAVE_LIBXAR ${HAVE_LIBXAR}

llvm/lib/Support/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ elseif( CMAKE_HOST_UNIX )
2121
STRING(REGEX REPLACE "^lib" "" Backtrace_LIBFILE ${Backtrace_LIBFILE})
2222
set(system_libs ${system_libs} ${Backtrace_LIBFILE})
2323
endif()
24-
if(LLVM_ENABLE_TERMINFO)
25-
if(HAVE_TERMINFO)
26-
set(system_libs ${system_libs} ${TERMINFO_LIBS})
27-
endif()
24+
if( LLVM_ENABLE_TERMINFO )
25+
set(system_libs ${system_libs} ${TERMINFO_LIB})
2826
endif()
2927
if( LLVM_ENABLE_THREADS AND (HAVE_LIBATOMIC OR HAVE_CXX_LIBATOMICS64) )
3028
set(system_libs ${system_libs} atomic)

llvm/lib/Support/Unix/Process.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ unsigned Process::StandardErrColumns() {
313313
return getColumns();
314314
}
315315

316-
#ifdef HAVE_TERMINFO
316+
#ifdef LLVM_ENABLE_TERMINFO
317317
// We manually declare these extern functions because finding the correct
318318
// headers from various terminfo, curses, or other sources is harder than
319319
// writing their specs down.
@@ -323,12 +323,12 @@ extern "C" int del_curterm(struct term *termp);
323323
extern "C" int tigetnum(char *capname);
324324
#endif
325325

326-
#ifdef HAVE_TERMINFO
326+
#ifdef LLVM_ENABLE_TERMINFO
327327
static ManagedStatic<std::mutex> TermColorMutex;
328328
#endif
329329

330330
static bool terminalHasColors(int fd) {
331-
#ifdef HAVE_TERMINFO
331+
#ifdef LLVM_ENABLE_TERMINFO
332332
// First, acquire a global lock because these C routines are thread hostile.
333333
std::lock_guard<std::mutex> G(*TermColorMutex);
334334

llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ write_cmake_config("config") {
284284
}
285285

286286
if (llvm_enable_terminfo) {
287-
values += [ "HAVE_TERMINFO=1" ]
287+
values += [ "LLVM_ENABLE_TERMINFO=1" ]
288288
} else {
289-
values += [ "HAVE_TERMINFO=" ]
289+
values += [ "LLVM_ENABLE_TERMINFO=" ]
290290
}
291291

292292
if (llvm_enable_dia_sdk) {

0 commit comments

Comments
 (0)