From 66517796eec3672376898f3e95ed95ca4ffa08c0 Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Fri, 1 Nov 2019 16:01:52 +0300 Subject: [PATCH] Import replxx into contrib --- .gitmodules | 3 ++ cmake/find/readline_edit.cmake | 70 +++++++++++++++-------------- contrib/CMakeLists.txt | 4 ++ contrib/replxx | 1 + contrib/replxx-cmake/CMakeLists.txt | 20 +++++++++ 5 files changed, 65 insertions(+), 33 deletions(-) create mode 160000 contrib/replxx create mode 100644 contrib/replxx-cmake/CMakeLists.txt diff --git a/.gitmodules b/.gitmodules index 6075b7e9243..8342064a055 100644 --- a/.gitmodules +++ b/.gitmodules @@ -134,3 +134,6 @@ [submodule "contrib/libc-headers"] path = contrib/libc-headers url = https://github.com/ClickHouse-Extras/libc-headers.git +[submodule "contrib/replxx"] + path = contrib/replxx + url = https://github.com/AmokHuginnsson/replxx.git diff --git a/cmake/find/readline_edit.cmake b/cmake/find/readline_edit.cmake index 96518a66887..10983b8e339 100644 --- a/cmake/find/readline_edit.cmake +++ b/cmake/find/readline_edit.cmake @@ -1,41 +1,45 @@ -include (CMakePushCheckState) -cmake_push_check_state () - option (ENABLE_READLINE "Enable readline" ${ENABLE_LIBRARIES}) + if (ENABLE_READLINE) + option (USE_INTERNAL_REPLXX "Use internal replxx library for line editing" ${NOT_UNBUNDLED}) -set (READLINE_PATHS "/usr/local/opt/readline/lib") -# 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 () + 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") -list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.2) + # 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 () -find_library (EDIT_LIB NAMES edit) + list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.2) -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}) + find_library (EDIT_LIB NAMES edit) + + 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 () - 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 () if (LINE_EDITING_LIBS AND READLINE_INCLUDE_DIR) @@ -53,8 +57,8 @@ if (LINE_EDITING_LIBS AND READLINE_INCLUDE_DIR) return 0; } " HAVE_READLINE_HISTORY) +elseif (USE_INTERNAL_REPLXX) + message (STATUS "Using line editing libraries: ${LINE_EDITING_LIBS}") else () message (STATUS "Not using any library for line editing.") endif () - -cmake_pop_check_state () diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 80ccd8cce58..d23a06ed05e 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -328,3 +328,7 @@ endif() if (USE_FASTOPS) add_subdirectory (fastops-cmake) endif() + +if (USE_INTERNAL_REPLXX) + add_subdirectory (replxx-cmake) +endif () diff --git a/contrib/replxx b/contrib/replxx new file mode 160000 index 00000000000..37582f0bb8c --- /dev/null +++ b/contrib/replxx @@ -0,0 +1 @@ +Subproject commit 37582f0bb8c52513c6c6b76797c02d852d701dad diff --git a/contrib/replxx-cmake/CMakeLists.txt b/contrib/replxx-cmake/CMakeLists.txt new file mode 100644 index 00000000000..cfe3102d33c --- /dev/null +++ b/contrib/replxx-cmake/CMakeLists.txt @@ -0,0 +1,20 @@ +set (LIBRARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/replxx") + +set(SRCS + ${LIBRARY_DIR}/src/conversion.cxx + ${LIBRARY_DIR}/src/ConvertUTF.cpp + ${LIBRARY_DIR}/src/escape.cxx + ${LIBRARY_DIR}/src/history.cxx + ${LIBRARY_DIR}/src/replxx_impl.cxx + ${LIBRARY_DIR}/src/io.cxx + ${LIBRARY_DIR}/src/prompt.cxx + ${LIBRARY_DIR}/src/replxx.cxx + ${LIBRARY_DIR}/src/util.cxx + ${LIBRARY_DIR}/src/wcwidth.cpp + ${LIBRARY_DIR}/src/windows.cxx +) + +add_library(replxx ${SRCS}) +target_include_directories(replxx PUBLIC ${LIBRARY_DIR}/include) + +add_definitions(-D USE_REPLXX)