From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 09E0E2717F for ; Thu, 5 Jul 2018 11:55:17 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sfsNVWDw3FKZ for ; Thu, 5 Jul 2018 11:55:16 -0400 (EDT) Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [94.100.177.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 5222526CCA for ; Thu, 5 Jul 2018 11:55:16 -0400 (EDT) Received: from [185.6.245.156] (port=18154 helo=localhost.localdomain) by smtp48.i.mail.ru with esmtpa (envelope-from ) id 1fb6bC-0000fz-Dd for tarantool-patches@freelists.org; Thu, 05 Jul 2018 18:55:14 +0300 From: Konstantin Belyavskiy Subject: [tarantool-patches] [PATCH] static linking Date: Thu, 5 Jul 2018 18:55:13 +0300 Message-Id: <20180705155513.22348-1-k.belyavskiy@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org 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)