ddnet/cmake/FindMySQL.cmake

70 lines
2.1 KiB
CMake
Raw Normal View History

2017-07-22 19:53:55 +00:00
find_program(MYSQL_CONFIG
NAMES mysql_config
)
if(MYSQL_CONFIG)
exec_program(${MYSQL_CONFIG}
ARGS --include
OUTPUT_VARIABLE MY_TMP
)
string(REGEX REPLACE "-I([^ ]*)( .*)?" "\\1" MY_TMP "${MY_TMP}")
set(MYSQL_CONFIG_INCLUDE_DIR ${MY_TMP} CACHE FILEPATH INTERNAL)
exec_program(${MYSQL_CONFIG}
ARGS --libs_r
OUTPUT_VARIABLE MY_TMP
)
set(MYSQL_CONFIG_LIBRARIES "")
string(REGEX MATCHALL "-l[^ ]*" MYSQL_LIB_LIST "${MY_TMP}")
foreach(LIB ${MYSQL_LIB_LIST})
string(REGEX REPLACE "[ ]*-l([^ ]*)" "\\1" LIB "${LIB}")
list(APPEND MYSQL_CONFIG_LIBRARIES "${LIB}")
endforeach(LIB ${MYSQL_LIBS})
2017-07-22 19:53:55 +00:00
set(MYSQL_CONFIG_LIBRARY_PATH "")
string(REGEX MATCHALL "-L[^ ]*" MYSQL_LIBDIR_LIST "${MY_TMP}")
foreach(LIB ${MYSQL_LIBDIR_LIST})
string(REGEX REPLACE "[ ]*-L([^ ]*)" "\\1" LIB "${LIB}")
list(APPEND MYSQL_CONFIG_LIBRARY_PATH "${LIB}")
endforeach(LIB ${MYSQL_LIBS})
endif(MYSQL_CONFIG)
set_extra_dirs_lib(MYSQL mysql)
find_library(MYSQL_LIBRARY
2017-02-23 13:51:09 +00:00
NAMES "mysqlclient" "mysqlclient_r" "mariadbclient"
HINTS ${HINTS_MYSQL_LIBDIR} ${MYSQL_CONFIG_LIBRARY_PATH}
PATHS ${PATHS_MYSQL_LIBDIR}
2017-07-22 19:53:55 +00:00
)
set_extra_dirs_include(MYSQL mysql "${MYSQL_LIBRARY}")
find_path(MYSQL_INCLUDEDIR
NAMES "mysql.h"
HINTS ${HINTS_MYSQL_INCLUDEDIR} ${MYSQL_CONFIG_INCLUDE_DIR}
PATHS ${PATHS_MYSQL_INCLUDEDIR}
2017-07-22 19:53:55 +00:00
)
set_extra_dirs_lib(MYSQL_CPPCONN mysql)
2017-07-22 19:53:55 +00:00
find_library(MYSQL_CPPCONN_LIBRARY
NAMES "mysqlcppconn" "mysqlcppconn-static"
HINTS ${HINTS_MYSQL_CPPCONN_LIBDIR} ${MYSQL_CONFIG_LIBRARY_PATH}
PATHS ${PATHS_MYSQL_CPPCONN_LIBDIR}
)
set_extra_dirs_include(MYSQL_CPPCONN mysql "${MYSQL_CPPCONN_LIBRARY}")
find_path(MYSQL_CPPCONN_INCLUDEDIR
NAMES "mysql_connection.h"
HINTS ${HINTS_MYSQL_CPPCONN_INCLUDEDIR} ${MYSQL_CONFIG_INCLUDE_DIR}
PATHS ${PATHS_MYSQL_CPPCONN_INCLUDEDIR}
)
include(FindPackageHandleStandardArgs)
2017-07-22 19:53:55 +00:00
find_package_handle_standard_args(MySQL DEFAULT_MSG MYSQL_LIBRARY MYSQL_INCLUDEDIR)
2017-07-22 19:53:55 +00:00
set(MYSQL_LIBRARIES ${MYSQL_LIBRARY} ${MYSQL_CPPCONN_LIBRARY})
set(MYSQL_INCLUDE_DIRS ${MYSQL_INCLUDEDIR} ${MYSQL_CPPCONN_INCLUDEDIR})
2017-07-22 19:53:55 +00:00
mark_as_advanced(MYSQL_INCLUDEDIR MYSQL_LIBRARY)