File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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# ------------------------------------------------------------------------------
344350if (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 ()
346365endif ()
347366
348367if (VIX_DB_HAS_SQLITE)
Original file line number Diff line number Diff line change @@ -78,6 +78,22 @@ if (NOT MYSQLCPPCONN_LIB OR NOT MYSQLCPPCONN_INCLUDE_DIR)
7878 return ()
7979endif ()
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
8298add_library (MySQLCppConn::MySQLCppConn UNKNOWN IMPORTED )
8399
You can’t perform that action at this time.
0 commit comments