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 include(CMakePushCheckState)
25 cmake_push_check_state()
26 list(APPEND CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS})
27 list(APPEND CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES})
28 check_include_file(histedit.h HAVE_HISTEDIT_H)
29 cmake_pop_check_state()
31 file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
32 libedit_major_version_str
33 REGEX "^#define[ \t]+LIBEDIT_MAJOR[ \t]+[0-9]+")
34 string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MAJOR[ \t]+([0-9]+)" "\\1"
35 libedit_major_version "${libedit_major_version_str}")
37 file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
38 libedit_minor_version_str
39 REGEX "^#define[ \t]+LIBEDIT_MINOR[ \t]+[0-9]+")
40 string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MINOR[ \t]+([0-9]+)" "\\1"
41 libedit_minor_version "${libedit_minor_version_str}")
43 set(LibEdit_VERSION_STRING "${libedit_major_version}.${libedit_minor_version}")
45 set(LibEdit_INCLUDE_DIRS "")
46 set(LibEdit_LIBRARIES "")
50 include(FindPackageHandleStandardArgs)
51 find_package_handle_standard_args(LibEdit
58 LibEdit_VERSION_STRING)
59 mark_as_advanced(LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES)
61 if (LibEdit_FOUND AND NOT TARGET LibEdit::LibEdit)
62 add_library(LibEdit::LibEdit UNKNOWN IMPORTED)
63 set_target_properties(LibEdit::LibEdit PROPERTIES
64 IMPORTED_LOCATION ${LibEdit_LIBRARIES}
65 INTERFACE_INCLUDE_DIRECTORIES ${LibEdit_INCLUDE_DIRS})