Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] static build: add openssl build as part of cmake
@ 2020-06-02 12:02 HustonMmmavr
  0 siblings, 0 replies; only message in thread
From: HustonMmmavr @ 2020-06-02 12:02 UTC (permalink / raw)
  To: tarantool-patches, yaroslav.dynnikov

From: Yaroslav Dynnikov <yaroslav.dynnikov@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
---
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 <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})
+
+    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 <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-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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-02 12:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 12:02 [Tarantool-patches] [PATCH] static build: add openssl build as part of cmake HustonMmmavr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox