From b1aed14bfea07508e4b9d864168c1ae6b5b5c665 Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Thu, 12 May 2022 15:59:41 -0700 Subject: [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 --- cmake/Modules/FindLibEdit.cmake | 70 ++++++++++++++++++++++ lldb/cmake/modules/FindLibEdit.cmake | 64 -------------------- lldb/cmake/modules/LLDBStandalone.cmake | 10 ++++ lldb/source/Core/CMakeLists.txt | 4 -- lldb/source/Host/CMakeLists.txt | 7 +-- lldb/source/Interpreter/CMakeLists.txt | 3 - .../ScriptInterpreter/Python/CMakeLists.txt | 8 +-- llvm/cmake/config-ix.cmake | 6 +- llvm/lib/LineEditor/CMakeLists.txt | 2 +- llvm/utils/gn/secondary/lldb/source/Host/BUILD.gn | 2 +- 10 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 cmake/Modules/FindLibEdit.cmake delete mode 100644 lldb/cmake/modules/FindLibEdit.cmake diff --git a/cmake/Modules/FindLibEdit.cmake b/cmake/Modules/FindLibEdit.cmake new file mode 100644 index 0000000..94c6150 --- /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() diff --git a/lldb/cmake/modules/FindLibEdit.cmake b/lldb/cmake/modules/FindLibEdit.cmake deleted file mode 100644 index 8b00d34..0000000 --- a/lldb/cmake/modules/FindLibEdit.cmake +++ /dev/null @@ -1,64 +0,0 @@ -#.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() - diff --git a/lldb/cmake/modules/LLDBStandalone.cmake b/lldb/cmake/modules/LLDBStandalone.cmake index 1d3d1bb..d2f0757 100644 --- a/lldb/cmake/modules/LLDBStandalone.cmake +++ b/lldb/cmake/modules/LLDBStandalone.cmake @@ -4,6 +4,12 @@ if(POLICY CMP0116) cmake_policy(SET CMP0116 OLD) endif() +if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) + set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +endif() + +list(APPEND CMAKE_MODULE_PATH "${LLVM_COMMON_CMAKE_UTILS}/Modules") + option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF) find_package(LLVM REQUIRED CONFIG HINTS ${LLVM_DIR} NO_CMAKE_FIND_ROOT_PATH) @@ -105,6 +111,10 @@ include_directories( "${LLVM_INCLUDE_DIRS}" "${CLANG_INCLUDE_DIRS}") +if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) + set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +endif() + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index 0efaab5..d907177 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -103,10 +103,6 @@ add_dependencies(lldbCore # TODO: Remove once we have better layering set_target_properties(lldbCore PROPERTIES LINK_INTERFACE_MULTIPLICITY 5) -if (LLDB_ENABLE_LIBEDIT) - target_include_directories(lldbCore PRIVATE ${LibEdit_INCLUDE_DIRS}) -endif() - if (LLDB_ENABLE_CURSES) target_include_directories(lldbCore PRIVATE ${CURSES_INCLUDE_DIRS}) endif() diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index 70942e07..64d9bb0 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -141,7 +141,7 @@ if (HAVE_LIBDL) list(APPEND EXTRA_LIBS ${CMAKE_DL_LIBS}) endif() if (LLDB_ENABLE_LIBEDIT) - list(APPEND EXTRA_LIBS ${LibEdit_LIBRARIES}) + list(APPEND EXTRA_LIBS LibEdit::LibEdit) endif() if (LLDB_ENABLE_LZMA) list(APPEND EXTRA_LIBS ${LIBLZMA_LIBRARIES}) @@ -151,7 +151,7 @@ if (WIN32) endif() if (LLDB_ENABLE_LIBEDIT) - list(APPEND LLDB_LIBEDIT_LIBS ${LibEdit_LIBRARIES}) + list(APPEND LLDB_LIBEDIT_LIBS LibEdit::LibEdit) if (LLVM_BUILD_STATIC) list(APPEND LLDB_SYSTEM_LIBS gpm) endif() @@ -171,6 +171,3 @@ add_lldb_library(lldbHost Support ) -if (LLDB_ENABLE_LIBEDIT) - target_include_directories(lldbHost PUBLIC ${LibEdit_INCLUDE_DIRS}) -endif() diff --git a/lldb/source/Interpreter/CMakeLists.txt b/lldb/source/Interpreter/CMakeLists.txt index af9b0ce..d22e94a 100644 --- a/lldb/source/Interpreter/CMakeLists.txt +++ b/lldb/source/Interpreter/CMakeLists.txt @@ -68,6 +68,3 @@ add_dependencies(lldbInterpreter LLDBInterpreterPropertiesGen LLDBInterpreterPropertiesEnumGen) -if (LLDB_ENABLE_LIBEDIT) - target_include_directories(lldbInterpreter PRIVATE ${LibEdit_INCLUDE_DIRS}) -endif() diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt b/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt index 1dd6282..ed62a69 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt +++ b/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt @@ -10,7 +10,7 @@ add_definitions(-DLLDB_PYTHON_EXE_RELATIVE_PATH="${LLDB_PYTHON_EXE_RELATIVE_PATH if (LLDB_ENABLE_LIBEDIT) - list(APPEND LLDB_LIBEDIT_LIBS ${LibEdit_LIBRARIES}) + list(APPEND LLDB_LIBEDIT_LIBS LibEdit::LibEdit) endif() add_lldb_library(lldbPluginScriptInterpreterPython PLUGIN @@ -35,9 +35,3 @@ add_lldb_library(lldbPluginScriptInterpreterPython PLUGIN LINK_COMPONENTS Support ) - -if (LLDB_ENABLE_LIBEDIT) - target_include_directories(lldbPluginScriptInterpreterPython PUBLIC - ${LibEdit_INCLUDE_DIRS} - ) -endif() diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake index df7c43b..0da93ec 100644 --- a/llvm/cmake/config-ix.cmake +++ b/llvm/cmake/config-ix.cmake @@ -64,7 +64,6 @@ check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT) 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) @@ -184,8 +183,9 @@ if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*") # 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.*") + find_package(LibEdit) + set(HAVE_LIBEDIT ${LibEdit_FOUND}) else() set(HAVE_LIBEDIT 0) endif() diff --git a/llvm/lib/LineEditor/CMakeLists.txt b/llvm/lib/LineEditor/CMakeLists.txt index 61328f7..c4cd91c 100644 --- a/llvm/lib/LineEditor/CMakeLists.txt +++ b/llvm/lib/LineEditor/CMakeLists.txt @@ -1,5 +1,5 @@ if(HAVE_LIBEDIT) - set(link_libs edit) + set(link_libs LibEdit::LibEdit) endif() add_llvm_component_library(LLVMLineEditor diff --git a/llvm/utils/gn/secondary/lldb/source/Host/BUILD.gn b/llvm/utils/gn/secondary/lldb/source/Host/BUILD.gn index 97a53cb..cd6511a 100644 --- a/llvm/utils/gn/secondary/lldb/source/Host/BUILD.gn +++ b/llvm/utils/gn/secondary/lldb/source/Host/BUILD.gn @@ -142,7 +142,7 @@ static_library("Host") { # list(APPEND EXTRA_LIBS ${CMAKE_DL_LIBS}) # endif() # if (LLDB_ENABLE_LIBEDIT) - # list(APPEND EXTRA_LIBS ${LibEdit_LIBRARIES}) + # list(APPEND EXTRA_LIBS LibEdit::LibEdit) # endif() # if (LLDB_ENABLE_LZMA) # list(APPEND EXTRA_LIBS ${LIBLZMA_LIBRARIES}) -- cgit v1.1