diff --git a/.travis.yml b/.travis.yml index 964f8cb1..e143ced8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,11 +34,8 @@ before_script: - mysql --version - (while ! mysqladmin -u root status ; do sleep 1; done) # wait for mysql to start - mysqladmin -u root create sqlpp_mysql - - mkdir build - - cd build - if [[ "$CXX" = "g++" && "$CONFIG" = "Debug" && "$TRAVIS_OS_NAME" = "linux" ]]; then export CXXFLAGS="--coverage"; fi - - ls .. - - cmake .. -DCMAKE_BUILD_TYPE=$CONFIG -DMYSQL_CONNECTOR=ON -DSQLITE3_CONNECTOR=ON + - cmake -B build -DCMAKE_BUILD_TYPE=$CONFIG -DBUILD_MYSQL_CONNECTOR=ON -DBUILD_SQLITE3_CONNECTOR=ON script: - cmake --build . --config $CONFIG diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ae82716..a83ac431 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,134 +30,122 @@ project(sqlpp11 VERSION 0.1 LANGUAGES CXX) ### Project Wide Setup list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") -option(MARIADB_CONNECTOR "Build MariaDB Connector" OFF) -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(GNUInstallDirs) 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 "\ Use find_package to find installed HowardHinnant's \ 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) endif() -### Dependencies add_subdirectory(dependencies) ### Core targets +include(Sqlpp11TargetHelper) + add_library(sqlpp11 INTERFACE) add_library(sqlpp11::sqlpp11 ALIAS sqlpp11) target_link_libraries(sqlpp11 INTERFACE date::date) - target_include_directories(sqlpp11 INTERFACE - $ - $ - ) + $ +) +target_compile_features(sqlpp11 INTERFACE cxx_std_11) -target_compile_features(sqlpp11 INTERFACE - cxx_alias_templates - cxx_auto_type - cxx_constexpr - cxx_decltype - cxx_defaulted_functions - cxx_defaulted_move_initializers - cxx_deleted_functions - cxx_explicit_conversions - cxx_lambdas - cxx_noexcept - cxx_nullptr - cxx_range_for - cxx_right_angle_brackets - cxx_rvalue_references - cxx_static_assert - cxx_trailing_return_types - cxx_uniform_initialization - cxx_template_template_parameters - cxx_variadic_templates - ) + +if(BUILD_SQLITE3_CONNECTOR) + add_component(NAME sqlite3 DEPENDENCIES SQLite::SQLite3) +endif() + +if(BUILD_SQLCIPHER_CONNECTOR) + add_component(NAME sqlcipher DEPENDENCIES SQLite::SQLCipher) + target_compile_definitions(sqlpp11_sqlcipher INTERFACE SQLPP_USE_SQLCIPHER) +endif() + +if(BUILD_MYSQL_CONNECTOR) + add_component(NAME mysql DEPENDENCIES MySQL::MySQL) +endif() + +if(BUILD_MARIADB_CONNECTOR) + add_component(NAME mariadb DEPENDENCIES MariaDB::MariaDB) +endif() + +if(BUILD_POSTGRESQL_CONNECTOR) + add_component(NAME postgresql DEPENDENCIES PostgreSQL::PostgreSQL) +endif() ### Packaging -install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/sqlpp11" - DESTINATION include -) - -install(TARGETS sqlpp11 - EXPORT Sqlpp11Targets -) - -install(PROGRAMS "${PROJECT_SOURCE_DIR}/scripts/ddl2cpp" +install(PROGRAMS ${PROJECT_SOURCE_DIR}/scripts/ddl2cpp RENAME sqlpp11-ddl2cpp - DESTINATION bin + DESTINATION ${CMAKE_INSTALL_BINDIR} ) -include(CMakePackageConfigHelpers) - -write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11ConfigVersion.cmake" - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion +write_basic_package_version_file(Sqlpp11ConfigVersion.cmake + COMPATIBILITY SameMajorVersion + ARCH_INDEPENDENT ) -export(EXPORT Sqlpp11Targets - FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11Targets.cmake" +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Sqlpp11ConfigVersion.cmake + DESTINATION ${SQLPP11_INSTALL_CMAKEDIR} ) -configure_file(cmake/Sqlpp11Config.cmake - "${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11Config.cmake" - COPYONLY -) +install_component(NAME Sqlpp11 TARGETS sqlpp11 DIRECTORY) -set(ConfigPackageLocation lib/cmake/Sqlpp11) -install(EXPORT Sqlpp11Targets - NAMESPACE sqlpp11:: - DESTINATION - ${ConfigPackageLocation} -) +if(BUILD_SQLITE3_CONNECTOR) + install_component(NAME Sqlpp11SQLite3 TARGETS sqlpp11_sqlite3 DIRECTORY sqlite3) +endif() + +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 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) diff --git a/README.md b/README.md index d39aa98c..bf4c19a0 100644 --- a/README.md +++ b/README.md @@ -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. -sqlpp11's core is vendor-neutral. +sqlpp11’s core is vendor-neutral. 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. 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:__ 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: -``` --DMYSQL_CONNECTOR=ON --DMARIADB_CONNECTOR=ON --DSQLITE3_CONNECTOR=ON --DSQLCIPHER_CONNECTOR=ON -``` +* MySQL +* MariaDB +* SQLite3 +* SQLCipher +* PostgreSQL Other connectors can be found here: - * PostgreSQL: https://github.com/matthijs/sqlpp11-connector-postgresql * ODBC: https://github.com/Erroneous1/sqlpp11-connector-odbc (experimental) __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 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`. Build and Install ----------------- @@ -160,7 +158,24 @@ cmake -B build 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. Don’t check if the dependencies such as Sqlite3 are installed and don’t 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):__ @@ -193,10 +208,20 @@ Basic usage: ------------- __Use 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. Find package (installation required, see above) +1. FetchContent (Recommended, no installation required) +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__: ``` @@ -208,9 +233,9 @@ Create headers for them with provided Python script: ``` %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 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.) -Include generated header (MyTable.h), that's all. +Include generated header (MyTable.h), that’s all. If you prefer Ruby over Python, you might want to take a look at https://github.com/douyw/sqlpp11gen diff --git a/cmake/Sqlpp11TargetHelper.cmake b/cmake/Sqlpp11TargetHelper.cmake new file mode 100644 index 00000000..33063935 --- /dev/null +++ b/cmake/Sqlpp11TargetHelper.cmake @@ -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() \ No newline at end of file diff --git a/cmake/Sqlpp11Config.cmake b/cmake/configs/Sqlpp11Config.cmake similarity index 68% rename from cmake/Sqlpp11Config.cmake rename to cmake/configs/Sqlpp11Config.cmake index ed7b6900..c50a71a6 100644 --- a/cmake/Sqlpp11Config.cmake +++ b/cmake/configs/Sqlpp11Config.cmake @@ -23,12 +23,31 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") - include(CMakeFindDependencyMacro) +find_dependency(Threads) 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 if(NOT TARGET sqlpp11::ddl2cpp) @@ -41,4 +60,4 @@ if(NOT TARGET sqlpp11::ddl2cpp) IMPORTED_LOCATION "${sqlpp11_ddl2cpp_location}" ) unset(sqlpp11_ddl2cpp_location) -endif() +endif() \ No newline at end of file diff --git a/cmake/configs/Sqlpp11MariaDBConfig.cmake b/cmake/configs/Sqlpp11MariaDBConfig.cmake new file mode 100644 index 00000000..32a594a9 --- /dev/null +++ b/cmake/configs/Sqlpp11MariaDBConfig.cmake @@ -0,0 +1,2 @@ +include(CMakeFindDependencyMacro) +find_dependency(MariaDB) \ No newline at end of file diff --git a/cmake/configs/Sqlpp11MySQLConfig.cmake b/cmake/configs/Sqlpp11MySQLConfig.cmake new file mode 100644 index 00000000..0d2a5b3b --- /dev/null +++ b/cmake/configs/Sqlpp11MySQLConfig.cmake @@ -0,0 +1,2 @@ +include(CMakeFindDependencyMacro) +find_dependency(MySQL) \ No newline at end of file diff --git a/cmake/configs/Sqlpp11PostgreSQLConfig.cmake b/cmake/configs/Sqlpp11PostgreSQLConfig.cmake new file mode 100644 index 00000000..9e4fffa0 --- /dev/null +++ b/cmake/configs/Sqlpp11PostgreSQLConfig.cmake @@ -0,0 +1,2 @@ +include(CMakeFindDependencyMacro) +find_dependency(PostgreSQL) \ No newline at end of file diff --git a/cmake/configs/Sqlpp11SQLCipherConfig.cmake b/cmake/configs/Sqlpp11SQLCipherConfig.cmake new file mode 100644 index 00000000..08926312 --- /dev/null +++ b/cmake/configs/Sqlpp11SQLCipherConfig.cmake @@ -0,0 +1,2 @@ +include(CMakeFindDependencyMacro) +find_dependency(SQLCipher) \ No newline at end of file diff --git a/cmake/configs/Sqlpp11SQLite3Config.cmake b/cmake/configs/Sqlpp11SQLite3Config.cmake new file mode 100644 index 00000000..cf1098b8 --- /dev/null +++ b/cmake/configs/Sqlpp11SQLite3Config.cmake @@ -0,0 +1,2 @@ +include(CMakeFindDependencyMacro) +find_dependency(SQLite3) \ No newline at end of file diff --git a/dependencies/hinnant_date/CMakeLists.txt b/dependencies/hinnant_date/CMakeLists.txt index 27a9d2b3..d15b1764 100644 --- a/dependencies/hinnant_date/CMakeLists.txt +++ b/dependencies/hinnant_date/CMakeLists.txt @@ -21,5 +21,8 @@ # 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. +FetchContent_MakeAvailable(date) -FetchContent_MakeAvailable(date) \ No newline at end of file +# 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}") \ No newline at end of file diff --git a/examples/usage_fetch_content/dependencies/sqlpp11/CMakeLists.txt b/examples/usage_fetch_content/dependencies/sqlpp11/CMakeLists.txt index 2c86850e..6f082628 100644 --- a/examples/usage_fetch_content/dependencies/sqlpp11/CMakeLists.txt +++ b/examples/usage_fetch_content/dependencies/sqlpp11/CMakeLists.txt @@ -22,5 +22,13 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # 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) \ No newline at end of file diff --git a/examples/usage_fetch_content/src/CMakeLists.txt b/examples/usage_fetch_content/src/CMakeLists.txt index cf207bf3..ebe64c74 100644 --- a/examples/usage_fetch_content/src/CMakeLists.txt +++ b/examples/usage_fetch_content/src/CMakeLists.txt @@ -23,7 +23,16 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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 PRIVATE diff --git a/examples/usage_find_package/CMakeLists.txt b/examples/usage_find_package/CMakeLists.txt index e3eee50c..262f36bb 100644 --- a/examples/usage_find_package/CMakeLists.txt +++ b/examples/usage_find_package/CMakeLists.txt @@ -32,7 +32,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) ### 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 ### add_subdirectory(src) \ No newline at end of file diff --git a/examples/usage_find_package/src/CMakeLists.txt b/examples/usage_find_package/src/CMakeLists.txt index cf207bf3..9c17c3f9 100644 --- a/examples/usage_find_package/src/CMakeLists.txt +++ b/examples/usage_find_package/src/CMakeLists.txt @@ -23,8 +23,16 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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 PRIVATE main.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a2a481da..e5c68c3b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,15 +23,15 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. add_subdirectory(core/) -if(MYSQL_CONNECTOR) +if(BUILD_MYSQL_CONNECTOR) add_subdirectory(mysql) endif() -if(POSTGRESQL_CONNECTOR) +if(BUILD_POSTGRESQL_CONNECTOR) add_subdirectory(postgresql) endif() -if(SQLITE3_CONNECTOR OR SQLCIPHER_CONNECTOR) +if(BUILD_SQLITE3_CONNECTOR OR BUILD_SQLCIPHER_CONNECTOR) add_subdirectory(sqlite3) endif() diff --git a/tests/core/constraints/CMakeLists.txt b/tests/core/constraints/CMakeLists.txt index 9f8ef69d..264ce02f 100644 --- a/tests/core/constraints/CMakeLists.txt +++ b/tests/core/constraints/CMakeLists.txt @@ -26,10 +26,10 @@ function(test_constraint name pattern) set(test sqlpp11.core.constraints.${name}) set(target sqlpp11_${name}) 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} COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${target} - ) + ) set_property(TEST ${test} PROPERTY PASS_REGULAR_EXPRESSION ${pattern}) # conditionally bump to a higher C++ standard to test compatibility if (SQLPP11_TESTS_CXX_STD) diff --git a/tests/core/serialize/CMakeLists.txt b/tests/core/serialize/CMakeLists.txt index ef17916f..2d6b6d14 100644 --- a/tests/core/serialize/CMakeLists.txt +++ b/tests/core/serialize/CMakeLists.txt @@ -40,7 +40,7 @@ set(test_names create_test_sourcelist(test_sources test_serializer_main.cpp ${test_names}) 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 if (SQLPP11_TESTS_CXX_STD) diff --git a/tests/core/static_asserts/CMakeLists.txt b/tests/core/static_asserts/CMakeLists.txt index 9ecec43f..149ed89a 100644 --- a/tests/core/static_asserts/CMakeLists.txt +++ b/tests/core/static_asserts/CMakeLists.txt @@ -25,7 +25,7 @@ function(test_compile name) set(target sqlpp11_assert_${name}) 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 if (SQLPP11_TESTS_CXX_STD) set_property(TARGET sqlpp11_assert_${name} PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) diff --git a/tests/core/types/CMakeLists.txt b/tests/core/types/CMakeLists.txt index 29aee3a9..9ee7b850 100644 --- a/tests/core/types/CMakeLists.txt +++ b/tests/core/types/CMakeLists.txt @@ -25,7 +25,7 @@ function(test_compile name) set(target sqlpp11_${name}) 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 if (SQLPP11_TESTS_CXX_STD) set_property(TARGET sqlpp11_${name} PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) diff --git a/tests/core/usage/CMakeLists.txt b/tests/core/usage/CMakeLists.txt index b885e04b..8bdb062f 100644 --- a/tests/core/usage/CMakeLists.txt +++ b/tests/core/usage/CMakeLists.txt @@ -26,7 +26,7 @@ add_library(sqlpp11_testing INTERFACE) target_include_directories(sqlpp11_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) if (NOT MSVC) -target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic) + target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic) endif () set(test_names @@ -56,7 +56,7 @@ endif() create_test_sourcelist(test_sources test_main.cpp ${test_names}) 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 if (SQLPP11_TESTS_CXX_STD) set_property(TARGET sqlpp11_core_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) diff --git a/tests/mysql/usage/CMakeLists.txt b/tests/mysql/usage/CMakeLists.txt index 7b4ecb4f..3f374e34 100644 --- a/tests/mysql/usage/CMakeLists.txt +++ b/tests/mysql/usage/CMakeLists.txt @@ -28,41 +28,38 @@ add_library(sqlpp11_mysql_testing INTERFACE) target_include_directories(sqlpp11_mysql_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) set(test_names -Json -CustomQuery -DateTime -Sample -Select -Union -DynamicSelect -MoveConstructor -Prepared -Truncated -Update -Remove - ) + Json + CustomQuery + DateTime + Sample + Select + Union + DynamicSelect + MoveConstructor + Prepared + Truncated + Update + Remove +) create_test_sourcelist(test_sources test_main.cpp ${test_names}) 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::sqlpp11) +target_link_libraries(sqlpp11_mysql_tests PRIVATE sqlpp11::mysql sqlpp11_testing sqlpp11_mysql_testing) 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) target_compile_options(sqlpp11_mysql_tests PRIVATE -Wall -Wextra -pedantic) endif() # conditionally bump to a higher C++ standard to test compatibility 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_REQUIRED yes) + 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_EXTENSIONS no) endif() foreach(test IN LISTS test_names) add_test(NAME sqlpp11.mysql.usage.${test} COMMAND sqlpp11_mysql_tests ${test} - ) + ) endforeach() diff --git a/tests/postgresql/constraints/CMakeLists.txt b/tests/postgresql/constraints/CMakeLists.txt index 96a3d03f..f12b2950 100644 --- a/tests/postgresql/constraints/CMakeLists.txt +++ b/tests/postgresql/constraints/CMakeLists.txt @@ -26,11 +26,10 @@ function(test_constraint name pattern) set(test sqlpp11.postgresql.constraints.${name}) set(target sqlpp11_postgresql_${name}) add_executable(${target} EXCLUDE_FROM_ALL ${name}.cpp) - target_link_libraries(${target} PRIVATE sqlpp11 sqlpp11_testing) - target_link_libraries(${target} PRIVATE PostgreSQL::PostgreSQL) + target_link_libraries(${target} PRIVATE sqlpp11::postgresql sqlpp11_testing) add_test(NAME ${test} COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${target} - ) + ) set_property(TEST ${test} PROPERTY PASS_REGULAR_EXPRESSION ${pattern}) # conditionally bump to a higher C++ standard to test compatibility if (SQLPP11_TESTS_CXX_STD) diff --git a/tests/postgresql/usage/CMakeLists.txt b/tests/postgresql/usage/CMakeLists.txt index 58b41456..28d9fbef 100644 --- a/tests/postgresql/usage/CMakeLists.txt +++ b/tests/postgresql/usage/CMakeLists.txt @@ -28,7 +28,7 @@ target_include_directories(sqlpp11_postgresql_testing INTERFACE ${CMAKE_CURRENT_ set(test_names Basic - Blob + Blob Constructor Date DateTime @@ -38,28 +38,25 @@ set(test_names Select Transaction Type - ) +) create_test_sourcelist(test_sources test_main.cpp ${test_names}) 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::sqlpp11) -target_link_libraries(sqlpp11_postgresql_tests PRIVATE PostgreSQL::PostgreSQL) -target_link_libraries(sqlpp11_postgresql_tests PRIVATE date::date) +target_link_libraries(sqlpp11_postgresql_tests PRIVATE sqlpp11::postgresql sqlpp11_testing sqlpp11_postgresql_testing) if(NOT MSVC) target_compile_options(sqlpp11_postgresql_tests PRIVATE -Wall -Wextra -pedantic) endif() # conditionally bump to a higher C++ standard to test compatibility 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_REQUIRED yes) + 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_EXTENSIONS no) endif() foreach(test IN LISTS test_names) add_test(NAME sqlpp11.postgresql.usage.${test} COMMAND sqlpp11_postgresql_tests ${test} - ) + ) endforeach() diff --git a/tests/sqlite3/usage/CMakeLists.txt b/tests/sqlite3/usage/CMakeLists.txt index 7c45c0fc..bf494299 100644 --- a/tests/sqlite3/usage/CMakeLists.txt +++ b/tests/sqlite3/usage/CMakeLists.txt @@ -41,30 +41,29 @@ set(test_names ) create_test_sourcelist(test_sources test_main.cpp ${test_names}) + 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::sqlpp11) -if (SQLCIPHER) - target_compile_definitions(sqlpp11_sqlite3_tests PRIVATE SQLPP_USE_SQLCIPHER) - target_link_libraries(sqlpp11_sqlite3_tests PRIVATE SQLCipher::SQLCipher) +target_link_libraries(sqlpp11_sqlite3_tests PRIVATE sqlpp11_testing sqlpp11_sqlite3_testing) +if (BUILD_SQLCIPHER_CONNECTOR) + target_link_libraries(sqlpp11_sqlite3_tests PRIVATE sqlpp11::sqlcipher) if (SQLPP_DYNAMIC_LOADING) target_include_directories(sqlpp11_sqlite3_tests PRIVATE ${SQLCIPHER_INCLUDE_DIRS}) endif() else() - target_link_libraries(sqlpp11_sqlite3_tests PRIVATE SQLite::SQLite3) + target_link_libraries(sqlpp11_sqlite3_tests PRIVATE sqlpp11::sqlite3) endif() # conditionally bump to a higher C++ standard to test compatibility 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_REQUIRED yes) - set_property(TARGET sqlpp11_sqlite3_tests PROPERTY CXX_EXTENSIONS no) + set_property(TARGET sqlpp11_sqlite3_tests PROPERTY CXX_STANDARD_REQUIRED ON) + set_property(TARGET sqlpp11_sqlite3_tests PROPERTY CXX_EXTENSIONS OFF) endif() foreach(test IN LISTS test_names) add_test(NAME sqlpp11.sqlite3.usage.${test} COMMAND sqlpp11_sqlite3_tests ${test} - ) + ) endforeach() # the dynamic loading test needs the extra option "SQLPP_DYNAMIC_LOADING" and does NOT link the sqlite libs