summaryrefslogtreecommitdiff
path: root/cmake/FindReadline.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/FindReadline.cmake')
-rw-r--r--cmake/FindReadline.cmake40
1 files changed, 37 insertions, 3 deletions
diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
index 16dd72236..edac03027 100644
--- a/cmake/FindReadline.cmake
+++ b/cmake/FindReadline.cmake
@@ -8,12 +8,43 @@
find_path(Readline_INCLUDE_DIR NAMES readline/readline.h)
find_library(Readline_LIBRARIES NAMES readline)
-# Check which standard of readline is installed on the system.
-# https://github.com/CVC4/CVC4/issues/702
+# 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)
+ set(CMAKE_REQUIRED_LIBRARIES ${Readline_LIBRARIES})
check_cxx_source_compiles(
"#include <stdio.h>
#include <readline/readline.h>
@@ -33,3 +64,6 @@ mark_as_advanced(
Readline_LIBRARIES
Readline_COMPENTRY_FUNC_RETURNS_CHARPTR
)
+if(Readline_LIBRARIES)
+ message(STATUS "Found Readline libs: ${Readline_LIBRARIES}")
+endif()
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback