Skip to content

Commit 8fff0c1

Browse files
[lldb] Add terminfo dependency for ncurses support (llvm#126810)
For some operating systems (e.g. chromiumos), terminfo is a separate package and library from ncurses. Both are still requirements for curses support in lldb, individually. This is a rework of this original spack commit: spack/spack@9ea2612 Instead though, this PR uses CMake to detect whether the symbol is present and defined in the curses library, and only falls back to a separate tinfo if not found. Without this fix, LLDB cannot be built on these systems. Fixes llvm#101368
1 parent 66465c3 commit 8fff0c1

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

lldb/cmake/modules/FindCursesAndPanel.cmake

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,55 @@
22
# FindCursesAndPanel
33
# -----------
44
#
5-
# Find the curses and panel library as a whole.
5+
# Find the curses, terminfo, and panel library as a whole.
66

7-
if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
7+
include(CMakePushCheckState)
8+
9+
function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
10+
cmake_reset_check_state()
11+
set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
12+
# acs_map is one of many symbols that are part of tinfo but could
13+
# be bundled in curses.
14+
check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
15+
endfunction()
16+
17+
if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND PANEL_LIBRARIES)
818
set(CURSESANDPANEL_FOUND TRUE)
919
else()
1020
find_package(Curses QUIET)
1121
find_library(PANEL_LIBRARIES NAMES panel DOC "The curses panel library" QUIET)
1222
include(FindPackageHandleStandardArgs)
23+
24+
if(CURSES_FOUND AND PANEL_LIBRARIES)
25+
# Sometimes the curses libraries define their own terminfo symbols,
26+
# other times they're extern and are defined by a separate terminfo library.
27+
# Auto-detect which.
28+
lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
29+
if (NOT CURSES_HAS_TINFO)
30+
message(STATUS "curses library missing terminfo symbols, looking for tinfo separately")
31+
find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" QUIET)
32+
list(APPEND CURSES_LIBRARIES "${TINFO_LIBRARIES}")
33+
endif()
34+
set(HAS_TERMINFO_SYMBOLS "$<OR:$<BOOL:${TERMINFO_LIBRARIES}>,$<BOOL:${CURSES_HAS_TINFO}>>")
35+
endif()
36+
1337
find_package_handle_standard_args(CursesAndPanel
1438
FOUND_VAR
1539
CURSESANDPANEL_FOUND
1640
REQUIRED_VARS
1741
CURSES_INCLUDE_DIRS
1842
CURSES_LIBRARIES
19-
PANEL_LIBRARIES)
20-
if(CURSES_FOUND AND PANEL_LIBRARIES)
21-
mark_as_advanced(CURSES_INCLUDE_DIRS CURSES_LIBRARIES PANEL_LIBRARIES)
43+
PANEL_LIBRARIES
44+
HAS_TERMINFO_SYMBOLS)
45+
46+
if(CURSES_FOUND AND PANEL_LIBRARIES AND HAS_TERMINFO_SYMBOLS)
47+
mark_as_advanced(CURSES_INCLUDE_DIRS
48+
PANEL_LIBRARIES
49+
HAS_TERMINFO_SYMBOLS
50+
CURSES_HAS_TINFO)
51+
endif()
52+
if(TINFO_LIBRARIES)
53+
mark_as_advanced(TINFO_LIBRARIES)
2254
endif()
2355
endif()
2456

0 commit comments

Comments
 (0)