Skip to content

Commit eb8aa60

Browse files
committed
testapp: Make WITH_SSL option support using bundled OpenSSL libraries.
If OpenSSL libraries are bundled with connector install then passing config option WITH_SSL=bundled will use these libraries to buld test application (if needed). Also, WITH_SSL can now point directly at OpenSSL library location rather than at the top-level OpenSSL install location.
1 parent c97b246 commit eb8aa60

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

testapp/CMakeLists.txt

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,42 @@ PROJECT(MySQL_CONCPP_TEST)
6060
# ========================================================================
6161
# Dependencies
6262

63+
function(find_openssl where)
64+
65+
if(where STREQUAL "bundled")
66+
if(mysql-concpp_DIR)
67+
set(WITH_SSL "${mysql-concpp_DIR}")
68+
else()
69+
message(WARNING
70+
"A request to use bundled OpenSSL libraries was made but"
71+
" Connector/C++ install location was not explicitly given"
72+
" via mysql-concpp_DIR or WITH_CONCPP setting."
73+
)
74+
return()
75+
endif()
76+
endif()
6377

64-
if(WITH_SSL)
78+
find_library(openssl
79+
NAMES ssl
80+
PATHS "${WITH_SSL}"
81+
PATH_SUFFIXES "" "lib" "lib64"
82+
NO_DEFAULT_PATH
83+
NO_CACHE
84+
)
85+
86+
if(NOT openssl)
87+
message(WARNING
88+
"OpenSSL libraries not found at specified location: ${WITH_SSL}"
89+
)
90+
return()
91+
endif()
6592

93+
get_filename_component(WITH_SSL "${openssl}" DIRECTORY CACHE)
6694
message(STATUS "Using custom OpenSSL libraries at: ${WITH_SSL}")
6795

6896
add_library(openssl INTERFACE)
6997
# TODO: Is this path correct also on non-Win platforms?
70-
target_link_directories(openssl INTERFACE "${WITH_SSL}/lib")
98+
target_link_directories(openssl INTERFACE "${WITH_SSL}")
7199

72100
if(WIN32)
73101
set(ssl_libs libssl libcrypto)
@@ -78,12 +106,16 @@ if(WITH_SSL)
78106
target_link_libraries(openssl INTERFACE ${ssl_libs})
79107
add_library(mysql::openssl ALIAS openssl)
80108

81-
endif()
109+
endfunction()
110+
82111

83112
if(NOT DEFINED mysql-concpp_DIR AND DEFINED WITH_CONCPP)
84113
set(mysql-concpp_DIR "${WITH_CONCPP}")
85114
endif()
86115

116+
if(WITH_SSL)
117+
find_openssl("${WITH_SSL}")
118+
endif()
87119

88120
find_package(mysql-concpp REQUIRED ${REQUIRED_COMPONENTS})
89121

0 commit comments

Comments
 (0)