Skip to content

Commit

Permalink
[build] Fix OpenSSL static linking error (#2369).
Browse files Browse the repository at this point in the history
* Use OPENSSL_USE_STATIC_LIBS option to leverage `pkg-config --static` for openssl static linking.
* Removed useless 'OPENSSL_USE_STATIC_LIBS' parameter in Android build script.
* Updated docs.
  • Loading branch information
wangyoucao577 authored Jun 15, 2022
1 parent e8b713e commit 060c0d1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ option(ENABLE_CODE_COVERAGE "Enable code coverage reporting" OFF)
option(ENABLE_MONOTONIC_CLOCK "Enforced clock_gettime with monotonic clock on GC CV" ${ENABLE_MONOTONIC_CLOCK_DEFAULT})
option(ENABLE_STDCXX_SYNC "Use C++11 chrono and threads for timing instead of pthreads" ${ENABLE_STDCXX_SYNC_DEFAULT})
option(USE_OPENSSL_PC "Use pkg-config to find OpenSSL libraries" ON)
option(OPENSSL_USE_STATIC_LIBS "Link OpenSSL libraries statically." OFF)
option(USE_BUSY_WAITING "Enable more accurate sending times at a cost of potentially higher CPU load" OFF)
option(USE_GNUSTL "Get c++ library/headers from the gnustl.pc" OFF)
option(ENABLE_SOCK_CLOEXEC "Enable setting SOCK_CLOEXEC on a socket" ON)
Expand Down Expand Up @@ -345,6 +346,10 @@ if (ENABLE_ENCRYPTION)
# fall back to find_package method otherwise
if (USE_OPENSSL_PC)
pkg_check_modules(SSL ${SSL_REQUIRED_MODULES})
if (OPENSSL_USE_STATIC_LIBS)
# use `pkg-config --static xxx` found libs
set(SSL_LIBRARIES ${SSL_STATIC_LIBRARIES})
endif()
endif()
if (SSL_FOUND)
# We have some cases when pkg-config is improperly configured
Expand Down
1 change: 1 addition & 0 deletions configure-data.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ set cmake_options {
enable-thread-check "Enable #include <threadcheck.h> that implements THREAD_* macros"
enable-stdc++-sync "Use standard C++11 chrono/threads instead of pthread wrapper (default: OFF, on Windows: ON)"
use-openssl-pc "Use pkg-config to find OpenSSL libraries (default: ON)"
openssl-use-static-libs "Link OpenSSL statically (default: OFF)."
use-busy-waiting "Enable more accurate sending times at a cost of potentially higher CPU load (default: OFF)"
use-gnustl "Get c++ library/headers from the gnustl.pc"
enable-sock-cloexec "Enable setting SOCK_CLOEXEC on a socket (default: ON)"
Expand Down
7 changes: 7 additions & 0 deletions docs/build/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Option details are given further below.
| [`USE_ENCLIB`](#use_enclib) | 1.3.3 | `STRING` | openssl | Encryption library to be used (`openssl`, `gnutls`, `mbedtls`). |
| [`USE_GNUSTL`](#use_gnustl) | 1.3.4 | `BOOL` | OFF | Use `pkg-config` with the `gnustl` package name to extract the header and library path for the C++ standard library. |
| [`USE_OPENSSL_PC`](#use_openssl_pc) | 1.3.0 | `BOOL` | ON | Use `pkg-config` to find OpenSSL libraries. |
| [`OPENSSL_USE_STATIC_LIBS`](#openssl_use_static_libs) | 1.5.0 | `BOOL` | OFF | Link OpenSSL statically. |
| [`USE_STATIC_LIBSTDCXX`](#use_static_libstdcxx) | 1.2.0 | `BOOL` | OFF | Enforces linking the SRT library against the static libstdc++ library. |
| [`WITH_COMPILER_PREFIX`](#with_compiler_prefix) | 1.3.0 | `STRING` | OFF | Sets C/C++ toolchains as `<prefix><c-compiler>` and `<prefix><c++-compiler>`, overriding the default compiler. |
| [`WITH_COMPILER_TYPE`](#with_compiler_type) | 1.3.0 | `STRING` | OFF | Sets the compiler type to be used (values: gcc, cc, clang, etc.). |
Expand Down Expand Up @@ -551,6 +552,12 @@ built-in one).
When ON, uses `pkg-config` to find OpenSSL libraries. You can turn this OFF to
force `cmake` to find OpenSSL by its own preferred method.

### OPENSSL_USE_STATIC_LIBS
**`--openssl-use-static-libs`** (default: OFF)

When ON, OpenSSL libraries are linked statically.
When `pkg-config`(`-DUSE_OPENSSL_PC=ON`) is used, static OpenSSL libraries are listed in `SSL_STATIC_LIBRARIES`. See `<prefix>_STATIC` in [CMake's FindPkgConfig](https://cmake.org/cmake/help/latest/module/FindPkgConfig.html).
On Windows additionally links `crypt32.lib`.

#### USE_STATIC_LIBSTDCXX
**`--use-static-libstdc++`** (default: OFF)
Expand Down
1 change: 1 addition & 0 deletions scripts/ShowProjectConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function(ShowProjectConfig)
" ENABLE_MONOTONIC_CLOCK: ${ENABLE_MONOTONIC_CLOCK}\n"
" ENABLE_STDCXX_SYNC: ${ENABLE_STDCXX_SYNC}\n"
" USE_OPENSSL_PC: ${USE_OPENSSL_PC}\n"
" OPENSSL_USE_STATIC_LIBS: ${OPENSSL_USE_STATIC_LIBS}\n"
" USE_BUSY_WAITING: ${USE_BUSY_WAITING}\n"
" USE_GNUSTL: ${USE_GNUSTL}\n"
" ENABLE_SOCK_CLOEXEC: ${ENABLE_SOCK_CLOEXEC}\n"
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-android/mksrt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ done

cd $SRC_DIR
./configure --use-enclib=$ENC_LIB \
--use-openssl-pc=OFF --OPENSSL_USE_STATIC_LIBS=TRUE \
--use-openssl-pc=OFF \
--OPENSSL_INCLUDE_DIR=$INSTALL_DIR/include \
--OPENSSL_CRYPTO_LIBRARY=$INSTALL_DIR/lib/libcrypto.a --OPENSSL_SSL_LIBRARY=$INSTALL_DIR/lib/libssl.a \
--STATIC_MBEDTLS=FALSE \
Expand Down

0 comments on commit 060c0d1

Please sign in to comment.