Skip to content

Commit 19fafe1

Browse files
committed
cmake: Ensure that required -L option is passed when linking to MySQL client lib.
1 parent 19090de commit 19fafe1

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

cmake/DepFindMySQL.cmake

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ add_config_option(WITH_MYSQL PATH
5757
"Base location of (monolithic) MySQL installation."
5858
)
5959

60-
add_config_option(MYSQL_INCLUDE_DIR PATH "Path to MYSQL headers.")
61-
add_config_option(MYSQL_LIB_DIR PATH "Path to MYSQL libraries.")
60+
add_config_option(MYSQL_INCLUDE_DIR PATH ADVANCED "Path to MYSQL headers.")
61+
add_config_option(MYSQL_LIB_DIR PATH ADVANCED "Path to MYSQL libraries.")
6262

6363

6464
function(main)
@@ -235,13 +235,6 @@ function(main)
235235
PROPERTY VERSION ${MYSQL_VERSION}
236236
)
237237

238-
# Setting this should ensure that bundled external dependencies are used,
239-
# if available.
240-
241-
set_property(TARGET MySQL::client-static
242-
PROPERTY INTERFACE_LINK_DIRECTORIES "${MYSQL_DIR}/lib" "${MYSQL_DIR}/bin"
243-
)
244-
245238
#
246239
# Detect shared libraries on which MySQL client lib depends (if possible).
247240
# Stores result in MYSQL_EXTERNAL_DEPENDENCIES.
@@ -253,6 +246,20 @@ function(main)
253246
message(" include path: ${MYSQL_INCLUDE_DIR}")
254247
message(" library location: ${MYSQL_LIB}")
255248

249+
# Using INTERFACE_LINK_LIBRARIES we ensure that -L option will appear
250+
# in the link line of the consumer of this library. Adding this -L option
251+
# is needed to resolve dependencies, such as -lssl, to the libraries that
252+
# are bundled with the server.
253+
#
254+
# Note: This must be done before populating INTERFACE_LINK_LIBRARIES with
255+
# the dependencies themselves.
256+
257+
if(NOT MSVC)
258+
set_property(TARGET MySQL::client-static
259+
PROPERTY INTERFACE_LINK_LIBRARIES "-L${MYSQL_DIR}/lib"
260+
)
261+
endif()
262+
256263
if(MYSQL_EXTERNAL_DEPENDENCIES)
257264
string(REPLACE ";" " " deps "${MYSQL_EXTERNAL_DEPENDENCIES}")
258265
message(" dependencies: ${deps}")
@@ -267,6 +274,7 @@ function(main)
267274

268275
endif()
269276

277+
270278
endfunction(main)
271279

272280

0 commit comments

Comments
 (0)