Skip to content

Commit 1962378

Browse files
committed
db(mysql): fix Connector/C++ alias linkage and CMake detection
1 parent 9285821 commit 1962378

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ if (VIX_DB_USE_MYSQL)
7777
if (TARGET MySQLCppConn::MySQLCppConn)
7878
set(VIX_DB_HAS_MYSQL ON)
7979
message(STATUS "[vix_db] mysql: enabled (alias)")
80+
get_target_property(_vix_mysql_loc MySQLCppConn::MySQLCppConn IMPORTED_LOCATION)
81+
if (NOT _vix_mysql_loc)
82+
message(WARNING "[vix_db] mysql: alias target exists but has no IMPORTED_LOCATION. Disabling.")
83+
set(VIX_DB_HAS_MYSQL OFF)
84+
set(VIX_DB_USE_MYSQL OFF)
85+
endif()
8086
else()
8187
if (VIX_DB_REQUIRE_MYSQL)
8288
message(FATAL_ERROR "[vix_db] mysql requested but Connector/C++ not found (VIX_DB_REQUIRE_MYSQL=ON).")
@@ -342,7 +348,20 @@ endif()
342348
# Link drivers (single source of truth)
343349
# ------------------------------------------------------------------------------
344350
if (VIX_DB_HAS_MYSQL)
345-
target_link_libraries(vix_db PUBLIC MySQLCppConn::MySQLCppConn)
351+
# Flatten the imported target into real link flags so consumers
352+
# always link the connector (important for static vix_db).
353+
get_target_property(_vix_mysql_lib MySQLCppConn::MySQLCppConn IMPORTED_LOCATION)
354+
get_target_property(_vix_mysql_inc MySQLCppConn::MySQLCppConn INTERFACE_INCLUDE_DIRECTORIES)
355+
356+
if (NOT _vix_mysql_lib)
357+
message(FATAL_ERROR "[vix_db] mysql enabled but MySQLCppConn::MySQLCppConn has no IMPORTED_LOCATION")
358+
endif()
359+
360+
target_link_libraries(vix_db PUBLIC "${_vix_mysql_lib}")
361+
362+
if (_vix_mysql_inc)
363+
target_include_directories(vix_db PUBLIC "${_vix_mysql_inc}")
364+
endif()
346365
endif()
347366

348367
if (VIX_DB_HAS_SQLITE)

cmake/MySQLCppConnAlias.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ if (NOT MYSQLCPPCONN_LIB OR NOT MYSQLCPPCONN_INCLUDE_DIR)
7878
return()
7979
endif()
8080

81+
# ------------------------------------------------------------------------------
82+
# Validate that the picked library really provides the symbol we need.
83+
# Avoid "half-found" connector variants that compile but fail at link time.
84+
# ------------------------------------------------------------------------------
85+
if (UNIX AND EXISTS "${MYSQLCPPCONN_LIB}")
86+
execute_process(
87+
COMMAND bash -c "nm -D \"${MYSQLCPPCONN_LIB}\" 2>/dev/null | grep -q \"get_driver_instance\""
88+
RESULT_VARIABLE _vix_mysql_has_symbol
89+
)
90+
if (NOT _vix_mysql_has_symbol EQUAL 0)
91+
message(WARNING "[vix_db] MySQLCppConn fallback: '${MYSQLCPPCONN_LIB}' does not export get_driver_instance(). Disabling MySQL driver.")
92+
unset(MYSQLCPPCONN_LIB CACHE)
93+
return()
94+
endif()
95+
endif()
96+
8197
# Define imported target
8298
add_library(MySQLCppConn::MySQLCppConn UNKNOWN IMPORTED)
8399

0 commit comments

Comments
 (0)