From 2f65c3a7b818e565ba7ace040832180a913f6873 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 3 Feb 2016 11:35:01 +0200 Subject: [PATCH] MariaDB Connector C is build from source if it is not found on the system The FindMariaDBConnector.cmake file now checks if the found library actually is the MariaDB Connector-C library. If the found library is not the MariaDB Connector-C, it will be built from source. --- CMakeLists.txt | 6 ++++++ cmake/BuildMariaDBConnector.cmake | 26 ++++++++++++++++++++++++++ cmake/FindMariaDBConnector.cmake | 25 +++++++++++++++++-------- query_classifier/test/CMakeLists.txt | 8 ++++++-- server/core/CMakeLists.txt | 2 +- 5 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 cmake/BuildMariaDBConnector.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c276ea6e..b81ba7f09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,12 @@ find_package(RabbitMQ) # Read BuildPCRE2 for details about how to add pcre2 as a dependency to a target include(cmake/BuildPCRE2.cmake) +# If the connector was not found, download and build it from source +if(NOT MARIADB_CONNECTOR_FOUND) + message(STATUS "Building MariaDB Connector-C from source.") + include(cmake/BuildMariaDBConnector.cmake) +endif() + # You can find the variables set by this in the FindCURL.cmake file # which is a default module in CMake. diff --git a/cmake/BuildMariaDBConnector.cmake b/cmake/BuildMariaDBConnector.cmake new file mode 100644 index 000000000..ed316c7ec --- /dev/null +++ b/cmake/BuildMariaDBConnector.cmake @@ -0,0 +1,26 @@ +# Build the MariaDB Connector-C +# +# If the MariaDB connector is not found, the last option is to download it +# and build it from source. This file downloads and builds the connector and +# sets the variables set by FindMariaDBConnector.cmake so that it appears that +# the system has the connector. + +include(ExternalProject) + +ExternalProject_Add(connector-c + GIT_REPOSITORY https://github.com/MariaDB/mariadb-connector-c.git + GIT_TAG v2.2.1 + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/connector-c/install + BINARY_DIR ${CMAKE_BINARY_DIR}/connector-c + INSTALL_DIR ${CMAKE_BINARY_DIR}/connector-c/install) + +set(MARIADB_CONNECTOR_FOUND TRUE CACHE INTERNAL "" FORCE) +set(MARIADB_CONNECTOR_STATIC_FOUND TRUE CACHE INTERNAL "" FORCE) +set(MARIADB_CONNECTOR_INCLUDE_DIR + ${CMAKE_BINARY_DIR}/connector-c/install/include/mariadb CACHE INTERNAL "" FORCE) +set(MARIADB_CONNECTOR_STATIC_LIBRARIES + ${CMAKE_BINARY_DIR}/connector-c/install/lib/mariadb/libmariadbclient.a + CACHE INTERNAL "" FORCE) +set(MARIADB_CONNECTOR_LIBRARIES + ${CMAKE_BINARY_DIR}/connector-c/install/lib/mariadb/libmariadbclient.a + CACHE INTERNAL "" FORCE) diff --git a/cmake/FindMariaDBConnector.cmake b/cmake/FindMariaDBConnector.cmake index b425f8976..787bd90fa 100644 --- a/cmake/FindMariaDBConnector.cmake +++ b/cmake/FindMariaDBConnector.cmake @@ -6,28 +6,37 @@ # MARIADB_CONNECTOR_STATIC_LIBRARIES - The static connector libraries # MARIADB_CONNECTOR_INCLUDE_DIR - The connector headers -find_library(MARIADB_CONNECTOR_LIB NAMES mysqlclient PATH_SUFFIXES mysql mariadb) -if(${MARIADB_CONNECTOR_LIB} MATCHES "NOTFOUND") +find_library(MARIADB_CONNECTOR_LIBRARIES NAMES mysqlclient PATH_SUFFIXES mysql mariadb) +if(${MARIADB_CONNECTOR_LIBRARIES} MATCHES "NOTFOUND") set(MARIADB_CONNECTOR_FOUND FALSE CACHE INTERNAL "") message(STATUS "Dynamic MySQL client library not found.") - unset(MARIADB_CONNECTOR_LIB) + unset(MARIADB_CONNECTOR_LIBRARIES) else() set(MARIADB_CONNECTOR_FOUND TRUE CACHE INTERNAL "") - message(STATUS "Found dynamic MySQL client library: ${MARIADB_CONNECTOR_LIB}") + message(STATUS "Found dynamic MySQL client library: ${MARIADB_CONNECTOR_LIBRARIES}") endif() set(OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") -find_library(MARIADB_CONNECTOR_STATIC_LIB NAMES mysqlclient PATH_SUFFIXES mysql mariadb) +find_library(MARIADB_CONNECTOR_STATIC_LIBRARIES NAMES mysqlclient PATH_SUFFIXES mysql mariadb) set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES}) -if(${MARIADB_CONNECTOR_STATIC_LIB} MATCHES "NOTFOUND") +if(${MARIADB_CONNECTOR_STATIC_LIBRARIES} MATCHES "NOTFOUND") set(MARIADB_CONNECTOR_STATIC_FOUND FALSE CACHE INTERNAL "") message(STATUS "Static MySQL client library not found.") - unset(MARIADB_CONNECTOR_STATIC_LIB) + unset(MARIADB_CONNECTOR_STATIC_LIBRARIES) else() set(MARIADB_CONNECTOR_STATIC_FOUND TRUE CACHE INTERNAL "") - message(STATUS "Found statc MySQL client library: ${MARIADB_CONNECTOR_STATIC_LIB}") + message(STATUS "Found statc MySQL client library: ${MARIADB_CONNECTOR_STATIC_LIBRARIES}") endif() find_path(MARIADB_CONNECTOR_INCLUDE_DIR mysql.h PATH_SUFFIXES mysql mariadb) + +include(CheckSymbolExists) +check_symbol_exists(LIBMARIADB ${MARIADB_CONNECTOR_INCLUDE_DIR}/mysql.h HAVE_MARIADB_CONNECTOR) + +if(HAVE_MARIADB_CONNECTOR) + message(STATUS "Found MariaDB Connector-C") +else() + set(MARIADB_CONNECTOR_FOUND FALSE CACHE INTERNAL "" FORCE) +endif() diff --git a/query_classifier/test/CMakeLists.txt b/query_classifier/test/CMakeLists.txt index 59ec4d7a8..0741f9fba 100644 --- a/query_classifier/test/CMakeLists.txt +++ b/query_classifier/test/CMakeLists.txt @@ -1,5 +1,9 @@ -# Use the client libraries in the tests -include_directories(${MYSQLCLIENT_INCLUDE_DIR}) +# Include the embedded library headers +subdirs(MYSQL_INCLUDE_DIR_ALL ${MYSQL_EMBEDDED_INCLUDE_DIR}) +foreach(DIR ${MYSQL_INCLUDE_DIR_ALL}) + include_directories(${DIR}) +endforeach() +include_directories(${MYSQL_EMMBEDDED_INCLUDE_DIR}/..) if(${ERRMSG} MATCHES "ERRMSG-NOTFOUND") message(FATAL_ERROR "The errmsg.sys file was not found, please define the path with -DERRMSG=") diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 7eae4fdeb..015ffa22c 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(maxscale-common SHARED adminusers.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c maxscale_pcre2.c memlog.c modutil.c monitor.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c ${CMAKE_SOURCE_DIR}/log_manager/log_manager.cc ${CMAKE_SOURCE_DIR}/utils/skygw_utils.cc statistics.c) -target_link_libraries(maxscale-common ${MARIADB_CONNECTOR_LIB} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${CURL_LIBRARIES} ssl aio pthread crypt dl crypto inih z rt m stdc++) +target_link_libraries(maxscale-common ${MARIADB_CONNECTOR_LIBRARIES} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${CURL_LIBRARIES} ssl aio pthread crypt dl crypto inih z rt m stdc++) if(WITH_JEMALLOC) target_link_libraries(maxscale-common ${JEMALLOC_LIBRARIES})