From 7983bc2d34f49692c33c21edc58a98d2fd05bd28 Mon Sep 17 00:00:00 2001 From: Lawrin Novitsky Date: Wed, 10 Feb 2021 12:35:52 +0100 Subject: [PATCH] CONCPP-67 Fix of tarball directory structure Added project, to ensure that example application can be built with tarball headers and binaries --- CMakeLists.txt | 32 ++++++++++++++++--- cmake/connector_c.cmake | 2 +- cmake/install.cmake | 1 + include/CMakeLists.txt | 14 ++++++--- install_test/CMakeLists.txt.in | 47 ++++++++++++++++++++++++++++ install_test/example.cpp | 56 ++++++++++++++++++++++++++++++++++ wininstall/CMakeLists.txt | 2 +- 7 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 install_test/CMakeLists.txt.in create mode 100644 install_test/example.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b442c01..f55ddef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # ************************************************************************************ -# Copyright (C) 2013,2019 MariaDB Corporation AB +# Copyright (C) 2013,2021 MariaDB Corporation AB # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public @@ -393,9 +393,10 @@ ELSE() MESSAGE(STATUS "Configuring to build without SSL support") ENDIF() -### Setting installation paths - should go before C/C subproject sets its own. We need to have control over those +### Setting installation paths - should go before C/C subproject sets its own. We need to have control over those INCLUDE("${CMAKE_SOURCE_DIR}/cmake/install.cmake") +ADD_CUSTOM_TARGET(DEPENDENCIES_FOR_PACKAGE) ### Including C/C subproject IF(EXISTS ${CMAKE_SOURCE_DIR}/libmariadb) IF(GIT_BUILD_SRCPKG) @@ -407,8 +408,28 @@ IF(EXISTS ${CMAKE_SOURCE_DIR}/libmariadb) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/connector_c.cmake) INSTALL(FILES $ - DESTINATION ./${INSTALL_LIB_SUFFIX}/mariadb - COMPONENT ConCLib) + DESTINATION ./${INSTALL_LIBDIR} + COMPONENT ConCLib) + MESSAGE(STATUS "Configuring to install libmariadb to ${INSTALL_LIBDIR}") + + SET(OWN_PLUGINS_LIST mysql_clear_password dialog client_ed25519 sha256_password caching_sha2_password) + IF (PLUGINS_DYNAMIC) + # The list from CC is visible for us + SET(PLUGINS_LIST ${PLUGINS_DYNAMIC}) + ELSE() + SET(PLUGINS_LIST ${OWN_PLUGINS_LIST}) + ENDIF() + FOREACH(CC_PLUGIN ${PLUGINS_LIST}) + IF(NOT PLUGINS_DYNAMIC OR "${PLUGIN_${CC_PLUGIN}_TYPE}" STREQUAL "MARIADB_CLIENT_PLUGIN_AUTH") + MESSAGE(STATUS "Configuring to install ${CC_PLUGIN} to ${INSTALL_PLUGINDIR}") + ADD_DEPENDENCIES(DEPENDENCIES_FOR_PACKAGE ${CC_PLUGIN}) + INSTALL(FILES + $ + DESTINATION ./${INSTALL_PLUGINDIR} + COMPONENT ConCPlugins) + ENDIF() + ENDFOREACH() +# ADD_DEPENDENCIES(libmariadb DEPENDENCIES_FOR_PACKAGE) ELSE() SET(USE_SYSTEM_INSTALLED_LIB TRUE) MESSAGE(STATUS "There is no Connector/C sub-project folder, linking against libmariadb installed on the system") @@ -464,6 +485,7 @@ ELSE() ENDIF() TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${MARIADB_CLIENT_TARGET_NAME} ${PLATFORM_DEPENDENCIES}) +ADD_DEPENDENCIES(${LIBRARY_NAME} DEPENDENCIES_FOR_PACKAGE) ########## Packaging ########## @@ -527,6 +549,8 @@ ELSE() SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-cpp-${CPACK_PACKAGE_VERSION}-${MACPP_VERSION_QUALITY}-${SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") ENDIF() MESSAGE(STATUS "Package Name: ${CPACK_PACKAGE_FILE_NAME}") +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/install_test/CMakeLists.txt.in + ${CMAKE_SOURCE_DIR}/install_test/CMakeLists.txt @ONLY) SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") SET(CPACK_PACKAGE_API_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/") diff --git a/cmake/connector_c.cmake b/cmake/connector_c.cmake index 4366300..d9d9b06 100644 --- a/cmake/connector_c.cmake +++ b/cmake/connector_c.cmake @@ -42,4 +42,4 @@ SET(PLUGIN_INSTALL_DIR ${INSTALL_PLUGINDIR}) SET(MARIADB_UNIX_ADDR ${MYSQL_UNIX_ADDR}) MESSAGE("== Configuring MariaDB Connector/C") -ADD_SUBDIRECTORY(libmariadb) +ADD_SUBDIRECTORY(libmariadb EXCLUDE_FROM_ALL) diff --git a/cmake/install.cmake b/cmake/install.cmake index db9a1f8..6200b2a 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -135,6 +135,7 @@ IF(INSTALL_INCLUDEDIR) ENDIF() IF(INSTALL_BINDIR) + message(STATUS "-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-") SET(INSTALL_BINDIR_${INSTALL_LAYOUT} ${INSTALL_BINDIR}) ENDIF() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index e7a2b43..c61fb3a 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,4 +1,6 @@ -SET(MARIADBCPP_PUBLIC_API ${CMAKE_SOURCE_DIR}/include/conncpp/Driver.hpp +SET(MARIADBCPP_PUBLIC_API ${CMAKE_SOURCE_DIR}/include/conncpp.hpp) + +SET(MARIADBCPP_PUBLIC_CLASSES ${CMAKE_SOURCE_DIR}/include/conncpp/Driver.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/DriverManager.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/Connection.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/Statement.hpp @@ -14,10 +16,10 @@ SET(MARIADBCPP_PUBLIC_API ${CMAKE_SOURCE_DIR}/include/conncpp/Driver.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/Savepoint.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/Types.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/jdbccompat.hpp - ${CMAKE_SOURCE_DIR}/include/conncpp.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/buildconf.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/CArray.hpp ) + SET(MARIADBCPP_COMPAT_STUBS ${CMAKE_SOURCE_DIR}/include/conncpp/compat/Array.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/compat/Executor.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/compat/Object.hpp @@ -25,15 +27,19 @@ SET(MARIADBCPP_COMPAT_STUBS ${CMAKE_SOURCE_DIR}/include/conncpp/compat/Array.hpp ${CMAKE_SOURCE_DIR}/include/conncpp/compat/Struct.hpp ) IF(WIN32) - SET(WIX_INCLUDES ${MARIADBCPP_PUBLIC_API} {MARIADBCPP_COMPAT_STUBS} PARENT_SCOPE) + SET(WIX_INCLUDES ${MARIADBCPP_PUBLIC_API} MARIADBCPP_PUBLIC_CLASSES {MARIADBCPP_COMPAT_STUBS} PARENT_SCOPE) ENDIF() INSTALL(FILES ${MARIADBCPP_PUBLIC_API} DESTINATION ./${INSTALL_INCLUDEDIR} COMPONENT PublicAPI) +INSTALL(FILES + ${MARIADBCPP_PUBLIC_CLASSES} + DESTINATION ./${INSTALL_INCLUDEDIR}/conncpp + COMPONENT PublicAPI) INSTALL(FILES ${MARIADBCPP_COMPAT_STUBS} - DESTINATION ./${INSTALL_INCLUDEDIR}/compat + DESTINATION ./${INSTALL_INCLUDEDIR}/conncpp/compat COMPONENT PublicAPI) diff --git a/install_test/CMakeLists.txt.in b/install_test/CMakeLists.txt.in new file mode 100644 index 0000000..5cde75a --- /dev/null +++ b/install_test/CMakeLists.txt.in @@ -0,0 +1,47 @@ +# ************************************************************************************ +# Copyright (C) 2021 MariaDB Corporation AB +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not see +# or write to the Free Software Foundation, Inc., +# 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +# *************************************************************************************/ + +cmake_minimum_required(VERSION 3.1) + +PROJECT(mariadbcpp-example + LANGUAGES CXX) +IF(WIN32) + MESSAGE(SEND_ERROR "Not supported on Windows") +ELSE() + SET(CMAKE_CXX_STANDARD 11) + SET(CMAKE_CXX_STANDARD_REQUIRED ON) + + SET(LIBRARY_NAME "libmariadbcpp.so") + + EXECUTE_PROCESS(COMMAND tar zxf @CMAKE_BINARY_DIR@/@CPACK_PACKAGE_FILE_NAME@.tar.gz) + ADD_CUSTOM_TARGET(LIST_CONTENTS + COMMAND ls -lR ${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/@INSTALL_LIB_SUFFIX@/mariadb/*.so* ${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/) + + FILE(GLOB LIBS_IN_PACK + ${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/@INSTALL_LIB_SUFFIX@/mariadb/lib*.so*) + MESSAGE(STATUS "Configuring to search for headers in the ${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/include") + INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/include") + ADD_EXECUTABLE(example example.cpp) + + MESSAGE(STATUS "Configuring to link against libs in the package ${LIBS_IN_PACK}") + FOREACH(PACKEDLIB ${LIBS_IN_PACK}) + TARGET_LINK_LIBRARIES(example ${PACKEDLIB}) + ENDFOREACH() + ADD_DEPENDENCIES(example LIST_CONTENTS) +ENDIF() diff --git a/install_test/example.cpp b/install_test/example.cpp new file mode 100644 index 0000000..0542501 --- /dev/null +++ b/install_test/example.cpp @@ -0,0 +1,56 @@ +/************************************************************************************ + Copyright (C) 2020 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*************************************************************************************/ + +#include +#include +#include + +#include "mariadb/conncpp.hpp" + +int main() +{ + // Instantiate Driver + sql::Driver* driver = sql::mariadb::get_driver_instance(); + + // Configure Connection + sql::SQLString url("jdbc:mariadb://localhost:3306/test"); + sql::Properties properties({ {"user", "root"}, {"password", ""} }); + + // Establish Connection + try { + std::unique_ptr con(driver->connect(url, properties)); + + std::unique_ptr stmt(con->createStatement()); + std::unique_ptr rs(stmt->executeQuery("SELECT 1, 'Hello world'")); + if (rs->next()) { + std::cout << rs->getInt(1) << rs->getString(2) << std::endl; + } + } + catch (sql::SQLSyntaxErrorException & e) { + std::cerr << "[" << e.getSQLState() << "] " << e.what() << "("<< e.getErrorCode() << ")" << std::endl; + } + catch (std::regex_error& e) { + std::cerr << "Regex exception:" << e.what() << std::endl; + } + catch (std::exception& e) { + std::cerr << "Standard exception:" << e.what() << std::endl; + } + + return 0; +} diff --git a/wininstall/CMakeLists.txt b/wininstall/CMakeLists.txt index 6a5a640..34122c9 100644 --- a/wininstall/CMakeLists.txt +++ b/wininstall/CMakeLists.txt @@ -91,6 +91,6 @@ ADD_CUSTOM_TARGET( ADD_DEPENDENCIES(${MSI_PACKAGE} CPP_WIX) ADD_DEPENDENCIES(CPP_WIX ${LIBRARY_NAME}) IF(NOT USE_SYSTEM_INSTALLED_LIB) - ADD_DEPENDENCIES(CPP_WIX ${LIBRARY_NAME} caching_sha2_password auth_gssapi_client sha256_password mysql_clear_password) + ADD_DEPENDENCIES(CPP_WIX ${LIBRARY_NAME} dialog caching_sha2_password auth_gssapi_client sha256_password mysql_clear_password) ENDIF()