2019-10-05 19:25:31 +00:00
|
|
|
option (ENABLE_READLINE "Enable readline" ${ENABLE_LIBRARIES})
|
2019-11-01 13:01:52 +00:00
|
|
|
|
2019-10-05 19:25:31 +00:00
|
|
|
if (ENABLE_READLINE)
|
2019-11-01 13:01:52 +00:00
|
|
|
option (USE_INTERNAL_REPLXX "Use internal replxx library for line editing" ${NOT_UNBUNDLED})
|
2018-06-19 18:09:09 +00:00
|
|
|
|
2019-11-01 13:01:52 +00:00
|
|
|
if (USE_INTERNAL_REPLXX)
|
|
|
|
set (LINE_EDITING_LIBS replxx)
|
|
|
|
# include directories should be imported along with link target.
|
|
|
|
else ()
|
|
|
|
set (READLINE_PATHS "/usr/local/opt/readline/lib")
|
2017-01-17 21:00:23 +00:00
|
|
|
|
2019-11-01 13:01:52 +00:00
|
|
|
# First try find custom lib for macos users (default lib without history support)
|
|
|
|
find_library (READLINE_LIB NAMES readline PATHS ${READLINE_PATHS} NO_DEFAULT_PATH)
|
|
|
|
if (NOT READLINE_LIB)
|
|
|
|
find_library (READLINE_LIB NAMES readline PATHS ${READLINE_PATHS})
|
|
|
|
endif ()
|
2017-01-17 21:00:23 +00:00
|
|
|
|
2019-11-01 13:01:52 +00:00
|
|
|
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.2)
|
2017-01-17 21:00:23 +00:00
|
|
|
|
2019-11-01 13:01:52 +00:00
|
|
|
find_library (EDIT_LIB NAMES edit)
|
2017-04-23 19:17:51 +00:00
|
|
|
|
2019-11-01 13:01:52 +00:00
|
|
|
set(READLINE_INCLUDE_PATHS "/usr/local/opt/readline/include")
|
|
|
|
if (READLINE_LIB AND TERMCAP_LIBRARY)
|
|
|
|
find_path (READLINE_INCLUDE_DIR NAMES readline/readline.h PATHS ${READLINE_INCLUDE_PATHS} NO_DEFAULT_PATH)
|
|
|
|
if (NOT READLINE_INCLUDE_DIR)
|
|
|
|
find_path (READLINE_INCLUDE_DIR NAMES readline/readline.h PATHS ${READLINE_INCLUDE_PATHS})
|
|
|
|
endif ()
|
|
|
|
if (READLINE_INCLUDE_DIR AND READLINE_LIB)
|
|
|
|
set (USE_READLINE 1)
|
|
|
|
set (LINE_EDITING_LIBS ${READLINE_LIB} ${TERMCAP_LIBRARY})
|
|
|
|
message (STATUS "Using line editing libraries (readline): ${READLINE_INCLUDE_DIR} : ${LINE_EDITING_LIBS}")
|
|
|
|
endif ()
|
|
|
|
elseif (EDIT_LIB AND TERMCAP_LIBRARY)
|
|
|
|
find_library (CURSES_LIB NAMES curses)
|
|
|
|
find_path (READLINE_INCLUDE_DIR NAMES editline/readline.h PATHS ${READLINE_INCLUDE_PATHS})
|
|
|
|
if (CURSES_LIB AND READLINE_INCLUDE_DIR)
|
|
|
|
set (USE_LIBEDIT 1)
|
|
|
|
set (LINE_EDITING_LIBS ${EDIT_LIB} ${CURSES_LIB} ${TERMCAP_LIBRARY})
|
|
|
|
message (STATUS "Using line editing libraries (edit): ${READLINE_INCLUDE_DIR} : ${LINE_EDITING_LIBS}")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2018-06-19 18:09:09 +00:00
|
|
|
endif ()
|
|
|
|
|
2017-04-23 19:17:51 +00:00
|
|
|
if (LINE_EDITING_LIBS AND READLINE_INCLUDE_DIR)
|
|
|
|
include (CheckCXXSourceRuns)
|
2017-01-25 20:14:41 +00:00
|
|
|
|
2017-04-23 19:17:51 +00:00
|
|
|
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LINE_EDITING_LIBS})
|
2017-11-16 21:26:20 +00:00
|
|
|
set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${READLINE_INCLUDE_DIR})
|
2017-04-23 19:17:51 +00:00
|
|
|
check_cxx_source_runs ("
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <readline/readline.h>
|
|
|
|
#include <readline/history.h>
|
|
|
|
int main() {
|
2017-12-19 15:30:12 +00:00
|
|
|
add_history(NULL);
|
|
|
|
append_history(1,NULL);
|
2017-04-23 19:17:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
" HAVE_READLINE_HISTORY)
|
2019-11-01 13:01:52 +00:00
|
|
|
elseif (USE_INTERNAL_REPLXX)
|
|
|
|
message (STATUS "Using line editing libraries: ${LINE_EDITING_LIBS}")
|
2017-04-23 19:17:51 +00:00
|
|
|
else ()
|
|
|
|
message (STATUS "Not using any library for line editing.")
|
|
|
|
endif ()
|