File: FindReadline.cmake

package info (click to toggle)
cvc4 1.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 69,876 kB
  • sloc: cpp: 274,686; sh: 5,833; python: 1,893; java: 929; lisp: 763; ansic: 275; perl: 214; makefile: 22; awk: 2
file content (69 lines) | stat: -rw-r--r-- 2,422 bytes parent folder | download
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
# Find Readline
# Readline_FOUND - system has Readline lib
# Readline_INCLUDE_DIR - the Readline include directory
# Readline_LIBRARIES - Libraries needed to use Readline
# Readline_COMPENTRY_FUNC_RETURNS_CHARPTR - Indicates if compentry function
#                                           returns a (char *)

find_path(Readline_INCLUDE_DIR NAMES readline/readline.h)
find_library(Readline_LIBRARIES NAMES readline)

# Try to compile and link a simple program against readline. 'libs' can be
# used to specify additional required libraries.
function(try_compile_readline libs _result)
  set(CMAKE_REQUIRED_QUIET TRUE)
  set(CMAKE_REQUIRED_LIBRARIES ${Readline_LIBRARIES} ${libs})
  check_cxx_source_compiles(
    "
    #include <stdio.h>
    #include <readline/readline.h>
    int main() { readline(\"\"); return 0; }
    "
    ${_result}
  )
  set(${_result} ${${_result}} PARENT_SCOPE)
endfunction()

if(Readline_INCLUDE_DIR)
  # We only need to figure out readline's additional libraries dependencies if
  # we compile static.
  # Note: It might be the case that we need to check for more/other libraries
  # depending on what the installed version of readline is linked against
  # (e.g., termcap, ncurses, ...).
    find_library(TINFO_LIBRARY tinfo)
    try_compile_readline(${TINFO_LIBRARY} OK)
    if(OK)
      list(APPEND Readline_LIBRARIES ${TINFO_LIBRARY})
    else()
      message(FATAL_ERROR
              "Could not link against readline. "
              "Check CMakeError.log for more details")
    endif()

  # Check which standard of readline is installed on the system.
  # https://github.com/CVC4/CVC4/issues/702
  include(CheckCXXSourceCompiles)
  set(CMAKE_REQUIRED_QUIET TRUE)
  set(CMAKE_REQUIRED_LIBRARIES ${Readline_LIBRARIES})
  check_cxx_source_compiles(
    "#include <stdio.h>
     #include <readline/readline.h>
     char* foo(const char*, int) { return (char*)0; }
     int main() { rl_completion_entry_function = foo; return 0; }"
     Readline_COMPENTRY_FUNC_RETURNS_CHARPTR
  )
  unset(CMAKE_REQUIRED_QUIET)
  unset(CMAKE_REQUIRED_LIBRARIES)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Readline
  DEFAULT_MSG Readline_INCLUDE_DIR Readline_LIBRARIES)
mark_as_advanced(
  Readline_INCLUDE_DIR
  Readline_LIBRARIES
  Readline_COMPENTRY_FUNC_RETURNS_CHARPTR
)
if(Readline_LIBRARIES)
  message(STATUS "Found Readline libs: ${Readline_LIBRARIES}")
endif()