1 include (CheckIncludeFile)
2 include (CheckFunctionExists)
3 include (FindPackageHandleStandardArgs)
5 macro (_ADD_LIBRARY_IF_EXISTS _LST _LIB)
6 string (TOUPPER "${_LIB}" _LIBVAR)
7 find_library (${_LIBVAR}_LIB "${_LIB}")
10 list (APPEND ${_LST} ${${_LIBVAR}_LIB})
11 endif (${_LIBVAR}_LIB)
13 unset (${_LIBVAR}_LIB CACHE)
16 # Modified version of the library CHECK_FUNCTION_EXISTS
17 # This version will not produce any output, and the result variable is only
18 # set when the function is found
19 macro (_CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
21 try_compile (_RESULT_VAR
23 ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
24 CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING="-DCHECK_FUNCTION_EXISTS=${FUNCTION}"
25 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
26 OUTPUT_VARIABLE OUTPUT)
29 set (${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
30 file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
31 "Determining if the function ${FUNCTION} exists passed with the following output:\n${OUTPUT}\n\n")
33 file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
34 "Determining if the function ${FUNCTION} exists failed with the following output:\n${OUTPUT}\n\n")
38 if (HAVE_LIBREADLINE MATCHES ^HAVE_LIBREADLINE$)
39 foreach (_maybe_readline_lib "readline" "edit" "editline")
40 _ADD_LIBRARY_IF_EXISTS (_readline_libs ${_maybe_readline_lib})
43 foreach (_maybe_termcap_lib "termcap" "curses" "ncurses")
44 _ADD_LIBRARY_IF_EXISTS (_termcap_libs ${_maybe_termcap_lib})
47 message (STATUS "Looking for readline")
49 foreach (_readline_lib IN LISTS _readline_libs)
50 set (CMAKE_REQUIRED_LIBRARIES "${_readline_lib}")
51 _CHECK_FUNCTION_EXISTS (readline HAVE_LIBREADLINE)
57 foreach (_termcap_lib IN LISTS _termcap_libs)
58 set (CMAKE_REQUIRED_LIBRARIES "${_readline_lib}" "${_termcap_lib}")
59 _CHECK_FUNCTION_EXISTS (readline HAVE_LIBREADLINE)
72 message (STATUS "Looking for readline - found")
73 else (HAVE_LIBREADLINE)
74 message (STATUS "Looking for readline - not found")
75 endif (HAVE_LIBREADLINE)
79 set (READLINE_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}"
80 CACHE STRING "Required link libraries for the readline library"
83 check_function_exists (add_history HAVE_READLINE_HISTORY)
84 set (CMAKE_REQUIRED_LIBRARIES "")
87 check_include_file (stdio.h HAVE_STDIO_H)
89 # Stripped down and output modified version of the library CHECK_INCLUDE_FILES
90 macro (_CHECK_INCLUDE_FILES INCLUDE VARIABLE)
91 if (${VARIABLE} MATCHES ^${VARIABLE}$)
92 set (CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
94 foreach (FILE ${INCLUDE})
95 set (CMAKE_CONFIGURABLE_FILE_CONTENT "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
96 set (_LAST_INCLUDE "${FILE}")
99 set (CMAKE_CONFIGURABLE_FILE_CONTENT "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")
100 configure_file ("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
101 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c" @ONLY IMMEDIATE
104 message (STATUS "Looking for ${_LAST_INCLUDE}")
105 try_compile (${VARIABLE}
107 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c
108 OUTPUT_VARIABLE OUTPUT
112 message (STATUS "Looking for ${_LAST_INCLUDE} - found")
113 set (${VARIABLE} 1 CACHE INTERNAL "Have ${_LAST_INCLUDE}")
114 file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
115 "Determining if ${_LAST_INCLUDE} exist passed with the following output:\n${OUTPUT}\n\n"
118 message (STATUS "Looking for ${_LAST_INCLUDE} - not found.")
119 set (${VARIABLE} 0 CACHE INTERNAL "Have ${_LAST_INCLUDE}")
120 file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
121 "Determining if ${_LAST_INCLUDE} exist failed with the following output:\n${OUTPUT}\n"
122 "Source:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n"
129 _check_include_files ("stdio.h;readline.h" HAVE_READLINE_H)
132 _check_include_files ("stdio.h;readline.h;history.h" HAVE_HISTORY_H)
134 _check_include_files ("stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H)
136 if (HAVE_READLINE_READLINE_H)
137 _check_include_files ("stdio.h;readline/readline.h;readline/history.h" HAVE_READLINE_HISTORY_H)
139 if (NOT HAVE_READLINE_HISTORY_H)
140 _check_include_files ("stdio.h;readline/readline.h;history.h" HAVE_HISTORY_H)
141 endif(NOT HAVE_READLINE_HISTORY_H)
146 find_package_handle_standard_args (readline DEFAULT_MSG READLINE_LIBRARIES)