Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / cmake_modules / FindReadline.cmake
blob6edc2f9bcbca8572d2e1b7d0a0d20a6889cefc41
1 if(NOT READLINE_INCLUDE_DIR OR NOT READLINE_LIBRARY)
2     find_path(READLINE_INCLUDE_DIR readline/readline.h)
3     find_library(READLINE_LIBRARY NAMES readline)
4 endif()
6 if (READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
7     set(READLINE_FOUND TRUE)
8 endif()
10 if (READLINE_INCLUDE_DIR AND EXISTS "${READLINE_INCLUDE_DIR}/readline/readline.h")
11   file(STRINGS "${READLINE_INCLUDE_DIR}/readline/readline.h"
12                READLINE_MAJOR_VERSION
13        REGEX "^#define RL_VERSION_MAJOR.*$")
14   file(STRINGS "${READLINE_INCLUDE_DIR}/readline/readline.h"
15                READLINE_MINOR_VERSION
16        REGEX "^#define RL_VERSION_MINOR.*$")
18   string(REGEX REPLACE "^.*RL_VERSION_MAJOR.*([0-9]+).*$"
19                        "\\1"
20                        READLINE_MAJOR_VERSION
21                        "${READLINE_MAJOR_VERSION}")
22   string(REGEX REPLACE "^.*RL_VERSION_MINOR.*([0-9]+).*$"
23                        "\\1"
24                        READLINE_MINOR_VERSION
25                        "${READLINE_MINOR_VERSION}")
27   if(READLINE_MAJOR_VERSION)
28     set(READLINE_VERSION "${READLINE_MAJOR_VERSION}.${READLINE_MINOR_VERSION}")
29   else()
30     set(READLINE_VERSION "(unknown)")
31   endif()
32 endif ()
34 if (READLINE_FOUND)
35   if (Readline_FIND_VERSION VERSION_GREATER READLINE_VERSION)
36     message(STATUS "Found version ${READLINE_VERSION} of GNU Readline at ${READLINE_LIBRARY}, but version ${Readline_FIND_VERSION} required")
37     unset(READLINE_FOUND)
38   else()
39     if (NOT READLINE_FIND_QUIETLY)
40       message(STATUS "Found GNU Readline version ${READLINE_VERSION}: ${READLINE_LIBRARY}")
41     endif ()
42   endif ()
43 else ()
44   if (READLINE_FIND_REQUIRED)
45     message(FATAL_ERROR "Could not find GNU Readline")
46   endif ()
47 endif ()