From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id F2DB7469710 for ; Tue, 2 Jun 2020 15:02:22 +0300 (MSK) Received: by mail-lj1-f179.google.com with SMTP id o9so12233299ljj.6 for ; Tue, 02 Jun 2020 05:02:22 -0700 (PDT) From: HustonMmmavr Date: Tue, 2 Jun 2020 15:02:17 +0300 Message-Id: <20200602120217.17513-1-huston.mavr@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] static build: add openssl build as part of cmake List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, yaroslav.dynnikov@gmail.com From: Yaroslav Dynnikov * Moved openssl build from Dockerfile.staticbuild to CMakeLists.txt as `ExternalProject_Add()` * Prevent build shared libcurl libraries if cmake option -DBUILD_STATIC=ON is set --- Branch: https://github.com/tarantool/tarantool/tree/HustonMmmavr/cmake-staicbuild-openssl CMakeLists.txt | 34 +++++++++++++++++++++++++++++----- Dockerfile.staticbuild | 9 --------- cmake/BuildLibCURL.cmake | 7 ++++++- src/lib/crypto/CMakeLists.txt | 1 + 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d80b6806..2e6ddf7e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ include(TestBigEndian) include(CheckFunctionExists) include(FindOptionalPackage) include(FindPackageMessage) +include(ExternalProject) find_program(ECHO echo) find_program(CAT cat) @@ -320,14 +321,37 @@ endif() # # OpenSSL # -find_package(OpenSSL) -if (OPENSSL_FOUND) - message(STATUS "OpenSSL ${OPENSSL_VERSION} found") - include_directories(${OPENSSL_INCLUDE_DIR}) +if(BUILD_STATIC) + set(OPENSSL_VERSION 1.1.1f) + ExternalProject_Add(openssl + URL https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz + CONFIGURE_COMMAND /config --libdir=lib --prefix= no-shared + INSTALL_COMMAND $(MAKE) install_sw + ) + ExternalProject_Get_Property(openssl install_dir) + message(STATUS "OpenSSL ${OPENSSL_VERSION} added as ExternalProject") + set(OPENSSL_FOUND TRUE) + set(OPENSSL_INCLUDE_DIR ${install_dir}/include) + set(OPENSSL_CRYPTO_LIBRARY ${install_dir}/lib/libcrypto.a) + set(OPENSSL_SSL_LIBRARY ${install_dir}/lib/libssl.a) + set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ${CMAKE_DL_LIBS}) + + add_library(static-openssl STATIC IMPORTED GLOBAL) + add_dependencies(static-openssl openssl) + set(OPENSSL_DEPENDENCY ${OPENSSL_DEPENDENCY} static-openssl) else() - message(FATAL_ERROR "Could NOT find OpenSSL development files (libssl-dev/openssl-devel package)") + find_package(OpenSSL) + if(OPENSSL_FOUND) + message(STATUS "OpenSSL ${OPENSSL_VERSION} found") + else() + message(FATAL_ERROR "Could NOT find OpenSSL development files (libssl-dev/openssl-devel package)") + endif() + add_custom_target(openssl-found) + set(OPENSSL_DEPENDENCY ${OPENSSL_DEPENDENCY} openssl-found) endif() +include_directories(${OPENSSL_INCLUDE_DIR}) + # # OpenSSL can require Z library (depending on build time options), so we add # it to libraries list in case of static openssl linking. diff --git a/Dockerfile.staticbuild b/Dockerfile.staticbuild index 253f2d5e9..0e830078e 100644 --- a/Dockerfile.staticbuild +++ b/Dockerfile.staticbuild @@ -38,14 +38,6 @@ RUN yum -y install ncurses-static readline-static zlib-static pcre-static glibc- RUN yum -y install python-devel python-pip -RUN set -x && \ - cd / && \ - curl -O -L https://www.openssl.org/source/openssl-1.1.1f.tar.gz && \ - tar -xvf openssl-1.1.1f.tar.gz && \ - cd openssl-1.1.1f && \ - ./config --libdir=lib && \ - make -j && make install - RUN set -x && \ cd / && \ curl -O -L https://github.com/unicode-org/icu/releases/download/release-62-1/icu4c-62_1-src.tgz && \ @@ -84,7 +76,6 @@ RUN set -x && \ -DENABLE_DIST:BOOL=ON \ -DBUILD_STATIC=ON \ -DOPENSSL_USE_STATIC_LIBS=ON \ - -DOPENSSL_ROOT_DIR=/usr/local \ . && \ make -j && make install diff --git a/cmake/BuildLibCURL.cmake b/cmake/BuildLibCURL.cmake index 5f8b15a63..5fa095318 100644 --- a/cmake/BuildLibCURL.cmake +++ b/cmake/BuildLibCURL.cmake @@ -88,7 +88,10 @@ macro(curl_build) --prefix --enable-static - --enable-shared + + # Disable building shared libcurl libraries if + # cmake option -DBUILD_STATIC=ON is set + $<$:--disable-shared>$<$>:--enable-static> --with-zlib ${LIBCURL_OPENSSL_OPT} @@ -159,6 +162,8 @@ macro(curl_build) # Need to build ares first add_dependencies(bundled-libcurl-project bundled-ares) endif() + + add_dependencies(bundled-libcurl-project ${OPENSSL_DEPENDENCY}) add_dependencies(bundled-libcurl bundled-libcurl-project) set(CURL_INCLUDE_DIRS ${LIBCURL_INSTALL_DIR}/include) diff --git a/src/lib/crypto/CMakeLists.txt b/src/lib/crypto/CMakeLists.txt index 4e2e5e403..30dfd2283 100644 --- a/src/lib/crypto/CMakeLists.txt +++ b/src/lib/crypto/CMakeLists.txt @@ -2,4 +2,5 @@ set(lib_sources crypto.c) set_source_files_compile_flags(${lib_sources}) add_library(crypto STATIC ${lib_sources}) +add_dependencies(crypto ${OPENSSL_DEPENDENCY}) target_link_libraries(crypto ${OPENSSL_LIBRARIES} core) -- 2.26.2