Skip to content

Commit bca29c1

Browse files
committed
Bug #34417381 Fix libssl dependency when bundled
Change-Id: Id7e1a4ab88651684be059d02f48c624a9cd6dfb0
1 parent 1211e34 commit bca29c1

File tree

2 files changed

+90
-51
lines changed

2 files changed

+90
-51
lines changed

cdk/cmake/DepFindSSL.cmake

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -305,16 +305,21 @@ function(bundle_ssl_libs)
305305
endif()
306306

307307
foreach(lib ${glob1} ${glob2})
308+
# Copy SSL libs to binary dir as below we will modify them (change the path to
309+
# libcrypto dependency).
310+
file(COPY ${lib} DESTINATION ${CMAKE_BINARY_DIR}/SSL)
308311

309312
message("-- bundling OpenSSL library: ${lib}")
310313

314+
get_filename_component(lib_filename ${lib} NAME)
315+
311316
if(WIN32 OR APPLE)
312-
install(FILES ${lib}
317+
install(FILES ${CMAKE_BINARY_DIR}/SSL/${lib_filename}
313318
DESTINATION "${INSTALL_LIB_DIR}"
314319
COMPONENT OpenSSLDll
315320
)
316321
else()
317-
install(FILES ${lib}
322+
install(FILES ${CMAKE_BINARY_DIR}/SSL/${lib_filename}
318323
DESTINATION "${INSTALL_LIB_DIR}/private"
319324
COMPONENT OpenSSLDll
320325
)
@@ -344,6 +349,41 @@ function(bundle_ssl_libs)
344349

345350
endif()
346351

352+
if(APPLE)
353+
# Replace libcrypto local path of libssl
354+
EXECUTE_PROCESS(
355+
COMMAND otool -L "${OPENSSL_LIBRARY}"
356+
OUTPUT_VARIABLE OTOOL_OPENSSL_DEPS)
357+
STRING(REPLACE "\n" ";" DEPS_LIST ${OTOOL_OPENSSL_DEPS})
358+
359+
foreach(LINE ${DEPS_LIST})
360+
if(${LINE} MATCHES "ssl")
361+
STRING(REGEX MATCH "(/.*libssl.*${CMAKE_SHARED_LIBRARY_SUFFIX})" XXXXX ${LINE})
362+
363+
if(CMAKE_MATCH_1)
364+
get_filename_component(OPENSSL_LIBRARY_VERSION ${CMAKE_MATCH_1} NAME)
365+
endif()
366+
elseif(${LINE} MATCHES "crypto")
367+
STRING(REGEX MATCH "(/.*libcrypto.*${CMAKE_SHARED_LIBRARY_SUFFIX})" XXXXX ${LINE})
368+
369+
if(CMAKE_MATCH_1)
370+
SET(LIBSSL_DEPS "${CMAKE_MATCH_1}")
371+
get_filename_component(CRYPTO_LIBRARY_VERSION ${CMAKE_MATCH_1} NAME)
372+
endif()
373+
endif()
374+
375+
endforeach()
376+
377+
if(LIBSSL_DEPS)
378+
# install_name_tool -change old new file
379+
EXECUTE_PROCESS(
380+
COMMAND chmod +w "${CRYPTO_LIBRARY_VERSION} ${OPENSSL_LIBRARY_VERSION}"
381+
COMMAND install_name_tool -change "${LIBSSL_DEPS}" "@loader_path/${CRYPTO_LIBRARY_VERSION}" "${OPENSSL_LIBRARY_VERSION}"
382+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/SSL"
383+
)
384+
endif()
385+
endif()
386+
347387
endfunction(bundle_ssl_libs)
348388

349389

jdbc/CMakeLists.txt

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2008, 2020, Oracle and/or its affiliates.
1+
# Copyright (c) 2008, 2022, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -375,13 +375,13 @@ endif()
375375
# Bundle 3rd party dependencies if needed
376376
# =======================================
377377

378-
# List client-side plugins, their dependencies and dependencies of the client
379-
# library that are bundled with the server and should be bundled with
380-
# connector. Also list plugins and libraries that can be found with the server
378+
# List client-side plugins, their dependencies and dependencies of the client
379+
# library that are bundled with the server and should be bundled with
380+
# connector. Also list plugins and libraries that can be found with the server
381381
# but which should be ignored.
382382
#
383-
# When building in MAINTAINER_MODE cmake will report error if it finds
384-
# a plugin or 3rd party librariy which is not listed here. When that happens
383+
# When building in MAINTAINER_MODE cmake will report error if it finds
384+
# a plugin or 3rd party librariy which is not listed here. When that happens
385385
# the lists should be updated.
386386

387387
set(AUTH_PLUGINS
@@ -395,12 +395,12 @@ set(AUTH_PLUGINS
395395
# Plugin dependencies.
396396
#
397397
# Warning: If one library name is a prefix of the other, the longer name
398-
# should be listed first, otherwise the logic detecting missing dependencies
398+
# should be listed first, otherwise the logic detecting missing dependencies
399399
# will break... For example: `krb5support` must go before `krb5`
400400

401401
set(AUTH_DEPS_fido fido2)
402402

403-
# Note: Windows implementation does not depend on MIT Kerberos library, it uses
403+
# Note: Windows implementation does not depend on MIT Kerberos library, it uses
404404
# native Win APIs
405405

406406
if(NOT WIN32)
@@ -416,11 +416,10 @@ endif()
416416

417417
set(PLUGINS)
418418

419-
# additional bundled dependencies of the client library
419+
# additional bundled dependencies of the client library other than the openssl
420+
# libraries that are handled separately (in DepFindSSL.cmake)
420421

421-
set(BUNDLED_LIBS
422-
libssl libcrypto ssleay libeay
423-
)
422+
set(BUNDLED_LIBS)
424423

425424
set(IGNORED_PLUGINS qa_auth_client)
426425

@@ -429,6 +428,7 @@ set(IGNORED_LIBS
429428
ldap # note: this is needed only by server-side plugin
430429
libcurl libmecab zlib
431430
jemalloc
431+
libssl libcrypto
432432
)
433433

434434

@@ -451,21 +451,29 @@ function(bundle_lib lib)
451451
COMPONENT JDBCDll
452452
)
453453
else()
454+
if(APPLE)
455+
# On Apple, its on the lib dir
454456
install(FILES ${lib}
455-
DESTINATION "${INSTALL_LIB_DIR}/private"
457+
DESTINATION "${INSTALL_LIB_DIR}"
456458
COMPONENT JDBCDll
457459
)
460+
else()
461+
install(FILES ${lib}
462+
DESTINATION "${INSTALL_LIB_DIR}/private"
463+
COMPONENT JDBCDll
464+
)
465+
endif()
458466
endif()
459467

460468
endfunction(bundle_lib)
461469

462470

463471
# Bundle libraries listed in a list variable ${to_bundle}.
464-
# Libraries that were found and bundled are removed from ${to_bundle} list.
465-
# Other libraries found but not listed in ${to_bundle} are returned
472+
# Libraries that were found and bundled are removed from ${to_bundle} list.
473+
# Other libraries found but not listed in ${to_bundle} are returned
466474
# in ${ignored} variable.
467-
# If additional arguments are given, they are used as glob expressions to find
468-
# the libraries to be bundled, otherwise 3rd parties bundled in with the server
475+
# If additional arguments are given, they are used as glob expressions to find
476+
# the libraries to be bundled, otherwise 3rd parties bundled in with the server
469477
# are searched in ${MYSQL_LIB_DIR} locations.
470478

471479
macro(bundle_libs to_bundle ignored)
@@ -478,13 +486,20 @@ macro(bundle_libs to_bundle ignored)
478486
if(${ARGC} GREATER 2)
479487

480488
file(GLOB _bundled ${ARGN})
481-
489+
482490
else()
483491

484-
file(GLOB _bundled
485-
"${MYSQL_LIB_DIR}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
486-
"${MYSQL_LIB_DIR}/private/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
487-
)
492+
# On Apple, libs are only on the lib dir, not on private
493+
if(APPLE)
494+
file(GLOB _bundled
495+
"${MYSQL_LIB_DIR}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
496+
)
497+
else()
498+
file(GLOB _bundled
499+
"${MYSQL_LIB_DIR}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
500+
"${MYSQL_LIB_DIR}/private/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
501+
)
502+
endif()
488503

489504
# On windows, libs are in bin directory
490505

@@ -532,9 +547,9 @@ macro(bundle_libs to_bundle ignored)
532547
endmacro(bundle_libs)
533548

534549

535-
# Bundle plugins listed in PLUGINS list. Each bundled plugin P is removed from
536-
# the list and its dependedencies listed in DEPS_${P} are also bundled. Client
537-
# side plugins found with the server and not listed in PLUGINS are returned
550+
# Bundle plugins listed in PLUGINS list. Each bundled plugin P is removed from
551+
# the list and its dependedencies listed in DEPS_${P} are also bundled. Client
552+
# side plugins found with the server and not listed in PLUGINS are returned
538553
# in ${ignored} list.
539554

540555
macro(bundle_plugins ignored)
@@ -555,7 +570,7 @@ macro(bundle_plugins ignored)
555570

556571
#message("== looking at client-side plugin: ${lib_name}")
557572

558-
# Match plugin name against names in PLUGINS list and in case of match
573+
# Match plugin name against names in PLUGINS list and in case of match
559574
# remove that name from the list
560575

561576
unset(plugin)
@@ -651,7 +666,7 @@ if(BUNDLE_DEPENDENCIES)
651666
endforeach()
652667

653668
# Bundle the plugins and their dependencies.
654-
669+
655670
unset(ingored)
656671
bundle_plugins(ignored)
657672

@@ -678,45 +693,29 @@ if(BUNDLE_DEPENDENCIES)
678693

679694
message(STATUS "Looking for bundled client lib dependencies")
680695

681-
# Bundle additional libraries listed in BUNDLED_LIBS
682-
# For OpenSSL libs, first look in the location of the library that
683-
# is actually being used in the build (for the win case, look also in ../bin/
684-
# because this is where the DLLs can be found, as opposed to the
685-
# corresponding link libraries).
696+
# Bundle additional libraries listed in BUNDLED_LIBS
686697

687-
#message("== BUNDLED_LIBS: ${BUNDLED_LIBS}")
688-
#message("== IGNORED_LIBS: ${IGNORED_LIBS}")
689-
690-
get_filename_component(OPENSSL_DIR ${OPENSSL_LIBRARY} DIRECTORY)
691-
692-
#message(STATUS "bundle openssl libs")
693-
bundle_libs(BUNDLED_LIBS extra_libs
694-
"${OPENSSL_DIR}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
695-
"${OPENSSL_DIR}/../bin/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
696-
)
697698
#message(STATUS "bundle other libs")
698699
unset(extra_libs)
699700
bundle_libs(BUNDLED_LIBS extra_libs)
700701

701-
# In MAINTAINER_MODE check whether all 3rd party libs found but not bundled
702+
# In MAINTAINER_MODE check whether all 3rd party libs found but not bundled
702703
# are listed in IGNORED_LIBS
703704

704705
if(MAINTAINER_MODE)
705706

706-
# Extend ignore list with libraries that are dependencies of known plugins
707+
# Extend ignore list with libraries that are dependencies of known plugins
707708
# and are not listed in BUNDLED_LIBS. Otherwise we would get false errors
708709
# below.
709710

710711
foreach(plugin PLUGINS)
711712
list(APPEND IGNORED_LIBS ${DEPS_${plugin}})
712713
endforeach()
713714

714-
# Remove from ${extra_libs} the libraries that we know we should ignore.
715-
# Also the openssl libs that might end up in ${extra_libs} bacause of two
716-
# stage search logic above.
715+
# Remove from ${extra_libs} the libraries that we know we should ignore.
717716

718717
#message("== extra_libs: ${extra_libs}")
719-
foreach(lib ${IGNORED_LIBS} libssl libcrypto ssleay libeay)
718+
foreach(lib ${IGNORED_LIBS})
720719
#message(STATUS "removing: ${lib}")
721720
list(FILTER extra_libs EXCLUDE REGEX "^${lib}")
722721
list(FILTER extra_libs EXCLUDE REGEX "^lib${lib}")

0 commit comments

Comments
 (0)