Skip to content

Commit ef097c0

Browse files
committed
feat(build): add option to use system OpenSSL
* Introduced `GPGFRONTEND_USE_SYSTEM_OPENSSL` option to allow using the system-installed OpenSSL instead of building it. * Updated CMake configuration to handle OpenSSL linking based on the new option. * Ensured static libraries are used for OpenSSL to support application self-checking and avoid potential issues with shared library loading.
1 parent d853366 commit ef097c0

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ option(GPGFRONTEND_XCODE_ENABLE_SANDBOX "Enable SandBox For Xcode Build" OFF)
7070

7171
# check options
7272
option(GPGFRONTEND_LINK_GPGME_INTO_CORE "Statically link GpgME into the core library" OFF)
73+
option(GPGFRONTEND_USE_SYSTEM_OPENSSL "Use system OpenSSL instead of building it" OFF)
7374
option(GPGFRONTEND_RUST_SUPPORT "Enable Rust support for GpgFrontend" OFF)
7475

7576
if(GPGFRONTEND_BUILD_APP_IMAGE)
@@ -107,6 +108,12 @@ else()
107108
set(BUILD_AND_STATIC_LINK_GPGME 0)
108109
endif()
109110

111+
if(GPGFRONTEND_USE_SYSTEM_OPENSSL)
112+
set(USE_SYSTEM_OPENSSL 1)
113+
else()
114+
set(USE_SYSTEM_OPENSSL 0)
115+
endif()
116+
110117
if (GPGFRONTEND_RUST_SUPPORT)
111118
set(BUILD_RUST_SUPPORT 1)
112119
else()
@@ -247,6 +254,12 @@ if(MINGW)
247254

248255
set(OS_PLATFORM 0)
249256

257+
# for mingw, we will always use the system openssl, since it's easier to get
258+
# it working on windows and the openssl project provides official pre-built
259+
# binaries for windows. And in the msys2 environment, the openssl is also
260+
# available as a package, and it's often the latest version.
261+
set(USE_SYSTEM_OPENSSL 1)
262+
250263
include_directories(
251264
${CMAKE_CURRENT_SOURCE_DIR}/src
252265
${CMAKE_CURRENT_SOURCE_DIR}/third_party

third_party/CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,19 @@ if(BUILD_AND_STATIC_LINK_GPGME AND XCODE_BUILD)
201201
target_link_libraries(GnuPGDeps INTERFACE ${GPGME_STATIC_LIB} ${ASSUAN_STATIC_LIB} ${GPG_ERROR_STATIC_LIB})
202202
endif()
203203

204-
# Introduce OpenSSL
205-
if(MINGW)
206-
# since OpenSSL on msys2 is often the latest version and is well maintained ,
207-
# and it's better to use it to avoid build issues.
204+
# Introduce OpenSSL targets
205+
if(USE_SYSTEM_OPENSSL)
208206
set(SYSTEM_OPENSSL ON)
209207
set(BUILD_OPENSSL OFF)
210-
# static linking on Windows for better security and portability, and it's
211-
# generally recommended for OpenSSL on Windows.
212-
set(OPENSSL_USE_STATIC_LIBS ON)
213208
else()
214209
set(SYSTEM_OPENSSL OFF)
215210
set(BUILD_OPENSSL ON)
216211
endif()
217212

218213
set(OPENSSL_BUILD_VERSION "3.6.1")
214+
# We will always use static libraries for openssl for the support of application
215+
# self-checking. This may avoid the potential issues of corrupted shared library
216+
# loading.
219217
set(OPENSSL_USE_STATIC_LIBS ON)
220218
add_subdirectory(openssl-cmake)
221219

0 commit comments

Comments
 (0)