Skip to content

Commit b8fd9e5

Browse files
committed
link_test and testapp: Fix handling of dependencies.
On Win dependnecies should be handled by #pragma and need not to be specified in the project. Otherwise OpenSSL libs and other dependencies need to be added to the link line only when using static linking.
1 parent e2b6152 commit b8fd9e5

File tree

3 files changed

+53
-61
lines changed

3 files changed

+53
-61
lines changed

testapp/CMakeLists.txt

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ PROJECT(MySQL_CONCPP_TEST)
4545
#
4646
# WITH_JDBC also build JDBC API test application
4747
#
48-
# WITH_BOOST where to look for Boost (required only when building
49-
# JDBC API application)
50-
#
5148
#
5249
# Note: Either WITH_CONCPP or CONCPP_INCLUDE_DIR and CONCPP_LIB_DIR must be
5350
# set.
@@ -122,28 +119,14 @@ set(WITH_SSL $ENV{WITH_SSL} CACHE STRING
122119
"Set to 'builtin' if connector was built with built-in SSL support"
123120
)
124121

125-
if(NOT WITH_SSL MATCHES "^(system|yes)$")
126-
127-
if(EXISTS ${WITH_SSL}/include/openssl/ssl.h)
128-
set(OPENSSL_ROOT_DIR "${WITH_SSL}")
129-
endif()
130-
131-
endif()
132-
133-
find_package(OpenSSL)
134-
135-
if(OPENSSL_FOUND)
136-
MESSAGE(STATUS "OPENSSL_VERSION = ${OPENSSL_VERSION}")
137-
MESSAGE(STATUS "OPENSSL_SSL_LIBRARY = ${OPENSSL_SSL_LIBRARY}")
138-
MESSAGE(STATUS "OPENSSL_CRYPTO_LIBRARY = ${OPENSSL_CRYPTO_LIBRARY}")
139-
endif()
140-
141122
option(WITH_JDBC "Also build the JDBC API test application" OFF)
142123

143124
option(BUILD_STATIC "Link statically with the connector library" OFF)
144125

145126
if(BUILD_STATIC)
146127
message("Linking statically")
128+
else()
129+
message("Liniking dynamically")
147130
endif()
148131

149132
option(STATIC_MSVCRT "Use static MSVC runtime library" OFF)
@@ -266,52 +249,58 @@ set_target_properties(MySQL::conncpp PROPERTIES
266249

267250

268251
#
269-
# We need to link with libraries on which connector depends
270-
# (however, no need to do it on Windows).
252+
# When linking statically, we need to link with libraries on which
253+
# connector depends (however, no need to do it on Windows).
271254
#
272255

273-
if(NOT WIN32)
256+
if(BUILD_STATIC AND NOT WIN32)
274257

275-
# Connector/C++ requires these libraries on Unix.
258+
set(libs)
276259

277-
if(NOT APPLE)
278-
set_property(TARGET MySQL::conncpp
279-
APPEND PROPERTY INTERFACE_LINK_LIBRARIES pthread # rt
280-
)
281-
endif()
260+
# Connector/C++ requires these libraries on Unix.
282261

283-
# On Solaris we additionally need couple more libs.
262+
if(NOT APPLE)
263+
list(APPEND libs pthread)
264+
endif()
284265

285-
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
286-
set_property(TARGET MySQL::conncpp
287-
APPEND PROPERTY INTERFACE_LINK_LIBRARIES socket nsl
288-
)
289-
endif()
266+
# On Solaris we additionally need couple more libs.
290267

291-
#
292-
# If connector uses OpenSSL libraries, we need to
293-
# link to them too.
294-
#
268+
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
269+
list(APPEND libs socket nsl)
270+
endif()
295271

296-
if(OPENSSL_FOUND)
297-
set_property(TARGET MySQL::conncpp
298-
APPEND PROPERTY INTERFACE_LINK_LIBRARIES
299-
${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}
300-
)
301-
endif()
272+
if(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
273+
# Connector needs to Link with libresolv
274+
list(APPEND libs resolv)
275+
endif()
276+
277+
# OpenSSL dependency
278+
279+
if(WITH_SSL MATCHES "^(system|yes)$")
280+
281+
list(APPEND libs ssl crypto)
282+
283+
else()
302284

303-
if(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
304-
# Connector needs to Link with libresolv
305-
set_property(TARGET MySQL::conncpp
306-
APPEND PROPERTY INTERFACE_LINK_LIBRARIES resolv
307-
)
285+
if(EXISTS ${WITH_SSL}/include/openssl/ssl.h)
286+
set(OPENSSL_ROOT_DIR "${WITH_SSL}")
308287
endif()
309288

310-
else()
311-
# Connector needs to Link with Dnsapi
289+
find_package(OpenSSL REQUIRED)
290+
291+
MESSAGE(STATUS "OPENSSL_VERSION = ${OPENSSL_VERSION}")
292+
MESSAGE(STATUS "OPENSSL_SSL_LIBRARY = ${OPENSSL_SSL_LIBRARY}")
293+
MESSAGE(STATUS "OPENSSL_CRYPTO_LIBRARY = ${OPENSSL_CRYPTO_LIBRARY}")
294+
295+
list(APPEND libs ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
296+
297+
endif()
298+
312299
set_property(TARGET MySQL::conncpp
313-
APPEND PROPERTY INTERFACE_LINK_LIBRARIES Dnsapi
300+
APPEND PROPERTY INTERFACE_LINK_LIBRARIES
301+
${libs}
314302
)
303+
315304
endif()
316305

317306

testing/tests.cmake

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ set_target_properties(sub_project_test PROPERTIES FOLDER "Tests")
101101
# We don't want this to happen to make sure that test code can be built with
102102
# connector library only, as we distribute it.
103103
#
104+
# Note: For this test to work on platforms which do not provide required
105+
# dependencies (such as OpenSSL), connector build tree must be configured
106+
# with BUNDLE_DEPENDENCIES option enabled
107+
#
104108
# Note: internal installation into <binary_dir>/install is done by directly
105109
# executing cmake_install.cmake script which is generated by cmake.
106110
#
@@ -113,16 +117,18 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/link_test)
113117
unset(jdbc_options)
114118
if(WITH_JDBC)
115119
#message("-- BOOST_ROOT: ${BOOST_ROOT}")
116-
list(APPEND jdbc_options -DWITH_JDBC=ON -DWITH_BOOST=${BOOST_ROOT})
120+
list(APPEND jdbc_options -DWITH_JDBC=ON)
117121
endif()
118122

119123
add_custom_target(link_test
124+
COMMAND ${CMAKE_COMMAND} -E echo "==== Installing con/C++ ===="
120125
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_BINARY_DIR}/install
121126
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/install
122127
COMMAND ${CMAKE_COMMAND}
123128
-D CMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/install
124129
-D CMAKE_INSTALL_CONFIG_NAME=$<$<BOOL:$<CONFIGURATION>>:$<CONFIGURATION>>$<$<NOT:$<BOOL:$<CONFIGURATION>>>:Release>
125130
-P ${PROJECT_BINARY_DIR}/cmake_install.cmake
131+
COMMAND ${CMAKE_COMMAND} -E echo "==== Configuring test application build ===="
126132
COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/link_test/CMakeCache.txt
127133
COMMAND ${CMAKE_COMMAND}
128134
-G "${CMAKE_GENERATOR}"
@@ -132,20 +138,17 @@ add_custom_target(link_test
132138
-D STATIC_MSVCRT=${STATIC_MSVCRT}
133139
${jdbc_options}
134140
${PROJECT_SOURCE_DIR}/testapp
141+
COMMAND ${CMAKE_COMMAND} -E echo "==== Building test application ===="
135142
COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIGURATION> --clean-first
136143
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/link_test
137-
VERBATIM
138144
)
139145

140146
set_target_properties(link_test PROPERTIES FOLDER "Tests")
141147

142148
add_dependencies(link_test connector)
143-
#if(TARGET connector-merge)
144-
# add_dependencies(link_test connector-merge)
145-
#endif()
146-
#if(WITH_JDBC)
147-
# add_dependencies(link_test build_jdbc)
148-
#endif()
149+
if(WITH_JDBC)
150+
add_dependencies(link_test connector-jdbc)
151+
endif()
149152

150153
# TDOD: Use ${CMAKE_COMMAND}, but evaluated at test time, not here.
151154

0 commit comments

Comments
 (0)