From: Konstantin Belyavskiy <k.belyavskiy@tarantool.org> To: tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH] static linking Date: Thu, 5 Jul 2018 18:55:13 +0300 [thread overview] Message-ID: <20180705155513.22348-1-k.belyavskiy@tarantool.org> (raw) 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)
reply other threads:[~2018-07-05 15:55 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180705155513.22348-1-k.belyavskiy@tarantool.org \ --to=k.belyavskiy@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH] static linking' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox