Skip to content

Commit b4c9bf6

Browse files
committed
link_test: Fix handling of dependencies
On Win, dependencies should be handled by #pragma in headers, not specified in the project.
1 parent fbc0ea0 commit b4c9bf6

File tree

1 file changed

+48
-63
lines changed

1 file changed

+48
-63
lines changed

link_test/CMakeLists.txt

Lines changed: 48 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,6 @@ endif()
156156
# ========================================================================
157157
# Dependencies
158158

159-
160-
if(NOT OPENSSL_FOUND)
161-
if(NOT WITH_SSL MATCHES "^(system|yes)$")
162-
163-
if(EXISTS ${WITH_SSL}/include/openssl/ssl.h)
164-
set(OPENSSL_ROOT_DIR "${WITH_SSL}")
165-
endif()
166-
167-
endif()
168-
169-
find_package(OpenSSL)
170-
171-
if(OPENSSL_FOUND)
172-
MESSAGE(STATUS "OPENSSL_VERSION = ${OPENSSL_VERSION}")
173-
MESSAGE(STATUS "OPENSSL_SSL_LIBRARY = ${OPENSSL_SSL_LIBRARY}")
174-
MESSAGE(STATUS "OPENSSL_CRYPTO_LIBRARY = ${OPENSSL_CRYPTO_LIBRARY}")
175-
endif()
176-
177-
endif()
178-
179159
#
180160
# Find Connector/C++ legacy library
181161
#
@@ -284,34 +264,63 @@ set_target_properties(MySQL::conncpp-jdbc PROPERTIES
284264

285265

286266
#
287-
# We need to link with libraries on which connector depends
288-
# (however, no need to do it on Windows).
267+
# When linking statically, we need to link with libraries on which
268+
# connector depends (however, no need to do it on Windows).
289269
#
290270

291-
if(NOT WIN32)
271+
if(BUILD_STATIC AND NOT WIN32)
292272

293-
# Connector/C++ requires these libraries on Unix.
273+
set(libs)
294274

295-
if(NOT APPLE)
296-
set_property(TARGET MySQL::conncpp-jdbc
297-
APPEND PROPERTY INTERFACE_LINK_LIBRARIES pthread dl rt
298-
)
299-
endif()
275+
# Connector/C++ requires these libraries on Unix.
300276

301-
# On Solaris we additionally need couple more libs.
277+
if(NOT APPLE)
278+
list(APPEND libs pthread dl rt)
279+
endif()
302280

303-
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
304-
set_property(TARGET MySQL::conncpp-jdbc
305-
APPEND PROPERTY INTERFACE_LINK_LIBRARIES socket nsl
306-
)
307-
endif()
281+
# On Solaris we additionally need couple more libs.
282+
283+
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
284+
list(APPEND libs socket nsl)
285+
endif()
286+
287+
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
288+
list(APPEND libs execinfo unwind)
289+
else()
290+
list(APPEND libs resolv)
291+
endif()
292+
293+
# OpenSSL dependency
294+
295+
if(WITH_SSL MATCHES "^(system|yes)$")
296+
297+
list(APPEND libs ssl crypto)
298+
299+
else()
300+
301+
if(NOT OPENSSL_FOUND)
302+
303+
if(EXISTS ${WITH_SSL}/include/openssl/ssl.h)
304+
set(OPENSSL_ROOT_DIR "${WITH_SSL}")
305+
endif()
306+
307+
find_package(OpenSSL REQUIRED)
308+
309+
MESSAGE(STATUS "OPENSSL_VERSION = ${OPENSSL_VERSION}")
310+
MESSAGE(STATUS "OPENSSL_SSL_LIBRARY = ${OPENSSL_SSL_LIBRARY}")
311+
MESSAGE(STATUS "OPENSSL_CRYPTO_LIBRARY = ${OPENSSL_CRYPTO_LIBRARY}")
308312

309-
if(OPENSSL_FOUND)
310-
set_property(TARGET MySQL::conncpp-jdbc
311-
APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}
312-
)
313313
endif()
314314

315+
list(APPEND libs ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
316+
317+
endif()
318+
319+
set_property(TARGET MySQL::conncpp-jdbc
320+
APPEND PROPERTY INTERFACE_LINK_LIBRARIES
321+
${libs}
322+
)
323+
315324
endif()
316325

317326

@@ -402,30 +411,6 @@ endif(jdbc_test_stand_alone)
402411
add_executable(jdbc_test jdbc_test.cc)
403412
target_link_libraries(jdbc_test PRIVATE MySQL::conncpp-jdbc)
404413

405-
if(WIN32)
406-
# Connector needs to Link with Dnsapi
407-
target_link_libraries(jdbc_test PRIVATE Dnsapi)
408-
elseif(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
409-
# Connector needs to Link with libresolv
410-
target_link_libraries(jdbc_test PRIVATE resolv)
411-
endif()
412-
413-
#
414-
# FreeBSD has other dependencies
415-
#
416-
417-
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
418-
target_link_libraries(jdbc_test PRIVATE execinfo unwind)
419-
endif()
420-
421-
#
422-
# We need to link to OpenSSL libraries too.
423-
#
424-
425-
if(NOT WIN32 AND OPENSSL_FOUND)
426-
target_link_libraries(jdbc_test PRIVATE ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}
427-
)
428-
endif()
429414

430415
#
431416
# Set RPATH so that libraries in run/ folder are found by the executable

0 commit comments

Comments
 (0)