[PATCH] D120418: [LLVM] Support histedit.h and libedit.a in non-standard locations

Riyaz V Puthiyapurayil via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 23 09:07:41 PST 2022


RVP created this revision.
RVP added a reviewer: pcc.
RVP added a project: LLVM.
Herald added subscribers: hiraditya, mgorny.
RVP requested review of this revision.
Herald added a subscriber: llvm-commits.

When `histedit.h` and `libedit.a` are in non-standard locations which is not uncommon, `cmake` does not automatically configure LLVM to build the line editor. But completion and history provided by `LineEditor`  are very useful  in `clang-query`.

To use this `LLVM_ENABLE_LIBEDIT=ON` must be specified along with the location of `libedit.a` and `histedit.h` in `CMAKE_LIBRARY_PATH` and `CMAKE_INCLUDE_PATH` respectively.

There are some instances such as when using sanitizers, building with `libedit` is skipped. That will continue to be the case.


https://reviews.llvm.org/D120418

Files:
  llvm/cmake/config-ix.cmake
  llvm/lib/LineEditor/CMakeLists.txt


Index: llvm/lib/LineEditor/CMakeLists.txt
===================================================================
--- llvm/lib/LineEditor/CMakeLists.txt
+++ llvm/lib/LineEditor/CMakeLists.txt
@@ -1,5 +1,8 @@
 if(HAVE_LIBEDIT)
-  set(link_libs edit)
+  set(link_libs ${LIBEDIT_LIBRARY})
+endif()
+if(HAVE_HISTEDIT_H)
+  include_directories(${HISTEDIT_DIR})
 endif()
 
 add_llvm_component_library(LLVMLineEditor
Index: llvm/cmake/config-ix.cmake
===================================================================
--- llvm/cmake/config-ix.cmake
+++ llvm/cmake/config-ix.cmake
@@ -63,7 +63,6 @@
 check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
 
 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
-check_include_file(histedit.h HAVE_HISTEDIT_H)
 check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H)
 if(APPLE)
   include(CheckCSourceCompiles)
@@ -186,8 +185,16 @@
   # Don't look for these libraries on Windows.
   if (NOT PURE_WINDOWS)
     # Skip libedit if using ASan as it contains memory leaks.
-    if (LLVM_ENABLE_LIBEDIT AND HAVE_HISTEDIT_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")
-      check_library_exists(edit el_init "" HAVE_LIBEDIT)
+    if (LLVM_ENABLE_LIBEDIT AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")
+      # If histedit.h is in a non-standard path, find it in CMAKE_INCLUDE_PATH
+      find_file(HISTEDIT_FILE histedit.h)
+      get_filename_component(HISTEDIT_DIR "${HISTEDIT_FILE}" DIRECTORY CACHE)
+      check_include_file(histedit.h HAVE_HISTEDIT_H "-I${HISTEDIT_DIR}")
+
+      # If libedit.a is in a non-standard path, find it in CMAKE_LIBRARY_PATH
+      find_library(LIBEDIT_LIBRARY libedit.a)
+      get_filename_component(LIBEDIT_DIR "${LIBEDIT_LIBRARY}" DIRECTORY CACHE)
+      check_library_exists(edit el_init "${LIBEDIT_DIR}" HAVE_LIBEDIT)
     else()
       set(HAVE_LIBEDIT 0)
     endif()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120418.410840.patch
Type: text/x-patch
Size: 1866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220223/932ed05d/attachment.bin>


More information about the llvm-commits mailing list