Skip to content

Commit 7b77d4c

Browse files
ethourislilinxiongMikolaj Malecki
authored
[build] Fix use of the OPENSSL_USE_STATIC_LIBS CMake option (#3117).
Now SRT_USE_OPENSSL_STATIC_LIBS is the CMake option of SRT. The OPENSSL_USE_STATIC_LIBS is CMake's option, still has to be used if SRT_USE_OPENSSL_STATIC_LIBS is set. --------- Co-authored-by: lilinxiong <[email protected]> Co-authored-by: Mikolaj Malecki <[email protected]>
1 parent fd56385 commit 7b77d4c

File tree

5 files changed

+76
-56
lines changed

5 files changed

+76
-56
lines changed

CMakeLists.txt

100644100755
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,20 @@ option(ENABLE_CODE_COVERAGE "Enable code coverage reporting" OFF)
172172
option(ENABLE_MONOTONIC_CLOCK "Enforced clock_gettime with monotonic clock on GC CV" ${ENABLE_MONOTONIC_CLOCK_DEFAULT})
173173
option(ENABLE_STDCXX_SYNC "Use C++11 chrono and threads for timing instead of pthreads" ${ENABLE_STDCXX_SYNC_DEFAULT})
174174
option(USE_OPENSSL_PC "Use pkg-config to find OpenSSL libraries" ON)
175-
option(OPENSSL_USE_STATIC_LIBS "Link OpenSSL libraries statically." OFF)
175+
option(SRT_USE_OPENSSL_STATIC_LIBS "Link OpenSSL libraries statically." OFF)
176176
option(USE_BUSY_WAITING "Enable more accurate sending times at a cost of potentially higher CPU load" OFF)
177177
option(USE_GNUSTL "Get c++ library/headers from the gnustl.pc" OFF)
178178
option(ENABLE_SOCK_CLOEXEC "Enable setting SOCK_CLOEXEC on a socket" ON)
179179
option(ENABLE_SHOW_PROJECT_CONFIG "Enable show Project Configuration" OFF)
180180

181181
option(ENABLE_CLANG_TSA "Enable Clang Thread Safety Analysis" OFF)
182182

183+
if (DEFINED OPENSSL_USE_STATIC_LIBS AND "${OPENSSL_USE_STATIC_LIBS}" STREQUAL "ON")
184+
message(WARNING "Use of OPENSSL_USE_STATIC_LIBS as SRT build option here is deprecated.
185+
Please use SRT_USE_OPENSSL_STATIC_LIBS instead.")
186+
set(SRT_USE_OPENSSL_STATIC_LIBS ${OPENSSL_USE_STATIC_LIBS})
187+
endif()
188+
183189
# NOTE: Use ATOMIC_USE_SRT_SYNC_MUTEX and will override the auto-detection of the
184190
# Atomic implemetation in srtcore/atomic.h.
185191
option(ATOMIC_USE_SRT_SYNC_MUTEX "Use srt::sync::Mutex to Implement Atomics" OFF)
@@ -389,7 +395,7 @@ if (ENABLE_ENCRYPTION)
389395
# fall back to find_package method otherwise
390396
if (USE_OPENSSL_PC)
391397
pkg_check_modules(SSL ${SSL_REQUIRED_MODULES})
392-
if (OPENSSL_USE_STATIC_LIBS)
398+
if (SRT_USE_OPENSSL_STATIC_LIBS)
393399
# use `pkg-config --static xxx` found libs
394400
set(SSL_LIBRARIES ${SSL_STATIC_LIBRARIES})
395401
endif()
@@ -413,6 +419,11 @@ if (ENABLE_ENCRYPTION)
413419
)
414420
message(STATUS "SSL via pkg-config: -L ${SSL_LIBRARY_DIRS} -I ${SSL_INCLUDE_DIRS} -l;${SSL_LIBRARIES}")
415421
else()
422+
if (SRT_USE_OPENSSL_STATIC_LIBS)
423+
# use `pkg-config --static xxx` found libs
424+
set(OPENSSL_USE_STATIC_LIBS True)
425+
set(OPENSSL_MSVC_STATIC_RT True)
426+
endif()
416427
find_package(OpenSSL REQUIRED)
417428
set (SSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
418429
set (SSL_LIBRARIES ${OPENSSL_LIBRARIES})
@@ -466,6 +477,10 @@ if (ENABLE_ENCRYPTION)
466477
# fall back to find_package method otherwise
467478
if (USE_OPENSSL_PC)
468479
pkg_check_modules(SSL ${SSL_REQUIRED_MODULES})
480+
if (SRT_USE_OPENSSL_STATIC_LIBS)
481+
# use `pkg-config --static xxx` found libs
482+
set(SSL_LIBRARIES ${SSL_STATIC_LIBRARIES})
483+
endif()
469484
endif()
470485
if (SSL_FOUND)
471486
# We have some cases when pkg-config is improperly configured
@@ -486,6 +501,11 @@ if (ENABLE_ENCRYPTION)
486501
)
487502
message(STATUS "SSL via pkg-config: -L ${SSL_LIBRARY_DIRS} -I ${SSL_INCLUDE_DIRS} -l;${SSL_LIBRARIES}")
488503
else()
504+
if (SRT_USE_OPENSSL_STATIC_LIBS)
505+
# use `pkg-config --static xxx` found libs
506+
set(OPENSSL_USE_STATIC_LIBS True)
507+
set(OPENSSL_MSVC_STATIC_RT True)
508+
endif()
489509
find_package(OpenSSL REQUIRED)
490510
set (SSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
491511
set (SSL_LIBRARIES ${OPENSSL_LIBRARIES})
@@ -1082,7 +1102,7 @@ if (srt_libspec_shared)
10821102
if (MICROSOFT)
10831103
target_link_libraries(${TARGET_srt}_shared PRIVATE ws2_32.lib)
10841104
if (NOT (ENABLE_ENCRYPTION AND "${USE_ENCLIB}" STREQUAL "botan"))
1085-
if (OPENSSL_USE_STATIC_LIBS)
1105+
if (SRT_USE_OPENSSL_STATIC_LIBS)
10861106
target_link_libraries(${TARGET_srt}_shared PRIVATE crypt32.lib)
10871107
else()
10881108
set_target_properties(${TARGET_srt}_shared PROPERTIES LINK_FLAGS "/DELAYLOAD:libeay32.dll")
@@ -1121,7 +1141,7 @@ if (srt_libspec_static)
11211141
endif()
11221142
if (MICROSOFT)
11231143
target_link_libraries(${TARGET_srt}_static PRIVATE ws2_32.lib)
1124-
if (OPENSSL_USE_STATIC_LIBS)
1144+
if (SRT_USE_OPENSSL_STATIC_LIBS)
11251145
target_link_libraries(${TARGET_srt}_static PRIVATE crypt32.lib)
11261146
endif()
11271147
elseif (MINGW)
@@ -1135,7 +1155,7 @@ endif()
11351155
target_include_directories(srt_virtual PRIVATE ${SSL_INCLUDE_DIRS})
11361156

11371157
if (MICROSOFT)
1138-
if (OPENSSL_USE_STATIC_LIBS)
1158+
if (SRT_USE_OPENSSL_STATIC_LIBS)
11391159
set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ws2_32.lib crypt32.lib)
11401160
else()
11411161
set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ws2_32.lib)
@@ -1177,7 +1197,7 @@ endif()
11771197
if (srt_libspec_shared)
11781198
if (MICROSOFT)
11791199
target_link_libraries(${TARGET_srt}_shared PUBLIC Ws2_32.lib)
1180-
if (OPENSSL_USE_STATIC_LIBS)
1200+
if (SRT_USE_OPENSSL_STATIC_LIBS)
11811201
target_link_libraries(${TARGET_srt}_shared PUBLIC crypt32.lib)
11821202
endif()
11831203
endif()

docs/build/build-options.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Option details are given further below.
6464
| [`USE_ENCLIB`](#use_enclib) | 1.3.3 | `STRING` | openssl | Encryption library to be used (`openssl`, `openssl-evp` (since 1.5.1), `gnutls`, `mbedtls`, `botan` (since 1.6.0)). |
6565
| [`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. |
6666
| [`USE_OPENSSL_PC`](#use_openssl_pc) | 1.3.0 | `BOOL` | ON | Use `pkg-config` to find OpenSSL libraries. |
67-
| [`OPENSSL_USE_STATIC_LIBS`](#openssl_use_static_libs) | 1.5.0 | `BOOL` | OFF | Link OpenSSL statically. |
67+
| [`SRT_USE_OPENSSL_STATIC_LIBS`](#srt_use_openssl_static_libs)| 1.5.0 | `BOOL` | OFF | Link OpenSSL statically. |
6868
| [`USE_STATIC_LIBSTDCXX`](#use_static_libstdcxx) | 1.2.0 | `BOOL` | OFF | Enforces linking the SRT library against the static `libstdc++` library. |
6969
| [`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. |
7070
| [`WITH_COMPILER_TYPE`](#with_compiler_type) | 1.3.0 | `STRING` | OFF | Sets the compiler type to be used (values: gcc, cc, clang, etc.). |
@@ -618,8 +618,8 @@ built-in one).
618618
When ON, uses `pkg-config` to find OpenSSL libraries. You can turn this OFF to
619619
force `cmake` to find OpenSSL by its own preferred method.
620620

621-
### OPENSSL_USE_STATIC_LIBS
622-
**`--openssl-use-static-libs`** (default: OFF)
621+
### SRT_USE_OPENSSL_STATIC_LIBS
622+
**`--srt-use-openssl-static-libs`** (default: OFF)
623623

624624
When ON, OpenSSL libraries are linked statically.
625625
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).

scripts/ShowProjectConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function(ShowProjectConfig)
166166
" ENABLE_MONOTONIC_CLOCK: ${ENABLE_MONOTONIC_CLOCK}\n"
167167
" ENABLE_STDCXX_SYNC: ${ENABLE_STDCXX_SYNC}\n"
168168
" USE_OPENSSL_PC: ${USE_OPENSSL_PC}\n"
169-
" OPENSSL_USE_STATIC_LIBS: ${OPENSSL_USE_STATIC_LIBS}\n"
169+
" SRT_USE_OPENSSL_STATIC_LIBS: ${SRT_USE_OPENSSL_STATIC_LIBS}\n"
170170
" USE_BUSY_WAITING: ${USE_BUSY_WAITING}\n"
171171
" USE_GNUSTL: ${USE_GNUSTL}\n"
172172
" ENABLE_SOCK_CLOEXEC: ${ENABLE_SOCK_CLOEXEC}\n"

scripts/build-windows.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ if ( $VCPKG_OPENSSL -eq 'ON' ) {
175175
$cmakeFlags += " -DCMAKE_TOOLCHAIN_FILE=$projectRoot\vcpkg\scripts\buildsystems\vcpkg.cmake"
176176
}
177177
else {
178-
$cmakeFlags += " -DOPENSSL_USE_STATIC_LIBS=$STATIC_LINK_SSL "
178+
$cmakeFlags += " -DSRT_USE_OPENSSL_STATIC_LIBS=$STATIC_LINK_SSL "
179179
}
180180

181181
# cmake uses a flag for architecture from vs2019, so add that as a suffix

srtcore/srt_shared.rc

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
// Microsoft Visual C++ generated resource script.
2-
//
3-
#include "version.h"
4-
#include "winres.h"
5-
6-
/////////////////////////////////////////////////////////////////////////////
7-
//
8-
// Version
9-
//
10-
11-
VS_VERSION_INFO VERSIONINFO
12-
#ifdef SRT_VERSION_BUILD
13-
FILEVERSION SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH, SRT_VERSION_BUILD
14-
#else
15-
FILEVERSION SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH
16-
#endif
17-
FILEFLAGSMASK 0x3fL
18-
#ifdef _DEBUG
19-
FILEFLAGS 0x1L
20-
#else
21-
FILEFLAGS 0x0L
22-
#endif
23-
FILEOS 0x40004L
24-
FILETYPE 0x2L
25-
FILESUBTYPE 0x0L
26-
BEGIN
27-
BLOCK "StringFileInfo"
28-
BEGIN
29-
BLOCK "080904b0"
30-
BEGIN
31-
VALUE "CompanyName", "SRT Alliance"
32-
VALUE "FileDescription", "SRT Local Build"
33-
VALUE "InternalName", "srt.dll"
34-
VALUE "LegalCopyright", ""
35-
VALUE "OriginalFilename", "srt.dll"
36-
VALUE "ProductName", "SRT"
37-
VALUE "ProductVersion", SRT_VERSION_STRING
38-
END
39-
END
40-
BLOCK "VarFileInfo"
41-
BEGIN
42-
VALUE "Translation", 0x809, 1200
43-
END
44-
END
45-
1+
// Microsoft Visual C++ generated resource script.
2+
//
3+
#include "version.h"
4+
#include "winres.h"
5+
6+
/////////////////////////////////////////////////////////////////////////////
7+
//
8+
// Version
9+
//
10+
11+
VS_VERSION_INFO VERSIONINFO
12+
#ifdef SRT_VERSION_BUILD
13+
FILEVERSION SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH, SRT_VERSION_BUILD
14+
#else
15+
FILEVERSION SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH
16+
#endif
17+
FILEFLAGSMASK 0x3fL
18+
#ifdef _DEBUG
19+
FILEFLAGS 0x1L
20+
#else
21+
FILEFLAGS 0x0L
22+
#endif
23+
FILEOS 0x40004L
24+
FILETYPE 0x2L
25+
FILESUBTYPE 0x0L
26+
BEGIN
27+
BLOCK "StringFileInfo"
28+
BEGIN
29+
BLOCK "080904b0"
30+
BEGIN
31+
VALUE "CompanyName", "SRT Alliance"
32+
VALUE "FileDescription", "SRT Local Build"
33+
VALUE "InternalName", "srt.dll"
34+
VALUE "LegalCopyright", ""
35+
VALUE "OriginalFilename", "srt.dll"
36+
VALUE "ProductName", "SRT"
37+
VALUE "ProductVersion", SRT_VERSION_STRING
38+
END
39+
END
40+
BLOCK "VarFileInfo"
41+
BEGIN
42+
VALUE "Translation", 0x809, 1200
43+
END
44+
END
45+

0 commit comments

Comments
 (0)