[Tarantool-patches] [PATCH v2] static build: add openssl build as part of cmake
HustonMmmavr
huston.mavr at gmail.com
Wed Jun 3 21:11:51 MSK 2020
From: Yaroslav Dynnikov <yaroslav.dynnikov at gmail.com>
* 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
Closes #5043
---
Issue: https://github.com/tarantool/tarantool/issues/5043
Branch: https://github.com/tarantool/tarantool/tree/HustonMmmavr/cmake-staicbuild-openssl
CMakeLists.txt | 28 +++++++++++++++++++++++-----
Dockerfile.staticbuild | 9 ---------
cmake/BuildLibCURL.cmake | 10 +++++++++-
src/lib/crypto/CMakeLists.txt | 3 +++
4 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1d80b6806..e1bc69732 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,31 @@ 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 <SOURCE_DIR>/config --libdir=lib --prefix=<INSTALL_DIR> 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})
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()
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..bc13f4af0 100644
--- a/cmake/BuildLibCURL.cmake
+++ b/cmake/BuildLibCURL.cmake
@@ -88,7 +88,11 @@ macro(curl_build)
--prefix <INSTALL_DIR>
--enable-static
- --enable-shared
+
+ # Disable building shared libcurl libraries if
+ # cmake option -DBUILD_STATIC=ON is set
+ $<$<BOOL:${BUILD_STATIC}>:--disable-shared>
+ $<$<NOT:$<BOOL:${BUILD_STATIC}>>:--enable-shared>
--with-zlib
${LIBCURL_OPENSSL_OPT}
@@ -159,6 +163,10 @@ macro(curl_build)
# Need to build ares first
add_dependencies(bundled-libcurl-project bundled-ares)
endif()
+
+ if (BUILD_STATIC)
+ add_dependencies(bundled-libcurl-project openssl)
+ endif()
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..d7e9b1d9e 100644
--- a/src/lib/crypto/CMakeLists.txt
+++ b/src/lib/crypto/CMakeLists.txt
@@ -2,4 +2,7 @@ set(lib_sources crypto.c)
set_source_files_compile_flags(${lib_sources})
add_library(crypto STATIC ${lib_sources})
+if (BUILD_STATIC)
+ add_dependencies(crypto openssl)
+endif()
target_link_libraries(crypto ${OPENSSL_LIBRARIES} core)
--
2.26.2
More information about the Tarantool-patches
mailing list