Skip to content

Commit 361e3b8

Browse files
Chip Turnersteaphangreene
authored andcommitted
Adjust linking flags to not embed some libs
Summary: Feature: Basic Build Fixes Adjust mysql linking flags to not embed openssl and zlib in static libs. By default, libmysqlclient.a includes a copy of the openssl and zlib it was linked against, thanks to a MERGE_LIBRARY call. This isn't ideal in fbcode's third-party environment where we want targets to have to link in openssl on their own. This change removes the ssl and zlib libraries from the merge and instead sets them as a dependency for the build, so that other built targets, such as the command line tools, still end up properly linked but libmysqlclient.a doesn't include embedded copies. It also removes the munging of the library names when doing a static build so that they are not called "imported_crypto" and "imported_openssl" and instead are called by their normal names. Test Plan: mtr; also builting in third-party, confirming the .a file does not contain openssl symbols and that building a third-party library that depends on libmysqlclient works as expected Reviewers: flamingcow, pivanof, jeremycole, andrew-ford, inaam-rana Reviewed By: pivanof CC: jtolmer, MarkCallaghan Differential Revision: https://reviews.facebook.net/D15657
1 parent c261c31 commit 361e3b8

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

cmake/build_configurations/mysql_release.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ ENDIF()
3434
IF(UNIX)
3535
SET(WITH_EXTRA_CHARSETS all CACHE STRING "")
3636

37-
OPTION(WITH_PIC "" ON) # Why?
38-
3937
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
4038
IF(NOT IGNORE_AIO_CHECK)
4139
# Ensure aio is available on Linux (required by InnoDB)

cmake/ssl.cmake

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,6 @@ MACRO (MYSQL_CHECK_SSL)
189189
# to get LOCATION and do correct dependency analysis.
190190
SET(MY_CRYPTO_LIBRARY "${CRYPTO_LIBRARY}")
191191
SET(MY_OPENSSL_LIBRARY "${OPENSSL_LIBRARY}")
192-
IF (WITH_SSL_PATH)
193-
GET_FILENAME_COMPONENT(CRYPTO_EXT "${CRYPTO_LIBRARY}" EXT)
194-
GET_FILENAME_COMPONENT(OPENSSL_EXT "${OPENSSL_LIBRARY}" EXT)
195-
IF (CRYPTO_EXT STREQUAL ".a")
196-
SET(MY_CRYPTO_LIBRARY imported_crypto)
197-
ADD_LIBRARY(imported_crypto STATIC IMPORTED)
198-
SET_TARGET_PROPERTIES(imported_crypto
199-
PROPERTIES IMPORTED_LOCATION "${CRYPTO_LIBRARY}")
200-
ENDIF()
201-
IF (OPENSSL_EXT STREQUAL ".a")
202-
SET(MY_OPENSSL_LIBRARY imported_openssl)
203-
ADD_LIBRARY(imported_openssl STATIC IMPORTED)
204-
SET_TARGET_PROPERTIES(imported_openssl
205-
PROPERTIES IMPORTED_LOCATION "${OPENSSL_LIBRARY}")
206-
ENDIF()
207-
ENDIF()
208192

209193
MESSAGE(STATUS "OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}")
210194
MESSAGE(STATUS "OPENSSL_LIBRARY = ${OPENSSL_LIBRARY}")

libmysql/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ ADD_CONVENIENCE_LIBRARY(clientlib ${CLIENT_SOURCES})
167167
DTRACE_INSTRUMENT(clientlib)
168168
ADD_DEPENDENCIES(clientlib GenError)
169169

170-
SET(LIBS clientlib dbug strings vio mysys mysys_ssl ${ZLIB_LIBRARY} ${SSL_LIBRARIES} ${LIBDL})
170+
# Don't merge zlib, ssl, etc when building static libraries.
171+
SET(STATIC_MERGE_LIBS clientlib dbug strings vio mysys mysys_ssl ${LIBDL})
172+
173+
SET(LIBS ${STATIC_MERGE_LIBS} ${ZLIB_LIBRARY} ${SSL_LIBRARIES})
171174

172175
#
173176
# On Windows platform client library includes the client-side
@@ -180,7 +183,8 @@ IF(WIN32)
180183
ENDIF()
181184

182185
# Merge several convenience libraries into one big mysqlclient
183-
MERGE_LIBRARIES(mysqlclient STATIC ${LIBS} COMPONENT Development)
186+
MERGE_LIBRARIES(mysqlclient STATIC ${STATIC_MERGE_LIBS} COMPONENT Development)
187+
TARGET_LINK_LIBRARIES(mysqlclient ${ZLIB_LIBRARY} ${SSL_LIBRARIES})
184188

185189
# Visual Studio users need debug static library for debug projects
186190
INSTALL_DEBUG_SYMBOLS(clientlib)

0 commit comments

Comments
 (0)