CONCPP-67 Fix of tarball directory structure

Added project, to ensure that example application can be built with
tarball headers and binaries
This commit is contained in:
Lawrin Novitsky
2021-02-10 12:35:52 +01:00
parent 68ee879c70
commit 7983bc2d34
7 changed files with 144 additions and 10 deletions

View File

@ -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
$<TARGET_FILE:libmariadb>
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
$<TARGET_FILE:${CC_PLUGIN}>
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/")

View File

@ -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)

View File

@ -135,6 +135,7 @@ IF(INSTALL_INCLUDEDIR)
ENDIF()
IF(INSTALL_BINDIR)
message(STATUS "-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-")
SET(INSTALL_BINDIR_${INSTALL_LAYOUT} ${INSTALL_BINDIR})
ENDIF()

View File

@ -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)

View File

@ -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 <http://www.gnu.org/licenses>
# 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()

56
install_test/example.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#include <iostream>
#include <memory>
#include <regex>
#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<sql::Connection> con(driver->connect(url, properties));
std::unique_ptr<sql::Statement> stmt(con->createStatement());
std::unique_ptr<sql::ResultSet> 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;
}

View File

@ -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()