5 # Find libedit library and headers
7 # The module defines the following variables:
11 # LibEdit_FOUND - true if libedit was found
12 # LibEdit_INCLUDE_DIRS - include search path
13 # LibEdit_LIBRARIES - libraries to link
14 # LibEdit_VERSION_STRING - version number
16 find_package(PkgConfig QUIET)
17 pkg_check_modules(PC_LIBEDIT QUIET libedit)
19 find_path(LibEdit_INCLUDE_DIRS NAMES histedit.h HINTS ${PC_LIBEDIT_INCLUDE_DIRS})
20 find_library(LibEdit_LIBRARIES NAMES edit HINTS ${PC_LIBEDIT_LIBRARY_DIRS})
22 include(CheckIncludeFile)
23 if(LibEdit_INCLUDE_DIRS AND EXISTS "${LibEdit_INCLUDE_DIRS}/histedit.h")
24 cmake_push_check_state()
25 list(APPEND CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS})
26 list(APPEND CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES})
27 check_include_file(histedit.h HAVE_HISTEDIT_H)
28 cmake_pop_check_state()
30 file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
31 libedit_major_version_str
32 REGEX "^#define[ \t]+LIBEDIT_MAJOR[ \t]+[0-9]+")
33 string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MAJOR[ \t]+([0-9]+)" "\\1"
34 libedit_major_version "${libedit_major_version_str}")
36 file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
37 libedit_minor_version_str
38 REGEX "^#define[ \t]+LIBEDIT_MINOR[ \t]+[0-9]+")
39 string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MINOR[ \t]+([0-9]+)" "\\1"
40 libedit_minor_version "${libedit_minor_version_str}")
42 set(LibEdit_VERSION_STRING "${libedit_major_version}.${libedit_minor_version}")
44 set(LibEdit_INCLUDE_DIRS "")
45 set(LibEdit_LIBRARIES "")
49 include(FindPackageHandleStandardArgs)
50 find_package_handle_standard_args(LibEdit
57 LibEdit_VERSION_STRING)
58 mark_as_advanced(LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES)
60 if (LibEdit_FOUND AND NOT TARGET LibEdit::LibEdit)
61 add_library(LibEdit::LibEdit UNKNOWN IMPORTED)
62 set_target_properties(LibEdit::LibEdit PROPERTIES
63 IMPORTED_LOCATION ${LibEdit_LIBRARIES}
64 INTERFACE_INCLUDE_DIRECTORIES ${LibEdit_INCLUDE_DIRS})