Debian Codegraph @

cmake/FindReadline.cmake

raw
1 # - Try to find readline include dirs and libraries
2 #
3 # Usage of this module as follows:
4 #
5 # find_package(Readline)
6 #
7 # Variables used by this module, they can change the default behaviour and need
8 # to be set before calling find_package:
9 #
10 # Readline_ROOT_DIR Set this variable to the root installation of
11 # readline if the module has problems finding the
12 # proper installation path.
13 #
14 # Variables defined by this module:
15 #
16 # READLINE_FOUND System has readline, include and lib dirs found
17 # GNU_READLINE_FOUND Version of readline found is GNU readline, not libedit!
18 # LIBEDIT_FOUND Version of readline found is libedit, not GNU readline!
19 # Readline_INCLUDE_DIR The readline include directories.
20 # Readline_LIBRARY The readline library.
21 # GNU_READLINE_LIBRARY The GNU readline library or empty string.
22 # LIBEDIT_LIBRARY The libedit library or empty string.
23
24 find_path(Readline_ROOT_DIR
25 NAMES include/readline/readline.h
26 PATHS /usr/local/opt/readline/ /opt/homebrew/opt/readline/ /opt/local/ /usr/local/ /usr/
27 NO_DEFAULT_PATH
28 )
29
30 find_path(Readline_INCLUDE_DIR
31 NAMES readline/readline.h
32 PATHS ${Readline_ROOT_DIR}/include
33 NO_DEFAULT_PATH
34 )
35
36 find_library(Readline_LIBRARY
37 NAMES readline
38 PATHS ${Readline_ROOT_DIR}/lib
39 NO_DEFAULT_PATH
40 )
41
42 find_library(Termcap_LIBRARY
43 NAMES tinfo termcap ncursesw ncurses cursesw curses
44 )
45
46 if(Readline_INCLUDE_DIR AND Readline_LIBRARY)
47 set(READLINE_FOUND TRUE)
48 else(Readline_INCLUDE_DIR AND Readline_LIBRARY)
49 FIND_LIBRARY(Readline_LIBRARY NAMES readline PATHS Readline_ROOT_DIR)
50 include(FindPackageHandleStandardArgs)
51 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG Readline_INCLUDE_DIR Readline_LIBRARY )
52 MARK_AS_ADVANCED(Readline_INCLUDE_DIR Readline_LIBRARY)
53 endif(Readline_INCLUDE_DIR AND Readline_LIBRARY)
54
55 mark_as_advanced(
56 Readline_ROOT_DIR
57 Readline_INCLUDE_DIR
58 Readline_LIBRARY
59 )
60
61 set(CMAKE_REQUIRED_INCLUDES ${Readline_INCLUDE_DIR})
62 set(CMAKE_REQUIRED_LIBRARIES ${Readline_LIBRARY})
63
64 include(CheckFunctionExists)
65 check_function_exists(rl_copy_text HAVE_COPY_TEXT)
66 check_function_exists(rl_filename_completion_function HAVE_COMPLETION_FUNCTION)
67
68 if(NOT HAVE_COMPLETION_FUNCTION)
69 if (Readline_LIBRARY)
70 set(CMAKE_REQUIRED_LIBRARIES ${Readline_LIBRARY} ${Termcap_LIBRARY})
71 endif(Readline_LIBRARY)
72 check_function_exists(rl_copy_text HAVE_COPY_TEXT_TC)
73 check_function_exists(rl_filename_completion_function HAVE_COMPLETION_FUNCTION_TC)
74 set(HAVE_COMPLETION_FUNCTION ${HAVE_COMPLETION_FUNCTION_TC})
75 set(HAVE_COPY_TEXT ${HAVE_COPY_TEXT_TC})
76 if(HAVE_COMPLETION_FUNCTION)
77 set(Readline_LIBRARY ${Readline_LIBRARY} ${Termcap_LIBRARY})
78 endif(HAVE_COMPLETION_FUNCTION)
79 endif(NOT HAVE_COMPLETION_FUNCTION)
80
81 set(LIBEDIT_LIBRARY "")
82 set(GNU_READLINE_LIBRARY "")
83
84 if(HAVE_COMPLETION_FUNCTION AND HAVE_COPY_TEXT)
85 set(GNU_READLINE_FOUND TRUE)
86 set(GNU_READLINE_LIBRARY ${Readline_LIBRARY})
87 elseif(READLINE_FOUND AND NOT HAVE_COPY_TEXT)
88 set(LIBEDIT_FOUND TRUE)
89 set(LIBEDIT_LIBRARY ${Readline_LIBRARY})
90 endif(HAVE_COMPLETION_FUNCTION AND HAVE_COPY_TEXT)
91