1#.rst:
2# FindLibEdit
3# -----------
4#
5# Find libedit library and headers
6#
7# The module defines the following variables:
8#
9# ::
10#
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
15
16if(LibEdit_INCLUDE_DIRS AND LibEdit_LIBRARIES)
17  set(LibEdit_FOUND TRUE)
18else()
19  find_package(PkgConfig QUIET)
20  pkg_check_modules(PC_LIBEDIT QUIET libedit)
21
22  find_path(LibEdit_INCLUDE_DIRS
23            NAMES
24              histedit.h
25            HINTS
26              ${PC_LIBEDIT_INCLUDEDIR}
27              ${PC_LIBEDIT_INCLUDE_DIRS}
28              ${CMAKE_INSTALL_FULL_INCLUDEDIR})
29  find_library(LibEdit_LIBRARIES
30               NAMES
31                 edit libedit
32               HINTS
33                 ${PC_LIBEDIT_LIBDIR}
34                 ${PC_LIBEDIT_LIBRARY_DIRS}
35                 ${CMAKE_INSTALL_FULL_LIBDIR})
36
37  if(LibEdit_INCLUDE_DIRS AND EXISTS "${LibEdit_INCLUDE_DIRS}/histedit.h")
38    file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
39         libedit_major_version_str
40         REGEX "^#define[ \t]+LIBEDIT_MAJOR[ \t]+[0-9]+")
41    string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MAJOR[ \t]+([0-9]+)" "\\1"
42           LIBEDIT_MAJOR_VERSION "${libedit_major_version_str}")
43
44    file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
45         libedit_minor_version_str
46         REGEX "^#define[ \t]+LIBEDIT_MINOR[ \t]+[0-9]+")
47    string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MINOR[ \t]+([0-9]+)" "\\1"
48           LIBEDIT_MINOR_VERSION "${libedit_minor_version_str}")
49
50    set(LibEdit_VERSION_STRING "${libedit_major_version}.${libedit_minor_version}")
51  endif()
52
53  include(FindPackageHandleStandardArgs)
54  find_package_handle_standard_args(LibEdit
55                                    FOUND_VAR
56                                      LibEdit_FOUND
57                                    REQUIRED_VARS
58                                      LibEdit_INCLUDE_DIRS
59                                      LibEdit_LIBRARIES
60                                    VERSION_VAR
61                                      LibEdit_VERSION_STRING)
62  mark_as_advanced(LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES)
63endif()
64
65