File: FindReadline.cmake

package info (click to toggle)
fluidsynth 2.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,268 kB
  • sloc: ansic: 45,303; cpp: 4,897; xml: 864; sh: 200; makefile: 74
file content (85 lines) | stat: -rw-r--r-- 2,621 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#[=======================================================================[.rst:
FindReadline
-------

Finds the Readline library.

Imported Targets
^^^^^^^^^^^^^^^^

This module provides the following imported targets, if found:

``Readline::Readline``
  The Readline library

Result Variables
^^^^^^^^^^^^^^^^

This will define the following variables:

``Readline_FOUND``
  True if the system has the Readline library.
``Readline_VERSION``
  The version of the Readline library which was found.

#]=======================================================================]

# Use pkg-config if available
find_package(PkgConfig QUIET)
pkg_check_modules(PC_READLINE QUIET readline)

# Search for the headers and library
find_path(
  Readline_INCLUDE_DIR
  NAMES "history.h"
  HINTS "${PC_READLINE_INCLUDEDIR}"
  PATH_SUFFIXES "readline")

find_library(
  Readline_LIBRARY
  NAMES "readline"
  HINTS "${PC_READLINE_LIBDIR}")

# Get version from pkg-config or read the config header
if(PC_READLINE_VERSION)
  set(Readline_VERSION "${PC_READLINE_VERSION}")
elseif(Readline_INCLUDE_DIR)
  file(READ "${Readline_INCLUDE_DIR}/readline.h" _readline_h)
  string(REGEX MATCH "#define[ \t]+RL_VERSION_MAJOR[ \t]+([0-9]+)"
               _readline_major_re "${_readline_h}")
  set(_readline_major "${CMAKE_MATCH_1}")
  string(REGEX MATCH "#define[ \t]+RL_VERSION_MINOR[ \t]+([0-9]+)"
               _readline_minor_re "${_readline_h}")
  set(_readline_minor "${CMAKE_MATCH_1}")
  if(_readline_major_re AND _readline_minor_re)
    set(readline_VERSION "${_readline_major}.${_readline_minor}")
  endif()
endif()

# Forward the result to CMake
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
  Readline
  REQUIRED_VARS "Readline_LIBRARY" "Readline_INCLUDE_DIR"
  VERSION_VAR "Readline_VERSION")

# Handle transitive dependencies
if(PC_READLINE_FOUND)
  get_target_properties_from_pkg_config("${ReadLine_LIBRARY}" "PC_READLINE"
                                        "_readline")
endif()

# Create the target
if(Readline_FOUND AND NOT TARGET Readline::Readline)
  add_library(Readline::Readline UNKNOWN IMPORTED)
  set_target_properties(
    Readline::Readline
    PROPERTIES IMPORTED_LOCATION "${Readline_LIBRARY}"
               INTERFACE_COMPILE_OPTIONS "${_readline_compile_options}"
               INTERFACE_INCLUDE_DIRECTORIES
               "${Readline_INCLUDE_DIR};${Readline_INCLUDE_DIR}/.."
               INTERFACE_LINK_LIBRARIES "${_readline_link_libraries}"
               INTERFACE_LINK_DIRECTORIES "${_readline_link_directories}")
endif()

mark_as_advanced(Readline_INCLUDE_DIR Readline_LIBRARY)