[cosmetic] separate c-lang format commit
[xbmc.git] / cmake / modules / FindMariaDBClient.cmake
blob98099a411d5361714601a6aafb25b3b40245276e
1 #.rst:
2 # FindMariaDBClient
3 # ---------------
4 # Finds the MariaDBClient library
6 # This will define the following target:
8 #   ${APP_NAME_LC}::MariaDBClient   - The MariaDBClient library
10 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
11   find_package(PkgConfig)
13   if(PKG_CONFIG_FOUND)
14     pkg_search_module(PC_MARIADBCLIENT libmariadb mariadb QUIET)
15   endif()
17   find_path(MARIADBCLIENT_INCLUDE_DIR NAMES mariadb/mysql.h mariadb/server/mysql.h
18                                       HINTS ${PC_MARIADBCLIENT_INCLUDEDIR})
19   find_library(MARIADBCLIENT_LIBRARY_RELEASE NAMES mariadbclient mariadb libmariadb
20                                              HINTS ${PC_MARIADBCLIENT_LIBDIR}
21                                              PATH_SUFFIXES mariadb
22                                              ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
23   find_library(MARIADBCLIENT_LIBRARY_DEBUG NAMES mariadbclient mariadb libmariadbd
24                                            HINTS ${PC_MARIADBCLIENT_LIBDIR}
25                                            PATH_SUFFIXES mariadb
26                                            ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
28   if(PC_MARIADBCLIENT_VERSION)
29     set(MARIADBCLIENT_VERSION_STRING ${PC_MARIADBCLIENT_VERSION})
30   elseif(MARIADBCLIENT_INCLUDE_DIR AND EXISTS "${MARIADBCLIENT_INCLUDE_DIR}/mariadb/mariadb_version.h")
31     file(STRINGS "${MARIADBCLIENT_INCLUDE_DIR}/mariadb/mariadb_version.h" mariadb_version_str REGEX "^#define[\t ]+MARIADB_CLIENT_VERSION_STR[\t ]+\".*\".*")
32     string(REGEX REPLACE "^#define[\t ]+MARIADB_CLIENT_VERSION_STR[\t ]+\"([^\"]+)\".*" "\\1" MARIADBCLIENT_VERSION_STRING "${mariadb_version_str}")
33     unset(mariadb_version_str)
34   endif()
36   include(SelectLibraryConfigurations)
37   select_library_configurations(MARIADBCLIENT)
39   include(FindPackageHandleStandardArgs)
40   find_package_handle_standard_args(MariaDBClient
41                                     REQUIRED_VARS MARIADBCLIENT_LIBRARY MARIADBCLIENT_INCLUDE_DIR
42                                     VERSION_VAR MARIADBCLIENT_VERSION_STRING)
44   if(MARIADBCLIENT_FOUND)
45     add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
46     if(MARIADBCLIENT_LIBRARY_RELEASE)
47       set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
48                                                                        IMPORTED_CONFIGURATIONS RELEASE
49                                                                        IMPORTED_LOCATION_RELEASE "${MARIADBCLIENT_LIBRARY_RELEASE}")
50     endif()
51     if(MARIADBCLIENT_LIBRARY_DEBUG)
52       set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
53                                                                        IMPORTED_LOCATION_DEBUG "${MARIADBCLIENT_LIBRARY_DEBUG}")
54       set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
55                                                                             IMPORTED_CONFIGURATIONS DEBUG)
56     endif()
57     set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
58                                                                      INTERFACE_INCLUDE_DIRECTORIES "${MARIADBCLIENT_INCLUDE_DIR}"
59                                                                      INTERFACE_COMPILE_DEFINITIONS HAS_MARIADB)
60     if(CORE_SYSTEM_NAME STREQUAL osx)
61       target_link_libraries(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} INTERFACE gssapi_krb5)
62     endif()
63   endif()
64 endif()