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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
include (CheckIncludeFile)
include (CheckFunctionExists)
include (FindPackageHandleStandardArgs)
macro (_ADD_LIBRARY_IF_EXISTS _LST _LIB)
string (TOUPPER "${_LIB}" _LIBVAR)
find_library (${_LIBVAR}_LIB "${_LIB}")
if (${_LIBVAR}_LIB)
list (APPEND ${_LST} ${${_LIBVAR}_LIB})
endif (${_LIBVAR}_LIB)
unset (${_LIBVAR}_LIB CACHE)
endmacro()
# Modified version of the library CHECK_FUNCTION_EXISTS
# This version will not produce any output, and the result variable is only
# set when the function is found
macro (_CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
unset (_RESULT_VAR)
try_compile (_RESULT_VAR
${CMAKE_BINARY_DIR}
${CMAKE_ROOT}/Modules/CheckFunctionExists.c
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING="-DCHECK_FUNCTION_EXISTS=${FUNCTION}"
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
OUTPUT_VARIABLE OUTPUT)
if (_RESULT_VAR)
set (${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the function ${FUNCTION} exists passed with the following output:\n${OUTPUT}\n\n")
else()
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the function ${FUNCTION} exists failed with the following output:\n${OUTPUT}\n\n")
endif()
endmacro()
if (HAVE_LIBREADLINE MATCHES ^HAVE_LIBREADLINE$)
foreach (_maybe_readline_lib "readline" "edit" "editline")
_ADD_LIBRARY_IF_EXISTS (_readline_libs ${_maybe_readline_lib})
endforeach()
foreach (_maybe_termcap_lib "termcap" "curses" "ncurses")
_ADD_LIBRARY_IF_EXISTS (_termcap_libs ${_maybe_termcap_lib})
endforeach()
message (STATUS "Looking for readline")
foreach (_readline_lib IN LISTS _readline_libs)
set (CMAKE_REQUIRED_LIBRARIES "${_readline_lib}")
_CHECK_FUNCTION_EXISTS (readline HAVE_LIBREADLINE)
if (HAVE_LIBREADLINE)
break()
endif()
foreach (_termcap_lib IN LISTS _termcap_libs)
set (CMAKE_REQUIRED_LIBRARIES "${_readline_lib}" "${_termcap_lib}")
_CHECK_FUNCTION_EXISTS (readline HAVE_LIBREADLINE)
if (HAVE_LIBREADLINE)
break()
endif()
endforeach()
if (HAVE_LIBREADLINE)
break()
endif()
endforeach()
if (HAVE_LIBREADLINE)
message (STATUS "Looking for readline - found")
else (HAVE_LIBREADLINE)
message (STATUS "Looking for readline - not found")
endif (HAVE_LIBREADLINE)
endif()
if (HAVE_LIBREADLINE)
set (READLINE_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}"
CACHE STRING "Required link libraries for the readline library"
)
check_function_exists (add_history HAVE_READLINE_HISTORY)
set (CMAKE_REQUIRED_LIBRARIES "")
endif()
check_include_file (stdio.h HAVE_STDIO_H)
# Stripped down and output modified version of the library CHECK_INCLUDE_FILES
macro (_CHECK_INCLUDE_FILES INCLUDE VARIABLE)
if (${VARIABLE} MATCHES ^${VARIABLE}$)
set (CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
foreach (FILE ${INCLUDE})
set (CMAKE_CONFIGURABLE_FILE_CONTENT "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
set (_LAST_INCLUDE "${FILE}")
endforeach()
set (CMAKE_CONFIGURABLE_FILE_CONTENT "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")
configure_file ("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c" @ONLY IMMEDIATE
)
message (STATUS "Looking for ${_LAST_INCLUDE}")
try_compile (${VARIABLE}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c
OUTPUT_VARIABLE OUTPUT
)
if (${VARIABLE})
message (STATUS "Looking for ${_LAST_INCLUDE} - found")
set (${VARIABLE} 1 CACHE INTERNAL "Have ${_LAST_INCLUDE}")
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if ${_LAST_INCLUDE} exist passed with the following output:\n${OUTPUT}\n\n"
)
else()
message (STATUS "Looking for ${_LAST_INCLUDE} - not found.")
set (${VARIABLE} 0 CACHE INTERNAL "Have ${_LAST_INCLUDE}")
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if ${_LAST_INCLUDE} exist failed with the following output:\n${OUTPUT}\n"
"Source:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n"
)
endif()
endif()
endmacro()
if (HAVE_STDIO_H)
_check_include_files ("stdio.h;readline.h" HAVE_READLINE_H)
if (HAVE_READLINE_H)
_check_include_files ("stdio.h;readline.h;history.h" HAVE_HISTORY_H)
else()
_check_include_files ("stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H)
if (HAVE_READLINE_READLINE_H)
_check_include_files ("stdio.h;readline/readline.h;readline/history.h" HAVE_READLINE_HISTORY_H)
if (NOT HAVE_READLINE_HISTORY_H)
_check_include_files ("stdio.h;readline/readline.h;history.h" HAVE_HISTORY_H)
endif(NOT HAVE_READLINE_HISTORY_H)
endif()
endif()
endif()
find_package_handle_standard_args (readline DEFAULT_MSG READLINE_LIBRARIES)
|