2022-08-17 08:43:54 +00:00
# mariadb connector cpp
# On Windows ClangCL can't compile the connector from source but can link to an msvc compiled one,
# so prefer the prebuilt binaries unless MARIADB_BUILD_SOURCE is specified
if ( WIN32 AND NOT MARIADB_BUILD_SOURCE )
2024-12-11 15:18:45 +00:00
set ( MARIADB_MSI_DIR "${CMAKE_BINARY_DIR}/msi" )
set ( MARIADB_CONNECTOR_DIR "${CMAKE_BINARY_DIR}/mariadbcpp" )
2022-08-17 08:43:54 +00:00
set ( MARIADB_C_CONNECTOR_DIR "${MARIADB_CONNECTOR_DIR}/MariaDB/MariaDB Connector C 64-bit" )
set ( MARIADB_CPP_CONNECTOR_DIR "${MARIADB_CONNECTOR_DIR}/MariaDB/MariaDB C++ Connector 64-bit" )
file ( MAKE_DIRECTORY "${MARIADB_MSI_DIR}" )
file ( MAKE_DIRECTORY "${MARIADB_CONNECTOR_DIR}" )
2023-07-24 01:51:13 +00:00
# These values need to be updated whenever a new minor release replaces an old one
# Go to https://mariadb.com/downloads/connectors/ to find the up-to-date URL parts
set ( MARIADB_CONNECTOR_C_VERSION "3.2.7" )
set ( MARIADB_CONNECTOR_C_BUCKET "2319651" )
set ( MARIADB_CONNECTOR_C_MD5 "f8636d733f1d093af9d4f22f3239f885" )
set ( MARIADB_CONNECTOR_CPP_VERSION "1.0.2" )
set ( MARIADB_CONNECTOR_CPP_BUCKET "2531525" )
set ( MARIADB_CONNECTOR_CPP_MD5 "3034bbd6ca00a0125345f9fd1a178401" )
set ( MARIADB_CONNECTOR_C_MSI "mariadb-connector-c-${MARIADB_CONNECTOR_C_VERSION}-win64.msi" )
set ( MARIADB_CONNECTOR_CPP_MSI "mariadb-connector-cpp-${MARIADB_CONNECTOR_CPP_VERSION}-win64.msi" )
if ( NOT EXISTS "${MARIADB_MSI_DIR}/${MARIADB_CONNECTOR_C_MSI}" )
2024-03-06 02:13:24 +00:00
message ( STATUS "Downloading mariadb connector/c" )
2023-07-24 01:51:13 +00:00
file ( DOWNLOAD https://dlm.mariadb.com/ ${ MARIADB_CONNECTOR_C_BUCKET } /Connectors/c/connector-c- ${ MARIADB_CONNECTOR_C_VERSION } / ${ MARIADB_CONNECTOR_C_MSI }
" $ { M A R I A D B _ M S I _ D I R } / $ { M A R I A D B _ C O N N E C T O R _ C _ M S I } "
E X P E C T E D _ H A S H M D 5 = $ { M A R I A D B _ C O N N E C T O R _ C _ M D 5 } )
2022-08-17 08:43:54 +00:00
endif ( )
2023-07-24 01:51:13 +00:00
if ( NOT EXISTS "${MARIADB_MSI_DIR}/${MARIADB_CONNECTOR_CPP_MSI}" )
2024-03-06 02:13:24 +00:00
message ( STATUS "Downloading mariadb connector/c++" )
2023-07-24 01:51:13 +00:00
file ( DOWNLOAD https://dlm.mariadb.com/ ${ MARIADB_CONNECTOR_CPP_BUCKET } /Connectors/cpp/connector-cpp- ${ MARIADB_CONNECTOR_CPP_VERSION } / ${ MARIADB_CONNECTOR_CPP_MSI }
" $ { M A R I A D B _ M S I _ D I R } / $ { M A R I A D B _ C O N N E C T O R _ C P P _ M S I } "
E X P E C T E D _ H A S H M D 5 = $ { M A R I A D B _ C O N N E C T O R _ C P P _ M D 5 } )
2022-08-17 08:43:54 +00:00
endif ( )
file ( TO_NATIVE_PATH "${MARIADB_CONNECTOR_DIR}" MSIEXEC_TARGETDIR )
# extract msi files without installing to users system
if ( NOT EXISTS "${MARIADB_C_CONNECTOR_DIR}" )
2023-07-24 01:51:13 +00:00
file ( TO_NATIVE_PATH "${MARIADB_MSI_DIR}/${MARIADB_CONNECTOR_C_MSI}" MSI_DIR )
2022-08-17 08:43:54 +00:00
execute_process ( COMMAND msiexec /a ${ MSI_DIR } /qn TARGETDIR= ${ MSIEXEC_TARGETDIR } )
endif ( )
2024-03-06 02:13:24 +00:00
set ( MARIADBC_SHARED_LIBRARY_LOCATION "${MARIADB_C_CONNECTOR_DIR}/lib/libmariadb.dll" )
2022-08-17 08:43:54 +00:00
if ( NOT EXISTS "${MARIADB_CPP_CONNECTOR_DIR}" )
2023-07-24 01:51:13 +00:00
file ( TO_NATIVE_PATH "${MARIADB_MSI_DIR}/${MARIADB_CONNECTOR_CPP_MSI}" MSI_DIR )
2022-08-17 08:43:54 +00:00
execute_process ( COMMAND msiexec /a ${ MSI_DIR } /qn TARGETDIR= ${ MSIEXEC_TARGETDIR } )
endif ( )
2024-03-06 02:13:24 +00:00
set ( MARIADBCPP_SHARED_LIBRARY_LOCATION "${MARIADB_CPP_CONNECTOR_DIR}/mariadbcpp.dll" )
2022-08-17 08:43:54 +00:00
set ( MARIADB_IMPLIB_LOCATION "${MARIADB_CPP_CONNECTOR_DIR}/mariadbcpp.lib" )
set ( MARIADB_INCLUDE_DIR "${MARIADB_CPP_CONNECTOR_DIR}/include/mariadb" )
add_custom_target ( mariadb_connector_cpp )
add_custom_command ( TARGET mariadb_connector_cpp POST_BUILD
2022-10-30 20:06:05 +00:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t
2024-03-06 02:13:24 +00:00
" $ { M A R I A D B C P P _ S H A R E D _ L I B R A R Y _ L O C A T I O N } "
" $ { M A R I A D B C _ S H A R E D _ L I B R A R Y _ L O C A T I O N } "
2024-12-11 15:18:45 +00:00
" $ { C M A K E _ B I N A R Y _ D I R } " )
2022-08-17 08:43:54 +00:00
# MariaDB uses plugins that the database needs to load, the prebuilt binaries by default will try to find the libraries in system directories,
# so set this define and the servers will set the MARIADB_PLUGIN_DIR environment variable to the appropriate directory.
# Plugin directory is determined at dll load time (this will happen before main()) so we need to delay the dll load so that we can set the environment variable
2024-03-06 02:13:24 +00:00
add_link_options ( /DELAYLOAD: ${ MARIADBCPP_SHARED_LIBRARY_LOCATION } )
2022-08-17 08:43:54 +00:00
add_compile_definitions ( MARIADB_PLUGIN_DIR_OVERRIDE= "${MARIADB_CPP_CONNECTOR_DIR}/plugin" )
else ( ) # Build from source
include ( ExternalProject )
if ( WIN32 )
set ( MARIADB_EXTRA_CMAKE_ARGS
- D C M A K E _ C _ F L A G S = / w # disable zlib warnings
- D C M A K E _ C X X _ F L A G S = / E H s c
- D W I T H _ M S I = O F F )
elseif ( APPLE )
set ( MARIADB_EXTRA_CMAKE_ARGS
- D W I T H _ E X T E R N A L _ Z L I B = O N
- D O P E N S S L _ R O O T _ D I R = $ { O P E N S S L _ R O O T _ D I R }
- D C M A K E _ C _ F L A G S = - w # disable zlib warnings
- D C M A K E _ C X X _ F L A G S = - D _ G L I B C X X _ U S E _ C X X 1 1 _ A B I = 0 )
else ( )
set ( MARIADB_EXTRA_CMAKE_ARGS
- D C M A K E _ C _ F L A G S = - w # disable zlib warnings
- D C M A K E _ C X X _ F L A G S = - D _ G L I B C X X _ U S E _ C X X 1 1 _ A B I = 0 )
endif ( )
2024-12-11 15:18:45 +00:00
set ( MARIADBCPP_INSTALL_DIR ${ CMAKE_BINARY_DIR } /prefix )
set ( MARIADBCPP_LIBRARY_DIR ${ CMAKE_BINARY_DIR } /mariadbcpp )
2024-03-06 02:13:24 +00:00
set ( MARIADBCPP_PLUGIN_DIR ${ MARIADBCPP_LIBRARY_DIR } /plugin )
set ( MARIADBCPP_SOURCE_DIR ${ PROJECT_SOURCE_DIR } /thirdparty/mariadb-connector-cpp )
set ( MARIADB_INCLUDE_DIR "${MARIADBCPP_SOURCE_DIR}/include" )
2022-08-17 08:43:54 +00:00
ExternalProject_Add ( mariadb_connector_cpp
2024-12-11 15:18:45 +00:00
P R E F I X " $ { C M A K E _ B I N A R Y _ D I R } / t h i r d p a r t y / m a r i a d b - c o n n e c t o r - c p p "
2024-03-06 02:13:24 +00:00
S O U R C E _ D I R $ { M A R I A D B C P P _ S O U R C E _ D I R }
I N S T A L L _ D I R $ { M A R I A D B C P P _ I N S T A L L _ D I R }
C M A K E _ A R G S - W n o - d e v
- D W I T H _ U N I T _ T E S T S = O F F
- D M A R I A D B _ L I N K _ D Y N A M I C = O F F
- D C M A K E _ B U I L D _ R P A T H _ U S E _ O R I G I N = $ { C M A K E _ B U I L D _ R P A T H _ U S E _ O R I G I N }
- D C M A K E _ I N S T A L L _ P R E F I X = < I N S T A L L _ D I R >
- D I N S T A L L _ L I B D I R = $ { M A R I A D B C P P _ L I B R A R Y _ D I R }
- D I N S T A L L _ P L U G I N D I R = $ { M A R I A D B C P P _ P L U G I N _ D I R }
$ { M A R I A D B _ E X T R A _ C M A K E _ A R G S }
B U I L D _ A L W A Y S t r u e
)
2022-08-17 08:43:54 +00:00
if ( WIN32 )
set ( MARIADB_SHARED_LIBRARY_NAME mariadbcpp.dll )
set ( MARIADB_PLUGIN_SUFFIX .dll )
2024-03-06 02:13:24 +00:00
set ( MARIADB_IMPLIB_LOCATION "${MARIADBCPP_LIBRARY_DIR}/mariadbcpp.lib" )
2022-08-17 08:43:54 +00:00
# When built from source windows only seems to check same folder as exe instead specified folder, so use
# environment variable to force it
add_link_options ( /DELAYLOAD:mariadbcpp.dll )
2024-03-06 02:13:24 +00:00
add_compile_definitions ( MARIADB_PLUGIN_DIR_OVERRIDE= "${MARIADBCPP_PLUGIN_DIR}" )
2022-08-17 08:43:54 +00:00
else ( )
set ( MARIADB_SHARED_LIBRARY_NAME libmariadbcpp ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
2024-03-06 02:13:24 +00:00
set ( MARIADB_PLUGIN_SUFFIX ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
2022-08-17 08:43:54 +00:00
endif ( )
2024-03-06 02:13:24 +00:00
set ( MARIADBCPP_SHARED_LIBRARY_LOCATION "${MARIADBCPP_LIBRARY_DIR}/${MARIADB_SHARED_LIBRARY_NAME}" )
if ( WIN32 )
set ( MARIADBC_SHARED_LIBRARY_LOCATION "${MARIADBCPP_LIBRARY_DIR}/libmariadb.lib" )
2022-08-17 08:43:54 +00:00
endif ( )
endif ( )
# Create mariadb connector library object
2024-12-11 15:18:45 +00:00
add_library ( mariadb_cpp_connector SHARED IMPORTED GLOBAL )
add_dependencies ( mariadb_cpp_connector mariadb_connector_cpp )
set_target_properties ( mariadb_cpp_connector PROPERTIES
2024-03-06 02:13:24 +00:00
I M P O R T E D _ L O C A T I O N " $ { M A R I A D B C P P _ S H A R E D _ L I B R A R Y _ L O C A T I O N } " )
2022-08-17 08:43:54 +00:00
if ( WIN32 )
2024-12-11 15:18:45 +00:00
set_target_properties ( mariadb_cpp_connector PROPERTIES
2024-03-06 02:13:24 +00:00
I M P O R T E D _ I M P L I B " $ { M A R I A D B _ I M P L I B _ L O C A T I O N } " )
elseif ( APPLE )
2024-12-11 15:18:45 +00:00
set_target_properties ( mariadb_cpp_connector PROPERTIES
2024-03-06 02:13:24 +00:00
I M P O R T E D _ S O N A M E " l i b m a r i a d b c p p " )
2022-08-17 08:43:54 +00:00
endif ( )
# Add directories to include lists
2024-12-11 15:18:45 +00:00
target_include_directories ( mariadb_cpp_connector SYSTEM INTERFACE ${ MARIADB_INCLUDE_DIR } )
2024-03-06 02:13:24 +00:00
2024-12-11 15:18:45 +00:00
set ( mariadb_found TRUE )