2018-10-10 13:43:34 +02:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
|
|
|
|
|
|
#.rst:
|
|
|
|
# FindMySQL
|
|
|
|
# -------
|
|
|
|
#
|
|
|
|
# Find MySQL Runtime
|
|
|
|
#
|
|
|
|
# This will define the following variables::
|
|
|
|
#
|
|
|
|
# MYSQL_FOUND - True if the system has the libraries
|
|
|
|
# MYSQL_INCLUDE_DIRS - where to find the headers
|
|
|
|
# MYSQL_LIBRARIES - where to find the libraries
|
|
|
|
# MYSQL_DEFINITIONS - compile definitons
|
|
|
|
#
|
|
|
|
# Hints:
|
|
|
|
# Set ``MYSQL_ROOT_DIR`` to the root directory of an installation.
|
|
|
|
#
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
|
|
|
|
find_package(PkgConfig QUIET)
|
|
|
|
pkg_check_modules(PC_MYSQL QUIET mysqlclient)
|
|
|
|
pkg_check_modules(PC_MARIADB QUIET mariadb)
|
|
|
|
|
2015-09-26 11:11:23 +02:00
|
|
|
SET(BINDIR32_ENV_NAME "ProgramFiles(x86)")
|
|
|
|
SET(BINDIR32 $ENV{${BINDIR32_ENV_NAME}})
|
|
|
|
|
2012-06-26 14:37:02 +02:00
|
|
|
find_path(MYSQL_INCLUDE_DIR mysql.h
|
2018-10-10 13:43:34 +02:00
|
|
|
HINTS
|
|
|
|
${MYSQL_ROOT_DIR}/include
|
|
|
|
${MYSQL_ROOT_INCLUDE_DIRS}
|
|
|
|
PATHS
|
|
|
|
${PC_MYSQL_INCLUDE_DIRS}
|
|
|
|
${PC_MARIADB_INCLUDE_DIRS}
|
|
|
|
/usr/include
|
|
|
|
/usr/local/include
|
2012-06-26 14:37:02 +02:00
|
|
|
/opt/mysql/mysql/include
|
|
|
|
/usr/local/mysql/include
|
|
|
|
$ENV{MYSQL_INCLUDE_DIR}
|
|
|
|
$ENV{MYSQL_DIR}/include
|
|
|
|
$ENV{ProgramFiles}/MySQL/*/include
|
2015-09-26 11:11:23 +02:00
|
|
|
${BINDIR32}/MySQL/include
|
2018-10-10 13:43:34 +02:00
|
|
|
$ENV{SystemDrive}/MySQL/*/include
|
|
|
|
PATH_SUFFIXES
|
|
|
|
mysql
|
|
|
|
mariadb
|
|
|
|
)
|
2017-11-02 21:04:58 +01:00
|
|
|
|
2012-06-26 14:37:02 +02:00
|
|
|
if (WIN32)
|
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL Debug)
|
|
|
|
set(libsuffixDist debug)
|
|
|
|
set(libsuffixBuild Debug)
|
|
|
|
else (CMAKE_BUILD_TYPE STREQUAL Debug)
|
|
|
|
set(libsuffixDist opt)
|
|
|
|
set(libsuffixBuild Release)
|
2018-10-10 13:43:34 +02:00
|
|
|
set(WIN_MYSQL_DEFINITONS " -DDBUG_OFF")
|
2012-06-26 14:37:02 +02:00
|
|
|
endif (CMAKE_BUILD_TYPE STREQUAL Debug)
|
|
|
|
|
2018-10-10 13:43:34 +02:00
|
|
|
find_library(MYSQL_LIBRARY NAMES mysqlclient
|
|
|
|
HINTS
|
|
|
|
${MYSQL_ROOT_DIR}/lib/${libsuffixDist}
|
|
|
|
${MYSQL_ROOT_LIBRARY_DIRS}
|
2012-06-26 14:37:02 +02:00
|
|
|
PATHS
|
2018-10-10 13:43:34 +02:00
|
|
|
${PC_MYSQL_LIBRARY_DIRS}
|
|
|
|
${PC_MARIADB_LIBRARY_DIRS}
|
|
|
|
$ENV{MYSQL_DIR}/lib/${libsuffixDist}
|
|
|
|
$ENV{MYSQL_DIR}/libmysql/${libsuffixBuild}
|
|
|
|
$ENV{MYSQL_DIR}/client/${libsuffixBuild}
|
|
|
|
$ENV{ProgramFiles}/MySQL/*/lib/${libsuffixDist}
|
|
|
|
${BINDIR32}/MySQL/lib
|
|
|
|
$ENV{SystemDrive}/MySQL/*/lib/${libsuffixDist}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
find_library(MYSQL_LIBRARY NAMES mysqlclient mysqlclient_r mariadbclient
|
|
|
|
HINTS
|
|
|
|
${MYSQL_ROOT_DIR}/lib
|
|
|
|
${MYSQL_ROOT_LIBRARY_DIRS}
|
2012-06-26 14:37:02 +02:00
|
|
|
PATHS
|
2018-10-10 13:43:34 +02:00
|
|
|
${PC_MYSQL_LIBRARY_DIRS}
|
|
|
|
${PC_MARIADB_LIBRARY_DIRS}
|
|
|
|
/usr/lib
|
|
|
|
/usr/local/lib
|
|
|
|
/usr/local/mysql/lib
|
|
|
|
/opt/mysql/mysql/lib
|
|
|
|
$ENV{MYSQL_DIR}/libmysql_r/.libs
|
|
|
|
$ENV{MYSQL_DIR}/lib
|
|
|
|
PATH_SUFFIXES
|
|
|
|
mysql
|
|
|
|
mariadb
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(MYSQL_VERSION ${PC_MYSQL_VERSION})
|
|
|
|
|
|
|
|
find_package_handle_standard_args(MYSQL
|
|
|
|
FOUND_VAR MYSQL_FOUND
|
|
|
|
REQUIRED_VARS
|
|
|
|
MYSQL_INCLUDE_DIR
|
|
|
|
MYSQL_LIBRARY
|
|
|
|
VERSION_VAR MYSQL_VERSION
|
|
|
|
)
|
|
|
|
|
|
|
|
if(MYSQL_FOUND)
|
|
|
|
set(MYSQL_LIBRARIES ${MYSQL_LIBRARY})
|
|
|
|
set(MYSQL_INCLUDE_DIRS ${MYSQL_INCLUDE_DIR})
|
|
|
|
set(MYSQL_DEFINITIONS "${PC_MYSQL_CFLAGS_OTHER}${WIN_MYSQL_DEFINITONS}")
|
|
|
|
endif()
|
2017-11-02 21:04:58 +01:00
|
|
|
|
2018-10-10 13:43:34 +02:00
|
|
|
if(MYSQL_FOUND AND NOT TARGET MySQL::client)
|
|
|
|
add_library(MySQL::client UNKNOWN IMPORTED)
|
|
|
|
set_target_properties(MySQL::client PROPERTIES
|
|
|
|
IMPORTED_LOCATION "${MYSQL_LIBRARY}"
|
|
|
|
INTERFACE_COMPILE_OPTIONS "${PC_MYSQL_CFLAGS_OTHER}${WIN_MYSQL_DEFINITONS}"
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${MYSQL_INCLUDE_DIR}"
|
|
|
|
)
|
|
|
|
endif()
|
2012-06-26 14:37:02 +02:00
|
|
|
|
2018-10-10 13:43:34 +02:00
|
|
|
mark_as_advanced(
|
|
|
|
MYSQL_LIBRARY
|
|
|
|
MYSQL_INCLUDE_DIR
|
|
|
|
)
|