diff options
author | Vladislav Vaintroub <wlad@mariadb.com> | 2016-08-19 20:03:05 +0000 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2016-08-25 16:27:57 +0200 |
commit | 56c4cfe0bea0fea8f80692c3df684b204cbfa731 (patch) | |
tree | dc433fb0f163f8d06498b1cc425c6a57298cf060 /libmariadb | |
parent | 31a8cf54c8a7913338480a0571feaf32143b5f64 (diff) | |
download | mariadb-git-56c4cfe0bea0fea8f80692c3df684b204cbfa731.tar.gz |
MDEV-9293 - Use MariaDB's Connector/C in server
Diffstat (limited to 'libmariadb')
-rw-r--r-- | libmariadb/CMakeLists.txt | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt new file mode 100644 index 00000000000..1f6b299d4d8 --- /dev/null +++ b/libmariadb/CMakeLists.txt @@ -0,0 +1,127 @@ +INCLUDE(${CMAKE_SOURCE_DIR}/cmake/mariadb_connector_c.cmake) + +SET(CONNECTOR_C_INSTALLDIR "${CMAKE_CURRENT_BINARY_DIR}/mariadb-connector-c/${CMAKE_CFG_INTDIR}" CACHE STRING "") +SET(CONNECTOR_C_INSTALL_PREFIX ${CONNECTOR_C_INSTALLDIR}) + + +IF(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") + STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${BUILD_TYPE}" CONNECTOR_C_INSTALL_PREFIX "${CONNECTOR_C_INSTALLDIR}") +ENDIF() + +SET(CONNECTOR_C_GIT_TAG "v3.0-cc-server-integ-0" CACHE STRING "Git tag or branch for connector/c") +IF(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/mariadb-connector-c) + # Building from source package + SET(CONNECTOR_C_SOURCE_DIR ${CMAKE_SOURCE_DIR}/mariadb-connector-c) + SET(GIT_PARAMS) +ELSE() + # Building from git, use git to get Connector/C + SET(GIT_PARAMS + GIT_REPOSITORY "https://github.com/MariaDB/mariadb-connector-c/" + GIT_TAG ${CONNECTOR_C_GIT_TAG} + ) + SET(CONNECTOR_C_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/mariadb-connector-c-src) +ENDIF() + +IF(TARGET zlib) + GET_PROPERTY(ZLIB_LIBRARY_LOCATION TARGET zlib PROPERTY LOCATION) +ELSE() + SET(ZLIB_LIBRARY_LOCATION ${ZLIB_LIBRARY}) +ENDIF() + + +INCLUDE(ExternalProject) +ExternalProject_Add( + mariadb_connector_c + ${GIT_PARAMS} + UPDATE_COMMAND "" + PATCH_COMMAND "" + SOURCE_DIR ${CONNECTOR_C_SOURCE_DIR} + INSTALL_DIR ${CONNECTOR_C_INSTALLDIR} + CMAKE_ARGS ${CC_CMAKE_OPTS} + -DCMAKE_INSTALL_PREFIX=${CONNECTOR_C_INSTALL_PREFIX} + -DWITH_EXTERNAL_ZLIB=1 + -DZLIB_FOUND=1 + -DZLIB_LIBRARY=${ZLIB_LIBRARY_LOCATION} + -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR} + -DSKIP_TESTS=1 + -DMARIADB_PORT=${MYSQL_TCP_PORT} + -DMARIADB_UNIX_ADDR=${MYSQL_UNIX_ADDR} + -DSHARED_LIB_MAJOR_VERSION=${SHARED_LIB_MAJOR_VERSION} + -DPLUGINDIR=${INSTALL_PLUGINDIR} + -DFOR_SERVER=1 + TEST_COMMAND "" +) + +IF(TARGET zlib) + ADD_DEPENDENCIES(mariadb_connector_c zlib) +ENDIF() + +SET(STATIC_LIB_LOCATION "${CONNECTOR_C_INSTALLDIR}/lib/mariadb/${CMAKE_STATIC_LIBRARY_PREFIX}mysqlclient${CMAKE_STATIC_LIBRARY_SUFFIX}") + +IF(WIN32) + SET(SHARED_LIB_LOCATION "${CONNECTOR_C_INSTALLDIR}/lib/mariadb/libmysql${CMAKE_SHARED_LIBRARY_SUFFIX}") +ELSE() + SET(SHARED_LIB_LOCATION "${CONNECTOR_C_INSTALLDIR}/lib/mariadb/libmysqlclient${CMAKE_SHARED_LIBRARY_SUFFIX}") +ENDIF() +IF(WIN32) + # On Windows, we need to install import library. We also install PDB for debugging + STRING(REPLACE ".dll" ".lib" IMPORT_LIB_LOCATION ${SHARED_LIB_LOCATION}) + STRING(REPLACE ".dll" ".pdb" PDB_LOCATION ${SHARED_LIB_LOCATION}) +ENDIF() + +ADD_LIBRARY(mariadbclient STATIC IMPORTED GLOBAL) +SET_TARGET_PROPERTIES(mariadbclient PROPERTIES IMPORTED_LOCATION ${STATIC_LIB_LOCATION}) +ADD_DEPENDENCIES(mariadbclient mariadb_connector_c GenError) + +ADD_LIBRARY(libmariadb SHARED IMPORTED GLOBAL) +SET_TARGET_PROPERTIES(libmariadb PROPERTIES IMPORTED_LOCATION ${SHARED_LIB_LOCATION}) +ADD_DEPENDENCIES(libmariadb mariadb_connector_c GenError) + +SET(CONNECTOR_C_LIBS ${STATIC_LIB_LOCATION} ${CC_LIBS} ${ZLIB_LIBRARY} PARENT_SCOPE) + + +# INSTALL Connector/C files + +# For multiconfig generators (Visual Studio and Xcode) +# we need to replace CMAKE_CFG_INTDIR in filepath with CMAKE_INSTALL_CONFIG_NAME +# for cpack. +FUNCTION(GET_INSTALL_LOCATION LOC VARNAME) + SET(val ${LOC}) + IF (NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") + STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${CMAKE_INSTALL_CONFIG_NAME}" val ${val}) + ENDIF() + SET(${VARNAME} ${val} PARENT_SCOPE) +ENDFUNCTION() + +GET_INSTALL_LOCATION(${STATIC_LIB_LOCATION} STATIC_LIB_INSTALL_LOCATION) +INSTALL(FILES ${STATIC_LIB_INSTALL_LOCATION} DESTINATION ${INSTALL_LIBDIR} COMPONENT Development) + +IF(UNIX) + STRING(REPLACE "mysqlclient" "mysqlclient_r" + STATIC_LIB_R_INSTALL_LOCATION "${STATIC_LIB_INSTALL_LOCATION}") + INSTALL(FILES ${STATIC_LIB_R_INSTALL_LOCATION} OPTIONAL DESTINATION ${INSTALL_LIBDIR} COMPONENT Development) +ENDIF() + +# Install shared library +IF(WIN32) + # On Windows, we need to install import library. We also install PDB for debugging + SET(SHARED_LIB_FILES ${SHARED_LIB_LOCATION} ${IMPLIB_LOCATION} ${PDB_LOCATION}) +ELSE() + STRING(REPLACE "mysqlclient" "mysqlclient_r" SHARED_LIB_R_LOCATION ${SHARED_LIB_LOCATION}) + STRING(REPLACE "mysqlclient.so" "mysqlclient.so.${SHARED_LIB_MAJOR_VERSION}" + SHARED_LIB_LINK1_LOCATION ${SHARED_LIB_LOCATION}) + STRING(REPLACE "mysqlclient.so" "mysqlclient.so.${SHARED_LIB_MAJOR_VERSION}.0.0" + SHARED_LIB_LINK2_LOCATION ${SHARED_LIB_LOCATION}) + + SET(SHARED_LIB_FILES ${SHARED_LIB_LOCATION} ${SHARED_LIB_R_LOCATION} + ${SHARED_LIB_LINK1_LOCATION} ${SHARED_LIB_LINK2_LOCATION}) + LIST(REMOVE_DUPLICATES SHARED_LIB_FILES) +ENDIF() + +FOREACH(file ${SHARED_LIB_FILES}) + GET_INSTALL_LOCATION(${file} loc) + IF(loc) + INSTALL(FILES ${loc} DESTINATION ${INSTALL_LIBDIR} COMPONENT SharedLibraries OPTIONAL) + ENDIF() +ENDFOREACH() + |