|
| 1 | +# FindLibEdit |
| 2 | +# ----------- |
| 3 | +# |
| 4 | +# Find libedit library and headers |
| 5 | +# |
| 6 | +# The module defines the following variables: |
| 7 | +# |
| 8 | +# :: |
| 9 | +# |
| 10 | +# libedit_FOUND - true if libedit was found |
| 11 | +# libedit_INCLUDE_DIRS - include search path |
| 12 | +# libedit_LIBRARIES - libraries to link |
| 13 | +# libedit_VERSION - version number |
| 14 | + |
| 15 | +# This cmake file is based on LLVM Project one's. |
| 16 | +# |
| 17 | +# Copyright (c) 2018-2022 LLVM Project |
| 18 | +# |
| 19 | + |
| 20 | +if(libedit_INCLUDE_DIRS AND libedit_LIBRARIES) |
| 21 | + set(libedit_FOUND TRUE) |
| 22 | +else() |
| 23 | + find_package(PkgConfig QUIET) |
| 24 | + pkg_check_modules(PC_LIBEDIT QUIET libedit) |
| 25 | + |
| 26 | + find_path(libedit_INCLUDE_DIRS |
| 27 | + NAMES |
| 28 | + histedit.h |
| 29 | + HINTS |
| 30 | + ${PC_LIBEDIT_INCLUDEDIR} |
| 31 | + ${PC_LIBEDIT_INCLUDE_DIRS} |
| 32 | + ${CMAKE_INSTALL_FULL_INCLUDEDIR}) |
| 33 | + find_library(libedit_LIBRARIES |
| 34 | + NAMES |
| 35 | + edit libedit |
| 36 | + HINTS |
| 37 | + ${PC_LIBEDIT_LIBDIR} |
| 38 | + ${PC_LIBEDIT_LIBRARY_DIRS} |
| 39 | + ${CMAKE_INSTALL_FULL_LIBDIR}) |
| 40 | + |
| 41 | + if(libedit_INCLUDE_DIRS AND EXISTS "${libedit_INCLUDE_DIRS}/histedit.h") |
| 42 | + file(STRINGS "${libedit_INCLUDE_DIRS}/histedit.h" |
| 43 | + libedit_major_version_str |
| 44 | + REGEX "^#define[ \t]+LIBEDIT_MAJOR[ \t]+[0-9]+") |
| 45 | + string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MAJOR[ \t]+([0-9]+)" "\\1" |
| 46 | + LIBEDIT_MAJOR_VERSION "${libedit_major_version_str}") |
| 47 | + |
| 48 | + file(STRINGS "${libedit_INCLUDE_DIRS}/histedit.h" |
| 49 | + libedit_minor_version_str |
| 50 | + REGEX "^#define[ \t]+LIBEDIT_MINOR[ \t]+[0-9]+") |
| 51 | + string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MINOR[ \t]+([0-9]+)" "\\1" |
| 52 | + LIBEDIT_MINOR_VERSION "${libedit_minor_version_str}") |
| 53 | + |
| 54 | + set(libedit_VERSION_STRING "${libedit_major_version}.${libedit_minor_version}") |
| 55 | + endif() |
| 56 | + |
| 57 | + include(FindPackageHandleStandardArgs) |
| 58 | + find_package_handle_standard_args(LibEdit |
| 59 | + REQUIRED_VARS |
| 60 | + libedit_INCLUDE_DIRS |
| 61 | + libedit_LIBRARIES |
| 62 | + VERSION_VAR |
| 63 | + libedit_VERSION_STRING) |
| 64 | + mark_as_advanced(libedit_INCLUDE_DIRS libedit_LIBRARIES) |
| 65 | +endif() |
| 66 | + |
| 67 | +if (libedit_INCLUDE_DIRS AND libedit_LIBRARIES AND NOT TARGET LibEdit::LibEdit) |
| 68 | + add_library(LibEdit::LibEdit UNKNOWN IMPORTED) |
| 69 | + set_target_properties(LibEdit::LibEdit PROPERTIES |
| 70 | + IMPORTED_LOCATION ${libedit_LIBRARIES} |
| 71 | + INTERFACE_INCLUDE_DIRECTORIES ${libedit_INCLUDE_DIRS}) |
| 72 | +endif() |
0 commit comments