* [tarantool-patches] [PATCH] static linking
@ 2018-07-05 15:55 Konstantin Belyavskiy
0 siblings, 0 replies; only message in thread
From: Konstantin Belyavskiy @ 2018-07-05 15:55 UTC (permalink / raw)
To: tarantool-patches
PoC version with readline library and dependencies:
libcurses for Mac OS and libtinfo for Linux.
Usage:
cmake . -DCMAKE_STATICBUILD=yes
Needed for #3445
---
Ticket: https://github.com/tarantool/tarantool/issues/3445
Branch: https://github.com/tarantool/tarantool/compare/kbelyavs/gh-3445-static-build
cmake/FindCurses.cmake | 34 ++++++++++++++++++++++++++++++++++
cmake/FindReadline.cmake | 15 +++++++++++++++
cmake/os.cmake | 14 ++++++++++++++
3 files changed, 63 insertions(+)
create mode 100644 cmake/FindCurses.cmake
diff --git a/cmake/FindCurses.cmake b/cmake/FindCurses.cmake
new file mode 100644
index 000000000..7c8e667bf
--- /dev/null
+++ b/cmake/FindCurses.cmake
@@ -0,0 +1,34 @@
+# find Curses includes and library
+#
+# CURSES_FOUND
+# CURSES_LIBRARY
+# CURSES_INCLUDE_DIR
+
+if (CMAKE_STATICBUILD)
+ set(TMP ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
+endif()
+if (DEFINED CURSES_ROOT)
+ set(_FIND_OPTS NO_CMAKE NO_CMAKE_SYSTEM_PATH)
+ find_library(CURSES_LIBRARY
+ NAMES curses
+ HINTS ${CURSES_ROOT}/lib
+ ${_FIND_OPTS})
+ find_path(CURSES_INCLUDE_DIR
+ NAMES curses.h
+ HINTS ${CURSES_ROOT}/include ${_FIND_OPTS})
+else()
+ find_library(CURSES_LIBRARY NAMES curses)
+ find_path(CURSES_INCLUDE_DIR curses.h)
+endif()
+if (CMAKE_STATICBUILD)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${TMP})
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Curses
+ REQUIRED_VARS CURSES_INCLUDE_DIR CURSES_LIBRARY)
+set(CURSES_INCLUDE_DIRS ${CURSES_INCLUDE_DIR})
+set(CURSES_LIBRARIES ${CURSES_LIBRARY})
+
+mark_as_advanced(CURSES_LIBRARIES CURSES_INCLUDE_DIRS)
diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
index 681a6f5de..93b4d3ac9 100644
--- a/cmake/FindReadline.cmake
+++ b/cmake/FindReadline.cmake
@@ -11,6 +11,13 @@ if(NOT CURSES_FOUND)
find_package(Termcap)
endif()
+if (CMAKE_STATICBUILD)
+ set(TMP ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
+ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+ find_library(TINFO_LIBRARY NAMES tinfo)
+ endif()
+endif()
if (DEFINED READLINE_ROOT)
set(_FIND_OPTS NO_CMAKE NO_CMAKE_SYSTEM_PATH)
find_library(READLINE_LIBRARY
@@ -24,6 +31,9 @@ else()
find_library(READLINE_LIBRARY NAMES readline)
find_path(READLINE_INCLUDE_DIR readline/readline.h)
endif()
+if (CMAKE_STATICBUILD)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${TMP})
+endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Readline
@@ -33,11 +43,16 @@ set(READLINE_LIBRARIES ${READLINE_LIBRARY})
if(READLINE_FOUND)
if(EXISTS ${READLINE_INCLUDE_DIR}/readline/rlconf.h)
+ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+ set(CURSES_LIBRARIES ${CURSES_LIBRARIES} -ltinfo)
+ endif()
+ set(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARIES})
check_library_exists(${READLINE_LIBRARY} rl_catch_sigwinch ""
HAVE_GNU_READLINE)
if(HAVE_GNU_READLINE)
find_package_message(GNU_READLINE "Detected GNU Readline"
"${HAVE_GNU_READLINE}")
+ unset(CMAKE_REQUIRED_LIBRARIES)
endif()
endif()
if(CURSES_FOUND)
diff --git a/cmake/os.cmake b/cmake/os.cmake
index ea581108b..87bcf294b 100644
--- a/cmake/os.cmake
+++ b/cmake/os.cmake
@@ -80,6 +80,20 @@ elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
"Work isn't guarenteed using system readline")
endif()
+ # Detecting LibCurses
+ execute_process(COMMAND ${HOMEBREW_EXECUTABLE} --prefix ncurses
+ OUTPUT_VARIABLE HOMEBREW_CURSES
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if(DEFINED HOMEBREW_CURSES)
+ if (NOT DEFINED CURSES_ROOT)
+ message(STATUS "Setting readline root to ${HOMEBREW_CURSES}")
+ set(CURSES_ROOT "${HOMEBREW_CURSES}")
+ endif()
+ elseif(NOT DEFINED ${CURSES_ROOT})
+ message(WARNING "Homebrew's curses isn't installed. "
+ "Work isn't guarenteed using system curses")
+ endif()
+
# Detecting OpenSSL
execute_process(COMMAND ${HOMEBREW_EXECUTABLE} --prefix openssl
OUTPUT_VARIABLE HOMEBREW_OPENSSL
--
2.14.3 (Apple Git-98)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-07-05 15:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-05 15:55 [tarantool-patches] [PATCH] static linking Konstantin Belyavskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox