[Lldb-commits] [lldb] [lldb] Add terminfo dependency for ncurses support (PR #126810)

Jordan R AW via lldb-commits lldb-commits at lists.llvm.org
Fri Feb 14 16:07:41 PST 2025


https://github.com/ajordanr-google updated https://github.com/llvm/llvm-project/pull/126810

>From ddd3febff5b77cc7b2101996d49729added00f2b Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead <ajordanr at google.com>
Date: Tue, 1 Oct 2024 18:41:28 +0000
Subject: [PATCH 1/3] [lldb] Add terminfo dependency for ncurses support

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 rebase of this original spack commit:
https://github.com/spack/spack/commit/9ea261265010eacd250691a8361f661d0576f25c

Without this fix, LLDB cannot be built on these systems.

Fixes #101368
---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake b/lldb/cmake/modules/FindCursesAndPanel.cmake
index aaadf214bf54b..df4980cc5e0d1 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -2,12 +2,15 @@
 # FindCursesAndPanel
 # -----------
 #
-# Find the curses and panel library as a whole.
+# Find the curses, terminfo, and panel library as a whole.
+# NOTE: terminfo and curses libraries are required separately, as
+# some systems do not bundle them together.
 
-if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
+if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND PANEL_LIBRARIES)
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
+  find_package(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" QUIET)
   find_library(PANEL_LIBRARIES NAMES panel DOC "The curses panel library" QUIET)
   include(FindPackageHandleStandardArgs)
   find_package_handle_standard_args(CursesAndPanel
@@ -16,9 +19,10 @@ else()
                                     REQUIRED_VARS
                                       CURSES_INCLUDE_DIRS
                                       CURSES_LIBRARIES
+                                      TINFO_LIBRARIES
                                       PANEL_LIBRARIES)
-  if(CURSES_FOUND AND PANEL_LIBRARIES)
-    mark_as_advanced(CURSES_INCLUDE_DIRS CURSES_LIBRARIES PANEL_LIBRARIES)
+  if(CURSES_FOUND AND TINFO_LIBRARIES AND PANEL_LIBRARIES)
+    mark_as_advanced(CURSES_INCLUDE_DIRS CURSES_LIBRARIES TINFO_LIBRARIES PANEL_LIBRARIES)
   endif()
 endif()
 

>From 41ad79112bc2242a1cb10ae688353863155d9038 Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead <ajordanr at google.com>
Date: Wed, 12 Feb 2025 18:22:09 +0000
Subject: [PATCH 2/3] fixup! [lldb] Add terminfo dependency for ncurses support

---
 lldb/source/Core/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt
index cf5f6ac9da489..6c7a50056f751 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -10,7 +10,7 @@ set(LLDB_CURSES_LIBS)
 set(LLDB_LIBEDIT_LIBS)
 
 if (LLDB_ENABLE_CURSES)
-  list(APPEND LLDB_CURSES_LIBS ${PANEL_LIBRARIES} ${CURSES_LIBRARIES})
+  list(APPEND LLDB_CURSES_LIBS ${PANEL_LIBRARIES} ${CURSES_LIBRARIES} ${TINFO_LIBRARIES})
   if (LLVM_BUILD_STATIC)
     list(APPEND LLDB_CURSES_LIBS gpm)
   endif()

>From 9ffc89356cc635ac31f11c66dcb6f32cd73380fc Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead <ajordanr at google.com>
Date: Wed, 12 Feb 2025 19:29:23 +0000
Subject: [PATCH 3/3] fixup! fixup! [lldb] Add terminfo dependency for ncurses
 support

---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 41 +++++++++++++++++----
 lldb/cmake/modules/FindTerminfo.cmake       | 21 +++++++++++
 lldb/source/Core/CMakeLists.txt             |  5 ++-
 3 files changed, 59 insertions(+), 8 deletions(-)
 create mode 100644 lldb/cmake/modules/FindTerminfo.cmake

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake b/lldb/cmake/modules/FindCursesAndPanel.cmake
index df4980cc5e0d1..646113155343d 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -3,26 +3,53 @@
 # -----------
 #
 # Find the curses, terminfo, and panel library as a whole.
-# NOTE: terminfo and curses libraries are required separately, as
-# some systems do not bundle them together.
+
+include(CMakePushCheckState)
+
+function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+  cmake_reset_check_state()
+  set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
+  # acs_map is one of many symbols that are part of tinfo but could
+  # be bundled in curses.
+  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+endfunction()
 
 if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND PANEL_LIBRARIES)
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
-  find_package(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" QUIET)
   find_library(PANEL_LIBRARIES NAMES panel DOC "The curses panel library" QUIET)
   include(FindPackageHandleStandardArgs)
+  
+  # Sometimes the curses libraries define their own terminfo symbols,
+  # other times they're extern and are defined by a separate terminfo library.
+  # Auto-detect which.
+  lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
+  if(CURSES_FOUND AND PANEL_LIBRARIES)
+    if (NOT CURSES_HAS_TINFO)
+      message(STATUS "curses library missing terminfo symbols, looking for tinfo separately")
+      find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" QUIET)
+    endif()
+    set(HAS_TERMINFO_SYMBOLS "$<OR:$<BOOL:${TERMINFO_LIBRARIES}>,$<BOOL:${CURSES_HAS_TINFO}>>")
+  endif()
   find_package_handle_standard_args(CursesAndPanel
                                     FOUND_VAR
                                       CURSESANDPANEL_FOUND
                                     REQUIRED_VARS
                                       CURSES_INCLUDE_DIRS
                                       CURSES_LIBRARIES
-                                      TINFO_LIBRARIES
-                                      PANEL_LIBRARIES)
-  if(CURSES_FOUND AND TINFO_LIBRARIES AND PANEL_LIBRARIES)
-    mark_as_advanced(CURSES_INCLUDE_DIRS CURSES_LIBRARIES TINFO_LIBRARIES PANEL_LIBRARIES)
+                                      PANEL_LIBRARIES
+                                      HAS_TERMINFO_SYMBOLS
+                                    )
+
+  if(CURSES_FOUND AND PANEL_LIBRARIES AND HAS_TERMINFO_SYMBOLS)
+    mark_as_advanced(CURSES_INCLUDE_DIRS
+                      PANEL_LIBRARIES
+                      HAS_TERMINFO_SYMBOLS
+                      CURSES_HAS_TINFO)
+  endif()
+  if(TINFO_LIBRARIES)
+    mark_as_advanced(TINFO_LIBRARIES)
   endif()
 endif()
 
diff --git a/lldb/cmake/modules/FindTerminfo.cmake b/lldb/cmake/modules/FindTerminfo.cmake
new file mode 100644
index 0000000000000..c6c71e0f29dbe
--- /dev/null
+++ b/lldb/cmake/modules/FindTerminfo.cmake
@@ -0,0 +1,21 @@
+#.rst:
+# FindTerminfo
+# -----------
+#
+# Find a separate libtinfo (terminfo) library, if not included in ncurses.
+# Some systems do not bundle them together, so we try to detect if it's needed.
+
+if(TINFO_LIBRARIES)
+  set(TERMINFO_FOUND TRUE)
+else()
+  find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" QUIET)
+  include(FindPackageHandleStandardArgs)
+  find_package_handle_standard_args(Terminfo
+                                    FOUND_VAR
+                                      TERMINFO_FOUND
+                                    REQUIRED_VARS
+                                      TINFO_LIBRARIES)
+  if(TERMINFO_FOUND)
+    mark_as_advanced(TERMINFO_FOUND)
+  endif()
+endif()
diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt
index 6c7a50056f751..8fda453ad8e45 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -10,7 +10,10 @@ set(LLDB_CURSES_LIBS)
 set(LLDB_LIBEDIT_LIBS)
 
 if (LLDB_ENABLE_CURSES)
-  list(APPEND LLDB_CURSES_LIBS ${PANEL_LIBRARIES} ${CURSES_LIBRARIES} ${TINFO_LIBRARIES})
+  list(APPEND LLDB_CURSES_LIBS ${PANEL_LIBRARIES} ${CURSES_LIBRARIES})
+  if(NOT CURSES_HAS_TINFO)
+    list(APPEND LLDB_CURSES_LIBS ${TINFO_LIBRARIES})
+  endif()
   if (LLVM_BUILD_STATIC)
     list(APPEND LLDB_CURSES_LIBS gpm)
   endif()



More information about the lldb-commits mailing list