summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorTobias Ribizel <ribizel@kit.edu>2022-05-12 15:59:41 -0700
committerFangrui Song <i@maskray.me>2022-05-12 15:59:41 -0700
commitb1aed14bfea07508e4b9d864168c1ae6b5b5c665 (patch)
tree83d53e40d9f5fd520f44074aaafa692f402c9e3d /cmake
parent6f3c7dfb7746b04cc98c2f29395dec5027e8d7f3 (diff)
downloadllvm-b1aed14bfea07508e4b9d864168c1ae6b5b5c665.tar.gz
[llvm][lldb] use FindLibEdit.cmake everywhere
Currently, LLVM's LineEditor and LLDB both use libedit, but find them in different (inconsistent) ways. This causes issues e.g. when you are using a locally installed version of libedit, which will not be used by clang-query, but by lldb if picked up by FindLibEdit.cmake Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D124673
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/FindLibEdit.cmake70
1 files changed, 70 insertions, 0 deletions
diff --git a/cmake/Modules/FindLibEdit.cmake b/cmake/Modules/FindLibEdit.cmake
new file mode 100644
index 000000000000..94c6150cefda
--- /dev/null
+++ b/cmake/Modules/FindLibEdit.cmake
@@ -0,0 +1,70 @@
+#.rst:
+# FindLibEdit
+# -----------
+#
+# Find libedit library and headers
+#
+# The module defines the following variables:
+#
+# ::
+#
+# LibEdit_FOUND - true if libedit was found
+# LibEdit_INCLUDE_DIRS - include search path
+# LibEdit_LIBRARIES - libraries to link
+# LibEdit_VERSION_STRING - version number
+
+if(LibEdit_INCLUDE_DIRS AND LibEdit_LIBRARIES)
+ set(LibEdit_FOUND TRUE)
+else()
+ find_package(PkgConfig QUIET)
+ pkg_check_modules(PC_LIBEDIT QUIET libedit)
+
+ find_path(LibEdit_INCLUDE_DIRS
+ NAMES
+ histedit.h
+ HINTS
+ ${PC_LIBEDIT_INCLUDEDIR}
+ ${PC_LIBEDIT_INCLUDE_DIRS}
+ "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
+ find_library(LibEdit_LIBRARIES
+ NAMES
+ edit libedit
+ HINTS
+ ${PC_LIBEDIT_LIBDIR}
+ ${PC_LIBEDIT_LIBRARY_DIRS}
+ "${CMAKE_INSTALL_FULL_LIBDIR}")
+
+ if(LibEdit_INCLUDE_DIRS AND EXISTS "${LibEdit_INCLUDE_DIRS}/histedit.h")
+ file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
+ libedit_major_version_str
+ REGEX "^#define[ \t]+LIBEDIT_MAJOR[ \t]+[0-9]+")
+ string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MAJOR[ \t]+([0-9]+)" "\\1"
+ LIBEDIT_MAJOR_VERSION "${libedit_major_version_str}")
+
+ file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
+ libedit_minor_version_str
+ REGEX "^#define[ \t]+LIBEDIT_MINOR[ \t]+[0-9]+")
+ string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MINOR[ \t]+([0-9]+)" "\\1"
+ LIBEDIT_MINOR_VERSION "${libedit_minor_version_str}")
+
+ set(LibEdit_VERSION_STRING "${libedit_major_version}.${libedit_minor_version}")
+ endif()
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(LibEdit
+ FOUND_VAR
+ LibEdit_FOUND
+ REQUIRED_VARS
+ LibEdit_INCLUDE_DIRS
+ LibEdit_LIBRARIES
+ VERSION_VAR
+ LibEdit_VERSION_STRING)
+ mark_as_advanced(LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES)
+endif()
+
+if (LibEdit_FOUND AND NOT TARGET LibEdit::LibEdit)
+ add_library(LibEdit::LibEdit UNKNOWN IMPORTED)
+ set_target_properties(LibEdit::LibEdit PROPERTIES
+ IMPORTED_LOCATION ${LibEdit_LIBRARIES}
+ INTERFACE_INCLUDE_DIRECTORIES ${LibEdit_INCLUDE_DIRS})
+endif()