]> git.stg.codes - stg.git/blob - cmake/modules/FindMySQLConnector.cmake
Port to CMake, get rid of os_int.h.
[stg.git] / cmake / modules / FindMySQLConnector.cmake
1 find_path ( MySQLConnector_INCLUDE_DIR NAMES mysql/mysql.h mysql/mysql_version.h DOC "Path to MySQLConnector header files." )
2 mark_as_advanced ( MySQLConnector_INCLUDE_DIR )
3
4 find_library ( MySQLConnector_LIB NAMES mysqlclient DOC "Location of MySQLConnector library." )
5 mark_as_advanced ( MySQLConnector_LIB )
6
7 if ( MySQLConnector_INCLUDE_DIR )
8     file ( READ "${MySQLConnector_INCLUDE_DIR}/mysql/mysql_version.h" ver )
9
10     string ( REGEX MATCH "LIBMYSQL_VERSION ([0-9]*)" _ ${ver} )
11
12     set ( MySQLConnector_VERSION ${CMAKE_MATCH_1} )
13
14     unset ( ver )
15 endif ( MySQLConnector_INCLUDE_DIR )
16
17 include ( FindPackageHandleStandardArgs )
18 find_package_handle_standard_args ( MySQLConnector
19                                     REQUIRED_VARS MySQLConnector_LIB MySQLConnector_INCLUDE_DIR
20                                     VERSION_VAR MySQLConnector_VERSION )
21
22 # Create the imported target
23 if ( MySQLConnector_FOUND )
24     set ( MySQLConnector_INCLUDE_DIRS ${MySQLConnector_INCLUDE_DIR} )
25     set ( MySQLConnector_LIBRARIES ${MySQLConnector_LIB} )
26     if ( NOT TARGET MySQL::Connector )
27         add_library ( MySQL::Connector UNKNOWN IMPORTED )
28         set_target_properties ( MySQL::Connector PROPERTIES
29                                 IMPORTED_LOCATION "${MySQLConnector_LIB}"
30                                 INTERFACE_INCLUDE_DIRECTORIES "${MySQLConnector_INCLUDE_DIR}" )
31     endif ( NOT TARGET MySQL::Connector )
32 endif ( MySQLConnector_FOUND )