CMake: Make it possible to specify a debug MySQL client library
An MSVC debug-and-release build of Qt with the MySQL plugin requires separate builds of the MySQL client library: a debug and a release build. There was no way to specify the debug version of the library. Now, it's possible to configure Qt like this: cmake ... \ -DMySQL_ROOT=D:\mysql-connector-c-6.1.11-winx64 \ -DMySQL_LIBRARY_DIR=D:\mysql-connector-c-6.1.11-winx64\lib\vs14 This will automatically detect the include dir and the debug and release library files. We expect that the debug build of the MySQL client library resides in a "debug" subdirectory below MySQL_LIBRARY_DIR. If the automatic detection doesn't work to due a different layout on the build machine, one can set the variable MySQL_LIBRARY_DEBUG to specify the debug variant of the MySQL client library. [ChangeLog][CMake] If pkg-config is not used, a debug build of the MySQL client library can be specified with -DMySQL_LIBRARY_DEBUG=<path-to-library>. The debug and release variants of the library are automatically detected. Setting MySQL_ROOT and MySQL_LIBRARY_DIR is sufficient in most cases. Pick-to: 6.2 6.4 Task-number: QTQAINFRA-4999 Change-Id: I663fb8ac1dbd07bc73484791be9cc21bff2f4a9b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io> Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
parent
65b7aacb40
commit
84c76d6205
@ -6,7 +6,25 @@
|
||||
# ---------
|
||||
#
|
||||
# Try to locate the mysql client library.
|
||||
# If found, this will define the following variables:
|
||||
#
|
||||
# By default, pkg-config is used, if available.
|
||||
# If pkg-config is not available or if you want to disable it, set the ``MySQL_ROOT`` variable.
|
||||
# The following variables can be set to control the behavior of this find module.
|
||||
#
|
||||
# ``MySQL_ROOT``
|
||||
# The root directory of the mysql client library's installation.
|
||||
# ``MySQL_INCLUDE_DIR``
|
||||
# The directory containing the include files of the mysql client library.
|
||||
# If not set, the directory is detected within ``MySQL_ROOT`` using find_path.
|
||||
# ``MySQL_LIBRARY_DIR``
|
||||
# The directory containing the binaries of the mysql client library.
|
||||
# This is used to detect ``MySQL_LIBRARY`` and passed as HINT to find_library.
|
||||
# ``MySQL_LIBRARY``
|
||||
# The file path to the mysql client library.
|
||||
# ``MySQL_LIBRARY_DEBUG``
|
||||
# The file path to the mysql client library for the DEBUG configuration.
|
||||
#
|
||||
# If the mysql client library is found, this will define the following variables:
|
||||
#
|
||||
# ``MySQL_FOUND``
|
||||
# True if the mysql library is available
|
||||
@ -21,17 +39,39 @@
|
||||
# ``MySQL::MySQL``
|
||||
# The mysql client library
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(PC_MySQL QUIET mysqlclient)
|
||||
if(NOT DEFINED MySQL_ROOT)
|
||||
find_package(PkgConfig QUIET)
|
||||
endif()
|
||||
if(PkgConfig_FOUND AND NOT DEFINED MySQL_ROOT)
|
||||
pkg_check_modules(PC_MySQL QUIET mysqlclient)
|
||||
set(MySQL_include_dir_hints ${PC_MySQL_INCLUDEDIR})
|
||||
set(MySQL_library_hints ${PC_MySQL_LIBDIR})
|
||||
set(MySQL_library_hints_debug "")
|
||||
else()
|
||||
set(MySQL_include_dir_hints "")
|
||||
if(NOT DEFINED MySQL_LIBRARY_DIR)
|
||||
set(MySQL_LIBRARY_DIR "${MySQL_ROOT}/lib")
|
||||
endif()
|
||||
set(MySQL_library_hints "${MySQL_LIBRARY_DIR}")
|
||||
set(MySQL_library_hints_debug "${MySQL_LIBRARY_DIR}/debug")
|
||||
endif()
|
||||
|
||||
find_path(MySQL_INCLUDE_DIR
|
||||
NAMES mysql.h
|
||||
HINTS ${PC_MySQL_INCLUDEDIR}
|
||||
HINTS "${MySQL_include_dir_hints}"
|
||||
PATH_SUFFIXES mysql mariadb)
|
||||
|
||||
find_library(MySQL_LIBRARY
|
||||
NO_PACKAGE_ROOT_PATH
|
||||
NAMES libmysql mysql mysqlclient libmariadb mariadb
|
||||
HINTS ${PC_MySQL_LIBDIR})
|
||||
HINTS ${MySQL_library_hints})
|
||||
|
||||
if(MySQL_library_hints_debug)
|
||||
find_library(MySQL_LIBRARY_DEBUG
|
||||
NO_PACKAGE_ROOT_PATH
|
||||
NAMES libmysql mysql mysqlclient libmariadb mariadb
|
||||
HINTS ${MySQL_library_hints_debug})
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(MySQL DEFAULT_MSG MySQL_LIBRARY MySQL_INCLUDE_DIR)
|
||||
@ -44,6 +84,10 @@ if(MySQL_FOUND)
|
||||
set_target_properties(MySQL::MySQL PROPERTIES
|
||||
IMPORTED_LOCATION "${MySQL_LIBRARIES}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${MySQL_INCLUDE_DIRS}")
|
||||
if(MySQL_LIBRARY_DEBUG)
|
||||
set_target_properties(MySQL::MySQL PROPERTIES
|
||||
IMPORTED_LOCATION_DEBUG "${MySQL_LIBRARY_DEBUG}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user