0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Add Connector CMake Logic (#394)

Add Connector Cmake logic

* Also install date when used with fetch content
* Install everything always
* Update documentation
* Add option to control dependency searching
* Adjust travis
This commit is contained in:
Leon De Andrade 2021-12-02 07:45:38 +01:00 committed by GitHub
parent 2fecf6b6f1
commit d17bce9644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 307 additions and 179 deletions

View File

@ -34,11 +34,8 @@ before_script:
- mysql --version - mysql --version
- (while ! mysqladmin -u root status ; do sleep 1; done) # wait for mysql to start - (while ! mysqladmin -u root status ; do sleep 1; done) # wait for mysql to start
- mysqladmin -u root create sqlpp_mysql - mysqladmin -u root create sqlpp_mysql
- mkdir build
- cd build
- if [[ "$CXX" = "g++" && "$CONFIG" = "Debug" && "$TRAVIS_OS_NAME" = "linux" ]]; then export CXXFLAGS="--coverage"; fi - if [[ "$CXX" = "g++" && "$CONFIG" = "Debug" && "$TRAVIS_OS_NAME" = "linux" ]]; then export CXXFLAGS="--coverage"; fi
- ls .. - cmake -B build -DCMAKE_BUILD_TYPE=$CONFIG -DBUILD_MYSQL_CONNECTOR=ON -DBUILD_SQLITE3_CONNECTOR=ON
- cmake .. -DCMAKE_BUILD_TYPE=$CONFIG -DMYSQL_CONNECTOR=ON -DSQLITE3_CONNECTOR=ON
script: script:
- cmake --build . --config $CONFIG - cmake --build . --config $CONFIG

View File

@ -30,134 +30,122 @@ project(sqlpp11 VERSION 0.1 LANGUAGES CXX)
### Project Wide Setup ### Project Wide Setup
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
option(MARIADB_CONNECTOR "Build MariaDB Connector" OFF) include(GNUInstallDirs)
option(MYSQL_CONNECTOR "Build MySQL Connector" OFF)
option(POSTGRESQL_CONNECTOR "Build PostgreSQL Connector" OFF)
option(SQLITE3_CONNECTOR "Build SQLite3 Connector" OFF)
option(SQLCIPHER_CONNECTOR "Build SQLite3 Connector with SQLCipher" OFF)
if(MYSQL_CONNECTOR)
find_package(MySQL REQUIRED)
else()
message(STATUS "Not building tests for MYSQL_CONNECTOR")
endif()
if(MARIADB_CONNECTOR)
find_package(MariaDB REQUIRED)
else()
message(STATUS "Not building tests for MARIAB_CONNECTOR")
endif()
if(POSTGRESQL_CONNECTOR)
find_package(PostgreSQL REQUIRED)
else()
message(STATUS "Not building tests for POSTGRESQL_CONNECTOR")
endif()
if(SQLITE3_CONNECTOR)
find_package(SQLite3 REQUIRED)
else()
message(STATUS "Not building tests for SQLITE3_CONNECTOR")
endif()
if(SQLCIPHER_CONNECTOR)
find_package(SQLCipher REQUIRED)
else()
message(STATUS "Not building tests for SQLCIPHER_CONNECTOR")
endif()
include(CTest) include(CTest)
option(BUILD_MYSQL_CONNECTOR "Build MySQL Connector" OFF)
option(BUILD_MARIADB_CONNECTOR "Build MariaDB Connector" OFF)
option(BUILD_POSTGRESQL_CONNECTOR "Build PostgreSQL Connector" OFF)
option(BUILD_SQLITE3_CONNECTOR "Build SQLite3 Connector" OFF)
option(BUILD_SQLCIPHER_CONNECTOR "Build SQLite3 Connector with SQLCipher" OFF)
option(DEPENDENCY_CHECK "Check for dependencies of connector and the library" ON)
option(USE_SYSTEM_DATE "\ option(USE_SYSTEM_DATE "\
Use find_package to find installed HowardHinnant's \ Use find_package to find installed HowardHinnant's \
date library instead of fetching it from github" OFF date library instead of fetching it from github" OFF
) )
if(USE_SYSTEM_DATE) set(SQLPP11_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Sqlpp11 CACHE STRING "Path to sqlpp11 cmake files")
### Dependencies
if(DEPENDENCY_CHECK AND BUILD_MYSQL_CONNECTOR)
find_package(MySQL REQUIRED)
endif()
if(DEPENDENCY_CHECK AND BUILD_MARIADB_CONNECTOR)
find_package(MariaDB REQUIRED)
endif()
if(DEPENDENCY_CHECK AND BUILD_POSTGRESQL_CONNECTOR)
find_package(PostgreSQL REQUIRED)
endif()
if(DEPENDENCY_CHECK AND BUILD_SQLITE3_CONNECTOR)
find_package(SQLite3 REQUIRED)
endif()
if(DEPENDENCY_CHECK AND BUILD_SQLCIPHER_CONNECTOR)
find_package(SQLCipher REQUIRED)
endif()
if(DEPENDENCY_CHECK AND USE_SYSTEM_DATE)
find_package(date REQUIRED) find_package(date REQUIRED)
endif() endif()
### Dependencies
add_subdirectory(dependencies) add_subdirectory(dependencies)
### Core targets ### Core targets
include(Sqlpp11TargetHelper)
add_library(sqlpp11 INTERFACE) add_library(sqlpp11 INTERFACE)
add_library(sqlpp11::sqlpp11 ALIAS sqlpp11) add_library(sqlpp11::sqlpp11 ALIAS sqlpp11)
target_link_libraries(sqlpp11 INTERFACE date::date) target_link_libraries(sqlpp11 INTERFACE date::date)
target_include_directories(sqlpp11 INTERFACE target_include_directories(sqlpp11 INTERFACE
$<BUILD_INTERFACE:${sqlpp11_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> )
) target_compile_features(sqlpp11 INTERFACE cxx_std_11)
target_compile_features(sqlpp11 INTERFACE
cxx_alias_templates if(BUILD_SQLITE3_CONNECTOR)
cxx_auto_type add_component(NAME sqlite3 DEPENDENCIES SQLite::SQLite3)
cxx_constexpr endif()
cxx_decltype
cxx_defaulted_functions if(BUILD_SQLCIPHER_CONNECTOR)
cxx_defaulted_move_initializers add_component(NAME sqlcipher DEPENDENCIES SQLite::SQLCipher)
cxx_deleted_functions target_compile_definitions(sqlpp11_sqlcipher INTERFACE SQLPP_USE_SQLCIPHER)
cxx_explicit_conversions endif()
cxx_lambdas
cxx_noexcept if(BUILD_MYSQL_CONNECTOR)
cxx_nullptr add_component(NAME mysql DEPENDENCIES MySQL::MySQL)
cxx_range_for endif()
cxx_right_angle_brackets
cxx_rvalue_references if(BUILD_MARIADB_CONNECTOR)
cxx_static_assert add_component(NAME mariadb DEPENDENCIES MariaDB::MariaDB)
cxx_trailing_return_types endif()
cxx_uniform_initialization
cxx_template_template_parameters if(BUILD_POSTGRESQL_CONNECTOR)
cxx_variadic_templates add_component(NAME postgresql DEPENDENCIES PostgreSQL::PostgreSQL)
) endif()
### Packaging ### Packaging
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/sqlpp11" install(PROGRAMS ${PROJECT_SOURCE_DIR}/scripts/ddl2cpp
DESTINATION include
)
install(TARGETS sqlpp11
EXPORT Sqlpp11Targets
)
install(PROGRAMS "${PROJECT_SOURCE_DIR}/scripts/ddl2cpp"
RENAME sqlpp11-ddl2cpp RENAME sqlpp11-ddl2cpp
DESTINATION bin DESTINATION ${CMAKE_INSTALL_BINDIR}
) )
include(CMakePackageConfigHelpers) write_basic_package_version_file(Sqlpp11ConfigVersion.cmake
COMPATIBILITY SameMajorVersion
write_basic_package_version_file( ARCH_INDEPENDENT
"${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
) )
export(EXPORT Sqlpp11Targets install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Sqlpp11ConfigVersion.cmake
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11Targets.cmake" DESTINATION ${SQLPP11_INSTALL_CMAKEDIR}
) )
configure_file(cmake/Sqlpp11Config.cmake install_component(NAME Sqlpp11 TARGETS sqlpp11 DIRECTORY)
"${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11Config.cmake"
COPYONLY
)
set(ConfigPackageLocation lib/cmake/Sqlpp11) if(BUILD_SQLITE3_CONNECTOR)
install(EXPORT Sqlpp11Targets install_component(NAME Sqlpp11SQLite3 TARGETS sqlpp11_sqlite3 DIRECTORY sqlite3)
NAMESPACE sqlpp11:: endif()
DESTINATION
${ConfigPackageLocation} if(BUILD_SQLCIPHER_CONNECTOR)
) install_component(NAME Sqlpp11SQLCipher TARGETS sqlpp11_sqlcipher DIRECTORY sqlite3)
endif()
if(BUILD_MYSQL_CONNECTOR)
install_component(NAME Sqlpp11MySQL TARGETS sqlpp11_mysql DIRECTORY mysql)
endif()
if(BUILD_MARIADB_CONNECTOR)
install_component(NAME Sqlpp11MariaDB TARGETS sqlpp11_mariadb DIRECTORY mysql)
endif()
if(BUILD_POSTGRESQL_CONNECTOR)
install_component(NAME Sqlpp11PostgreSQL TARGETS sqlpp11_postgresql DIRECTORY postgresql)
endif()
install(
FILES
"cmake/Sqlpp11Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11ConfigVersion.cmake"
DESTINATION
${ConfigPackageLocation}
)
### Tests ### Tests
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)

View File

@ -22,7 +22,7 @@ This results in several benefits, e.g.
The library supports both static and dynamic queries. The former offers greater benefit in terms of type and consistency checking. The latter makes it easier to construct queries in flight. The library supports both static and dynamic queries. The former offers greater benefit in terms of type and consistency checking. The latter makes it easier to construct queries in flight.
sqlpp11's core is vendor-neutral. sqlpp11s core is vendor-neutral.
Specific traits of databases (e.g. unsupported or non-standard features) are handled by connector libraries. Specific traits of databases (e.g. unsupported or non-standard features) are handled by connector libraries.
Connector libraries can inform the developer of missing features at compile time. Connector libraries can inform the developer of missing features at compile time.
They also interpret expressions specifically where needed. They also interpret expressions specifically where needed.
@ -129,22 +129,20 @@ sqlpp11 makes heavy use of C++11 and requires a recent compiler and STL. The fol
__Database Connector:__ __Database Connector:__
sqlpp11 requires a certain api in order to connect with the database, see database/api.h. sqlpp11 requires a certain api in order to connect with the database, see database/api.h.
Connectors for MySQL, MariaDB, sqlite3, sqlcipher are included in this repository. You can configure to use them via cmake options, i.e. This repository includes the following connectors:
``` * MySQL
-DMYSQL_CONNECTOR=ON * MariaDB
-DMARIADB_CONNECTOR=ON * SQLite3
-DSQLITE3_CONNECTOR=ON * SQLCipher
-DSQLCIPHER_CONNECTOR=ON * PostgreSQL
```
Other connectors can be found here: Other connectors can be found here:
* PostgreSQL: https://github.com/matthijs/sqlpp11-connector-postgresql
* ODBC: https://github.com/Erroneous1/sqlpp11-connector-odbc (experimental) * ODBC: https://github.com/Erroneous1/sqlpp11-connector-odbc (experimental)
__Date Library:__ __Date Library:__
sqlpp11 requires [Howard Hinnant's date library](https://github.com/HowardHinnant/date) for `date` and `date_time` data types. By default, sqlpp11 uses FetchContent to pull the library automatically in the project. If you want to use an already installed version of the library with `find_package`, set `USE_SYSTEM_DATE` option to `ON`. sqlpp11 requires [Howard Hinnants date library](https://github.com/HowardHinnant/date) for `date` and `date_time` data types. By default, sqlpp11 uses FetchContent to pull the library automatically in the project. If you want to use an already installed version of the library with `find_package`, set `USE_SYSTEM_DATE` option to `ON`.
Build and Install Build and Install
----------------- -----------------
@ -160,7 +158,24 @@ cmake -B build
cmake --build build --target install cmake --build build --target install
``` ```
The last step will build the library and install it system wide, therefore it might need admins right. The last step will build the library and install it system wide, therefore it might need admins rights.
By default only the core library will be installed. To also install connectors set the appropriate variable to `ON`:
* `BUILD_MYSQL_CONNECTOR`
* `BUILD_MARIADB_CONNECTOR`
* `BUILD_POSTGRESQL_CONNECTOR`
* `BUILD_SQLITE3_CONNECTOR`
* `BUILD_SQLCIPHER_CONNECTOR`
The library will check if all required dependencies are installed on the system. If connectors should be installed even if the dependencies are not yet available on the system, set `DEPENDENCY_CHECK` to `OFF`.
Example: Install the core library, sqlite3 connector and postgresql connector. Dont check if the dependencies such as Sqlite3 are installed and dont build any tests:
```bash
cmake -B build -DBUILD_POSTGRESQL_CONNECTOR=ON -DBUILD_SQLITE3_CONNECTOR=ON -DDEPENDENCY_CHECK=OFF -DBUILD_TESTING=OFF
cmake --build build --target install
```
__Install via Homebrew (MacOS):__ __Install via Homebrew (MacOS):__
@ -193,10 +208,20 @@ Basic usage:
------------- -------------
__Use with cmake__: __Use with cmake__:
The library officially supports two ways how it can be used with cmake. The library officially supports two ways how it can be used with cmake.
You can find examples for both methods in the example folder. You can find examples for both methods in the examples folder.
1. Fetch content (Recommend, no installation required) 1. FetchContent (Recommended, no installation required)
1. Find package (installation required, see above) 1. FindPackage (installation required, see above)
Both methods will provide the `sqlpp11::sqlpp11` target as well as targets for each connector:
* sqlpp11::mysql
* sqlpp11::mariadb
* sqlpp11::sqlite3
* sqlpp11::sqlcipher
* sqlpp11::postgresql
These targets will make sure all required dependencies are available and correctly linked and include directories are set correctly.
__Create DDL files__: __Create DDL files__:
``` ```
@ -208,9 +233,9 @@ Create headers for them with provided Python script:
``` ```
%sqlpp11_dir%/scripts/ddl2cpp ~/temp/MyTable.ddl ~/temp/MyTable %DatabaseNamespaceForExample% %sqlpp11_dir%/scripts/ddl2cpp ~/temp/MyTable.ddl ~/temp/MyTable %DatabaseNamespaceForExample%
``` ```
(In case you're getting notes about unsupported column type take a look at the other datatypes in sqlpp11/data_types. They are not hard to implement.) (In case youre getting notes about unsupported column type take a look at the other datatypes in sqlpp11/data_types. They are not hard to implement.)
Include generated header (MyTable.h), that's all. Include generated header (MyTable.h), thats all.
If you prefer Ruby over Python, you might want to take a look at https://github.com/douyw/sqlpp11gen If you prefer Ruby over Python, you might want to take a look at https://github.com/douyw/sqlpp11gen

View File

@ -0,0 +1,65 @@
# Copyright (c) 2021, Leon De Andrade
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
function(add_component)
set(options)
set(oneValueArgs NAME)
set(multiValueArgs DEPENDENCIES)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_library(sqlpp11_${ARG_NAME} INTERFACE)
add_library(sqlpp11::${ARG_NAME} ALIAS sqlpp11_${ARG_NAME})
set_target_properties(sqlpp11_${ARG_NAME} PROPERTIES EXPORT_NAME ${ARG_NAME})
target_link_libraries(sqlpp11_${ARG_NAME} INTERFACE sqlpp11 ${ARG_DEPENDENCIES})
endfunction()
function(install_component)
set(options)
set(oneValueArgs NAME DIRECTORY)
set(multiValueArgs TARGETS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
install(FILES ${PROJECT_SOURCE_DIR}/cmake/configs/${ARG_NAME}Config.cmake
DESTINATION ${SQLPP11_INSTALL_CMAKEDIR}
)
install(TARGETS ${ARG_TARGETS}
EXPORT Sqlpp11Targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT Sqlpp11Targets
DESTINATION ${SQLPP11_INSTALL_CMAKEDIR}
NAMESPACE sqlpp11::
)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/sqlpp11/${ARG_DIRECTORY}
DESTINATION include/sqlpp11
FILES_MATCHING
PATTERN *.h
)
endfunction()

View File

@ -23,12 +23,31 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
include(CMakeFindDependencyMacro) include(CMakeFindDependencyMacro)
find_dependency(Threads)
find_dependency(date REQUIRED) find_dependency(date REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/Sqlpp11Targets.cmake") # Work out the set of components to load
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
set(${CMAKE_FIND_PACKAGE_NAME}_comps ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS})
endif()
# Check all required components are available before trying to load any
foreach(comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_comps)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${comp} AND NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/Sqlpp11${comp}Config.cmake)
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "Sqlpp11 missing required component: ${comp}")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
return()
endif()
endforeach()
# Add the target file
include(${CMAKE_CURRENT_LIST_DIR}/Sqlpp11Targets.cmake)
# Load any optional components
foreach(comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_comps)
include(${CMAKE_CURRENT_LIST_DIR}/Sqlpp11${comp}Config.cmake OPTIONAL)
endforeach()
# Import "ddl2cpp" script # Import "ddl2cpp" script
if(NOT TARGET sqlpp11::ddl2cpp) if(NOT TARGET sqlpp11::ddl2cpp)

View File

@ -0,0 +1,2 @@
include(CMakeFindDependencyMacro)
find_dependency(MariaDB)

View File

@ -0,0 +1,2 @@
include(CMakeFindDependencyMacro)
find_dependency(MySQL)

View File

@ -0,0 +1,2 @@
include(CMakeFindDependencyMacro)
find_dependency(PostgreSQL)

View File

@ -0,0 +1,2 @@
include(CMakeFindDependencyMacro)
find_dependency(SQLCipher)

View File

@ -0,0 +1,2 @@
include(CMakeFindDependencyMacro)
find_dependency(SQLite3)

View File

@ -21,5 +21,8 @@
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
FetchContent_MakeAvailable(date) FetchContent_MakeAvailable(date)
# Make date a system library (no warnings for date headers when compiling)
get_property(date_include_dirs TARGET date PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
set_property(TARGET date PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${date_include_dirs}")

View File

@ -22,5 +22,13 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Configure before sqlpp11 # Configure the project here as needed
# set(BUILD_MYSQL_CONNECTOR ON)
# set(BUILD_MARIADB_CONNECTOR ON)
# set(BUILD_POSTGRESQL_CONNECTOR ON)
# set(BUILD_SQLITE3_CONNECTOR ON)
# set(BUILD_SQLCIPHER_CONNECTOR ON)
# set(USE_SYSTEM_DATE ON)
FetchContent_MakeAvailable(sqlpp11) FetchContent_MakeAvailable(sqlpp11)

View File

@ -23,7 +23,16 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
add_executable(Test) add_executable(Test)
target_link_libraries(Test PRIVATE sqlpp11::sqlpp11) target_link_libraries(Test
PRIVATE
sqlpp11::sqlpp11
# Corresponding targets for the connectors. These connectors need to be enabled in the the dependencies/sqlpp11 folder. These targets automatically link against sqlpp11::sqlpp11 and therefore sqlpp11::sqlpp11 doesn't need to be linked manually again
# sqlpp11::sqlite3
# sqlpp11::sqlcipher
# sqlpp11::mysql
# sqlpp11::mariadb
# sqlpp11::postgresql
)
target_sources(Test target_sources(Test
PRIVATE PRIVATE

View File

@ -32,7 +32,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
### Dependencies ### ### Dependencies ###
find_package(Sqlpp11 REQUIRED) find_package(Sqlpp11
# Optionally specify connectors needed to get corresponding targets. Only possible if connectors have been installed on the system as documented in the README
# COMPONENTS SQLite3 SQLCipher MySQL MariaDB PostgreSQL
REQUIRED
)
### Main Targets ### ### Main Targets ###
add_subdirectory(src) add_subdirectory(src)

View File

@ -23,8 +23,16 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
add_executable(Test) add_executable(Test)
target_link_libraries(Test PRIVATE sqlpp11::sqlpp11) target_link_libraries(Test
PRIVATE
sqlpp11::sqlpp11
# Corresponding targets for the Components specified in the find_package call
# sqlpp11::sqlite3
# sqlpp11::sqlcipher
# sqlpp11::mysql
# sqlpp11::mariadb
# sqlpp11::postgresql
)
target_sources(Test target_sources(Test
PRIVATE PRIVATE
main.cpp main.cpp

View File

@ -23,15 +23,15 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
add_subdirectory(core/) add_subdirectory(core/)
if(MYSQL_CONNECTOR) if(BUILD_MYSQL_CONNECTOR)
add_subdirectory(mysql) add_subdirectory(mysql)
endif() endif()
if(POSTGRESQL_CONNECTOR) if(BUILD_POSTGRESQL_CONNECTOR)
add_subdirectory(postgresql) add_subdirectory(postgresql)
endif() endif()
if(SQLITE3_CONNECTOR OR SQLCIPHER_CONNECTOR) if(BUILD_SQLITE3_CONNECTOR OR BUILD_SQLCIPHER_CONNECTOR)
add_subdirectory(sqlite3) add_subdirectory(sqlite3)
endif() endif()

View File

@ -26,7 +26,7 @@ function(test_constraint name pattern)
set(test sqlpp11.core.constraints.${name}) set(test sqlpp11.core.constraints.${name})
set(target sqlpp11_${name}) set(target sqlpp11_${name})
add_executable(${target} EXCLUDE_FROM_ALL ${name}.cpp) add_executable(${target} EXCLUDE_FROM_ALL ${name}.cpp)
target_link_libraries(${target} PRIVATE sqlpp11 sqlpp11_testing) target_link_libraries(${target} PRIVATE sqlpp11::sqlpp11 sqlpp11_testing)
add_test(NAME ${test} add_test(NAME ${test}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${target} COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${target}
) )

View File

@ -40,7 +40,7 @@ set(test_names
create_test_sourcelist(test_sources test_serializer_main.cpp ${test_names}) create_test_sourcelist(test_sources test_serializer_main.cpp ${test_names})
add_executable(sqlpp11_core_serialize ${test_sources}) add_executable(sqlpp11_core_serialize ${test_sources})
target_link_libraries(sqlpp11_core_serialize PRIVATE sqlpp11 sqlpp11_testing) target_link_libraries(sqlpp11_core_serialize PRIVATE sqlpp11::sqlpp11 sqlpp11_testing)
# conditionally bump to a higher C++ standard to test compatibility # conditionally bump to a higher C++ standard to test compatibility
if (SQLPP11_TESTS_CXX_STD) if (SQLPP11_TESTS_CXX_STD)

View File

@ -25,7 +25,7 @@
function(test_compile name) function(test_compile name)
set(target sqlpp11_assert_${name}) set(target sqlpp11_assert_${name})
add_executable(${target} ${name}.cpp) add_executable(${target} ${name}.cpp)
target_link_libraries(${target} PRIVATE sqlpp11 sqlpp11_testing) target_link_libraries(${target} PRIVATE sqlpp11::sqlpp11 sqlpp11_testing)
# conditionally bump to a higher C++ standard to test compatibility # conditionally bump to a higher C++ standard to test compatibility
if (SQLPP11_TESTS_CXX_STD) if (SQLPP11_TESTS_CXX_STD)
set_property(TARGET sqlpp11_assert_${name} PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) set_property(TARGET sqlpp11_assert_${name} PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD})

View File

@ -25,7 +25,7 @@
function(test_compile name) function(test_compile name)
set(target sqlpp11_${name}) set(target sqlpp11_${name})
add_executable(${target} ${name}.cpp) add_executable(${target} ${name}.cpp)
target_link_libraries(${target} PRIVATE sqlpp11 sqlpp11_testing) target_link_libraries(${target} PRIVATE sqlpp11::sqlpp11 sqlpp11_testing)
# conditionally bump to a higher C++ standard to test compatibility # conditionally bump to a higher C++ standard to test compatibility
if (SQLPP11_TESTS_CXX_STD) if (SQLPP11_TESTS_CXX_STD)
set_property(TARGET sqlpp11_${name} PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) set_property(TARGET sqlpp11_${name} PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD})

View File

@ -26,7 +26,7 @@ add_library(sqlpp11_testing INTERFACE)
target_include_directories(sqlpp11_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(sqlpp11_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
if (NOT MSVC) if (NOT MSVC)
target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic) target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic)
endif () endif ()
set(test_names set(test_names
@ -56,7 +56,7 @@ endif()
create_test_sourcelist(test_sources test_main.cpp ${test_names}) create_test_sourcelist(test_sources test_main.cpp ${test_names})
add_executable(sqlpp11_core_tests ${test_sources}) add_executable(sqlpp11_core_tests ${test_sources})
target_link_libraries(sqlpp11_core_tests PRIVATE sqlpp11 sqlpp11_testing) target_link_libraries(sqlpp11_core_tests PRIVATE sqlpp11::sqlpp11 sqlpp11_testing)
# conditionally bump to a higher C++ standard to test compatibility # conditionally bump to a higher C++ standard to test compatibility
if (SQLPP11_TESTS_CXX_STD) if (SQLPP11_TESTS_CXX_STD)
set_property(TARGET sqlpp11_core_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) set_property(TARGET sqlpp11_core_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD})

View File

@ -28,35 +28,32 @@ add_library(sqlpp11_mysql_testing INTERFACE)
target_include_directories(sqlpp11_mysql_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(sqlpp11_mysql_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
set(test_names set(test_names
Json Json
CustomQuery CustomQuery
DateTime DateTime
Sample Sample
Select Select
Union Union
DynamicSelect DynamicSelect
MoveConstructor MoveConstructor
Prepared Prepared
Truncated Truncated
Update Update
Remove Remove
) )
create_test_sourcelist(test_sources test_main.cpp ${test_names}) create_test_sourcelist(test_sources test_main.cpp ${test_names})
add_executable(sqlpp11_mysql_tests ${test_sources}) add_executable(sqlpp11_mysql_tests ${test_sources})
target_link_libraries(sqlpp11_mysql_tests PRIVATE sqlpp11 sqlpp11_testing sqlpp11_mysql_testing) target_link_libraries(sqlpp11_mysql_tests PRIVATE sqlpp11::mysql sqlpp11_testing sqlpp11_mysql_testing)
target_link_libraries(sqlpp11_mysql_tests PRIVATE sqlpp11::sqlpp11)
target_link_libraries(sqlpp11_mysql_tests PRIVATE Threads::Threads) target_link_libraries(sqlpp11_mysql_tests PRIVATE Threads::Threads)
target_link_libraries(sqlpp11_mysql_tests PRIVATE MySQL::MySQL)
target_link_libraries(sqlpp11_mysql_tests PRIVATE date::date)
if(NOT MSVC) if(NOT MSVC)
target_compile_options(sqlpp11_mysql_tests PRIVATE -Wall -Wextra -pedantic) target_compile_options(sqlpp11_mysql_tests PRIVATE -Wall -Wextra -pedantic)
endif() endif()
# conditionally bump to a higher C++ standard to test compatibility # conditionally bump to a higher C++ standard to test compatibility
if (SQLPP11_TESTS_CXX_STD) if (SQLPP11_TESTS_CXX_STD)
set_property(TARGET sqlpp11_mysql_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) set_property(TARGET sqlpp11_mysql_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD})
set_property(TARGET sqlpp11_mysql_tests PROPERTY CXX_STANDARD_REQUIRED yes) set_property(TARGET sqlpp11_mysql_tests PROPERTY CXX_STANDARD_REQUIRED yes)
set_property(TARGET sqlpp11_mysql_tests PROPERTY CXX_EXTENSIONS no) set_property(TARGET sqlpp11_mysql_tests PROPERTY CXX_EXTENSIONS no)
endif() endif()

View File

@ -26,8 +26,7 @@ function(test_constraint name pattern)
set(test sqlpp11.postgresql.constraints.${name}) set(test sqlpp11.postgresql.constraints.${name})
set(target sqlpp11_postgresql_${name}) set(target sqlpp11_postgresql_${name})
add_executable(${target} EXCLUDE_FROM_ALL ${name}.cpp) add_executable(${target} EXCLUDE_FROM_ALL ${name}.cpp)
target_link_libraries(${target} PRIVATE sqlpp11 sqlpp11_testing) target_link_libraries(${target} PRIVATE sqlpp11::postgresql sqlpp11_testing)
target_link_libraries(${target} PRIVATE PostgreSQL::PostgreSQL)
add_test(NAME ${test} add_test(NAME ${test}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${target} COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${target}
) )

View File

@ -38,22 +38,19 @@ set(test_names
Select Select
Transaction Transaction
Type Type
) )
create_test_sourcelist(test_sources test_main.cpp ${test_names}) create_test_sourcelist(test_sources test_main.cpp ${test_names})
add_executable(sqlpp11_postgresql_tests ${test_sources}) add_executable(sqlpp11_postgresql_tests ${test_sources})
target_link_libraries(sqlpp11_postgresql_tests PRIVATE sqlpp11 sqlpp11_testing sqlpp11_postgresql_testing) target_link_libraries(sqlpp11_postgresql_tests PRIVATE sqlpp11::postgresql sqlpp11_testing sqlpp11_postgresql_testing)
target_link_libraries(sqlpp11_postgresql_tests PRIVATE sqlpp11::sqlpp11)
target_link_libraries(sqlpp11_postgresql_tests PRIVATE PostgreSQL::PostgreSQL)
target_link_libraries(sqlpp11_postgresql_tests PRIVATE date::date)
if(NOT MSVC) if(NOT MSVC)
target_compile_options(sqlpp11_postgresql_tests PRIVATE -Wall -Wextra -pedantic) target_compile_options(sqlpp11_postgresql_tests PRIVATE -Wall -Wextra -pedantic)
endif() endif()
# conditionally bump to a higher C++ standard to test compatibility # conditionally bump to a higher C++ standard to test compatibility
if (SQLPP11_TESTS_CXX_STD) if (SQLPP11_TESTS_CXX_STD)
set_property(TARGET sqlpp11_postgresql_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) set_property(TARGET sqlpp11_postgresql_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD})
set_property(TARGET sqlpp11_postgresql_tests PROPERTY CXX_STANDARD_REQUIRED yes) set_property(TARGET sqlpp11_postgresql_tests PROPERTY CXX_STANDARD_REQUIRED yes)
set_property(TARGET sqlpp11_postgresql_tests PROPERTY CXX_EXTENSIONS no) set_property(TARGET sqlpp11_postgresql_tests PROPERTY CXX_EXTENSIONS no)
endif() endif()

View File

@ -41,24 +41,23 @@ set(test_names
) )
create_test_sourcelist(test_sources test_main.cpp ${test_names}) create_test_sourcelist(test_sources test_main.cpp ${test_names})
add_executable(sqlpp11_sqlite3_tests ${test_sources}) add_executable(sqlpp11_sqlite3_tests ${test_sources})
target_link_libraries(sqlpp11_sqlite3_tests PRIVATE sqlpp11 sqlpp11_testing sqlpp11_sqlite3_testing) target_link_libraries(sqlpp11_sqlite3_tests PRIVATE sqlpp11_testing sqlpp11_sqlite3_testing)
target_link_libraries(sqlpp11_sqlite3_tests PRIVATE sqlpp11::sqlpp11) if (BUILD_SQLCIPHER_CONNECTOR)
if (SQLCIPHER) target_link_libraries(sqlpp11_sqlite3_tests PRIVATE sqlpp11::sqlcipher)
target_compile_definitions(sqlpp11_sqlite3_tests PRIVATE SQLPP_USE_SQLCIPHER)
target_link_libraries(sqlpp11_sqlite3_tests PRIVATE SQLCipher::SQLCipher)
if (SQLPP_DYNAMIC_LOADING) if (SQLPP_DYNAMIC_LOADING)
target_include_directories(sqlpp11_sqlite3_tests PRIVATE ${SQLCIPHER_INCLUDE_DIRS}) target_include_directories(sqlpp11_sqlite3_tests PRIVATE ${SQLCIPHER_INCLUDE_DIRS})
endif() endif()
else() else()
target_link_libraries(sqlpp11_sqlite3_tests PRIVATE SQLite::SQLite3) target_link_libraries(sqlpp11_sqlite3_tests PRIVATE sqlpp11::sqlite3)
endif() endif()
# conditionally bump to a higher C++ standard to test compatibility # conditionally bump to a higher C++ standard to test compatibility
if (SQLPP11_TESTS_CXX_STD) if (SQLPP11_TESTS_CXX_STD)
set_property(TARGET sqlpp11_sqlite3_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) set_property(TARGET sqlpp11_sqlite3_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD})
set_property(TARGET sqlpp11_sqlite3_tests PROPERTY CXX_STANDARD_REQUIRED yes) set_property(TARGET sqlpp11_sqlite3_tests PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET sqlpp11_sqlite3_tests PROPERTY CXX_EXTENSIONS no) set_property(TARGET sqlpp11_sqlite3_tests PROPERTY CXX_EXTENSIONS OFF)
endif() endif()
foreach(test IN LISTS test_names) foreach(test IN LISTS test_names)