diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7f8708d1..eb6c76818 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,85 +29,114 @@ on: jobs: build: - runs-on: ${{ matrix.runner || 'ubuntu-22.04' }} - container: ${{ matrix.container }} - name: ${{ matrix.name }} strategy: fail-fast: false matrix: include: - # Note: the jobs are ordered in the order of decreasing running - # time, as this should minimize the total run-time of all jobs. - - backend: postgresql + # Ubuntu jobs + # Can't test DB2 as required db2exc package is no longer available after Ubuntu 14.04 + - lib_type: shared + backend: SQLite3 + runner: ubuntu-24.04 + unity_build: false + - lib_type: shared + backend: PostgreSQL + runner: ubuntu-24.04 + unity_build: false + - lib_type: shared + backend: MySQL + runner: ubuntu-24.04 + unity_build: false + - lib_type: shared + backend: Firebird + runner: ubuntu-24.04 + unity_build: false + - lib_type: shared + backend: Oracle + runner: ubuntu-22.04 + unity_build: false + - lib_type: shared + backend: ODBC + runner: ubuntu-24.04 + unity_build: false + - lib_type: shared + backend: Empty + runner: ubuntu-24.04 + unity_build: false + - lib_type: static + backend: SQLite3 + runner: ubuntu-24.04 + - lib_type: static + backend: PostgreSQL + runner: ubuntu-24.04 + - lib_type: static + backend: MySQL + runner: ubuntu-24.04 + - lib_type: static + backend: Firebird + runner: ubuntu-24.04 + - lib_type: static + backend: Oracle + runner: ubuntu-22.04 + - lib_type: static + backend: ODBC + runner: ubuntu-24.04 + - lib_type: static + backend: Empty + runner: ubuntu-24.04 + + # MacOS jobs + - lib_type: shared + backend: Empty runner: macos-14 - name: PostgreSQL macOS - - backend: oracle - name: Oracle 11 no_boost: true - - backend: valgrind - name: Valgrind - - backend: odbc - # There are many leak reports under Ubuntu 22.04, see #1008. - container: ubuntu:18.04 - name: ODBC - # UBSAN gives nonsensical errors on this system, to be reviewed - # after migrating to newer Ubuntu and compiler versions. - no_ubsan: true - - backend: firebird - name: Firebird - - backend: postgresql - name: PostgreSQL Linux - - backend: mysql - name: MySQL - - backend: sqlite3 + - lib_type: shared + backend: PostgreSQL runner: macos-14 - name: SQLite3 macOS - - backend: sqlite3 - name: SQLite3 C++17 - cxxstd: 17 - - backend: sqlite3 - name: SQLite3 - - backend: empty + no_boost: true + - lib_type: shared + backend: SQLite3 runner: macos-14 - name: Empty macOS - - backend: empty - name: Empty + no_boost: true + + # Special + - lib_type: shared + backend: SQLite3 + runner: ubuntu-24.04 + cxxstd: 17 + name: SQLite3 Cxx17 + - lib_type: shared + backend: Empty + runner: ubuntu-24.04 test_release_package: true - # Unsupported: db2exc package is only available in Ubuntu 14.04 not - # supported by GitHub Actions any longer, we'd need to run it in - # Docker container if we really need it. - # backend: db2 - - backend: empty - name: Examples + name: Release package + - lib_type: shared + backend: Empty + runner: ubuntu-24.04 build_examples: true + name: Examples + - lib_type: static + backend: Valgrind + runner: ubuntu-24.04 + name: Valgrind + + runs-on: ${{ matrix.runner }} + name: ${{ format('{0} on {1}', (matrix.name != '' && matrix.name || format('{0} ({1})', matrix.backend, matrix.lib_type)), matrix.runner) }} env: SOCI_CI: true SOCI_CI_BACKEND: ${{ matrix.backend }} SOCI_MYSQL_ROOT_PASSWORD: root ASAN_OPTIONS: fast_unwind_on_malloc=0 + UBSAN_OPTIONS: 'print_stacktrace=1:halt_on_error=1' + SOCI_CXXSTD: 14 steps: - name: Checkout - run: | - case "${{matrix.container}}" in - ubuntu:18.04) - export DEBIAN_FRONTEND=noninteractive - - apt-get update -qq - apt-get install -qq git - ;; - esac - - git config --global init.defaultBranch master - git config --global --add safe.directory `pwd` - git config --global advice.detachedHead false - git init . - git remote add origin https://github.com/SOCI/soci.git - git fetch --depth=1 origin $GITHUB_SHA - git checkout FETCH_HEAD + uses: actions/checkout@v4 - name: Set environment variables + shell: bash run: | set_env_var() { echo "Setting environment variable $1=$2" @@ -130,14 +159,6 @@ jobs: ;; esac - case "${{matrix.container}}" in - ubuntu:18.04) - # We need to use this option as GitHub certificate is not recognized by - # wget in this old container otherwise. - set_env_var SOCI_WGET_OPTIONS --no-check-certificate - ;; - esac - if [ -n "${{matrix.cxxstd}}" ]; then set_env_var SOCI_CXXSTD ${{matrix.cxxstd}} fi @@ -150,15 +171,20 @@ jobs: if [ "${{matrix.build_examples}}" = true ]; then set_env_var BUILD_EXAMPLES YES fi - if [ "${{matrix.no_ubsan}}" = true ]; then - set_env_var SOCI_NO_UBSAN 1 + if [ "${{matrix.lib_type}}" = "static" ]; then + set_env_var SOCI_BUILD_STATIC YES + fi + if [ "${{matrix.unity_build}}" = false ]; then + set_env_var SOCI_ENABLE_UNITY_BUILD ON else - set_env_var UBSAN_OPTIONS print_stacktrace=1:halt_on_error=1 + set_env_var SOCI_ENABLE_UNITY_BUILD OFF fi + # Ensure SOCI_CI_BACKEND is always lowercase + set_env_var SOCI_CI_BACKEND "$( echo "$SOCI_CI_BACKEND" | tr '[:upper:]' '[:lower:]' )" - name: Setup tmate - uses: mxschmitt/action-tmate@v3 if: ${{ github.event_name == 'workflow_dispatch' && inputs.enable_ssh }} + uses: mxschmitt/action-tmate@v3 - name: Install dependencies run: ./scripts/ci/install.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 24effe133..d9626be50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,316 +1,115 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2009-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -# General settings -############################################################################### -cmake_minimum_required(VERSION 2.8...3.20 FATAL_ERROR) +# Note: we need >= v3.23 in order to make use of file sets for header installation +cmake_minimum_required(VERSION 3.23...3.31 FATAL_ERROR) -project(SOCI) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/find_modules") -if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14) - set(CMAKE_CXX_STANDARD 14) -endif() -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Path to additional CMake modules -set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) -set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) - -include(SociUtilities) - -############################################################################### -# Build features and variants -############################################################################## - -option(SOCI_SHARED "Enable build of shared libraries" ON) -option(SOCI_STATIC "Enable build of static libraries" ON) -option(SOCI_TESTS "Enable build of collection of SOCI tests" ON) -option(SOCI_ASAN "Enable address sanitizer on GCC v4.8+/Clang v 3.1+" OFF) -option(SOCI_UBSAN "Enable undefined behaviour sanitizer" OFF) -option(SOCI_LTO "Enable link time optimization" OFF) -option(SOCI_VISIBILITY "Enable hiding private symbol using ELF visibility if supported by the platform" ON) +include(soci_parse_version) +soci_parse_version( + ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE SOCI_VERSION +) -if (SOCI_LTO) - cmake_minimum_required(VERSION 3.9) +project(SOCI + VERSION ${SOCI_VERSION} + DESCRIPTION "C++ database access library" + HOMEPAGE_URL "https://soci.sourceforge.net/" + LANGUAGES CXX +) - # Check and enable lto support - include(CheckIPOSupported) - check_ipo_supported(RESULT supported) +include(soci_utils) - if (NOT supported) - message(STATUS "IPO / LTO not supported") - endif() - - if (supported AND NOT SOCI_ASAN) - message(STATUS "IPO / LTO enabled") - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) - - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Check for lld as clang lto works best with its own linker - soci_use_ld_if_supported(lld) - endif() - elseif(supported) - message(STATUS "IPO / LTO is supported but conflicts with ASAN and not enabled") - endif() +if (NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14) + set(CMAKE_CXX_STANDARD 14) endif() +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) -if (SOCI_VISIBILITY) - # Test whether visibility is supported - include(CheckCSourceCompiles) - check_c_source_compiles( - " - __attribute__ (( visibility(\"default\") )) int f1() { return 0; } - __attribute__ (( visibility(\"hidden\") )) int f2() { return 1; } +include(CMakeDependentOption) +include(CheckIPOSupported) - int main(int argc, char* argv[]) { f1(); f2(); return 0; } - " - SOCI_HAVE_VISIBILITY_SUPPORT - ) +check_ipo_supported(RESULT LTO_AVAILABLE) - if (SOCI_HAVE_VISIBILITY_SUPPORT) - message(STATUS "gcc / clang visibility enabled") - set(CMAKE_CXX_VISIBILITY_PRESET hidden) - cmake_policy(SET CMP0063 NEW) - endif() +if (SOCI_STATIC) + set(SHARED_DEFAULT OFF) +elseif(DEFINED BUILD_SHARED_LIBS) + set(SHARED_DEFAULT ${BUILD_SHARED_LIBS}) else() - set(SOCI_HAVE_VISIBILITY_SUPPORT off) + set(SHARED_DEFAULT ON) endif() -# Allow using alternative linker such as mold, which can be significantly -# faster than GNU ld. -option(SOCI_LD "Use non-default linker, such as 'mold'" "") -if(SOCI_LD) - # -fuse-ld works only with recent gcc (>= 12), but we don't need to support - # this with all gcc versions as this is entirely optional. I.e. if we really - # wanted to, we could use -B option as explained in mold README to make it - # work with any gcc, but for now keep the things simple. - soci_use_ld_if_supported(${SOCI_LD}) -endif() - -############################################################################### -# SOCI configuration -############################################################################### -include(SociConfig) - -colormsg(_HIBLUE_ "Configuring SOCI:") +option(SOCI_SHARED "Enable building SOCI as a shared library" ${SHARED_DEFAULT}) +option(SOCI_TESTS "Enable building SOCI test cases" ${PROJECT_IS_TOP_LEVEL}) +cmake_dependent_option(SOCI_LTO "Enable link time optimizations in release builds" ON "LTO_AVAILABLE" OFF) -############################################################################### -# SOCI version information -############################################################################### -include(SociVersion) -soci_version() +# Configure LTO for anything but Debug builds (if enabled in the first place) +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${SOCI_LTO}) +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF) -############################################################################### -# Build features and variants -############################################################################## +if (NOT APPLE) + # This makes runtime loaders look for library dependencies + # in the same directory as the library is located in. + # For details see Craig Scott's CppCon 2019 talk -boost_report_value(SOCI_SHARED) -boost_report_value(SOCI_STATIC) -boost_report_value(SOCI_TESTS) -boost_report_value(SOCI_ASAN) -boost_report_value(SOCI_UBSAN) - -# from SociConfig.cmake -boost_report_value(LIB_SUFFIX) - -# Put the libaries and binaries that get built into directories at the -# top of the build tree rather than in hard-to-find leaf -# directories. This simplifies manual testing and the use of the build -# tree rather than installed Boost libraries. -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -############################################################################### -# Find SOCI dependencies -############################################################################### - -set(SOCI_CORE_TARGET) -set(SOCI_CORE_TARGET_STATIC) -set(SOCI_CORE_DEPS_LIBS) - -include(SociDependencies) - -get_property(SOCI_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - PROPERTY INCLUDE_DIRECTORIES) - -if(Threads_FOUND) - list(APPEND SOCI_CORE_DEPS_LIBS ${CMAKE_THREAD_LIBS_INIT}) -else() - message(FATAL_ERROR "No thread library found") + # Note: The variable's content is set to $ORIGIN literally, + # this is NOT a butchered cmake variable expansion + set(CMAKE_INSTALL_RPATH "$ORIGIN") endif() -if(NOT MSVC) - set(DL_FIND_QUIETLY TRUE) - find_package(DL) - if(DL_FOUND) - list(APPEND SOCI_CORE_DEPS_LIBS ${DL_LIBRARY}) - set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES ${DL_INCLUDE_DIR}) - add_definitions(-DHAVE_DL=1) +if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) + # Ensure that build artifacts are easy to find. And on Windows this + # guarantees that the built DLLs end up next to applications + # linking to them as otherwise they won't be found. + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + + if (NOT PROJECT_IS_TOP_LEVEL) + # If the embedding project does not define these variables, this can lead to + # inconsistencies which can cause issues on Windows when e.g. the embedding + # project has an executable that links to a SOCI DLL which will be put into + # a different directory which will lead to the exe not finding the DLL. + message(WARNING "Setting CMAKE_{LIBRARY, ARCHIVE, RUNTIME}_DIRECTORY variables which should have done by the embedding cmake project") endif() endif() -if(Boost_FOUND) - get_property(SOCI_COMPILE_DEFINITIONS - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - PROPERTY COMPILE_DEFINITIONS) - - set(SOCI_HAVE_BOOST ON) - - list(APPEND SOCI_COMPILE_DEFINITIONS "BOOST_ALL_NO_LIB") - - if(Boost_DATE_TIME_FOUND) - list(APPEND SOCI_CORE_DEPS_LIBS ${Boost_DATE_TIME_LIBRARY}) - set(SOCI_HAVE_BOOST_DATE_TIME ON) - endif() - - list(APPEND SOCI_INCLUDE_DIRS ${Boost_INCLUDE_DIRS}) - list(APPEND SOCI_CORE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS}) - - set_directory_properties(PROPERTY COMPILE_DEFINITIONS "${SOCI_COMPILE_DEFINITIONS}") - - set_property(DIRECTORY ${SOCI_SOURCE_DIR} - PROPERTY COMPILE_DEFINITIONS "${SOCI_COMPILE_DEFINITIONS}") +if (SOCI_SHARED) + set(SOCI_LIB_TYPE "SHARED") else() - set(SOCI_HAVE_BOOST OFF) - set(SOCI_HAVE_BOOST_DATE_TIME OFF) + set(SOCI_LIB_TYPE "STATIC") endif() -set(SOCI_HAVE_BOOST ${SOCI_HAVE_BOOST} CACHE INTERNAL "Boost library") -set(SOCI_HAVE_BOOST_DATE_TIME ${SOCI_HAVE_BOOST_DATE_TIME} CACHE INTERNAL "Boost date_time library") - -list(APPEND SOCI_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}) - -set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - PROPERTY - INCLUDE_DIRECTORIES ${SOCI_INCLUDE_DIRS}) - -############################################################################### -# Installation -############################################################################### - -include(GNUInstallDirs) - -############################################################################### -# Configuration files -############################################################################### -set(CONFIG_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) -install(DIRECTORY ${CONFIG_INCLUDE_DIR}/soci DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -set(CONFIG_FILE_IN "include/soci/soci-config.h.in") -set(CONFIG_FILE_OUT "${CONFIG_INCLUDE_DIR}/soci/soci-config.h") - +include(soci_compiler_options) +include(soci_install_dirs) -############################################################################### -# Build configured components -############################################################################### -include(SociBackend) - -include_directories(${SOCI_SOURCE_DIR}/include ${CONFIG_INCLUDE_DIR}) add_subdirectory(src) -if(SOCI_TESTS) - ############################################################################### - # Enable tests - ############################################################################### - enable_testing() - - file(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} TEST_ACCESS_PATH) - configure_file(${PROJECT_SOURCE_DIR}/cmake/configs/test-access.cmake ${PROJECT_SOURCE_DIR}/tests/odbc/test-access.dsn @ONLY) +include(soci_compat) - set(MYSQL_DRIVER_NAME "MySQL") - if(WIN32) - set(MYSQL_DRIVER_NAME "MySQL ODBC 5.3 ANSI Driver") - endif() - configure_file(${PROJECT_SOURCE_DIR}/cmake/configs/test-mysql.cmake ${PROJECT_SOURCE_DIR}/tests/odbc/test-mysql.dsn @ONLY) - # Define "make check" as alias for "make test" - add_custom_target(check COMMAND ctest) +if (SOCI_TESTS) + include(CTest) + enable_testing() add_subdirectory(tests) endif() -############################################################################### -# platform-dependent settings -############################################################################### - -include(CheckTypeSize) -check_type_size(long SOCI_SIZEOF_LONG) -set(SOCI_SIZEOF_LONG ${SOCI_SIZEOF_LONG} CACHE INTERNAL "Size of long") - -include(CheckCXXSourceCompiles) - -function(soci_check_types_are_same type1 type2) - string(TOUPPER ${type1} type1_upper) - string(MAKE_C_IDENTIFIER ${type1_upper} type1_id) - string(TOUPPER ${type2} type2_upper) - string(MAKE_C_IDENTIFIER ${type2_upper} type2_id) - - check_cxx_source_compiles(" -#include - -struct Foo { - void foo(${type1} x); - void foo(${type2} x); -}; - -int main() { return 0; } -" - "SOCI_TYPES_${type1_id}_AND_${type2_id}_DIFFER" - ) - - if(SOCI_TYPES_${type1_id}_AND_${type2_id}_DIFFER) - set(soci_types_equal FALSE) - else() - set(soci_types_equal TRUE) - endif() - - set("SOCI_${type1_id}_IS_${type2_id}" ${soci_types_equal} CACHE INTERNAL "${type1} and ${type2} are the same type") -endfunction() - -if(SOCI_SIZEOF_LONG EQUAL 8) - # int64_t can be defined as either long or long long in this case, find out - # which one we have. - soci_check_types_are_same("int64_t" "long") -elseif(SOCI_SIZEOF_LONG EQUAL 4) - # Nothing to do in this case, actually, as it's never going to be the same - # as int32_t which is defined as int and not long in this case. -else() - message(FATAL_ERROR "Unsupported size of long=${SOCI_SIZEOF_LONG}") -endif() - -soci_check_types_are_same("int8_t" "char") - -############################################################################### -# build config file -############################################################################### - -get_cmake_property(ALL_VARIABLES CACHE_VARIABLES) -set(CONFIGURED_VARIABLES) -foreach(v ${ALL_VARIABLES}) - if (v MATCHES "^SOCI_(HAVE|[A-Z0-9_]+_IS)_") - get_property(CACHE_HELPSTRING CACHE ${v} PROPERTY HELPSTRING) - set(CONFIGURED_VARIABLES "${CONFIGURED_VARIABLES}\n// ${CACHE_HELPSTRING}\n") - if (${${v}}) - set(CONFIGURED_VARIABLES "${CONFIGURED_VARIABLES}#define ${v}\n") - else() - set(CONFIGURED_VARIABLES "${CONFIGURED_VARIABLES}/* #undef ${v} */\n") - endif() - endif() - - if (v MATCHES "^SOCI_SIZEOF_") - get_property(CACHE_HELPSTRING CACHE ${v} PROPERTY HELPSTRING) - set(CONFIGURED_VARIABLES "${CONFIGURED_VARIABLES}\n// ${CACHE_HELPSTRING}\n") - set(CONFIGURED_VARIABLES "${CONFIGURED_VARIABLES}#define ${v} ${${v}}\n") - endif() -endforeach() -configure_file("${CONFIG_FILE_IN}" "${CONFIG_FILE_OUT}") -message(STATUS "") +# Packaging +include(CMakePackageConfigHelpers) +configure_package_config_file("soci-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/soci-config.cmake" + INSTALL_DESTINATION "${SOCI_INSTALL_CMAKEDIR}" +) +write_basic_package_version_file(soci-config-version.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/soci-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/soci-config-version.cmake" + DESTINATION "${SOCI_INSTALL_CMAKEDIR}" +) diff --git a/appveyor.yml b/appveyor.yml index 3b4cb4cae..8e4a2fccb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,39 +8,44 @@ configuration: Release environment: matrix: - - G: "Visual Studio 17 2022" - BOOST_ROOT: C:\Libraries\boost_1_77_0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + G: "Ninja" + BOOST_ROOT: C:\Libraries\boost_1_84_0 MSSQL_VER: 2019 - POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\13 - POSTGRESQL_VER: 13 + POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\15 + POSTGRESQL_VER: 15 MYSQL_VER: 80 MYSQL_DIR: C:\Program Files\MySql\MySQL Server 8.0 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 - - G: "Visual Studio 16 2019" - BOOST_ROOT: C:\Libraries\boost_1_73_0 + VCVARS_SCRIPT: "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build" + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + G: "Ninja" + BOOST_ROOT: C:\Libraries\boost_1_77_0 MSSQL_VER: 2017 - POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\12 - POSTGRESQL_VER: 12 + POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\13 + POSTGRESQL_VER: 13 MYSQL_VER: 80 MYSQL_DIR: C:\Program Files\MySql\MySQL Server 8.0 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - - G: "Visual Studio 15 2017 Win64" + VCVARS_SCRIPT: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build" + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + G: "Ninja" BOOST_ROOT: C:\Libraries\boost_1_69_0 MSSQL_VER: 2016 - POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\11 - POSTGRESQL_VER: 11 + POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\12 + POSTGRESQL_VER: 12 MYSQL_VER: 57 MYSQL_DIR: C:\Program Files\MySql\MySQL Server 5.7 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - - G: "Visual Studio 14 2015 Win64" + VCVARS_SCRIPT: "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build" + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + G: "Ninja" BOOST_ROOT: C:\Libraries\boost_1_60_0 MSSQL_VER: 2014 - POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\10 - POSTGRESQL_VER: 10 + POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\11 + POSTGRESQL_VER: 11 MYSQL_VER: 57 MYSQL_DIR: C:\Program Files\MySql\MySQL Server 5.7 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - - G: "MinGW Makefiles" + VCVARS_SCRIPT: "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC" + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + G: "MinGW Makefiles" MINGW_BIN: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin MSSQL_VER: 2014 BOOST_ROOT: C:\Libraries\boost_1_60_0 @@ -48,7 +53,7 @@ environment: POSTGRESQL_VER: 9.4 MYSQL_VER: 57 MYSQL_DIR: C:\Program Files\MySql\MySQL Server 5.7 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + VCVARS_SCRIPT: "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC" install: # Start these ones here as we can't specify the service name dynamically above. @@ -59,13 +64,18 @@ install: Import-Module C:\projects\soci\scripts\windows\Get-ODBCList.ps1 $drivers_list = Get-ODBCList Write-Output $drivers_list - if ($drivers_list -clike '*MySQL*') { - $env:SOCI_ODBC_TESTS = $env:SOCI_ODBC_TESTS + '|soci_odbc_test_mysql' + $env:SOCI_ODBC_SKIP_TESTS = "soci_odbc_ms_access_tests" + if (-Not ($drivers_list -contains 'MySQL')) { + $env:SOCI_ODBC_SKIP_TESTS = $env:SOCI_ODBC_SKIP_TESTS + '|soci_odbc_mysql_tests' } - if ($drivers_list -clike '*PostgreSQL*') { - $env:SOCI_ODBC_TESTS = $env:SOCI_ODBC_TESTS + '|soci_odbc_test_postgresql' + if (-Not ($drivers_list -contains 'PostgreSQL')) { + $env:SOCI_ODBC_SKIP_TESTS = $env:SOCI_ODBC_SKIP_TESTS + '|soci_odbc_postgresql_tests' } + Write-Output "To be skipped ODBC tests: $env:SOCI_ODBC_SKIP_TESTS" - git clone https://github.com/snikulov/sqlite.cmake.build.git C:\projects\sqlite\src + # Ensure we have a recent cmake version available + - choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' + - refreshenv before_build: - set SQLITE_ROOT=C:\projects\sqlite\sqlite @@ -87,7 +97,16 @@ before_build: else { $env:SQLITE3_LIBRARY = $env:SQLITE_ROOT + '/lib/sqlite3-static.lib' - $env:BUILD_TOOL_OPTIONS = '/m' + $env:BUILD_TOOL_OPTIONS = '' + # Set up Visual Studio environment (MSVC compiler etc.) + # Works by calling the respective bat script and then copying over the env vars + cd $env:VCVARS_SCRIPT + cmd /c "vcvarsall.bat x64&set" | + foreach { + if ($_ -match "=") { + $v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])" + } + } } - cd C:\projects\sqlite\src - mkdir build @@ -102,18 +121,18 @@ before_build: - set USER=root - mysql -e "create database soci_test;" --user=root - sqlcmd -U sa -P Password12! -S (local)\SQL%MSSQL_VER% -i C:\projects\soci\scripts\windows\mssql_db_create.sql - - cmake .. -G"%G%" -DSQLITE_BUILD_SHARED=OFF -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_INSTALL_PREFIX=%SQLITE_ROOT% + - cmake .. -G"%G%" -DSQLITE_BUILD_SHARED=OFF -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_INSTALL_PREFIX=%SQLITE_ROOT% -DCMAKE_UNITY_BUILD=ON - cmake --build . --config %CONFIGURATION% --target install build_script: - cd C:\projects\soci - mkdir build - cd build - - cmake .. -G"%G%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_VERBOSE_MAKEFILE=ON -DSOCI_ENABLE_WERROR=ON -DSQLITE3_INCLUDE_DIR=%SQLITE_ROOT%/include -DSQLITE3_LIBRARY=%SQLITE3_LIBRARY% + - cmake .. -G"%G%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_VERBOSE_MAKEFILE=ON -DSOCI_ENABLE_WERROR=ON -DCMAKE_PREFIX_PATH=%SQLITE_ROOT% -DSQLite3_LIBRARY=%SQLITE3_LIBRARY% -DCMAKE_UNITY_BUILD=ON - cmake --build . --config %CONFIGURATION% -- %BUILD_TOOL_OPTIONS% test_script: - - ctest -V --timeout 300 --output-on-failure -R "soci_empty|soci_postgresql|soci_sqlite3|soci_odbc_test_mssql|soci_mysql%SOCI_ODBC_TESTS%" + - ctest -V --timeout 300 --output-on-failure --build-config %CONFIGURATION% --exclude-regex "%SOCI_ODBC_SKIP_TESTS%" # Uncomment this to wait for RDP connection after the build end. #on_finish: diff --git a/cmake/.gitignore b/cmake/.gitignore deleted file mode 100644 index 61caff875..000000000 --- a/cmake/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -*~ -*.kdev[0-9] -*.swp -aclocal.m4 -autom4te.cache -confdefs.h -config.guess -config.log -config.status -config.sub -configure -depcomp -install-sh -libtool -ltmain.sh -m4 -missing -Makefile -Makefile.in -tmp - diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt deleted file mode 100644 index 317236e6a..000000000 --- a/cmake/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2009 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### - -# install the cmake modules -file(GLOB SOCI_CMAKE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cmake") diff --git a/cmake/SociBackend.cmake b/cmake/SociBackend.cmake deleted file mode 100644 index b5547f8f4..000000000 --- a/cmake/SociBackend.cmake +++ /dev/null @@ -1,390 +0,0 @@ -################################################################################ -# SociBackend.cmake - part of CMake configuration of SOCI library -################################################################################ -# Copyright (C) 2010-2013 Mateusz Loskot -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -################################################################################ -# Macros in this module: -# -# soci_backend -# - defines project of a database backend for SOCI library -# -# soci_backend_test -# - defines test project of a database backend for SOCI library -################################################################################ - -macro(soci_backend_deps_found NAME DEPS SUCCESS) - #message(STATUS "DEPS=${DEPS}") - - # Determine required dependencies - set(DEPS_INCLUDE_DIRS) - set(DEPS_LIBRARIES) - set(DEPS_NOT_FOUND) - - # CMake 2.8+ syntax only: - #foreach(dep IN LISTS DEPS) - foreach(dep ${DEPS}) - soci_check_package_found(${dep} DEPEND_FOUND) - if(NOT DEPEND_FOUND) - list(APPEND DEPS_NOT_FOUND ${dep}) - else() - string(TOUPPER "${dep}" DEPU) - if( ${DEPU}_INCLUDE_DIR ) - list(APPEND DEPS_INCLUDE_DIRS ${${DEPU}_INCLUDE_DIR}) - endif() - if( ${DEPU}_INCLUDE_DIRS ) - list(APPEND DEPS_INCLUDE_DIRS ${${DEPU}_INCLUDE_DIRS}) - endif() - list(APPEND DEPS_LIBRARIES ${${DEPU}_LIBRARIES}) - endif() - endforeach() - - list(LENGTH DEPS_NOT_FOUND NOT_FOUND_COUNT) - - if (NOT_FOUND_COUNT GREATER 0) - set(${SUCCESS} False) - else() - set(${NAME}_DEPS_INCLUDE_DIRS ${DEPS_INCLUDE_DIRS}) - set(${NAME}_DEPS_LIBRARIES ${DEPS_LIBRARIES}) - set(${SUCCESS} True) - endif() - - #message(STATUS "soci_backend_deps_found: ${SUCCESS}=${${SUCCESS}}") -endmacro() - -# Defines project of a database backend for SOCI library -# -# soci_backend(backendname -# DEPENDS dependency1 dependency2 -# DESCRIPTION description -# AUTHORS author1 author2 -# MAINTAINERS maintainer1 maintainer2) -# -macro(soci_backend NAME) - parse_arguments(THIS_BACKEND - "DEPENDS;DESCRIPTION;AUTHORS;MAINTAINERS;" - "" - ${ARGN}) - - colormsg(HIGREEN "${NAME} - ${THIS_BACKEND_DESCRIPTION}") - - # Backend name variants utils - string(TOLOWER "${PROJECT_NAME}" PROJECTNAMEL) - string(TOLOWER "${NAME}" NAMEL) - string(TOUPPER "${NAME}" NAMEU) - - # Backend option available to user - set(THIS_BACKEND_OPTION SOCI_${NAMEU}) - - soci_backend_deps_found(${NAMEU} "${THIS_BACKEND_DEPENDS}" ${NAMEU}_DEPS_FOUND) - if(NOT ${NAMEU}_DEPS_FOUND) - - colormsg(_RED_ "WARNING: Some required dependencies of ${NAME} backend not found:") - - if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8) - foreach(dep ${DEPENDS_NOT_FOUND}) - colormsg(RED " ${dep}") - endforeach() - else() - foreach(dep IN LISTS DEPENDS_NOT_FOUND) - colormsg(RED " ${dep}") - endforeach() - endif() - - # TODO: Abort or warn compilation may fail? --mloskot - colormsg(RED "Skipping") - - set(${THIS_BACKEND_OPTION} OFF) - - else() - - if(${THIS_BACKEND_OPTION}) - - get_directory_property(THIS_INCLUDE_DIRS INCLUDE_DIRECTORIES) - get_directory_property(THIS_COMPILE_DEFS COMPILE_DEFINITIONS) - - # Backend-specific depedencies - set(THIS_BACKEND_DEPENDS_INCLUDE_DIRS ${${NAMEU}_DEPS_INCLUDE_DIRS}) - set(THIS_BACKEND_DEPENDS_LIBRARIES ${${NAMEU}_DEPS_LIBRARIES}) - set(THIS_BACKEND_DEPENDS_DEFS ${${NAMEU}_DEPS_DEFS}) - - # Collect include directories - list(APPEND THIS_INCLUDE_DIRS ${SOCI_SOURCE_DIR}/include/private) - list(APPEND THIS_INCLUDE_DIRS ${THIS_BACKEND_DEPENDS_INCLUDE_DIRS}) - # Collect compile definitions - list(APPEND THIS_COMPILE_DEFS ${THIS_BACKEND_DEPENDS_DEFS}) - - set_directory_properties(PROPERTIES - INCLUDE_DIRECTORIES "${THIS_INCLUDE_DIRS}" - COMPILE_DEFINITIONS "${THIS_COMPILE_DEFS}") - - # Backend target - set(THIS_BACKEND_VAR SOCI_${NAMEU}) - set(THIS_BACKEND_TARGET ${PROJECTNAMEL}_${NAMEL}) - set(THIS_BACKEND_TARGET_VAR ${THIS_BACKEND_VAR}_TARGET) - set(${THIS_BACKEND_TARGET_VAR} ${THIS_BACKEND_TARGET}) - - soci_target_output_name(${THIS_BACKEND_TARGET} ${THIS_BACKEND_VAR}_OUTPUT_NAME) - - set(THIS_BACKEND_OUTPUT_NAME ${${THIS_BACKEND_VAR}_OUTPUT_NAME}) - set(THIS_BACKEND_OUTPUT_NAME_VAR ${THIS_BACKEND_VAR}_OUTPUT_NAME) - - set(${THIS_BACKEND_VAR}_COMPILE_DEFINITIONS ${THIS_COMPILE_DEFS}) - set(THIS_BACKEND_COMPILE_DEFINITIONS_VAR ${THIS_BACKEND_VAR}_COMPILE_DEFINITIONS) - - set(${THIS_BACKEND_VAR}_INCLUDE_DIRECTORIES ${THIS_INCLUDE_DIRS}) - set(THIS_BACKEND_INCLUDE_DIRECTORIES_VAR ${THIS_BACKEND_VAR}_INCLUDE_DIRECTORIES) - - # Backend installable headers and sources - file(GLOB THIS_BACKEND_HEADERS ${SOCI_SOURCE_DIR}/include/soci/${NAMEL}/*.h) - file(GLOB THIS_BACKEND_SOURCES *.cpp) - set(THIS_BACKEND_HEADERS_VAR SOCI_${NAMEU}_HEADERS) - set(${THIS_BACKEND_HEADERS_VAR} ${THIS_BACKEND_HEADERS}) - # Group source files for IDE source explorers (e.g. Visual Studio) - source_group("Header Files" FILES ${THIS_BACKEND_HEADERS}) - source_group("Source Files" FILES ${THIS_BACKEND_SOURCES}) - source_group("CMake Files" FILES CMakeLists.txt) - - # TODO: Extract as macros: soci_shared_lib_target and soci_static_lib_target --mloskot - # Shared library target - if (SOCI_SHARED) - add_library(${THIS_BACKEND_TARGET} - SHARED - ${THIS_BACKEND_SOURCES} - ${THIS_BACKEND_HEADERS}) - add_library(Soci::${NAMEL} ALIAS ${THIS_BACKEND_TARGET}) - - target_link_libraries(${THIS_BACKEND_TARGET} - ${SOCI_CORE_TARGET} - ${THIS_BACKEND_DEPENDS_LIBRARIES}) - - if(WIN32) - set_target_properties(${THIS_BACKEND_TARGET} - PROPERTIES - OUTPUT_NAME ${THIS_BACKEND_OUTPUT_NAME} - DEFINE_SYMBOL SOCI_DLL) - else() - set_target_properties(${THIS_BACKEND_TARGET} - PROPERTIES - SOVERSION ${${PROJECT_NAME}_SOVERSION} - INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib) - - if(APPLE) - set_target_properties(${THIS_BACKEND_TARGET} - PROPERTIES - LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress") - endif() - endif() - - set_target_properties(${THIS_BACKEND_TARGET} - PROPERTIES - VERSION ${${PROJECT_NAME}_VERSION} - CLEAN_DIRECT_OUTPUT 1) - endif() - - # Static library target - if(SOCI_STATIC) - set(THIS_BACKEND_TARGET_STATIC ${THIS_BACKEND_TARGET}_static) - - add_library(${THIS_BACKEND_TARGET_STATIC} - STATIC - ${THIS_BACKEND_SOURCES} - ${THIS_BACKEND_HEADERS}) - add_library(Soci::${NAMEL}_static ALIAS ${THIS_BACKEND_TARGET_STATIC}) - - # Still need to link the libraries for tests to work - target_link_libraries (${THIS_BACKEND_TARGET_STATIC} - ${THIS_BACKEND_DEPENDS_LIBRARIES} - ) - - set_target_properties(${THIS_BACKEND_TARGET_STATIC} - PROPERTIES - OUTPUT_NAME ${THIS_BACKEND_OUTPUT_NAME} - PREFIX "lib" - CLEAN_DIRECT_OUTPUT 1) - endif() - - # Backend installation - install(FILES ${THIS_BACKEND_HEADERS} - DESTINATION - ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECTNAMEL}/${NAMEL}) - - if (SOCI_SHARED) - install(TARGETS ${THIS_BACKEND_TARGET} - EXPORT SOCI - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() - - if (SOCI_STATIC) - install(TARGETS ${THIS_BACKEND_TARGET_STATIC} - EXPORT SOCI - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) - endif() - - else() - colormsg(YELLOW "${NAME} backend explicitly disabled") - endif() - - endif() - - boost_report_value(${THIS_BACKEND_OPTION}) - - if(${THIS_BACKEND_OPTION}) - boost_report_value(${THIS_BACKEND_TARGET_VAR}) - boost_report_value(${THIS_BACKEND_OUTPUT_NAME_VAR}) - boost_report_value(${THIS_BACKEND_COMPILE_DEFINITIONS_VAR}) - boost_report_value(${THIS_BACKEND_INCLUDE_DIRECTORIES_VAR}) - endif() - - # LOG - #message("soci_backend:") - #message("NAME: ${NAME}") - #message("${THIS_BACKEND_OPTION} = ${SOCI_BACKEND_SQLITE3}") - #message("DEPENDS: ${THIS_BACKEND_DEPENDS}") - #message("DESCRIPTION: ${THIS_BACKEND_DESCRIPTION}") - #message("AUTHORS: ${THIS_BACKEND_AUTHORS}") - #message("MAINTAINERS: ${THIS_BACKEND_MAINTAINERS}") - #message("SOURCES: ${THIS_BACKEND_SOURCES}") - #message("DEPENDS_LIBRARIES: ${THIS_BACKEND_DEPENDS_LIBRARIES}") - #message("DEPENDS_INCLUDE_DIRS: ${THIS_BACKEND_DEPENDS_INCLUDE_DIRS}") -endmacro() - -# Generates .vcxproj.user for target of each test. -# -# soci_backend_test_create_vcxproj_user( -# PostgreSQLTest -# "host=localhost dbname=soci_test user=mloskot") -# -function(soci_backend_test_create_vcxproj_user TARGET_NAME TEST_CMD_ARGS) - if(MSVC) - set(SYSTEM_NAME $ENV{USERDOMAIN}) - set(USER_NAME $ENV{USERNAME}) - set(SOCI_TEST_CMD_ARGS ${TEST_CMD_ARGS}) - - if(MSVC_VERSION EQUAL 1600) - configure_file( - ${SOCI_SOURCE_DIR}/cmake/resources/vs2010-test-cmd-args.vcxproj.user.in - ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}.vcxproj.user - @ONLY) - endif() - endif() -endfunction(soci_backend_test_create_vcxproj_user) - -# Defines test project of a database backend for SOCI library -# -# soci_backend_test(BACKEND mybackend SOURCE mytest1.cpp -# NAME mytest1 -# CONNSTR "my test connection" -# DEPENDS library1 library2) -# -macro(soci_backend_test) - parse_arguments(THIS_TEST - "BACKEND;SOURCE;CONNSTR;NAME;DEPENDS;" - "" - ${ARGN}) - - # Test backend name - string(TOUPPER "${THIS_TEST_BACKEND}" BACKENDU) - string(TOLOWER "${THIS_TEST_BACKEND}" BACKENDL) - - if(SOCI_TESTS AND SOCI_${BACKENDU} AND NOT SOCI_${BACKENDU}_DO_NOT_TEST) - - # Test name - if(THIS_TEST_NAME) - string(TOUPPER "${THIS_TEST_NAME}" NAMEU) - set(TEST_FULL_NAME SOCI_${BACKENDU}_TEST_${NAMEU}) - else() - set(TEST_FULL_NAME SOCI_${BACKENDU}_TEST) - endif() - string(TOLOWER "${TEST_FULL_NAME}" TEST_TARGET) - string(TOUPPER "${TEST_FULL_NAME}" NAMEU) - - soci_backend_deps_found(${NAMEU} "${THIS_TEST_DEPENDS}" ${NAMEU}_DEPS_FOUND) - if(${NAMEU}_DEPS_FOUND) - get_directory_property(THIS_INCLUDE_DIRS INCLUDE_DIRECTORIES) - get_directory_property(THIS_COMPILE_DEFS COMPILE_DEFINITIONS) - - set(THIS_TEST_DEPENDS_INCLUDE_DIRS ${${NAMEU}_DEPS_INCLUDE_DIRS}) - set(THIS_TEST_DEPENDS_LIBRARIES ${${NAMEU}_DEPS_LIBRARIES}) - set(THIS_TEST_DEPENDS_DEFS ${${NAMEU}_DEPS_DEFS}) - - list(APPEND THIS_INCLUDE_DIRS ${THIS_TEST_DEPENDS_INCLUDE_DIRS}) - list(APPEND THIS_COMPILE_DEFS ${THIS_TEST_DEPENDS_DEFS}) - - set_directory_properties(PROPERTIES - INCLUDE_DIRECTORIES "${THIS_INCLUDE_DIRS}" - COMPILE_DEFINITIONS "${THIS_COMPILE_DEFS}") - else() - colormsg(_RED_ "WARNING: Some dependencies of ${THIS_TEST_BACKEND} test not found") - endif() - - set(TEST_CONNSTR_VAR ${TEST_FULL_NAME}_CONNSTR) - set(${TEST_CONNSTR_VAR} "" - CACHE STRING "Connection string for ${BACKENDU} test") - - if(NOT ${TEST_CONNSTR_VAR} AND THIS_TEST_CONNSTR) - set(${TEST_CONNSTR_VAR} ${THIS_TEST_CONNSTR}) - endif() - - boost_message_value(${TEST_CONNSTR_VAR}) - - if( SOCI_SHARED ) - # Shared libraries test - add_executable(${TEST_TARGET} ${THIS_TEST_SOURCE}) - - target_link_libraries(${TEST_TARGET} - ${SOCI_CORE_DEPS_LIBS} - ${THIS_TEST_DEPENDS_LIBRARIES} - soci_tests_common - soci_core - soci_${BACKENDL}) - - add_test(${TEST_TARGET} - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_TARGET} - ${${TEST_CONNSTR_VAR}} --invisibles) - - soci_backend_test_create_vcxproj_user(${TEST_TARGET} "\"${${TEST_CONNSTR_VAR}}\"") - - # Ask make check to try to build tests first before executing them - add_dependencies(check ${TEST_TARGET}) - endif(SOCI_SHARED) - - # Static libraries test - if(SOCI_STATIC) - set(TEST_TARGET_STATIC ${TEST_TARGET}_static) - - add_executable(${TEST_TARGET_STATIC} ${THIS_TEST_SOURCE}) - - target_link_libraries(${TEST_TARGET_STATIC} - ${SOCI_CORE_DEPS_LIBS} - ${THIS_TEST_DEPENDS_LIBRARIES} - soci_tests_common - soci_${BACKENDL}_static - soci_core_static) - - add_test(${TEST_TARGET_STATIC} - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_TARGET_STATIC} - ${${TEST_CONNSTR_VAR}} --invisibles) - - soci_backend_test_create_vcxproj_user(${TEST_TARGET_STATIC} "\"${${TEST_CONNSTR_VAR}}\"") - - # Ask make check to try to build tests first before executing them - add_dependencies(check ${TEST_TARGET_STATIC}) - endif(SOCI_STATIC) - - - - # Group source files for IDE source explorers (e.g. Visual Studio) - source_group("Source Files" FILES ${THIS_TEST_SOURCE}) - source_group("CMake Files" FILES CMakeLists.txt) - - endif() -endmacro() diff --git a/cmake/SociConfig.cmake b/cmake/SociConfig.cmake deleted file mode 100644 index 84cd13998..000000000 --- a/cmake/SociConfig.cmake +++ /dev/null @@ -1,101 +0,0 @@ -################################################################################ -# SociConfig.cmake - CMake build configuration of SOCI library -################################################################################ -# Copyright (C) 2010 Mateusz Loskot -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -################################################################################ - -include(CheckCXXSymbolExists) - -if(WIN32) - check_cxx_symbol_exists("_M_AMD64" "" SOCI_TARGET_ARCH_X64) - if(NOT RTC_ARCH_X64) - check_cxx_symbol_exists("_M_IX86" "" SOCI_TARGET_ARCH_X86) - endif(NOT RTC_ARCH_X64) - # add check for arm here - # see http://msdn.microsoft.com/en-us/library/b0084kay.aspx -else(WIN32) - check_cxx_symbol_exists("__i386__" "" SOCI_TARGET_ARCH_X86) - check_cxx_symbol_exists("__x86_64__" "" SOCI_TARGET_ARCH_X64) - check_cxx_symbol_exists("__arm__" "" SOCI_TARGET_ARCH_ARM) -endif(WIN32) - -if(NOT DEFINED LIB_SUFFIX) - if(SOCI_TARGET_ARCH_X64) - set(_lib_suffix "64") - else() - set(_lib_suffix "") - endif() - set(LIB_SUFFIX ${_lib_suffix} CACHE STRING "Specifies suffix for the lib directory") -endif() - -# -# Force compilation flags and set desired warnings level -# - -# This is used to set the -Werror compilation flag only when explicitly -# requested, as e.g. in CI builds. -set(SOCI_WERROR_OPTION "") - -if (MSVC) - add_definitions(-D_CRT_SECURE_NO_DEPRECATE) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) - add_definitions(-D_CRT_NONSTDC_NO_WARNING) - add_definitions(-D_SCL_SECURE_NO_WARNINGS) - - if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /we4266") - endif() - - if (SOCI_ENABLE_WERROR) - set(SOCI_WERROR_OPTION "/WX") - endif (SOCI_ENABLE_WERROR) -else() - - if (SOCI_ENABLE_WERROR) - set(SOCI_WERROR_OPTION "-Werror") - endif (SOCI_ENABLE_WERROR) - - set(SOCI_GCC_CLANG_COMMON_FLAGS - "-pedantic -Wno-error=parentheses -Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wfloat-equal -Woverloaded-virtual -Wredundant-decls -Wno-long-long") - - if(SOCI_UBSAN) - set(SOCI_GCC_CLANG_COMMON_FLAGS "${SOCI_GCC_CLANG_COMMON_FLAGS} -fsanitize=undefined") - endif() - - - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER}" MATCHES "clang") - - if(NOT CMAKE_CXX_COMPILER_VERSION LESS 3.1 AND SOCI_ASAN) - set(SOCI_GCC_CLANG_COMMON_FLAGS "${SOCI_GCC_CLANG_COMMON_FLAGS} -fsanitize=address") - endif() - - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SOCI_GCC_CLANG_COMMON_FLAGS}") - - elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - - if(NOT CMAKE_CXX_COMPILER_VERSION LESS 4.8 AND SOCI_ASAN) - set(SOCI_GCC_CLANG_COMMON_FLAGS "${SOCI_GCC_CLANG_COMMON_FLAGS} -fsanitize=address") - endif() - - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SOCI_GCC_CLANG_COMMON_FLAGS} ") - if (CMAKE_COMPILER_IS_GNUCXX) - if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macros") - endif() - endif() - - else() - message(WARNING "Unknown toolset - using default flags to build SOCI") - endif() - -endif() - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SOCI_WERROR_OPTION}") diff --git a/cmake/SociDependencies.cmake b/cmake/SociDependencies.cmake deleted file mode 100644 index 5f174a51f..000000000 --- a/cmake/SociDependencies.cmake +++ /dev/null @@ -1,101 +0,0 @@ -################################################################################ -# SociDependencies.cmake - part of CMake configuration of SOCI library -# -# Based on BoostExternals.cmake from CMake configuration for Boost -################################################################################ -# Copyright (C) 2010 Mateusz Loskot -# Copyright (C) 2009 Troy Straszheim -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -################################################################################ -# Macros in this module: -# -# soci_backend - defines a database backend for SOCI library -# -################################################################################ - -# -# List of SOCI dependncies -# -set(SOCI_CORE_DEPENDENCIES - Threads - Boost) - -set(SOCI_BACKENDS_DB_DEPENDENCIES - MySQL - ODBC - Oracle - PostgreSQL - SQLite3 - Firebird - DB2) - -set(SOCI_ALL_DEPENDENCIES - ${SOCI_CORE_DEPENDENCIES} - ${SOCI_BACKENDS_DB_DEPENDENCIES}) - -# -# Perform checks -# -colormsg(_HIBLUE_ "Looking for SOCI dependencies:") - -macro(boost_external_report NAME) - - set(VARNAME ${NAME}) - string(TOUPPER ${NAME} VARNAMEU) - - set(VARNAMES ${ARGV}) - list(REMOVE_AT VARNAMES 0) - - # Test both, given original name and uppercase version too - if(NOT ${VARNAME}_FOUND AND NOT ${VARNAMEU}_FOUND) - colormsg(_RED_ "WARNING: ${NAME} libraries not found, some features will be disabled.") - endif() - - foreach(variable ${VARNAMES}) - if(${VARNAMEU}_FOUND) - boost_report_value(${VARNAMEU}_${variable}) - elseif(${VARNAME}_FOUND) - boost_report_value(${VARNAME}_${variable}) - endif() - endforeach() -endmacro() - -# -# Some externals default to OFF -# -option(WITH_VALGRIND "Run tests under valgrind" OFF) - -# -# Detect available dependencies -# -foreach(external ${SOCI_ALL_DEPENDENCIES}) - string(TOUPPER "${external}" EXTERNAL) - - # For historical reasons we use both WITH_xxx and SOCI_xxx options, and - # setting either of them to e.g. OFF should disable the corresponding - # dependency. - option(WITH_${EXTERNAL} "Attempt to find and configure ${external}" ON) - option(SOCI_${EXTERNAL} "Attempt to build ${external} backend" ON) - - if(NOT WITH_${EXTERNAL}) - set(disabled_var "WITH") - elseif(NOT SOCI_${EXTERNAL}) - set(disabled_var "SOCI") - endif() - - if(NOT DEFINED disabled_var) - colormsg(HICYAN "${external}:") - include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies/${external}.cmake) - else() - set(${EXTERNAL}_FOUND FALSE CACHE BOOL "${external} found" FORCE) - colormsg(HICYAN "${external}:" YELLOW "disabled, since ${disabled_var}_${EXTERNAL}=OFF") - unset(disabled_var) - endif() - - if(NOT ${EXTERNAL}_FOUND) - set(SOCI_${EXTERNAL} OFF) - endif() -endforeach() diff --git a/cmake/SociUtilities.cmake b/cmake/SociUtilities.cmake deleted file mode 100644 index 627ecfb1f..000000000 --- a/cmake/SociUtilities.cmake +++ /dev/null @@ -1,436 +0,0 @@ -################################################################################ -# SociUtilities.cmake - part of CMake configuration of SOCI library -# -# Based on BoostUtilities.cmake from CMake configuration for Boost -################################################################################ -# Copyright (C) 2007 Douglas Gregor -# Copyright (C) 2007 Troy Straszheim -# Copyright (C) 2010-2013 Mateusz Loskot -# -# Distributed under the Boost Software License, Version 1.0. -# See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt -################################################################################ -# Macros in this module: -# -# list_contains: Determine whether a string value is in a list. -# -# car: Return the first element in a list -# -# cdr: Return all but the first element in a list -# -# parse_arguments: Parse keyword arguments for use in other macros. -# -# soci_check_package_found: Test varname-FOUND for case-insensitive varname -# -################################################################################ - -# This utility macro determines whether a particular string value -# occurs within a list of strings: -# -# list_contains(result string_to_find arg1 arg2 arg3 ... argn) -# -# This macro sets the variable named by result equal to TRUE if -# string_to_find is found anywhere in the following arguments. -macro(list_contains var value) - set(${var}) - foreach (value2 ${ARGN}) - if (${value} STREQUAL ${value2}) - set(${var} TRUE) - endif (${value} STREQUAL ${value2}) - endforeach (value2) -endmacro(list_contains) - -# This utility macro extracts the first argument from the list of -# arguments given, and places it into the variable named var. -# -# car(var arg1 arg2 ...) -macro(car var) - set(${var} ${ARGV1}) -endmacro(car) - -# This utility macro extracts all of the arguments given except the -# first, and places them into the variable named var. -# -# car(var arg1 arg2 ...) -macro(cdr var junk) - set(${var} ${ARGN}) -endmacro(cdr) - -# The parse_arguments macro will take the arguments of another macro and -# define several variables. The first argument to parse_arguments is a -# prefix to put on all variables it creates. The second argument is a -# list of names, and the third argument is a list of options. Both of -# these lists should be quoted. The rest of parse_arguments are -# arguments from another macro to be parsed. -# -# parse_arguments(prefix arg_names options arg1 arg2...) -# -# For each item in options, parse_arguments will create a variable with -# that name, prefixed with prefix_. So, for example, if prefix is -# MY_MACRO and options is OPTION1;OPTION2, then parse_arguments will -# create the variables MY_MACRO_OPTION1 and MY_MACRO_OPTION2. These -# variables will be set to true if the option exists in the command line -# or false otherwise. -# -# For each item in arg_names, parse_arguments will create a variable -# with that name, prefixed with prefix_. Each variable will be filled -# with the arguments that occur after the given arg_name is encountered -# up to the next arg_name or the end of the arguments. All options are -# removed from these lists. parse_arguments also creates a -# prefix_DEFAULT_ARGS variable containing the list of all arguments up -# to the first arg_name encountered. -macro(parse_arguments prefix arg_names option_names) - set(DEFAULT_ARGS) - foreach(arg_name ${arg_names}) - set(${prefix}_${arg_name}) - endforeach(arg_name) - foreach(option ${option_names}) - set(${prefix}_${option} FALSE) - endforeach(option) - - set(current_arg_name DEFAULT_ARGS) - set(current_arg_list) - foreach(arg ${ARGN}) - list_contains(is_arg_name ${arg} ${arg_names}) - if (is_arg_name) - set(${prefix}_${current_arg_name} ${current_arg_list}) - set(current_arg_name ${arg}) - set(current_arg_list) - else (is_arg_name) - list_contains(is_option ${arg} ${option_names}) - if (is_option) - set(${prefix}_${arg} TRUE) - else (is_option) - set(current_arg_list ${current_arg_list} ${arg}) - endif (is_option) - endif (is_arg_name) - endforeach(arg) - set(${prefix}_${current_arg_name} ${current_arg_list}) -endmacro(parse_arguments) - -# Perform a reverse topological sort on the given LIST. -# -# topological_sort(my_list "MY_" "_EDGES") -# -# LIST is the name of a variable containing a list of elements to be -# sorted in reverse topological order. Each element in the list has a -# set of outgoing edges (for example, those other list elements that -# it depends on). In the resulting reverse topological ordering -# (written back into the variable named LIST), an element will come -# later in the list than any of the elements that can be reached by -# following its outgoing edges and the outgoing edges of any vertices -# they target, recursively. Thus, if the edges represent dependencies -# on build targets, for example, the reverse topological ordering is -# the order in which one would build those targets. -# -# For each element E in this list, the edges for E are contained in -# the variable named ${PREFIX}${E}${SUFFIX}, where E is the -# upper-cased version of the element in the list. If no such variable -# exists, then it is assumed that there are no edges. For example, if -# my_list contains a, b, and c, one could provide a dependency graph -# using the following variables: -# -# MY_A_EDGES b -# MY_B_EDGES -# MY_C_EDGES a b -# -# With the involcation of topological_sort shown above and these -# variables, the resulting reverse topological ordering will be b, a, -# c. -function(topological_sort LIST PREFIX SUFFIX) - # Clear the stack and output variable - set(VERTICES "${${LIST}}") - set(STACK) - set(${LIST}) - - # Loop over all of the vertices, starting the topological sort from - # each one. - foreach(VERTEX ${VERTICES}) - string(TOUPPER ${VERTEX} UPPER_VERTEX) - - # If we haven't already processed this vertex, start a depth-first - # search from where. - if (NOT FOUND_${UPPER_VERTEX}) - # Push this vertex onto the stack with all of its outgoing edges - string(REPLACE ";" " " NEW_ELEMENT - "${VERTEX};${${PREFIX}${UPPER_VERTEX}${SUFFIX}}") - list(APPEND STACK ${NEW_ELEMENT}) - - # We've now seen this vertex - set(FOUND_${UPPER_VERTEX} TRUE) - - # While the depth-first search stack is not empty - list(LENGTH STACK STACK_LENGTH) - while(STACK_LENGTH GREATER 0) - # Remove the vertex and its remaining out-edges from the top - # of the stack - list(GET STACK -1 OUT_EDGES) - list(REMOVE_AT STACK -1) - - # Get the source vertex and the list of out-edges - separate_arguments(OUT_EDGES) - list(GET OUT_EDGES 0 SOURCE) - list(REMOVE_AT OUT_EDGES 0) - - # While there are still out-edges remaining - list(LENGTH OUT_EDGES OUT_DEGREE) - while (OUT_DEGREE GREATER 0) - # Pull off the first outgoing edge - list(GET OUT_EDGES 0 TARGET) - list(REMOVE_AT OUT_EDGES 0) - - string(TOUPPER ${TARGET} UPPER_TARGET) - if (NOT FOUND_${UPPER_TARGET}) - # We have not seen the target before, so we will traverse - # its outgoing edges before coming back to our - # source. This is the key to the depth-first traversal. - - # We've now seen this vertex - set(FOUND_${UPPER_TARGET} TRUE) - - # Push the remaining edges for the current vertex onto the - # stack - string(REPLACE ";" " " NEW_ELEMENT - "${SOURCE};${OUT_EDGES}") - list(APPEND STACK ${NEW_ELEMENT}) - - # Setup the new source and outgoing edges - set(SOURCE ${TARGET}) - string(TOUPPER ${SOURCE} UPPER_SOURCE) - set(OUT_EDGES - ${${PREFIX}${UPPER_SOURCE}${SUFFIX}}) - endif(NOT FOUND_${UPPER_TARGET}) - - list(LENGTH OUT_EDGES OUT_DEGREE) - endwhile (OUT_DEGREE GREATER 0) - - # We have finished all of the outgoing edges for - # SOURCE; add it to the resulting list. - list(APPEND ${LIST} ${SOURCE}) - - # Check the length of the stack - list(LENGTH STACK STACK_LENGTH) - endwhile(STACK_LENGTH GREATER 0) - endif (NOT FOUND_${UPPER_VERTEX}) - endforeach(VERTEX) - - set(${LIST} ${${LIST}} PARENT_SCOPE) -endfunction(topological_sort) - -# Small little hack that tweaks a component name (as used for CPack) -# to make sure to avoid certain names that cause problems. Sets the -# variable named varname to the "sanitized" name. -# -# FIXME: This is a complete hack. We probably need to fix the CPack -# generators (NSIS in particular) to get rid of the need for this. -macro(fix_cpack_component_name varname name) - if (${name} STREQUAL "foreach") - set(${varname} "boost_foreach") - else() - set(${varname} ${name}) - endif() -endmacro() - - -# -# A big shout out to the cmake gurus @ compiz -# -function (colormsg) - string (ASCII 27 _escape) - set(WHITE "29") - set(GRAY "30") - set(RED "31") - set(GREEN "32") - set(YELLOW "33") - set(BLUE "34") - set(MAG "35") - set(CYAN "36") - - foreach (color WHITE GRAY RED GREEN YELLOW BLUE MAG CYAN) - set(HI${color} "1\;${${color}}") - set(LO${color} "2\;${${color}}") - set(_${color}_ "4\;${${color}}") - set(_HI${color}_ "1\;4\;${${color}}") - set(_LO${color}_ "2\;4\;${${color}}") - endforeach() - - set(str "") - set(coloron FALSE) - foreach(arg ${ARGV}) - if (NOT ${${arg}} STREQUAL "") - if (CMAKE_COLOR_DIAGNOSTICS) - set(str "${str}${_escape}[${${arg}}m") - set(coloron TRUE) - endif() - else() - set(str "${str}${arg}") - if (coloron) - set(str "${str}${_escape}[0m") - set(coloron FALSE) - endif() - set(str "${str} ") - endif() - endforeach() - message(STATUS ${str}) -endfunction() - -# colormsg("Colors:" -# WHITE "white" GRAY "gray" GREEN "green" -# RED "red" YELLOW "yellow" BLUE "blue" MAG "mag" CYAN "cyan" -# _WHITE_ "white" _GRAY_ "gray" _GREEN_ "green" -# _RED_ "red" _YELLOW_ "yellow" _BLUE_ "blue" _MAG_ "mag" _CYAN_ "cyan" -# _HIWHITE_ "white" _HIGRAY_ "gray" _HIGREEN_ "green" -# _HIRED_ "red" _HIYELLOW_ "yellow" _HIBLUE_ "blue" _HIMAG_ "mag" _HICYAN_ "cyan" -# HIWHITE "white" HIGRAY "gray" HIGREEN "green" -# HIRED "red" HIYELLOW "yellow" HIBLUE "blue" HIMAG "mag" HICYAN "cyan" -# "right?") - -# -# pretty-prints the value of a variable so that the -# equals signs align -# -function(boost_report_value NAME) - string(LENGTH "${NAME}" varlen) - # LOG - #message(STATUS "boost_report_value: NAME=${NAME} (${varlen})") - #message(STATUS "boost_report_value: \${NAME}=${${NAME}}") - math(EXPR padding_len 40-${varlen}) - string(SUBSTRING " " - 0 ${padding_len} varpadding) - colormsg("${NAME}${varpadding} = ${${NAME}}") -endfunction() - -function(boost_message_value NAME) - string(LENGTH "${NAME}" varlen) - math(EXPR padding_len 40-${varlen}) - string(SUBSTRING " " - 0 ${padding_len} varpadding) - message(STATUS "${NAME}${varpadding} = ${${NAME}}") -endfunction() - -function(trace NAME) - if(BOOST_CMAKE_TRACE) - string(LENGTH "${NAME}" varlen) - math(EXPR padding_len 40-${varlen}) - string(SUBSTRING "........................................" - 0 ${padding_len} varpadding) - message("${NAME} ${varpadding} ${${NAME}}") - endif() -endfunction() - -# -# pretty-prints the value of a variable so that the -# equals signs align -# -function(boost_report_pretty PRETTYNAME VARNAME) - string(LENGTH "${PRETTYNAME}" varlen) - math(EXPR padding_len 30-${varlen}) - string(SUBSTRING " " - 0 ${padding_len} varpadding) - message(STATUS "${PRETTYNAME}${varpadding} = ${${VARNAME}}") -endfunction() - -# -# assert that ARG is actually a library target -# -macro(dependency_check ARG) - trace(ARG) - if (NOT "${ARG}" STREQUAL "") - get_target_property(deptype ${ARG} TYPE) - if(NOT deptype MATCHES ".*_LIBRARY$") - set(DEPENDENCY_OKAY FALSE) - list(APPEND DEPENDENCY_FAILURES ${ARG}) - endif() - endif() -endmacro() - -# -# Tests package-FOUND for varname in three cases as given, lowercase and -# uppercase. -# -macro(soci_check_package_found NAME SUCCESS) - - set(${SUCCESS} FALSE) - set(VARNAME ${NAME}) - set(VARNAME_SUCCESS ${${VARNAME}_FOUND}) - - # Test both, given original name and uppercase version too - if(VARNAME_SUCCESS) - set(${SUCCESS} TRUE) - else() - string(TOUPPER ${NAME} VARNAME) - set(VARNAME_SUCCESS ${${VARNAME}_FOUND}) - if(VARNAME_SUCCESS) - set(${SUCCESS} TRUE) - endif() - endif() - - #message(STATUS "soci_check_package_found: ${SUCCESS}=${${SUCCESS}}") -endmacro() - -# -# Pretty-print of given property of current directory. -# -function(soci_report_directory_property PROPNAME) - get_directory_property(${PROPNAME} ${PROPNAME}) - boost_report_value(${PROPNAME}) -endfunction() - -# -# Scans the current directory and returns a list of subdirectories. -# Author: Robert Fleming -# Source: http://www.cmake.org/pipermail/cmake/2008-February/020114.html -# -# Third parameter is 1 if you want relative paths returned. -# Usage: list_subdirectories(the_list_is_returned_here /path/to/project TRUE) -# -macro(list_subdirectories retval curdir return_relative) - file(GLOB sub-dir RELATIVE ${curdir} *) - set(list_of_dirs "") - foreach(dir ${sub-dir}) - if(IS_DIRECTORY ${curdir}/${dir}) - if (${return_relative}) - set(list_of_dirs ${list_of_dirs} ${dir}) - else() - set(list_of_dirs ${list_of_dirs} ${curdir}/${dir}) - endif() - endif() - endforeach() - set(${retval} ${list_of_dirs}) -endmacro() - -# -# Generates output name for given target depending on platform and version. -# For instance, on Windows, libraries get ABI version suffix soci_coreXY.{dll|lib}. -# -function(soci_target_output_name TARGET_NAME OUTPUT_NAME) - if(NOT DEFINED TARGET_NAME) - message(SEND_ERROR "Error, the variable TARGET_NAME is not defined!") - endif() - - if(NOT DEFINED ${PROJECT_NAME}_VERSION) - message(SEND_ERROR "Error, the variable ${${PROJECT_NAME}_VERSION} is not defined!") - endif() - - # On Windows, ABI version is specified using binary file name suffix. - # On Unix, suffix is empty and SOVERSION is used instead. - if (WIN32) - string(LENGTH "${${PROJECT_NAME}_ABI_VERSION}" abilen) - if(abilen GREATER 0) - set(SUFFIX "_${${PROJECT_NAME}_ABI_VERSION}") - endif() - endif() - - set(${OUTPUT_NAME} ${TARGET_NAME}${SUFFIX} PARENT_SCOPE) -endfunction() - -# Check if the given linker is supported and use it if it is. -function(soci_use_ld_if_supported ld) - include(CheckCXXCompilerFlag) - set(ld_flag "-fuse-ld=${ld}") - check_cxx_compiler_flag(${ld_flag} can_use_ld) - if (can_use_ld) - add_link_options(${ld_flag}) - endif() -endfunction() diff --git a/cmake/SociVersion.cmake b/cmake/SociVersion.cmake deleted file mode 100644 index 5c8b5d75a..000000000 --- a/cmake/SociVersion.cmake +++ /dev/null @@ -1,62 +0,0 @@ -################################################################################ -# SociVersion.cmake - part of CMake configuration of SOCI library -################################################################################ -# Copyright (C) 2010 Mateusz Loskot -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -################################################################################ -# Macros in this module: -# -# soci_version - defines version information for SOCI library -# -################################################################################ - -# Defines version information for SOCI library -# -# soci_version(MAJOR major_version MINOR minor_version PATCH patch_level) -# -# MAJOR.MINOR version is used to set SOVERSION -# -macro(soci_version) - # get version from soci/version.h - file( - STRINGS - "${PROJECT_SOURCE_DIR}/include/soci/version.h" - _VERSION - REGEX - "#define SOCI_VERSION ([0-9]+)" - ) - string(REGEX MATCH "([0-9]+)" _VERSION "${_VERSION}") - - math(EXPR ${PROJECT_NAME}_VERSION_MAJOR "${_VERSION} / 100000") - math(EXPR ${PROJECT_NAME}_VERSION_MINOR "${_VERSION} / 100 % 1000") - math(EXPR ${PROJECT_NAME}_VERSION_PATCH "${_VERSION} % 100") - - # Set VERSION string - set(${PROJECT_NAME}_VERSION - "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}") - - # Set SOVERSION based on major and minor - set(${PROJECT_NAME}_SOVERSION - "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}") - - # Set ABI version string used to name binary output and, by SOCI loader, to find binaries. - # On Windows, ABI version is specified using binary file name suffix. - # On Unix, suffix ix empty and SOVERSION is used instead. - if (UNIX) - set(${PROJECT_NAME}_ABI_VERSION ${${PROJECT_NAME}_SOVERSION}) - elseif(WIN32) - set(${PROJECT_NAME}_ABI_VERSION - "${${PROJECT_NAME}_VERSION_MAJOR}_${${PROJECT_NAME}_VERSION_MINOR}") - else() - message(FATAL_ERROR "Ambiguous target platform with unknown ABI version scheme. Giving up.") - endif() - - boost_report_value(${PROJECT_NAME}_VERSION) - boost_report_value(${PROJECT_NAME}_ABI_VERSION) - - add_definitions(-DSOCI_ABI_VERSION="${${PROJECT_NAME}_ABI_VERSION}") - -endmacro() diff --git a/cmake/configs/test-access.cmake b/cmake/configs/test-access.cmake deleted file mode 100644 index abc44deb0..000000000 --- a/cmake/configs/test-access.cmake +++ /dev/null @@ -1,13 +0,0 @@ -[ODBC] -DRIVER=Microsoft Access Driver (*.mdb, *.accdb) -UID=admin -UserCommitSync=Yes -Threads=3 -SafeTransactions=0 -PageTimeout=5 -MaxScanRows=8 -MaxBufferSize=2048 -FIL=MS Access -DriverId=25 -DefaultDir=@TEST_ACCESS_PATH@\tests\odbc -DBQ=@TEST_ACCESS_PATH@\tests\odbc\soci_test.mdb diff --git a/cmake/configs/test-mysql.cmake b/cmake/configs/test-mysql.cmake deleted file mode 100644 index 48e54033d..000000000 --- a/cmake/configs/test-mysql.cmake +++ /dev/null @@ -1,4 +0,0 @@ -[ODBC] -DRIVER=@MYSQL_DRIVER_NAME@ -DATABASE=soci_test -OPTION=0 diff --git a/cmake/dependencies/Boost.cmake b/cmake/dependencies/Boost.cmake deleted file mode 100644 index 366d32b74..000000000 --- a/cmake/dependencies/Boost.cmake +++ /dev/null @@ -1,13 +0,0 @@ -set(Boost_FIND_QUIETLY TRUE) - -set(Boost_USE_MULTITHREADED ON) -find_package(Boost 1.33.1 COMPONENTS date_time) - -if (NOT Boost_DATE_TIME_FOUND) - find_package(Boost 1.33.1) -endif() - -set(Boost_RELEASE_VERSION - "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") - -boost_external_report(Boost RELEASE_VERSION INCLUDE_DIR LIBRARIES) diff --git a/cmake/dependencies/DB2.cmake b/cmake/dependencies/DB2.cmake deleted file mode 100644 index 063f1a17d..000000000 --- a/cmake/dependencies/DB2.cmake +++ /dev/null @@ -1,5 +0,0 @@ -set(DB2_FIND_QUIETLY TRUE) - -find_package(DB2) - -boost_external_report(DB2 INCLUDE_DIR LIBRARIES) diff --git a/cmake/dependencies/Firebird.cmake b/cmake/dependencies/Firebird.cmake deleted file mode 100644 index b072702b0..000000000 --- a/cmake/dependencies/Firebird.cmake +++ /dev/null @@ -1,9 +0,0 @@ -option(SOCI_FIREBIRD_EMBEDDED "Use embedded library in Firebird backend" OFF) -boost_report_value(SOCI_FIREBIRD_EMBEDDED) - -set(Firebird_FIND_QUIETLY TRUE) - -find_package(Firebird) - -boost_external_report(Firebird INCLUDE_DIR LIBRARIES VERSION) - diff --git a/cmake/dependencies/MySQL.cmake b/cmake/dependencies/MySQL.cmake deleted file mode 100644 index 5599b0885..000000000 --- a/cmake/dependencies/MySQL.cmake +++ /dev/null @@ -1,5 +0,0 @@ -set(MySQL_FIND_QUIETLY TRUE) - -find_package(MySQL) - -boost_external_report(MySQL INCLUDE_DIR LIBRARIES) diff --git a/cmake/dependencies/ODBC.cmake b/cmake/dependencies/ODBC.cmake deleted file mode 100644 index 88b85a1c5..000000000 --- a/cmake/dependencies/ODBC.cmake +++ /dev/null @@ -1,5 +0,0 @@ -set(ODBC_FIND_QUIETLY TRUE) - -find_package(ODBC) - -boost_external_report(ODBC INCLUDE_DIR LIBRARIES) diff --git a/cmake/dependencies/Oracle.cmake b/cmake/dependencies/Oracle.cmake deleted file mode 100644 index 32cc649ea..000000000 --- a/cmake/dependencies/Oracle.cmake +++ /dev/null @@ -1,5 +0,0 @@ -set(Oracle_FIND_QUIETLY TRUE) - -find_package(Oracle) - -boost_external_report(Oracle INCLUDE_DIR LIBRARIES) diff --git a/cmake/dependencies/PostgreSQL.cmake b/cmake/dependencies/PostgreSQL.cmake deleted file mode 100644 index c6f215425..000000000 --- a/cmake/dependencies/PostgreSQL.cmake +++ /dev/null @@ -1,5 +0,0 @@ -set(PostgreSQL_FIND_QUIETLY TRUE) - -find_package(PostgreSQL) - -boost_external_report(PostgreSQL INCLUDE_DIRS LIBRARIES VERSION) diff --git a/cmake/dependencies/SQLite3.cmake b/cmake/dependencies/SQLite3.cmake deleted file mode 100644 index 37f57f614..000000000 --- a/cmake/dependencies/SQLite3.cmake +++ /dev/null @@ -1,5 +0,0 @@ -set(SQLite3_FIND_QUIETLY TRUE) - -find_package(SQLite3) - -boost_external_report(SQLite3 INCLUDE_DIR LIBRARIES) diff --git a/cmake/dependencies/Threads.cmake b/cmake/dependencies/Threads.cmake deleted file mode 100644 index 6a5487554..000000000 --- a/cmake/dependencies/Threads.cmake +++ /dev/null @@ -1,4 +0,0 @@ -set(Threads_FIND_QUIETLY TRUE) - -find_package(Threads) -boost_report_value(CMAKE_THREAD_LIBS_INIT) diff --git a/cmake/modules/FindDB2.cmake b/cmake/find_modules/FindDB2.cmake similarity index 82% rename from cmake/modules/FindDB2.cmake rename to cmake/find_modules/FindDB2.cmake index a752f1110..b786d4374 100644 --- a/cmake/modules/FindDB2.cmake +++ b/cmake/find_modules/FindDB2.cmake @@ -3,9 +3,8 @@ # # On success, the macro sets the following variables: # DB2_FOUND = if the library found -# DB2_LIBRARY = full path to the library # DB2_LIBRARIES = full path to the library -# DB2_INCLUDE_DIR = where to find the library headers +# DB2_INCLUDE_DIRS = where to find the library headers # # Copyright (c) 2013 Denis Chapligin # @@ -70,14 +69,15 @@ elseif(WIN32) endif() endif() -find_path(DB2_INCLUDE_DIR sqlcli1.h +find_path(DB2_INCLUDE_DIRS sqlcli1.h $ENV{DB2_INCLUDE_DIR} + $ENV{DB2_INCLUDE_DIRS} $ENV{DB2_DIR}/include $ENV{DB2_HOME} $ENV{IBM_DB_INCLUDE} ${DB2_FIND_INCLUDE_PATHS}) -find_library(DB2_LIBRARY +find_library(DB2_LIBRARIES NAMES db2 db2api PATHS $ENV{DB2LIB} @@ -85,22 +85,16 @@ find_library(DB2_LIBRARY ${DB2_FIND_LIB_PATHS} ${DB2_FIND_LIB_NO_LIB}) -if(DB2_LIBRARY) - get_filename_component(DB2_LIBRARY_DIR ${DB2_LIBRARY} PATH) +if(DB2_LIBRARIES) + get_filename_component(DB2_LIBRARY_DIR ${DB2_LIBRARIES} PATH) endif() -if(DB2_INCLUDE_DIR AND DB2_LIBRARY_DIR) - set(DB2_FOUND TRUE) -endif() - -set(DB2_LIBRARIES ${DB2_LIBRARY}) - -# Handle the QUIETLY and REQUIRED arguments and set DB2_FOUND to TRUE -# if all listed variables are TRUE include(FindPackageHandleStandardArgs) find_package_handle_standard_args(DB2 - DEFAULT_MSG - DB2_INCLUDE_DIR - DB2_LIBRARIES) + REQUIRED_VARS DB2_INCLUDE_DIRS DB2_LIBRARIES +) -mark_as_advanced(DB2_INCLUDE_DIR DB2_LIBRARIES) +add_library(DB2 INTERFACE) +target_link_libraries(DB2 INTERFACE ${DB2_LIBRARIES}) +target_include_directories(DB2 SYSTEM INTERFACE ${DB2_INCLUDE_DIRS}) +add_library(DB2::DB2 ALIAS DB2) diff --git a/cmake/find_modules/FindFirebird.cmake b/cmake/find_modules/FindFirebird.cmake new file mode 100644 index 000000000..9a55a5742 --- /dev/null +++ b/cmake/find_modules/FindFirebird.cmake @@ -0,0 +1,39 @@ +############################################################## +# Copyright (c) 2008 Daniel Pfeifer # +# # +# Distributed under the Boost Software License, Version 1.0. # +############################################################## + +# This module defines +# Firebird_INCLUDE_DIRS - where to find ibase.h +# Firebird_LIBRARIES - the libraries to link against to use Firebird +# Firebird_FOUND - true if Firebird was found + +find_path(Firebird_INCLUDE_DIRS ibase.h + /usr/include + $ENV{ProgramFiles}/Firebird/*/include +) + +if (Firebird_SEARCH_EMBEDDED) + set(Firebird_LIB_NAMES fbembed) +else() + set(Firebird_LIB_NAMES fbclient fbclient_ms) +endif() + +find_library(Firebird_LIBRARIES + NAMES + ${Firebird_LIB_NAMES} + PATHS + /usr/lib + $ENV{ProgramFiles}/Firebird/*/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Firebird + REQUIRED_VARS Firebird_LIBRARIES Firebird_INCLUDE_DIRS +) + +add_library(Firebird INTERFACE) +target_link_libraries(Firebird INTERFACE ${Firebird_LIBRARIES}) +target_include_directories(Firebird SYSTEM INTERFACE ${Firebird_INCLUDE_DIRS}) +add_library(Firebird::Firebird ALIAS Firebird) diff --git a/cmake/find_modules/FindMySQL.cmake b/cmake/find_modules/FindMySQL.cmake new file mode 100644 index 000000000..e85b19d4d --- /dev/null +++ b/cmake/find_modules/FindMySQL.cmake @@ -0,0 +1,178 @@ +# - Try to find MariaDB / MySQL library +# Find the MySQL includes and client library +# This module defines +# MySQL_FOUND +# An interface target MySQL::MySQL to be used in a target_link_libraries call + + +if (DEFINED VCPKG_TARGET_TRIPLET) + # In vcpg the MySQL packages are called unofficial-libmysql + find_package(unofficial-libmysql) + + set(FOUND_VAR "unofficial-libmysql_FOUND") + set(LIBRARY_TARGET "unofficial::libmysql::libmysql") + + if (NOT ${FOUND_VAR}) + find_package(unofficial-libmariadb QUIET) + set(FOUND_VAR "unofficial-libmariadb_FOUND") + set(LIBRARY_TARGET "unofficial::libmariadb::libmariadb") + endif() + + if (${FOUND_VAR}) + set(MySQL_FOUND TRUE) + message(STATUS "Found MySQL via vcpkg installation") + add_library(MySQL::MySQL ALIAS ${LIBRARY_TARGET}) + return() + endif() +endif() + +find_package(PkgConfig QUIET) + +if (PKG_CONFIG_FOUND) + # Try via PkgConfig + pkg_check_modules(MYSQLCLIENT QUIET mysqlclient) + + if (MYSQLCLIENT_FOUND) + if (NOT BUILD_SHARED_LIBS AND MYSQLCLIENT_STATIC_FOUND) + set(PREFIX MYSQLCLIENT_STATIC) + else() + set(PREFIX MYSQLCLIENT) + endif() + + set(MySQL_LIBRARIES ${${PREFIX}_LINK_LIBRARIES}) + set(MySQL_LDFLAGS ${${PREFIX}_LDFLAGS} ${${PREFIX}_LDFLAGS_OTHER}) + set(MySQL_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${PREFIX}_INCLUDE_DIRS_OTHER}) + set(MySQL_CFLAGS ${${PREFIX}_CFLAGS} ${${PREFIX}_CFLAGS_OTHER}) + set(MySQL_VERSION ${MYSQLCLIENT_VERSION}) + endif() +endif() + +if (NOT MySQL_LIBRARIES) + # Try using config exe + find_program(CONFIG_EXE + NAMES + mysql_config mariadb_config + PATHS + $ENV{MYSQL_DIR} + $ENV{MYSQL_DIRS} + $ENV{ProgramFiles}/MySQL/ + $ENV{ProgramFiles}/MariaDB/ + ) + + if (CONFIG_EXE) + execute_process(COMMAND ${CONFIG_EXE} --include OUTPUT_VARIABLE MySQL_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${CONFIG_EXE} --libs OUTPUT_VARIABLE MySQL_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${CONFIG_EXE} --version OUTPUT_VARIABLE MySQL_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() +endif() + +if (NOT MySQL_LIBRARIES) + message(WARNING "Falling back to manual MySQL search -> this might miss dependencies") + set(MySQL_COMPILE_DEFINITIONS "") + + include(CheckCXXSourceCompiles) + + foreach(TOP_LEVEL_DIR IN ITEMS "mysql/" "") + if(WIN32) + find_path(MySQL_INCLUDE_DIRS ${TOP_LEVEL_DIR}mysql.h + PATHS + $ENV{MYSQL_INCLUDE_DIR} + $ENV{MYSQL_INCLUDE_DIRS} + $ENV{MYSQL_DIR}/include + $ENV{MYSQL_DIRS}/include + $ENV{ProgramFiles}/MySQL/*/include + $ENV{SystemDrive}/MySQL/*/include + $ENV{ProgramW6432}/MySQL/*/include + ) + else() + find_path(MySQL_INCLUDE_DIRS ${TOP_LEVEL_DIR}mysql.h + PATHS + $ENV{MYSQL_INCLUDE_DIR} + $ENV{MYSQL_INCLUDE_DIRS} + $ENV{MYSQL_DIR}/include + $ENV{MYSQL_DIRS}/include + PATH_SUFFIXES + mariadb + mysql + ) + endif() + + if (MySQL_INCLUDE_DIRS) + if (TOP_LEVEL_DIR STREQUAL "") + list(APPEND MySQL_COMPILE_DEFINITIONS SOCI_MYSQL_DIRECT_INCLUDE) + set(VERSION_FILE "${MySQL_INCLUDE_DIRS}/mysql_version.h") + else() + set(VERSION_FILE "${MySQL_INCLUDE_DIRS}/mysql/mysql_version.h") + endif() + + # Parse out MySQL version + file(READ "${VERSION_FILE}" VERSION_CONTENT) + string(REGEX MATCH "#define[ \t]+LIBMYSQL_VERSION[ \t]+\"([^\"]+)\"" VERSION_CONTENT "${VERSION_CONTENT}") + set(MySQL_VERSION "${CMAKE_MATCH_1}") + + break() + endif() + endforeach() + + if(WIN32) + if (${CMAKE_BUILD_TYPE}) + string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER) + endif() + + # path suffix for debug/release mode + # binary_dist: mysql binary distribution + # build_dist: custom build + if(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug") + set(binary_dist debug) + set(build_dist Debug) + else() + list(APPEND MySQL_COMPILE_DEFINITIONS DBUG_OFF) + set(binary_dist opt) + set(build_dist Release) + endif() + + set(MySQL_LIB_PATHS + $ENV{MYSQL_DIR}/lib/${binary_dist} + $ENV{MYSQL_DIR}/libmysql/${build_dist} + $ENV{MYSQL_DIR}/client/${build_dist} + $ENV{ProgramFiles}/MySQL/*/lib/${binary_dist} + $ENV{SystemDrive}/MySQL/*/lib/${binary_dist} + $ENV{MYSQL_DIR}/lib/opt + $ENV{MYSQL_DIR}/client/release + $ENV{ProgramFiles}/MySQL/*/lib/opt + $ENV{SystemDrive}/MySQL/*/lib/opt + $ENV{ProgramW6432}/MySQL/*/lib + ) + find_library(MySQL_LIBRARIES NAMES libmysql + PATHS + ${MySQL_LIB_PATHS} + ) + else() + set(MySQL_LIB_PATHS + $ENV{MySQL_DIR}/lib + PATH_SUFFIXES + mariadb + mysql + ) + find_library(MySQL_LIBRARIES NAMES mariadbclient mysqlclient + PATHS + ${MySQL_LIB_PATHS} + ) + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MySQL + REQUIRED_VARS MySQL_LIBRARIES MySQL_INCLUDE_DIRS + VERSION_VAR MySQL_VERSION +) + +if (MySQL_FOUND) + add_library(MySQL INTERFACE) + target_link_libraries(MySQL INTERFACE ${MySQL_LIBRARIES}) + target_include_directories(MySQL SYSTEM INTERFACE ${MySQL_INCLUDE_DIRS}) + target_compile_options(MySQL INTERFACE ${MySQL_CFLAGS}) + target_link_options(MySQL INTERFACE ${MySQL_LDFLAGS}) + target_compile_definitions(MySQL INTERFACE ${MySQL_COMPILE_DEFINITIONS}) + add_library(MySQL::MySQL ALIAS MySQL) +endif() diff --git a/cmake/find_modules/FindOracle.cmake b/cmake/find_modules/FindOracle.cmake new file mode 100644 index 000000000..b6cd10ff5 --- /dev/null +++ b/cmake/find_modules/FindOracle.cmake @@ -0,0 +1,96 @@ +############################################################################### +# +# CMake module to search for Oracle client library (OCI) +# +# On success, the macro sets the following variables: +# Oracle_FOUND = if the library found +# Oracle_LIBRARY = full path to the library +# Oracle_LIBRARIES = full path to the library +# Oracle_INCLUDE_DIRS = where to find the library headers also defined, +# but not for general use are +# Oracle_VERSION = version of library which was found, e.g. "1.2.5" +# +# Copyright (c) 2009-2013 Mateusz Loskot +# +# Developed with inspiration from Petr Vanek +# who wrote similar macro for TOra - http://torasql.com/ +# +# Module source: http://github.com/mloskot/workshop/tree/master/cmake/ +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# +############################################################################### + +# First check for CMAKE variable +if(NOT ORACLE_HOME AND NOT Oracle_HOME) + if(EXISTS $ENV{ORACLE_HOME}) + set(Oracle_HOME $ENV{ORACLE_HOME}) + endif() + if(EXISTS $ENV{Oracle_HOME}) + set(Oracle_HOME $ENV{Oracle_HOME}) + endif() +endif() +if (ORACLE_HOME) + set(Oracle_HOME "${ORACLE_HOME}") +endif() + +find_path(Oracle_INCLUDE_DIRS + NAMES oci.h + PATHS + ${Oracle_HOME}/rdbms/public + ${Oracle_HOME}/include + ${Oracle_HOME}/sdk/include # Oracle SDK + ${Oracle_HOME}/OCI/include # Oracle XE on Windows + # instant client from rpm + /usr/include/oracle/*/client${LIB_SUFFIX}) + +set(Oracle_VERSIONS 21 20 19 18 12 11 10) +set(Oracle_OCI_NAMES clntsh libclntsh oci) # Dirty trick might help on OSX, see issues/89 +set(Oracle_OCCI_NAMES libocci occi) +set(Oracle_NNZ_NAMES ociw32) + +foreach(loop_var IN LISTS Oracle_VERSIONS) + set(Oracle_OCCI_NAMES ${Oracle_OCCI_NAMES} oraocci${loop_var}) + set(Oracle_NNZ_NAMES ${Oracle_NNZ_NAMES} nnz${loop_var} libnnz${loop_var}) +endforeach(loop_var) + +set(Oracle_LIB_DIR + ${Oracle_HOME} + ${Oracle_HOME}/lib + ${Oracle_HOME}/sdk/lib # Oracle SDK + ${Oracle_HOME}/sdk/lib/msvc + ${Oracle_HOME}/OCI/lib/msvc # Oracle XE on Windows + # Instant client from rpm + /usr/lib/oracle/*/client${LIB_SUFFIX}/lib) + +find_library(Oracle_OCI_LIBRARY + NAMES ${Oracle_OCI_NAMES} PATHS ${Oracle_LIB_DIR}) +find_library(Oracle_OCCI_LIBRARY + NAMES ${Oracle_OCCI_NAMES} PATHS ${Oracle_LIB_DIR}) +find_library(Oracle_NNZ_LIBRARY + NAMES ${Oracle_NNZ_NAMES} PATHS ${Oracle_LIB_DIR}) + +if (Oracle_OCI_LIBRARY AND Oracle_OCCI_LIBRARY AND Oracle_NNZ_LIBRARY) + set(Oracle_LIBRARIES + ${Oracle_OCI_LIBRARY} + ${Oracle_OCCI_LIBRARY} + ${Oracle_NNZ_LIBRARY}) +endif() + +if(NOT WIN32 AND Oracle_CLNTSH_LIBRARY) + list(APPEND Oracle_LIBRARIES ${Oracle_CLNTSH_LIBRARY}) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Oracle + REQUIRED_VARS Oracle_LIBRARIES Oracle_INCLUDE_DIRS) + +if(Oracle_FOUND) + add_library(Oracle INTERFACE) + target_link_libraries(Oracle INTERFACE ${Oracle_LIBRARIES}) + target_include_directories(Oracle SYSTEM INTERFACE ${Oracle_INCLUDE_DIRS}) + add_library(Oracle::Oracle ALIAS Oracle) +else() + message(STATUS "None of the supported Oracle versions (${Oracle_VERSIONS}) could be found, consider updating Oracle_VERSIONS if the version you use is not among them.") +endif() diff --git a/cmake/modules/FindDL.cmake b/cmake/modules/FindDL.cmake deleted file mode 100644 index 3f7f889f3..000000000 --- a/cmake/modules/FindDL.cmake +++ /dev/null @@ -1,21 +0,0 @@ -if(DL_INCLUDE_DIR) - set(DL_FIND_QUIETLY TRUE) -endif() - -find_path(DL_INCLUDE_DIR dlfcn.h) -find_library(DL_LIBRARY NAMES dl) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(DL DEFAULT_MSG DL_LIBRARY DL_INCLUDE_DIR) - -if(NOT DL_FOUND) - # if dlopen can be found without linking in dl then, - # dlopen is part of libc, so don't need to link extra libs. - include(CheckFunctionExists) - check_function_exists(dlopen DL_FOUND) - set(DL_LIBRARY "") -endif() - -set(DL_LIBRARIES ${DL_LIBRARY}) - -mark_as_advanced(DL_LIBRARY DL_INCLUDE_DIR) diff --git a/cmake/modules/FindFirebird.cmake b/cmake/modules/FindFirebird.cmake deleted file mode 100644 index 0e9b6784b..000000000 --- a/cmake/modules/FindFirebird.cmake +++ /dev/null @@ -1,38 +0,0 @@ -############################################################## -# Copyright (c) 2008 Daniel Pfeifer # -# # -# Distributed under the Boost Software License, Version 1.0. # -############################################################## - -# This module defines -# FIREBIRD_INCLUDE_DIR - where to find ibase.h -# FIREBIRD_LIBRARIES - the libraries to link against to use FIREBIRD -# FIREBIRD_FOUND - true if FIREBIRD was found - -find_path(FIREBIRD_INCLUDE_DIR ibase.h - /usr/include - $ENV{ProgramFiles}/Firebird/*/include -) - -if(SOCI_FIREBIRD_EMBEDDED) - set(FIREBIRD_LIB_NAMES fbembed) -else() - set(FIREBIRD_LIB_NAMES fbclient fbclient_ms) -endif() - -find_library(FIREBIRD_LIBRARIES - NAMES - ${FIREBIRD_LIB_NAMES} - PATHS - /usr/lib - $ENV{ProgramFiles}/Firebird/*/lib -) - -# fbembed ? - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Firebird - DEFAULT_MSG FIREBIRD_LIBRARIES FIREBIRD_INCLUDE_DIR) - -mark_as_advanced(FIREBIRD_INCLUDE_DIR FIREBIRD_LIBRARIES) - diff --git a/cmake/modules/FindMySQL.cmake b/cmake/modules/FindMySQL.cmake deleted file mode 100644 index 73efa8809..000000000 --- a/cmake/modules/FindMySQL.cmake +++ /dev/null @@ -1,99 +0,0 @@ -# - Try to find MariaDB / MySQL library -# Find the MySQL includes and client library -# This module defines -# MYSQL_INCLUDE_DIR, where to find mysql.h -# MYSQL_LIBRARIES, the libraries needed to use MySQL. -# MYSQL_LIB_DIR, path to the MYSQL_LIBRARIES -# MYSQL_FOUND, If false, do not try to use MySQL. - -# Copyright (c) 2006-2008, JarosƂaw Staniek -# Copyright (c) 2023 Vadim Zeitline (MariaDB support) -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - -include(CheckCXXSourceCompiles) - -if(WIN32) - find_path(MYSQL_INCLUDE_DIR mysql.h - PATHS - $ENV{MYSQL_INCLUDE_DIR} - $ENV{MYSQL_DIR}/include - $ENV{ProgramFiles}/MySQL/*/include - $ENV{SystemDrive}/MySQL/*/include - $ENV{ProgramW6432}/MySQL/*/include - ) -else(WIN32) - find_path(MYSQL_INCLUDE_DIR mysql.h - PATHS - $ENV{MYSQL_INCLUDE_DIR} - $ENV{MYSQL_DIR}/include - PATH_SUFFIXES - mariadb - mysql - ) -endif(WIN32) - -if(WIN32) - if (${CMAKE_BUILD_TYPE}) - string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER) - endif() - - # path suffix for debug/release mode - # binary_dist: mysql binary distribution - # build_dist: custom build - if(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug") - set(binary_dist debug) - set(build_dist Debug) - else(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug") - ADD_DEFINITIONS(-DDBUG_OFF) - set(binary_dist opt) - set(build_dist Release) - endif(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug") - -# find_library(MYSQL_LIBRARIES NAMES mysqlclient - set(MYSQL_LIB_PATHS - $ENV{MYSQL_DIR}/lib/${binary_dist} - $ENV{MYSQL_DIR}/libmysql/${build_dist} - $ENV{MYSQL_DIR}/client/${build_dist} - $ENV{ProgramFiles}/MySQL/*/lib/${binary_dist} - $ENV{SystemDrive}/MySQL/*/lib/${binary_dist} - $ENV{MYSQL_DIR}/lib/opt - $ENV{MYSQL_DIR}/client/release - $ENV{ProgramFiles}/MySQL/*/lib/opt - $ENV{SystemDrive}/MySQL/*/lib/opt - $ENV{ProgramW6432}/MySQL/*/lib - ) - find_library(MYSQL_LIBRARIES NAMES libmysql - PATHS - ${MYSQL_LIB_PATHS} - ) -else(WIN32) -# find_library(MYSQL_LIBRARIES NAMES mysqlclient - set(MYSQL_LIB_PATHS - $ENV{MYSQL_DIR}/lib - PATH_SUFFIXES - mariadb - mysql - ) - find_library(MYSQL_LIBRARIES NAMES mariadbclient mysqlclient - PATHS - ${MYSQL_LIB_PATHS} - ) -endif(WIN32) - -if(MYSQL_LIBRARIES) - get_filename_component(MYSQL_LIB_DIR ${MYSQL_LIBRARIES} PATH) -endif(MYSQL_LIBRARIES) - -set( CMAKE_REQUIRED_INCLUDES ${MYSQL_INCLUDE_DIR} ) - -if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES) - set(MYSQL_FOUND TRUE) - message(STATUS "Found MySQL: ${MYSQL_INCLUDE_DIR}, ${MYSQL_LIBRARIES}") -else(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES) - set(MYSQL_FOUND FALSE) - message(STATUS "MySQL not found.") -endif(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES) - -mark_as_advanced(MYSQL_INCLUDE_DIR MYSQL_LIBRARIES) diff --git a/cmake/modules/FindODBC.cmake b/cmake/modules/FindODBC.cmake deleted file mode 100644 index 67e6237c7..000000000 --- a/cmake/modules/FindODBC.cmake +++ /dev/null @@ -1,242 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -FindODBC --------- - -Find the ODBC include directory and library. - -Use this module by invoking find_package with the form:: - -.. code-block:: cmake - - find_package(ODBC - [REQUIRED] # Fail with error if ODBC is not found - ) - -On Windows, when building with Visual Studio, this module assumes the ODBC -library is provided by the available Windows SDK. - -On Unix, this module allows to search for ODBC library provided by -unixODBC or iODBC implementations of ODBC API. -This module reads hint about location of the config program: - -.. variable:: ODBC_CONFIG - - Location of odbc_config or iodbc-config program - -Otherwise, this module tries to find the config program, -first from unixODBC, then from iODBC. -If no config program found, this module searches for ODBC header -and library in list of known locations. - -Imported targets -^^^^^^^^^^^^^^^^ - -This module defines the following :prop_tgt:`IMPORTED` targets: - -.. variable:: ODBC::ODBC - - Imported target for using the ODBC library, if found. - -Result variables -^^^^^^^^^^^^^^^^ - -.. variable:: ODBC_FOUND - - Set to true if ODBC library found, otherwise false or undefined. - -.. variable:: ODBC_INCLUDE_DIRS - - Paths to include directories listed in one variable for use by ODBC client. - May be empty on Windows, where the include directory corresponding to the - expected Windows SDK is already available in the compilation environment. - -.. variable:: ODBC_LIBRARIES - - Paths to libraries to linked against to use ODBC. - May just a library name on Windows, where the library directory corresponding - to the expected Windows SDK is already available in the compilation environment. - -.. variable:: ODBC_CONFIG - - Path to unixODBC or iODBC config program, if found or specified. - -Cache variables -^^^^^^^^^^^^^^^ - -For users who wish to edit and control the module behavior, this module -reads hints about search locations from the following variables:: - -.. variable:: ODBC_INCLUDE_DIR - - Path to ODBC include directory with ``sql.h`` header. - -.. variable:: ODBC_LIBRARY - - Path to ODBC library to be linked. - -NOTE: The variables above should not usually be used in CMakeLists.txt files! - -Limitations -^^^^^^^^^^^ - -On Windows, this module does not search for iODBC. -On Unix, there is no way to prefer unixODBC over iODBC, or vice versa, -other than providing the config program location using the ``ODBC_CONFIG``. -This module does not allow to search for a specific ODBC driver. - -#]=======================================================================] - -### Try Windows Kits ########################################################## -if(WIN32) - # List names of ODBC libraries on Windows - set(ODBC_LIBRARY odbc32.lib) - set(_odbc_lib_names odbc32;) - - # List additional libraries required to use ODBC library - if(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") - set(_odbc_required_libs_names odbccp32;ws2_32) - elseif(MINGW) - set(_odbc_required_libs_names odbccp32) - endif() -endif() - -### Try unixODBC or iODBC config program ###################################### -if (UNIX AND NOT ODBC_CONFIG) - find_program(ODBC_CONFIG - NAMES odbc_config iodbc-config - DOC "Path to unixODBC or iODBC config program") -endif() - -if (UNIX AND ODBC_CONFIG) - # unixODBC and iODBC accept unified command line options - execute_process(COMMAND ${ODBC_CONFIG} --cflags - OUTPUT_VARIABLE _cflags OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND ${ODBC_CONFIG} --libs - OUTPUT_VARIABLE _libs OUTPUT_STRIP_TRAILING_WHITESPACE) - - # Collect paths of include directories from CFLAGS - separate_arguments(_cflags NATIVE_COMMAND "${_cflags}") - foreach(arg IN LISTS _cflags) - if("${arg}" MATCHES "^-I(.*)$") - list(APPEND _odbc_include_paths "${CMAKE_MATCH_1}") - endif() - endforeach() - unset(_cflags) - - # Collect paths of library names and directories from LIBS - separate_arguments(_libs NATIVE_COMMAND "${_libs}") - foreach(arg IN LISTS _libs) - if("${arg}" MATCHES "^-L(.*)$") - list(APPEND _odbc_lib_paths "${CMAKE_MATCH_1}") - elseif("${arg}" MATCHES "^-l(.*)$") - set(_lib_name ${CMAKE_MATCH_1}) - string(REGEX MATCH "odbc" _is_odbc ${_lib_name}) - if(_is_odbc) - list(APPEND _odbc_lib_names ${_lib_name}) - else() - list(APPEND _odbc_required_libs_names ${_lib_name}) - endif() - unset(_lib_name) - endif() - endforeach() - unset(_libs) -endif() - -### Try unixODBC or iODBC in include/lib filesystems ########################## -if (UNIX AND NOT ODBC_CONFIG) - # List names of both ODBC libraries, unixODBC and iODBC - set(_odbc_lib_names odbc;iodbc;unixodbc;) - - set(_odbc_include_paths - /usr/local/odbc/include) - - set(_odbc_lib_paths - /usr/local/odbc/lib) -endif() - -# DEBUG -#message("ODBC_CONFIG=${ODBC_CONFIG}") -#message("_odbc_include_hints=${_odbc_include_hints}") -#message("_odbc_include_paths=${_odbc_include_paths}") -#message("_odbc_lib_paths=${_odbc_lib_paths}") -#message("_odbc_lib_names=${_odbc_lib_names}") - -### Find include directories ################################################## -find_path(ODBC_INCLUDE_DIR - NAMES sql.h - HINTS ${_odbc_include_hints} - PATHS ${_odbc_include_paths}) - -if(NOT ODBC_INCLUDE_DIR AND WIN32) - set(ODBC_INCLUDE_DIR "") -endif() - -### Find libraries ############################################################ -if(NOT ODBC_LIBRARY) - find_library(ODBC_LIBRARY - NAMES ${_odbc_lib_names} - PATHS ${_odbc_lib_paths} - PATH_SUFFIXES odbc) - - foreach(_lib IN LISTS _odbc_required_libs_names) - find_library(_lib_path - NAMES ${_lib} - PATHS ${_odbc_lib_paths} # system parths or collected from ODBC_CONFIG - PATH_SUFFIXES odbc) - if (_lib_path) - list(APPEND _odbc_required_libs_paths ${_lib_path}) - endif() - unset(_lib_path CACHE) - endforeach() - - unset(_odbc_lib_names) - unset(_odbc_lib_paths) - unset(_odbc_required_libs_names) -endif() - -### Set result variables ###################################################### -set(REQUIRED_VARS ODBC_LIBRARY) -if(NOT WIN32) - list(APPEND REQUIRED_VARS ODBC_INCLUDE_DIR) -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(ODBC DEFAULT_MSG ${REQUIRED_VARS}) - -mark_as_advanced(FORCE ODBC_LIBRARY ODBC_INCLUDE_DIR) - -if(ODBC_CONFIG) - mark_as_advanced(FORCE ODBC_CONFIG) -endif() - -set(ODBC_INCLUDE_DIRS ${ODBC_INCLUDE_DIR}) -list(APPEND ODBC_LIBRARIES ${ODBC_LIBRARY}) -list(APPEND ODBC_LIBRARIES ${_odbc_required_libs_paths}) - -### Import targets ############################################################ -if(ODBC_FOUND) - if(NOT TARGET ODBC::ODBC) - if(IS_ABSOLUTE "${ODBC_LIBRARY}") - add_library(ODBC::ODBC UNKNOWN IMPORTED) - set_target_properties(ODBC::ODBC PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${ODBC_LIBRARY}") - else() - add_library(ODBC::ODBC INTERFACE IMPORTED) - set_target_properties(ODBC::ODBC PROPERTIES - IMPORTED_LIBNAME "${ODBC_LIBRARY}") - endif() - set_target_properties(ODBC::ODBC PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${ODBC_INCLUDE_DIR}") - - if(_odbc_required_libs_paths) - set_property(TARGET ODBC::ODBC APPEND PROPERTY - INTERFACE_LINK_LIBRARIES "${_odbc_required_libs_paths}") - endif() - endif() -endif() - -unset(_odbc_required_libs_paths) diff --git a/cmake/modules/FindOracle.cmake b/cmake/modules/FindOracle.cmake deleted file mode 100644 index 37106f761..000000000 --- a/cmake/modules/FindOracle.cmake +++ /dev/null @@ -1,90 +0,0 @@ -############################################################################### -# -# CMake module to search for Oracle client library (OCI) -# -# On success, the macro sets the following variables: -# ORACLE_FOUND = if the library found -# ORACLE_LIBRARY = full path to the library -# ORACLE_LIBRARIES = full path to the library -# ORACLE_INCLUDE_DIR = where to find the library headers also defined, -# but not for general use are -# ORACLE_VERSION = version of library which was found, e.g. "1.2.5" -# -# Copyright (c) 2009-2013 Mateusz Loskot -# -# Developed with inspiration from Petr Vanek -# who wrote similar macro for TOra - http://torasql.com/ -# -# Module source: http://github.com/mloskot/workshop/tree/master/cmake/ -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# -############################################################################### - -# First check for CMAKE variable -if(NOT ORACLE_HOME) - # If ORACLE_HOME is not defined check for env var and if exists set from env var - if(EXISTS $ENV{ORACLE_HOME}) - set(ORACLE_HOME $ENV{ORACLE_HOME}) - endif() -endif() - -message(STATUS "ORACLE_HOME=${ORACLE_HOME}") - -find_path(ORACLE_INCLUDE_DIR - NAMES oci.h - PATHS - ${ORACLE_HOME}/rdbms/public - ${ORACLE_HOME}/include - ${ORACLE_HOME}/sdk/include # Oracle SDK - ${ORACLE_HOME}/OCI/include # Oracle XE on Windows - # instant client from rpm - /usr/include/oracle/*/client${LIB_SUFFIX}) - -set(ORACLE_VERSIONS 21 20 19 18 12 11 10) -set(ORACLE_OCI_NAMES clntsh libclntsh oci) # Dirty trick might help on OSX, see issues/89 -set(ORACLE_OCCI_NAMES libocci occi) -set(ORACLE_NNZ_NAMES ociw32) -foreach(loop_var IN LISTS ORACLE_VERSIONS) - set(ORACLE_OCCI_NAMES ${ORACLE_OCCI_NAMES} oraocci${loop_var}) - set(ORACLE_NNZ_NAMES ${ORACLE_NNZ_NAMES} nnz${loop_var} libnnz${loop_var}) -endforeach(loop_var) - -set(ORACLE_LIB_DIR - ${ORACLE_HOME} - ${ORACLE_HOME}/lib - ${ORACLE_HOME}/sdk/lib # Oracle SDK - ${ORACLE_HOME}/sdk/lib/msvc - ${ORACLE_HOME}/OCI/lib/msvc # Oracle XE on Windows - # Instant client from rpm - /usr/lib/oracle/*/client${LIB_SUFFIX}/lib) - -find_library(ORACLE_OCI_LIBRARY - NAMES ${ORACLE_OCI_NAMES} PATHS ${ORACLE_LIB_DIR}) -find_library(ORACLE_OCCI_LIBRARY - NAMES ${ORACLE_OCCI_NAMES} PATHS ${ORACLE_LIB_DIR}) -find_library(ORACLE_NNZ_LIBRARY - NAMES ${ORACLE_NNZ_NAMES} PATHS ${ORACLE_LIB_DIR}) - -set(ORACLE_LIBRARY - ${ORACLE_OCI_LIBRARY} - ${ORACLE_OCCI_LIBRARY} - ${ORACLE_NNZ_LIBRARY}) - -if(NOT WIN32) - set(ORACLE_LIBRARY ${ORACLE_LIBRARY} ${ORACLE_CLNTSH_LIBRARY}) -endif(NOT WIN32) - -set(ORACLE_LIBRARIES ${ORACLE_LIBRARY}) - -# Handle the QUIETLY and REQUIRED arguments and set ORACLE_FOUND to TRUE -# if all listed variables are TRUE -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Oracle DEFAULT_MSG ORACLE_LIBRARY ORACLE_INCLUDE_DIR) - -if(NOT ORACLE_FOUND) - message(STATUS "None of the supported Oracle versions (${ORACLE_VERSIONS}) could be found, consider updating ORACLE_VERSIONS if the version you use is not among them.") -endif() - -mark_as_advanced(ORACLE_INCLUDE_DIR ORACLE_LIBRARY) diff --git a/cmake/modules/FindPostgreSQL.cmake b/cmake/modules/FindPostgreSQL.cmake deleted file mode 100644 index e795f2e7a..000000000 --- a/cmake/modules/FindPostgreSQL.cmake +++ /dev/null @@ -1,191 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# FindPostgreSQL -# -------------- -# -# Find the PostgreSQL installation. -# -# This module defines -# -# :: -# -# POSTGRESQL_LIBRARIES - the PostgreSQL libraries needed for linking -# POSTGRESQL_INCLUDE_DIRS - the directories of the PostgreSQL headers -# POSTGRESQL_LIBRARY_DIRS - the link directories for PostgreSQL libraries -# POSTGRESQL_VERSION_STRING - the version of PostgreSQL found (since CMake 2.8.8) - -# ---------------------------------------------------------------------------- -# History: -# This module is derived from the module originally found in the VTK source tree. -# -# ---------------------------------------------------------------------------- -# Note: -# POSTGRESQL_ADDITIONAL_VERSIONS is a variable that can be used to set the -# version mumber of the implementation of PostgreSQL. -# In Windows the default installation of PostgreSQL uses that as part of the path. -# E.g C:\Program Files\PostgreSQL\8.4. -# Currently, the following version numbers are known to this module: -# "14" "13" "12" "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0" -# -# To use this variable just do something like this: -# set(POSTGRESQL_ADDITIONAL_VERSIONS "9.2" "8.4.4") -# before calling find_package(PostgreSQL) in your CMakeLists.txt file. -# This will mean that the versions you set here will be found first in the order -# specified before the default ones are searched. -# -# ---------------------------------------------------------------------------- -# You may need to manually set: -# POSTGRESQL_INCLUDE_DIR - the path to where the PostgreSQL include files are. -# POSTGRESQL_LIBRARY_DIR - The path to where the PostgreSQL library files are. -# If FindPostgreSQL.cmake cannot find the include files or the library files. -# -# ---------------------------------------------------------------------------- -# The following variables are set if PostgreSQL is found: -# POSTGRESQL_FOUND - Set to true when PostgreSQL is found. -# POSTGRESQL_INCLUDE_DIRS - Include directories for PostgreSQL -# POSTGRESQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries -# POSTGRESQL_LIBRARIES - The PostgreSQL libraries. -# -# ---------------------------------------------------------------------------- -# If you have installed PostgreSQL in a non-standard location. -# (Please note that in the following comments, it is assumed that -# points to the root directory of the include directory of PostgreSQL.) -# Then you have three options. -# 1) After CMake runs, set POSTGRESQL_INCLUDE_DIR to /include and -# POSTGRESQL_LIBRARY_DIR to wherever the library pq (or libpq in windows) is -# 2) Use CMAKE_INCLUDE_PATH to set a path to /PostgreSQL<-version>. This will allow find_path() -# to locate POSTGRESQL_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g. In your CMakeLists.txt file -# set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/include") -# 3) Set an environment variable called ${POSTGRESQL_ROOT} that points to the root of where you have -# installed PostgreSQL, e.g. . -# -# ---------------------------------------------------------------------------- - -set(POSTGRESQL_INCLUDE_PATH_DESCRIPTION "top-level directory containing the PostgreSQL include directories. E.g /usr/local/include/PostgreSQL/8.4 or C:/Program Files/PostgreSQL/8.4/include") -set(POSTGRESQL_INCLUDE_DIR_MESSAGE "Set the POSTGRESQL_INCLUDE_DIR cmake cache entry to the ${POSTGRESQL_INCLUDE_PATH_DESCRIPTION}") -set(POSTGRESQL_LIBRARY_PATH_DESCRIPTION "top-level directory containing the PostgreSQL libraries.") -set(POSTGRESQL_LIBRARY_DIR_MESSAGE "Set the POSTGRESQL_LIBRARY_DIR cmake cache entry to the ${POSTGRESQL_LIBRARY_PATH_DESCRIPTION}") -set(POSTGRESQL_ROOT_DIR_MESSAGE "Set the POSTGRESQL_ROOT system variable to where PostgreSQL is found on the machine E.g C:/Program Files/PostgreSQL/8.4") - - -set(POSTGRESQL_KNOWN_VERSIONS ${POSTGRESQL_ADDITIONAL_VERSIONS} - "14" "13" "12" "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0") - -# Define additional search paths for root directories. -set( POSTGRESQL_ROOT_DIRECTORIES - ENV POSTGRESQL_ROOT - ${POSTGRESQL_ROOT} -) -foreach(suffix ${POSTGRESQL_KNOWN_VERSIONS}) - if(WIN32) - list(APPEND POSTGRESQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES - "PostgreSQL/${suffix}/lib") - list(APPEND POSTGRESQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES - "PostgreSQL/${suffix}/include") - list(APPEND POSTGRESQL_TYPE_ADDITIONAL_SEARCH_SUFFIXES - "PostgreSQL/${suffix}/include/server") - endif() - if(UNIX) - list(APPEND POSTGRESQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES - "pgsql-${suffix}/lib") - list(APPEND POSTGRESQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES - "pgsql-${suffix}/include") - list(APPEND POSTGRESQL_TYPE_ADDITIONAL_SEARCH_SUFFIXES - "postgresql/${suffix}/server" - "pgsql-${suffix}/include/server") - endif() - if(APPLE) - list(APPEND POSTGRESQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES - "postgresql@${suffix}") - list(APPEND POSTGRESQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES - "postgresql@${suffix}") - endif() -endforeach() - -# -# Look for an installation. -# -find_path(POSTGRESQL_INCLUDE_DIR - NAMES libpq-fe.h - PATHS - # Look in other places. - ${POSTGRESQL_ROOT_DIRECTORIES} - PATH_SUFFIXES - pgsql - postgresql - include - ${POSTGRESQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES} - # Help the user find it if we cannot. - DOC "The ${POSTGRESQL_INCLUDE_DIR_MESSAGE}" -) - -# The PostgreSQL library. -set (POSTGRESQL_LIBRARY_TO_FIND pq) -# Setting some more prefixes for the library -set (POSTGRESQL_LIB_PREFIX "") -if ( WIN32 ) - set (POSTGRESQL_LIB_PREFIX ${POSTGRESQL_LIB_PREFIX} "lib") - set (POSTGRESQL_LIBRARY_TO_FIND ${POSTGRESQL_LIB_PREFIX}${POSTGRESQL_LIBRARY_TO_FIND}) -endif() - -function(__postgresql_find_library _name) - find_library(${_name} - NAMES ${ARGN} - PATHS - ${POSTGRESQL_ROOT_DIRECTORIES} - PATH_SUFFIXES - lib - ${POSTGRESQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES} - # Help the user find it if we cannot. - DOC "The ${POSTGRESQL_LIBRARY_DIR_MESSAGE}" - ) -endfunction() - -__postgresql_find_library(POSTGRESQL_LIBRARY ${POSTGRESQL_LIBRARY_TO_FIND}) -__postgresql_find_library(POSTGRESQL_LIBRARY_DEBUG ${POSTGRESQL_LIBRARY_TO_FIND}d) -get_filename_component(POSTGRESQL_LIBRARY_DIR ${POSTGRESQL_LIBRARY} PATH) - -if (POSTGRESQL_INCLUDE_DIR) - # Some platforms include multiple pg_config.hs for multi-lib configurations - # This is a temporary workaround. A better solution would be to compile - # a dummy c file and extract the value of the symbol. - file(GLOB _PG_CONFIG_HEADERS "${POSTGRESQL_INCLUDE_DIR}/pg_config*.h") - foreach(_PG_CONFIG_HEADER ${_PG_CONFIG_HEADERS}) - if(EXISTS "${_PG_CONFIG_HEADER}") - file(STRINGS "${_PG_CONFIG_HEADER}" pgsql_version_str - REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"") - if(pgsql_version_str) - string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" - "\\1" POSTGRESQL_VERSION_STRING "${pgsql_version_str}") - break() - endif() - endif() - endforeach() - unset(pgsql_version_str) -endif() - -# Did we find anything? -# -#include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -include(FindPackageHandleStandardArgs) -# -find_package_handle_standard_args(PostgreSQL - REQUIRED_VARS POSTGRESQL_LIBRARY POSTGRESQL_INCLUDE_DIR - VERSION_VAR POSTGRESQL_VERSION_STRING) -set(POSTGRESQL_FOUND ${POSTGRESQL_FOUND}) - -# Now try to get the include and library path. -if(POSTGRESQL_FOUND) - set(POSTGRESQL_INCLUDE_DIRS ${POSTGRESQL_INCLUDE_DIR}) - set(POSTGRESQL_LIBRARY_DIRS ${POSTGRESQL_LIBRARY_DIR}) - if(POSTGRESQL_LIBRARY AND POSTGRESQL_LIBRARY_DEBUG) - set(POSTGRESQL_LIBRARIES optimized ${POSTGRESQL_LIBRARY} debug ${POSTGRESQL_LIBRARY_DEBUG}) - else() - set(POSTGRESQL_LIBRARIES ${POSTGRESQL_LIBRARY}) - endif() - set(POSTGRESQL_VERSION ${POSTGRESQL_VERSION_STRING}) -endif() - -mark_as_advanced(POSTGRESQL_INCLUDE_DIR POSTGRESQL_LIBRARY) diff --git a/cmake/modules/FindSQLite3.cmake b/cmake/modules/FindSQLite3.cmake deleted file mode 100644 index 885a6569c..000000000 --- a/cmake/modules/FindSQLite3.cmake +++ /dev/null @@ -1,66 +0,0 @@ -############################################################################### -# CMake module to search for SQLite 3 library -# -# On success, the macro sets the following variables: -# SQLITE3_FOUND = if the library found -# SQLITE3_LIBRARY = full path to the library -# SQLITE3_LIBRARIES = full path to the library -# SQLITE3_INCLUDE_DIR = where to find the library headers -# -# Copyright (c) 2009 Mateusz Loskot -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# -############################################################################### - -find_path(SQLITE3_INCLUDE_DIR - NAMES sqlite3.h - PATH_PREFIXES sqlite sqlite3 - PATHS - /usr/include - /usr/local/include - $ENV{LIB_DIR}/include - $ENV{LIB_DIR}/include/sqlite - $ENV{LIB_DIR}/include/sqlite3 - $ENV{ProgramFiles}/SQLite/*/include - $ENV{ProgramFiles}/SQLite3/*/include - $ENV{SystemDrive}/SQLite/*/include - $ENV{SystemDrive}/SQLite3/*/include - $ENV{SQLITE_ROOT}/include - ${SQLITE_ROOT_DIR}/include - $ENV{OSGEO4W_ROOT}/include) - -set(SQLITE3_NAMES sqlite3_i sqlite3 sqlite3-static) -find_library(SQLITE3_LIBRARY - NAMES ${SQLITE3_NAMES} - PATHS - /usr/lib - /usr/local/lib - $ENV{LIB_DIR}/lib - $ENV{ProgramFiles}/SQLite/*/lib - $ENV{ProgramFiles}/SQLite3/*/lib - $ENV{SystemDrive}/SQLite/*/lib - $ENV{SystemDrive}/SQLite3/*/lib - $ENV{SQLITE_ROOT}/lib - ${SQLITE_ROOT_DIR}/lib - $ENV{OSGEO4W_ROOT}/lib) - -set(SQLITE3_LIBRARIES - ${SQLITE3_LIBRARIES} - ${SQLITE3_LIBRARY}) - -#message(STATUS ${SQLITE3_LIBRARY}) -# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE -# if all listed variables are TRUE -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(SQLite3 - DEFAULT_MSG - SQLITE3_LIBRARIES - SQLITE3_INCLUDE_DIR) - -if(NOT SQLITE3_FOUND) - message(STATUS "SQLite3 not found (SQLITE3_INCLUDE_DIR=${SQLITE3_INCLUDE_DIR}, SQLITE3_LIBRARY=${SQLITE3_LIBRARY}.") -endif() - -mark_as_advanced(SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR SQLITE3_LIBRARIES) diff --git a/cmake/modules/FindSoci.cmake b/cmake/modules/FindSoci.cmake deleted file mode 100644 index ece836e06..000000000 --- a/cmake/modules/FindSoci.cmake +++ /dev/null @@ -1,140 +0,0 @@ -############################################################################### -# CMake module to search for SOCI library -# -# This module defines: -# Soci_INCLUDE_DIRS = include dirs to be used when using the soci library -# Soci_LIBRARY = full path to the soci library -# Soci_VERSION = the soci version found -# Soci_FOUND = true if soci was found -# -# This module respects: -# LIB_SUFFIX = (64|32|"") Specifies the suffix for the lib directory -# -# For each component you specify in find_package(), the following variables are set. -# -# Soci_${COMPONENT}_PLUGIN = full path to the soci plugin (not set for the "core" component) -# Soci_${COMPONENT}_FOUND -# -# This module provides the following imported targets, if found: -# -# Soci::core = target for the core library and include directories -# Soci::${COMPONENT} = target for each plugin -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# -############################################################################### -# -### Global Configuration Section -# -set(_SOCI_ALL_PLUGINS mysql odbc postgresql sqlite3) -set(_SOCI_REQUIRED_VARS Soci_INCLUDE_DIR Soci_LIBRARY) - -# -### FIRST STEP: Find the soci headers. -# -find_path( - Soci_INCLUDE_DIR soci.h - HINTS "/usr/local" - PATH_SUFFIXES "" "soci" - DOC "Soci (http://soci.sourceforge.net) include directory") -mark_as_advanced(Soci_INCLUDE_DIR) - -set(Soci_INCLUDE_DIRS ${Soci_INCLUDE_DIR} CACHE STRING "") - -# -### SECOND STEP: Find the soci core library. Respect LIB_SUFFIX -# -find_library( - Soci_LIBRARY - NAMES soci_core - HINTS ${Soci_INCLUDE_DIR}/.. - PATH_SUFFIXES lib${LIB_SUFFIX}) -mark_as_advanced(Soci_LIBRARY) - -get_filename_component(Soci_LIBRARY_DIR ${Soci_LIBRARY} PATH) -mark_as_advanced(Soci_LIBRARY_DIR) - -# -### THIRD STEP: Find all installed plugins if the library was found -# -if(Soci_INCLUDE_DIR AND Soci_LIBRARY) - set(Soci_core_FOUND TRUE CACHE BOOL "") - - add_library(Soci::core UNKNOWN IMPORTED) - set_target_properties( - Soci::core - PROPERTIES IMPORTED_LOCATION "${Soci_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${Soci_INCLUDE_DIR}" - ) - - # - ### FOURTH STEP: Obtain SOCI version - # - set(Soci_VERSION_FILE "${Soci_INCLUDE_DIR}/version.h") - if(EXISTS "${Soci_VERSION_FILE}") - file(READ "${Soci_VERSION_FILE}" VERSION_CONTENT) - string(REGEX MATCH "#define[ \t]*SOCI_VERSION[ \t]*[0-9]+" VERSION_MATCH "${VERSION_CONTENT}") - string(REGEX REPLACE "#define[ \t]*SOCI_VERSION[ \t]*" "" VERSION_MATCH "${VERSION_MATCH}") - - if(NOT VERSION_MATCH) - message(WARNING "Failed to extract SOCI version") - else() - math(EXPR MAJOR "${VERSION_MATCH} / 100000" OUTPUT_FORMAT DECIMAL) - math(EXPR MINOR "${VERSION_MATCH} / 100 % 1000" OUTPUT_FORMAT DECIMAL) - math(EXPR PATCH "${VERSION_MATCH} % 100" OUTPUT_FORMAT DECIMAL) - - set(Soci_VERSION "${MAJOR}.${MINOR}.${PATCH}" CACHE STRING "") - endif() - else() - message(WARNING "Unable to check SOCI version") - endif() - - foreach(plugin IN LISTS _SOCI_ALL_PLUGINS) - - find_library( - Soci_${plugin}_PLUGIN - NAMES soci_${plugin} - HINTS ${Soci_INCLUDE_DIR}/.. - PATH_SUFFIXES lib${LIB_SUFFIX}) - mark_as_advanced(Soci_${plugin}_PLUGIN) - - if(Soci_${plugin}_PLUGIN) - set(Soci_${plugin}_FOUND TRUE CACHE BOOL "") - add_library(Soci::${plugin} UNKNOWN IMPORTED) - set_target_properties( - Soci::${plugin} - PROPERTIES IMPORTED_LOCATION "${Soci_${plugin}_PLUGIN}" - ) - target_link_libraries(Soci::${plugin} INTERFACE Soci::core) - else() - set(Soci_${plugin}_FOUND FALSE CACHE BOOL "") - endif() - - endforeach() -endif() - -# -### ADHERE TO STANDARDS -# -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Soci - REQUIRED_VARS ${_SOCI_REQUIRED_VARS} - VERSION_VAR Soci_VERSION - HANDLE_COMPONENTS -) - -# For compatibility with previous versions of this script -# DO NOT USE THESE VARIABLES IN NEW PROJECTS! -set(SOCI_FOUND ${Soci_FOUND}) -set(SOCI_INCLUDE_DIRS ${Soci_INCLUDE_DIRS}) -set(SOCI_LIBRARY ${Soci_LIBRARY}) -set(SOCI_VERSION ${Soci_VERSION}) -set(SOCI_mysql_FOUND ${Soci_mysql_FOUND}) -set(SOCI_odbc_FOUND ${Soci_odbc_FOUND}) -set(SOCI_postgresql_FOUND ${Soci_postgresql_PLUGIN}) -set(SOCI_sqlite3_FOUND ${Soci_sqlite3_PLUGIN}) -set(SOCI_mysql_PLUGIN ${Soci_mysql_PLUGIN}) -set(SOCI_odbc_PLUGIN ${Soci_odbc_PLUGIN}) -set(SOCI_postgresql_PLUGIN ${Soci_postgresql_PLUGIN}) -set(SOCI_sqlite3_PLUGIN ${Soci_sqlite3_PLUGIN}) diff --git a/cmake/resources/SOCIConfig.cmake.in b/cmake/resources/SOCIConfig.cmake.in deleted file mode 100644 index 8096a3c25..000000000 --- a/cmake/resources/SOCIConfig.cmake.in +++ /dev/null @@ -1,3 +0,0 @@ -@PACKAGE_INIT@ - -include(${CMAKE_CURRENT_LIST_DIR}/SOCITargets.cmake) diff --git a/cmake/resources/vs2010-test-cmd-args.vcxproj.user.in b/cmake/resources/vs2010-test-cmd-args.vcxproj.user.in deleted file mode 100644 index f41ec9b27..000000000 --- a/cmake/resources/vs2010-test-cmd-args.vcxproj.user.in +++ /dev/null @@ -1,7 +0,0 @@ -ï»ż - - - @SOCI_TEST_CMD_ARGS@ - WindowsLocalDebugger - - diff --git a/cmake/soci_compat.cmake b/cmake/soci_compat.cmake new file mode 100644 index 000000000..480cb36b4 --- /dev/null +++ b/cmake/soci_compat.cmake @@ -0,0 +1,27 @@ +# Take care of defining ALIAS targets to keep old target names working + +if (SOCI_SHARED) + set(SUFFIX "") +else() + set(SUFFIX "_static") +endif() + +set(OLD_NAMES core db2 empty firebird mysql odbc oracle postgresql sqlite3) +set(ALIAS_NAMES Core DB2 Empty Firebird MySQL ODBC Oracle PostgreSQL SQLite3) + +list(LENGTH ALIAS_NAMES N_ITEMS) +math(EXPR LAST_ITEM "${N_ITEMS} - 1") + +foreach (I RANGE ${LAST_ITEM}) + list(GET OLD_NAMES ${I} CURRENT_NAME) + list(GET ALIAS_NAMES ${I} CURRENT_ALIAS) + + if (NOT TARGET SOCI::${CURRENT_ALIAS}) + continue() + endif() + + get_target_property(UNDERLYING_LIB SOCI::${CURRENT_ALIAS} ALIASED_TARGET) + + add_library(Soci::${CURRENT_NAME}${SUFFIX} ALIAS ${UNDERLYING_LIB}) + add_library(SOCI::${CURRENT_NAME}${SUFFIX} ALIAS ${UNDERLYING_LIB}) +endforeach() diff --git a/cmake/soci_compiler_options.cmake b/cmake/soci_compiler_options.cmake new file mode 100644 index 000000000..936c19c18 --- /dev/null +++ b/cmake/soci_compiler_options.cmake @@ -0,0 +1,115 @@ +include(CheckCXXCompilerFlag) + + +add_library(soci_compiler_interface INTERFACE) + +# +# Force compilation flags and set desired warnings level +# + +option(SOCI_ENABLE_WERROR "Enables turning compiler warnings into errors" OFF) +option(SOCI_ASAN "Enable building SOCI with enabled address sanitizers" OFF) +option(SOCI_UBSAN "Enable undefined behaviour sanitizer" OFF) +set(SOCI_LD "" CACHE STRING "Specify a non-default linker") + + +if (WIN32) + target_compile_definitions(soci_compiler_interface + INTERFACE + _CRT_SECURE_NO_DEPRECATE + _CRT_SECURE_NO_WARNINGS + _CRT_NONSTDC_NO_WARNING + _SCL_SECURE_NO_WARNINGS + ) + + # Prevent the Windows header files from defining annoying macros + # and also cut down on the definitions in general + target_compile_definitions(soci_compiler_interface + INTERFACE + NOMINMAX + WIN32_LEAN_AND_MEAN + ) +endif() + +if (MSVC) + # Configure warnings + target_compile_options(soci_compiler_interface + INTERFACE + "$<$:/W4>" + "$<$:/we4266>" + ) + + if (SOCI_ENABLE_WERROR) + target_compile_options(soci_compiler_interface INTERFACE "/WX") + endif() + + if (SOCI_LD) + message(FATAL_ERROR "Using a non-default linker is not supported when using MSVC") + endif() + + target_compile_options(soci_compiler_interface INTERFACE "/bigobj" "/utf-8") +else() + + if (SOCI_ENABLE_WERROR) + target_compile_options(soci_compiler_interface INTERFACE "-Werror") + endif() + + if (SOCI_UBSAN) + target_compile_options(soci_compiler_interface INTERFACE "-fsanitize=undefined") + target_link_options(soci_compiler_interface INTERFACE "-fsanitize=undefined") + endif() + + if (SOCI_LD) + # CMake asks the compiler to do the linking so we have to pass the desired linker to the compiler + set(USE_LD_FLAG "-fuse-ld=${SOCI_LD}") + check_cxx_compiler_flag("${USE_LD_FLAG}" CAN_USE_CUSTOM_LD) + if (NOT CAN_USE_CUSTOM_LD) + message(FATAL_ERROR "Can't use custom linker '${SOCI_LD}' - compiler doesn't accept flag '${USE_LD_FLAG}'") + endif() + target_link_options(soci_compiler_options INTERFACE "${USE_LD_FLAG}") + endif() + + + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER}" MATCHES "clang") + if(SOCI_ASAN AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.1) + # This can also be used to set a linker flag + target_link_libraries(soci_compiler_interface INTERFACE "-fsanitize=address") + target_compile_options(soci_compiler_interface INTERFACE "-fsanitize=address") + endif() + + set(SOCI_USE_STD_FLAGS ON) + elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + if (SOCI_ASAN AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) + # This can also be used to set a linker flag + target_link_libraries(soci_compiler_interface INTERFACE "-fsanitize=address") + target_compile_options(soci_compiler_interface INTERFACE "-fsanitize=address") + endif() + + if (CMAKE_COMPILER_IS_GNUCXX) + if (NOT (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")) + target_compile_options(soci_compiler_interface INTERFACE "$<$:-Wno-variadic-macros>") + endif() + endif() + + set(SOCI_USE_STD_FLAGS ON) + else() + message(WARNING "Unknown toolset - using default flags to build SOCI") + endif() + + if (SOCI_USE_STD_FLAGS) + target_compile_options(soci_compiler_interface + INTERFACE + "$<$:-pedantic>" + "$<$:-Wno-error=parentheses>" + "$<$:-Wall>" + "$<$:-Wextra>" + "$<$:-Wpointer-arith>" + "$<$:-Wcast-align>" + "$<$:-Wcast-qual>" + "$<$:-Wfloat-equal>" + "$<$:-Woverloaded-virtual>" + "$<$:-Wredundant-decls>" + "$<$:-Wno-long-long>" + ) + endif() +endif() diff --git a/cmake/soci_define_backend_target.cmake b/cmake/soci_define_backend_target.cmake new file mode 100644 index 000000000..a981c1b51 --- /dev/null +++ b/cmake/soci_define_backend_target.cmake @@ -0,0 +1,178 @@ +include(soci_utils) + +# Defines a CMake target for a database backend. +# +# This function takes care of orchestrating the boilerplate that is needed in order to set up +# a library target as used for different DB backends. Accepted arguments are +# +# ALIAS_NAME Alias to use for the library. The alias name will be prefixed with "SOCI::" +# BACKEND_NAME Name of the backend +# ENABLED_VARIABLE CMake variable that indicates whether this backend is enabled. Will be set +# to OFF if one of the dependencies are not satisfied. +# MISSING_DEPENDENCY_BEHAVIOR What to do if a dependency is not found. Valid values are "ERROR" and "DISABLE" +# TARGET_NAME Name of the CMake target that shall be created for this backend +# DEPENDENCIES [... ] List of dependency specifications. Each specification has to be a single +# argument (single string) following the syntax +# YIELDS [DEFINES ] +# where will be passed to find_package to find the dependency. Upon +# success, all targets defined in are expected to exist. If provided, +# all defines specified in will be added as public compile definitions +# to the backend library if the dependency has been found. +# For now, all dependencies are expected to be public and required. +# FIND_PACKAGE_FILES [... ] List of files used by find_package to locate one of the dependencies. Specified +# files will be installed alongside SOCI in order to be usable from the install tree. +# HEADER_FILES [... ] List of public header files associated with this backend target. +# PRIVATE_INCLUDE_DIRS [... ] List of private include directories +# REQUIRED_COMPONENTS [... ] List of SOCI components (full target names) to link this backend target to +# SOURCE_FILES [... ] List of source files that shall be part of this backend component +function(soci_define_backend_target) + set(FLAGS "") + set(ONE_VAL_OPTIONS + "ALIAS_NAME" + "BACKEND_NAME" + "ENABLED_VARIABLE" + "MISSING_DEPENDENCY_BEHAVIOR" + "TARGET_NAME" + ) + set(MULTI_VAL_OPTIONS + "DEPENDENCIES" + "FIND_PACKAGE_FILES" + "HEADER_FILES" + "PRIVATE_INCLUDE_DIRS" + "REQUIRED_COMPONENTS" + "SOURCE_FILES" + ) + cmake_parse_arguments(DEFINE_BACKEND "${FLAGS}" "${ONE_VAL_OPTIONS}" "${MULTI_VAL_OPTIONS}" ${ARGV}) + + soci_verify_parsed_arguments( + PREFIX "DEFINE_BACKEND" + FUNCTION_NAME "soci_define_backend_target" + REQUIRED "BACKEND_NAME" "SOURCE_FILES" "ENABLED_VARIABLE" "TARGET_NAME" "ALIAS_NAME" + ) + + if (NOT DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR) + set(DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR "ERROR") + else() + string(TOUPPER "${DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR}" DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR) + endif() + + + if (DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR STREQUAL "ERROR") + set(REQUIRE_FLAG "REQUIRED") + set(ERROR_ON_MISSING_DEPENDENCY ON) + elseif(DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR STREQUAL "DISABLE") + set(DISABLE_ON_MISSING_DEPENDENCY ON) + else() + message(FATAL_ERROR "Invalid value '${DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR}' for option 'MISSING_DEPENDENCY_BEHAVIOR'") + endif() + + + set(PUBLIC_DEP_CALL_ARGS "") + + foreach(CURRENT_DEP_SPEC IN LISTS DEFINE_BACKEND_DEPENDENCIES) + if (NOT "${CURRENT_DEP_SPEC}" MATCHES "^([a-zA-Z0-9_:-;]+) YIELDS ([a-zA-Z0-9_:-;]+)( DEFINES [a-zA-Z0-9_;])?$") + message(FATAL_ERROR "Invalid format for dependency specification in '${CURRENT_DEP_SPEC}'") + endif() + set(CURRENT_DEP_SEARCH ${CMAKE_MATCH_1}) + set(CURRENT_DEP_TARGETS ${CMAKE_MATCH_2}) + set(CURRENT_DEP_DEFINES ${CMAKE_MATCH_3}) + + list(GET CURRENT_DEP_SEARCH 0 CURRENT_DEP) + + find_package(${CURRENT_DEP_SEARCH} ${REQUIRE_FLAG}) + + if (NOT ${CURRENT_DEP}_FOUND) + if (ERROR_ON_MISSING_DEPENDENCY) + message(FATAL_ERROR "Expected find_package to error due to unmet dependency '${CURRENT_DEP}'") + elseif(DISABLE_ON_MISSING_DEPENDENCY) + message(STATUS "Disabling SOCI backend '${DEFINE_BACKEND_BACKEND_NAME}' due to unsatisfied dependency on '${CURRENT_DEP}'") + + # Set this backend to disabled by overwriting the corresponding cache variable + # (without overwriting its description) + get_property(DESCRIPTION CACHE "${DEFINE_BACKEND_ENABLED_VARIABLE}" PROPERTY HELPSTRING) + set(${DEFINE_BACKEND_ENABLED_VARIABLE} OFF CACHE STRING "${DESCRIPTION}" FORCE) + return() + else() + message(FATAL_ERROR "Unspecified handling of unmet dependency") + endif() + endif() + + foreach (CURRENT IN LISTS CURRENT_DEP_TARGETS) + if (NOT TARGET "${CURRENT}") + message(FATAL_ERROR "Expected successful find_package call with '${CURRENT_DEP_SEARCH}' to define target '${CURRENT}'") + endif() + endforeach() + if (CURRENT_DEP_DEFINES) + set(MACRO_NAMES_ARG "MACRO_NAMES ${CURRENT_DEP_DEFINES}") + endif() + list(APPEND PUBLIC_DEP_CALL_ARGS + "NAME ${CURRENT_DEP} DEP_TARGETS ${CURRENT_DEP_TARGETS} TARGET SOCI::${DEFINE_BACKEND_ALIAS_NAME} ${MACRO_NAMES_ARG} REQUIRED" + ) + endforeach() + + + add_library(${DEFINE_BACKEND_TARGET_NAME} ${SOCI_LIB_TYPE} ${DEFINE_BACKEND_SOURCE_FILES}) + add_library(SOCI::${DEFINE_BACKEND_ALIAS_NAME} ALIAS ${DEFINE_BACKEND_TARGET_NAME}) + + foreach(CURRENT_ARG_SET IN LISTS PUBLIC_DEP_CALL_ARGS) + # Convert space-separated string to list + string(REPLACE " " ";" CURRENT_ARG_SET "${CURRENT_ARG_SET}") + soci_public_dependency(${CURRENT_ARG_SET}) + endforeach() + foreach (CURRENT_DEP IN LISTS DEFINE_BACKEND_REQUIRED_COMPONENTS) + target_link_libraries(${DEFINE_BACKEND_TARGET_NAME} PUBLIC "${CURRENT_DEP}") + endforeach() + + target_include_directories(${DEFINE_BACKEND_TARGET_NAME} PRIVATE ${DEFINE_BACKEND_PRIVATE_INCLUDE_DIRS}) + + set_target_properties(${DEFINE_BACKEND_TARGET_NAME} + PROPERTIES + SOVERSION ${PROJECT_VERSION_MAJOR} + VERSION ${PROJECT_VERSION} + EXPORT_NAME ${DEFINE_BACKEND_ALIAS_NAME} + ) + + if (DEFINE_BACKEND_HEADER_FILES) + target_sources(${DEFINE_BACKEND_TARGET_NAME} + PUBLIC + FILE_SET headers TYPE HEADERS + BASE_DIRS "${PROJECT_SOURCE_DIR}/include/" + FILES ${DEFINE_BACKEND_HEADER_FILES} + ) + endif() + + + target_link_libraries(soci_interface INTERFACE SOCI::${DEFINE_BACKEND_ALIAS_NAME}) + + + # Setup installation rules for this backend + install( + TARGETS ${DEFINE_BACKEND_TARGET_NAME} + EXPORT SOCI${DEFINE_BACKEND_BACKEND_NAME}Targets + RUNTIME DESTINATION "${SOCI_INSTALL_BINDIR}" + COMPONENT soci_runtime + LIBRARY DESTINATION "${SOCI_INSTALL_LIBDIR}" + COMPONENT soci_runtime + NAMELINK_COMPONENT soci_development + ARCHIVE DESTINATION "${SOCI_INSTALL_LIBDIR}" + COMPONENT soci_development + FILE_SET headers DESTINATION "${SOCI_INSTALL_INCLUDEDIR}" + COMPONENT soci_development + ) + # Generate and install a targets file + install( + EXPORT SOCI${DEFINE_BACKEND_BACKEND_NAME}Targets + DESTINATION "${SOCI_INSTALL_CMAKEDIR}" + FILE SOCI${DEFINE_BACKEND_BACKEND_NAME}Targets.cmake + NAMESPACE SOCI:: + COMPONENT soci_development + ) + + foreach(FIND_FILE IN LISTS DEFINE_BACKEND_FIND_PACKAGE_FILES) + install( + FILES "${FIND_FILE}" + DESTINATION "${SOCI_INSTALL_CMAKEDIR}/find_package_files/" + COMPONENT soci_development + ) + endforeach() +endfunction() diff --git a/cmake/soci_install_dirs.cmake b/cmake/soci_install_dirs.cmake new file mode 100644 index 000000000..95ba35d8b --- /dev/null +++ b/cmake/soci_install_dirs.cmake @@ -0,0 +1,15 @@ +include(GNUInstallDirs) + +set(SOCI_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/soci-${PROJECT_VERSION}" + CACHE FILEPATH "Directory into which cmake related files (e.g. SOCIConfig.cmake) are installed") + +set(SOCI_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}" + CACHE FILEPATH "Directory into which to install any SOCI executables") + +set(SOCI_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/soci" + CACHE FILEPATH "Directory into which any SOCI libraries (except DLLs on Windows) are installed") + +# Note that our headers are installed via a file set that already has the headers +# in a dedicated "soci" subdirectory (which will be part of the installation) +set(SOCI_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}" + CACHE FILEPATH "Directory into which the 'soci' directory with all SOCI header files is installed") diff --git a/cmake/soci_parse_version.cmake b/cmake/soci_parse_version.cmake new file mode 100644 index 000000000..d9d01cf54 --- /dev/null +++ b/cmake/soci_parse_version.cmake @@ -0,0 +1,43 @@ +include(soci_utils) + +# This function extracts the current SOCI version from the version header file +# +# Use as +# soci_parse_version( +# ROOT_DIR +# OUTPUT_VARIABLE +# ) +# where +# - is the path to SOCI's source tree root directory +# - is the name of the variable used to make the parsed version available. This variable +# will contain the version in a cmake-compatible format +function(soci_parse_version) + set(FLAGS "") + set(ONE_VAL_OPTIONS "OUTPUT_VARIABLE" "ROOT_DIR") + set(MULTI_VAL_OPTIONS "") + cmake_parse_arguments(PARSE_VERSION "${FLAGS}" "${ONE_VAL_OPTIONS}" "${MULTI_VAL_OPTIONS}" ${ARGV}) + soci_verify_parsed_arguments( + PREFIX "PARSE_VERSION" + FUNCTION_NAME "soci_parse_version" + REQUIRED "OUTPUT_VARIABLE" "ROOT_DIR" + ) + + set(VERSION_REGEX "^#define[ \\t]*SOCI_VERSION[ \\t]*([0-9]+)") + + file(STRINGS "${PARSE_VERSION_ROOT_DIR}/include/soci/version.h" VERSION_LINE + REGEX ${VERSION_REGEX} + LIMIT_COUNT 1 + ) + + if (NOT VERSION_LINE MATCHES "${VERSION_REGEX}") + message(STATUS "${PARSE_VERSION_ROOT_DIR}") + message(FATAL_ERROR "Failed at parsing version from header file") + endif() + + set(RAW_VERSION "${CMAKE_MATCH_1}") + math(EXPR MAJOR_VERSION "${RAW_VERSION} / 100000") + math(EXPR MINOR_VERSION "(${RAW_VERSION} / 100) % 1000") + math(EXPR PATCH_VERSION "${RAW_VERSION} % 100") + + set("${PARSE_VERSION_OUTPUT_VARIABLE}" "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}" PARENT_SCOPE) +endfunction() diff --git a/cmake/soci_utils.cmake b/cmake/soci_utils.cmake new file mode 100644 index 000000000..4d0524e6a --- /dev/null +++ b/cmake/soci_utils.cmake @@ -0,0 +1,226 @@ +# This function is meant to be called by other cmake functions that use the cmake_parse_arguments function. +# It implements the boilerplate that is associated with validating the parsed arguments (e.g. no unknown arguments used; +# ensuring all required options have been set). +# +# Use as +# soci_verify_parsed_arguments( +# PREFIX +# FUNCTION_NAME +# [REQUIRED 
] +# ) +# where +# - is the prefix used in the cmake_parse_arguments call that shall be validated +# - is the name of the calling function or macro - this will be part of error mesages +# - are names of options **without** the prefix +function(soci_verify_parsed_arguments) + set(FLAGS "") + set(ONE_VAL_OPTIONS "PREFIX" "FUNCTION_NAME") + set(MULTI_VAL_OPTIONS "REQUIRED") + cmake_parse_arguments(VERIFY_PARSED_ARGS "${FLAGS}" "${ONE_VAL_OPTIONS}" "${MULTI_VAL_OPTIONS}" ${ARGV}) + + # First, verify own arguments + if (DEFINED VERIFY_PARSED_ARGS_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "verify_parsed_arguments - Received unrecognized options: ${VERIFY_PARSED_ARGS_UNPARSED_ARGUMENTS}") + endif() + if (DEFINED VERIFY_PARSED_ARGS_KEYWORDS_MISSING_VALUES) + message(FATAL_ERROR "verify_parsed_arguments - The following options are missing argumens: ${VERIFY_PARSED_ARGS_KEYWORDS_MISSING_VALUES}") + endif() + if (NOT DEFINED VERIFY_PARSED_ARGS_PREFIX) + message(FATAL_ERROR "verify_parsed_arguments - Missing required option 'PREFIX'") + endif() + if (NOT DEFINED VERIFY_PARSED_ARGS_FUNCTION_NAME) + message(FATAL_ERROR "verify_parsed_arguments - Missing required option 'FUNCTION_NAME'") + endif() + + # Now start the function's actual job: Verifying a top-level function's call to cmake_parse_arguments + if (DEFINED ${VERIFY_PARSED_ARGS_PREFIX}_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "${VERIFY_PARSED_ARGS_FUNCTION_NAME} - Received unrecognized options: ${${VERIFY_PARSED_ARGS_PREFIX}_UNPARSED_ARGUMENTS}") + endif() + if (DEFINED ${VERIFY_PARSED_ARGS_PREFIX}_KEYWORDS_MISSING_VALUES) + message(FATAL_ERROR "${VERIFY_PARSED_ARGS_FUNCTION_NAME} - The following options are missing arguments: ${${VERIFY_PARSED_ARGS_PREFIX}_KEYWORDS_MISSING_VALUES}") + endif() + + if (DEFINED VERIFY_PARSED_ARGS_REQUIRED) + foreach(CURRENT_ARG IN LISTS VERIFY_PARSED_ARGS_REQUIRED) + set(CURRENT_ARG "${VERIFY_PARSED_ARGS_PREFIX}_${CURRENT_ARG}") + if (NOT DEFINED ${CURRENT_ARG}) + message(FATAL_ERROR "${VERIFY_PARSED_ARGS_FUNCTION_NAME - Missing required option '${CURRENT_ARG}'") + endif() + endforeach() + endif() +endfunction() + + +# Initialize variables populated by soci_public_dependency +set(SOCI_DEPENDENCY_VARIABLES + "SOCI_DEPENDENCY_SOCI_COMPONENTS" + "SOCI_DEPENDENCY_NAMES" + "SOCI_DEPENDENCY_TARGETS" + "SOCI_DEPENDENCY_REQUIRED" + "SOCI_DEPENDENCY_MACRO_NAMES" + "SOCI_DEPENDENCY_COMPONENTS" +) +if (NOT DEFINED SOCI_UTILS_ALREADY_INCLUDED) + foreach(VAR_NAME IN LISTS SOCI_DEPENDENCY_VARIABLES) + set("${VAR_NAME}" "" CACHE INTERNAL "") + endforeach() +endif() + +# This function declares a public dependency of a given target in such a way that +# the dependency is automatically populated to a generated SOCI config file. +# +# Use as +# soci_public_dependency( +# NAME +# DEP_TARGET +# TARGET +# [MACRO_NAMES ...] +# [REQUIRED] +# [COMPONENTS ...] +# ) +# where +# - is the name of the dependency (used for lookup via find_package) +# - is the name of the target that will be imported upon a +# successful find_package call +# - is the name of the ALIAS target to link the found dependency to +# - are the names of specific components of the dependency +function(soci_public_dependency) + set(FLAGS "REQUIRED") + set(ONE_VAL_OPTIONS "TARGET" "NAME") + set(MULTI_VAL_OPTIONS "COMPONENTS" "MACRO_NAMES" "DEP_TARGETS") + + cmake_parse_arguments(PUBLIC_DEP "${FLAGS}" "${ONE_VAL_OPTIONS}" "${MULTI_VAL_OPTIONS}" ${ARGV}) + soci_verify_parsed_arguments( + PREFIX "PUBLIC_DEP" + FUNCTION_NAME "soci_public_dependency" + REQUIRED "TARGET" "NAME" "DEP_TARGETS" + ) + + # Sanity checking + if (NOT TARGET "${PUBLIC_DEP_TARGET}") + message(FATAL_ERROR "Provided TARGET '${PUBLIC_DEP_TARGET}' does not exist") + endif() + + get_target_property(UNDERLYING_TARGET "${PUBLIC_DEP_TARGET}" ALIASED_TARGET) + if (NOT UNDERLYING_TARGET) + message(FATAL_ERROR "Provided TARGET '${PUBLIC_DEP_TARGET}' is expected to be an ALIAS target") + endif() + + + # Bookkeeping + list(APPEND SOCI_DEPENDENCY_SOCI_COMPONENTS "${PUBLIC_DEP_TARGET}") + list(APPEND SOCI_DEPENDENCY_NAMES "${PUBLIC_DEP_NAME}") + list(JOIN PUBLIC_DEP_DEP_TARGETS "|" STORED_TARGETS) + list(APPEND SOCI_DEPENDENCY_TARGETS "${STORED_TARGETS}") + list(APPEND SOCI_DEPENDENCY_REQUIRED "${PUBLIC_DEP_REQUIRED}") + if (PUBLIC_DEP_MACRO_NAMES) + list(JOIN PUBLIC_DEP_MACRO_NAMES "|" STORED_MACROS) + else() + set(STORED_MACROS "") + endif() + list(APPEND SOCI_DEPENDENCY_MACRO_NAMES "${STORED_MACROS}") + if (PUBLIC_DEP_COMPONENTS) + list(JOIN PUBLIC_DEP_COMPONENTS "|" STORED_COMPONENTS) + else() + set(STORED_COMPONENTS "") + endif() + list(APPEND SOCI_DEPENDENCY_COMPONENTS "${STORED_COMPONENTS}") + + + foreach(VAR_NAME IN LISTS SOCI_DEPENDENCY_VARIABLES) + set("${VAR_NAME}" "${${VAR_NAME}}" CACHE INTERNAL "") + endforeach() + + + # Search for the package now + if (PUBLIC_DEP_REQUIRED) + set(REQUIRED "REQUIRED") + else() + set(REQUIRED "") + endif() + + if (PUBLIC_DEP_COMPONENTS) + set(COMPONENTS COMPONENTS ${PUBLIC_DEP_COMPONENTS}) + else() + set(COMPONENTS "") + endif() + + set(SKIP_SEARCH ON) + foreach (TGT IN LISTS PUBLIC_DEP_DEP_TARGETS) + if (NOT TARGET "${TGT}") + set(SKIP_SEARCH OFF) + endif() + endforeach() + + if (NOT SKIP_SEARCH) + find_package("${PUBLIC_DEP_NAME}" ${COMPONENTS} ${REQUIRED}) + endif() + + set(FOUND_ONE OFF) + foreach (TGT IN LISTS PUBLIC_DEP_DEP_TARGETS) + if (NOT TARGET "${TGT}") + if (FOUND_ONE) + message(DEBUG "The following SOCI dependencies have been found only partially: ${PUBLIC_DEP_DEP_TARGETS}") + endif() + return() + endif() + + set(FOUND_ONE ON) + + target_link_libraries("${UNDERLYING_TARGET}" PUBLIC "$") + endforeach() + + foreach (MACRO_NAME IN LISTS PUBLIC_DEP_MACRO_NAMES) + # Note: We don't want these compile definitions to be exported to the install tree + # -> We put the logic of when they should be defined into the cmake config files + target_compile_definitions("${UNDERLYING_TARGET}" PUBLIC "$") + endforeach() +endfunction() + +# This function can be used to check whether two C++ types actually refer to the same +# type (e.g. if one is aliased to the other). +# +# Use as +# soci_are_types_same( +# TYPES [... ] +# OUTPUT_VARIABLE +# ) +# where +# - , , are the types to test +# - is the name of the variable that will hold the result of the check +function(soci_are_types_same) + set(FLAGS "") + set(ONE_VAL_OPTIONS "OUTPUT_VARIABLE") + set(MULTI_VAL_OPTIONS "TYPES") + + cmake_parse_arguments(TYPES_SAME "${FLAGS}" "${ONE_VAL_OPTIONS}" "${MULTI_VAL_OPTIONS}" ${ARGV}) + soci_verify_parsed_arguments( + PREFIX "TYPES_SAME" + FUNCTION_NAME "soci_are_types_same" + REQUIRED "TYPES" "OUTPUT_VARIABLE" + ) + + set(TEST_CODE "#include \nstruct Foo { ") + set(TEST_NAME "") + foreach(CURRENT_TYPE IN LISTS TYPES_SAME_TYPES) + string(APPEND TEST_CODE "void foo(${CURRENT_TYPE} x); ") + string(TOUPPER "${CURRENT_TYPE}" UPPER_TYPE) + string(APPEND TEST_NAME "${UPPER_TYPE}_") + endforeach() + string(APPEND TEST_CODE "};\nint main() {}") + string(APPEND TEST_NAME "ARE_DISTINGUISHABLE") + + include(CheckCXXSourceCompiles) + + # If some of the provided types are actually the same, compilation + # will fail due to duplication of function declarations. + check_cxx_source_compiles("${TEST_CODE}" ${TEST_NAME}) + + if (${TEST_NAME}) + set("${TYPES_SAME_OUTPUT_VARIABLE}" FALSE PARENT_SCOPE) + else() + set("${TYPES_SAME_OUTPUT_VARIABLE}" TRUE PARENT_SCOPE) + endif() +endfunction() + +set(SOCI_UTILS_ALREADY_INCLUDED TRUE) diff --git a/docs/installation.md b/docs/installation.md index 19a28ffc9..1acef0a88 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -5,8 +5,8 @@ Below is an overall list of SOCI core: * C++ compiler: [GCC](http://gcc.gnu.org/), [Microsoft Visual C++](http://msdn.microsoft.com/en-us/visualc), [LLVM/clang](http://clang.llvm.org/) -* [CMake](http://www.cmake.org) 2.8+ - in order to use build configuration for CMake -* [Boost C++ Libraries](http://www.boost.org): DateTime, Fusion, Optional, Preprocessor, Tuple +* [CMake](http://www.cmake.org) 3.23+ +* Optional: [Boost C++ Libraries](http://www.boost.org): DateTime, Fusion, Optional, Preprocessor, Tuple and backend-specific dependencies: @@ -32,7 +32,7 @@ git clone git://github.com/SOCI/soci.git ## Building with CMake -SOCI is configured to build using [CMake](http://cmake.org/) system in version 2.8+. +SOCI is configured to build using [CMake](http://cmake.org/) system in version 2.23+. The build configuration allows to control various aspects of compilation and installation by setting common CMake variables that change behaviour, describe @@ -44,28 +44,16 @@ Running CMake from the command line allows to set variables in the CMake cache with the following syntax: `-DVARIABLE:TYPE=VALUE`. If you are new to CMake, you may find the tutorial [Running CMake](http://cmake.org/cmake/help/runningcmake.html) helpful. -### Running CMake on Unix +### TL;DR Steps outline using GNU Make `Makefile`-s: ```console -mkdir build -cd build -cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_ORACLE=OFF (...) /path/to/soci-X.Y.Z -make -make install -``` - -### Running CMake on Windows - -Steps outline using Visual Studio 2010 and MSBuild: - -```console -mkdir build -cd build -cmake -G "Visual Studio 10" -DWITH_BOOST=OFF -DWITH_ORACLE=OFF (...) C:\path\to\soci-X.Y.Z -msbuild.exe SOCI.sln +cmake -DSOCI_ORACLE=OFF (...) -B build -S /path/to/soci-X.Y.Z +cmake --build build ``` +Optionally, SOCI defines an install target that can be executed (on Unix systems) +via `make install`. ### CMake configuration @@ -75,13 +63,6 @@ However, if CMake reports some of the core or backend-specific dependencies as missing, you will need specify relevant variables to tell CMake where to look for the required components. -CMake configures SOCI build performing sequence of steps. -Each subsequent step is dependant on result of previous steps corresponding with particular feature. -First, CMake checks system platform and compilation toolset. -Next, CMake tries to find all external dependencies. -Then, depending on the results of the dependency check, CMake determines SOCI backends which are possible to build. -The SOCI-specific variables described below provide users with basic control of this behaviour. - The following sections provide summary of variables accepted by CMake scripts configuring SOCI build. The lists consist of common variables for SOCI core and all backends as well as variables specific to SOCI backends and their direct dependencies. @@ -93,110 +74,77 @@ List of a few essential CMake variables: List of variables to control common SOCI features and dependencies: -* `SOCI_SHARED` - boolean - Request to build shared libraries for SOCI core and all successfully configured backends. Default is `ON`. -* `SOCI_STATIC` - boolean - Request to build static libraries for SOCI core and all successfully configured backends. Default is `ON`. -* `SOCI_TESTS` - boolean - Request to build regression tests for SOCI core and all successfully configured backends. -* `WITH_BOOST` - boolean - Should CMake try to detect [Boost C++ Libraries](http://www.boost.org/). If ON, CMake will try to find Boost headers and binaries of [Boost.Date_Time](http://www.boost.org/doc/libs/release/doc/html/date_time.html) library. +* `SOCI_SHARED` - boolean - Request to build shared libraries for SOCI. Default is `ON`. +* `SOCI_TESTS` - boolean - Request to build unit tests for SOCI. Default is `ON`, if you build SOCI standalone. Otherwise, it defaults to `OFF`. Some other build options: * `SOCI_ASAN` - boolean - Build with address sanitizer (ASAN) support. Useful for finding problems when debugging, but shouldn't be used for the production builds due to extra overhead. Default is `OFF`. * `SOCI_UBSAN` - boolean - Build with undefined behaviour sanitizer (ASAN) support. Default is `OFF`. * `SOCI_LTO` - boolean - Build with link-time optimizations, if supported. This produces noticeably smaller libraries. Default is `OFF`, but turning it on is recommended for the production builds. -* `SOCI_VISIBILITY` - boolean - Use hidden ELF visibility for private symbols if supported by the platform. This option produces smaller libraries by avoiding exporting internal function symbols. Default is `ON`. + +When it comes to enabling specific backends, SOCI supports three distinct options that can be used as `Enabler` type as used below: +- `AUTO`: Try to locate the backend's dependencies. If all dependencies are met, enable the backend, otherwise disable it and continue without it. +- `OFF`: Disable the backend. +- `ON`: Enables the backend. If one or more of its dependencies are unmet, error and abort configuration. #### Empty (sample backend) -* `SOCI_EMPTY` - boolean - Builds the [sample backend](backends/index.md) called Empty. Always ON by default. +* `SOCI_EMPTY` - Enabler - Enables the [sample backend](backends/index.md) called Empty. Always ON by default. * `SOCI_EMPTY_TEST_CONNSTR` - string - Connection string used to run regression tests of the Empty backend. It is a dummy value. Example: `-DSOCI_EMPTY_TEST_CONNSTR="dummy connection"` +* `SOCI_EMPTY_SKIP_TESTS` - boolean - Skips testing this backend. #### IBM DB2 -* `WITH_DB2` - boolean - Should CMake try to detect IBM DB2 Call Level Interface (CLI) library. -* `DB2_INCLUDE_DIR` - string - Path to DB2 CLI include directories where CMake should look for `sqlcli1.h` header. +* `SOCI_DB2` - Enabler - Enables the [DB2](backends/db2.md) backend. +* `DB2_INCLUDE_DIRS` - string - Path to DB2 CLI include directories where CMake should look for `sqlcli1.h` header. * `DB2_LIBRARIES` - string - Full paths to `db2` or `db2api` libraries to link SOCI against to enable the backend support. -* `SOCI_DB2` - boolean - Requests to build [DB2](backends/db2.md) backend. Automatically switched on, if `WITH_DB2` is set to ON. * `SOCI_DB2_TEST_CONNSTR` - string - See [DB2 backend reference](backends/db2.md) for details. Example: `-DSOCI_DB2_TEST_CONNSTR:STRING="DSN=SAMPLE;Uid=db2inst1;Pwd=db2inst1;autocommit=off"` +* `SOCI_DB2_SKIP_TESTS` - boolean - Skips testing this backend. #### Firebird -* `WITH_FIREBIRD` - boolean - Should CMake try to detect Firebird client library. -* `FIREBIRD_INCLUDE_DIR` - string - Path to Firebird include directories where CMake should look for `ibase.h` header. +* `SOCI_FIREBIRD` - Enabler - Enables the [Firebird](backends/firebird.md) backend. +* `FIREBIRD_INCLUDE_DIRS` - string - Path to Firebird include directories where CMake should look for `ibase.h` header. * `FIREBIRD_LIBRARIES` - string - Full paths to Firebird `fbclient` or `fbclient_ms` libraries to link SOCI against to enable the backend support. -* `SOCI_FIREBIRD` - boolean - Requests to build [Firebird](backends/firebird.md) backend. Automatically switched on, if `WITH_FIREBIRD` is set to ON. * `SOCI_FIREBIRD_TEST_CONNSTR` - string - See [Firebird backend reference](backends/firebird.md) for details. Example: `-DSOCI_FIREBIRD_TEST_CONNSTR:STRING="service=LOCALHOST:/tmp/soci_test.fdb user=SYSDBA password=masterkey"` +* `SOCI_FIREBIRD_SKIP_TESTS` - boolean - Skips testing this backend. #### MySQL -* `WITH_MYSQL` - boolean - Should CMake try to detect [mysqlclient](https://dev.mysql.com/doc/refman/5.5/en/c-api.html) libraries providing MySQL C API. Note, currently the [mysql_config](https://dev.mysql.com/doc/refman/5.5/en/c-api-building-clients.html) program is not being used. +* `SOCI_MYSQL` - Enabler - Enables the [MySQL](backends/mysql.md) backend. * `MYSQL_DIR` - string - Path to MySQL installation root directory. CMake will scan subdirectories `MYSQL_DIR/include` and `MYSQL_DIR/lib` respectively for MySQL headers and libraries. -* `MYSQL_INCLUDE_DIR` - string - Path to MySQL include directory where CMake should look for `mysql.h` header. +* `MYSQL_INCLUDE_DIRS` - string - Path to MySQL include directory where CMake should look for `mysql.h` header. * `MYSQL_LIBRARIES` - string - Full paths to libraries to link SOCI against to enable the backend support. -* `SOCI_MYSQL` - boolean - Requests to build [MySQL](backends/mysql.md) backend. Automatically switched on, if `WITH_MYSQL` is set to ON. * `SOCI_MYSQL_TEST_CONNSTR` - string - Connection string to MySQL test database. Format of the string is explained [MySQL backend reference](backends/mysql.md). Example: `-DSOCI_MYSQL_TEST_CONNSTR:STRING="db=mydb user=mloskot password=secret"` +* `SOCI_MYSQL_SKIP_TESTS` - boolean - Skips testing this backend. #### ODBC -* `WITH_ODBC` - boolean - Should CMake try to detect ODBC libraries. On Unix systems, CMake tries to find [unixODBC](http://www.unixodbc.org/) or [iODBC](http://www.iodbc.org/) implementations. -* `ODBC_INCLUDE_DIR` - string - Path to ODBC implementation include directories where CMake should look for `sql.h` header. -* `ODBC_LIBRARIES` - string - Full paths to libraries to link SOCI against to enable the backend support. -* `SOCI_ODBC` - boolean - Requests to build [ODBC](backends/odbc.md) backend. Automatically switched on, if `WITH_ODBC` is set to ON. +* `SOCI_ODBC` - Enabler - Enables the [ODBC](backends/odbc.md) backend. * `SOCI_ODBC_TEST_{database}_CONNSTR` - string - ODBC Data Source Name (DSN) or ODBC File Data Source Name (FILEDSN) to test database: Microsoft Access (.mdb), Microsoft SQL Server, MySQL, PostgreSQL or any other ODBC SQL data source. {database} is placeholder for name of database driver ACCESS, MYSQL, POSTGRESQL, etc. See [ODBC](backends/odbc.md) backend reference for details. Example: `-DSOCI_ODBC_TEST_POSTGRESQL_CONNSTR="FILEDSN=/home/mloskot/soci/build/test-postgresql.dsn"` +* `SOCI_ODBC_SKIP_TESTS` - boolean - Skips testing this backend. #### Oracle -* `WITH_ORACLE` - boolean - Should CMake try to detect [Oracle Call Interface (OCI)](http://en.wikipedia.org/wiki/Oracle_Call_Interface) libraries. -* `ORACLE_INCLUDE_DIR` - string - Path to Oracle include directory where CMake should look for `oci.h` header. +* `SOCI_ORACLE` - Enabler - Enables the [Oracle](backends/oracle.md) backend. +* `ORACLE_INCLUDE_DIRS` - string - Path to Oracle include directory where CMake should look for `oci.h` header. * `ORACLE_LIBRARIES` - string - Full paths to libraries to link SOCI against to enable the backend support. -* `SOCI_ORACLE` - boolean - Requests to build [Oracle](backends/oracle.md) backend. Automatically switched on, if `WITH_ORACLE` is set to ON. * `SOCI_ORACLE_TEST_CONNSTR` - string - Connection string to Oracle test database. Format of the string is explained [Oracle backend reference](backends/oracle.md). Example: `-DSOCI_ORACLE_TEST_CONNSTR:STRING="service=orcl user=scott password=tiger"` +* `SOCI_ORACLE_SKIP_TESTS` - boolean - Skips testing this backend. #### PostgreSQL -* `WITH_POSTGRESQL` - boolean - Should CMake try to detect PostgreSQL client interface libraries. SOCI relies on [libpq](http://www.postgresql.org/docs/current/static/libpq.html") C library. -* `POSTGRESQL_INCLUDE_DIR` - string - Path to PostgreSQL include directory where CMake should look for `libpq-fe.h` header. -* `POSTGRESQL_LIBRARY` - string - Full paths to libraries to link SOCI against to enable the backend support. The `POSTGRESQL_LIBRARIES` will be set with PostgreSQL libraries needed for linking. -* `SOCI_POSTGRESQL` - boolean - Requests to build [PostgreSQL](backends/postgresql.md) backend. Automatically switched on, if `WITH_POSTGRESQL` is set to ON. +* `SOCI_POSTGRESQL` - Enabler - Enables the [PostgreSQL](backends/postgresql.md) backend. * `SOCI_POSTGRESQL_TEST_CONNSTR` - string - Connection string to PostgreSQL test database. Format of the string is explained PostgreSQL backend reference. Example: `-DSOCI_POSTGRESQL_TEST_CONNSTR:STRING="dbname=mydb user=scott"` +* `SOCI_POSTGRESQL_SKIP_TESTS` - boolean - Skips testing this backend. #### SQLite 3 -* `WITH_SQLITE3` - boolean - Should CMake try to detect SQLite C/C++ library. As bonus, the configuration tries OSGeo4W distribution if OSGEO4W_ROOT environment variable is set. -* `SQLITE3_INCLUDE_DIR` - string - Path to SQLite 3 include directory where CMake should look for `sqlite3.h` header. -* `SQLITE3_LIBRARY` - string - Full paths to libraries to link SOCI against to enable the backend support. -* `SOCI_SQLITE3` - boolean - Requests to build [SQLite3](backends/sqlite3.md) backend. Automatically switched on, if `WITH_SQLITE3` is set to ON. +* `SOCI_SQLITE3` - Enabler - Enables the [SQLite3](backends/sqlite3.md) backend. * `SOCI_SQLITE3_TEST_CONNSTR` - string - Connection string is simply a file path where SQLite3 test database will be created (e.g. /home/john/soci_test.db). Check [SQLite3 backend reference](backends/sqlite3.md) for details. Example: `-DSOCI_SQLITE3_TEST_CONNSTR="my.db"` or `-DSOCI_SQLITE3_TEST_CONNSTR=":memory:"`. +* `SOCI_SQLITE3_SKIP_TESTS` - boolean - Skips testing this backend. -## Building with Makefiles on Unix - -*NOTE: These (classic) Makefiles have not been maintained for long time. -The officially maintained build configuration is CMake. -If you still want to use these Makefiles, you've been warned that you may need to patch them.* - -The classic set of Makefiles for Unix/Linux systems is provided for those users who need complete control over the whole processand who can benefit from the basic scaffolding that they can extend on their own. -In this sense, the basic Makefiles are supposed to provide a minimal starting point for custom experimentation and are not intended to be a complete build/installation solution. -At the same time, they are complete in the sense that they can compile the library with all test programs and for some users this level of support will be just fine. - -The `core` directory of the library distribution contains the `Makefile.basic` that can be used to compile the core part of the library. -Run `make -f Makefile.basic` or `make -f Makefile.basic shared` to get the static and shared versions, respectively. -Similarly, the `backends/name` directory contains the backend part for each supported backend with the appropriate `Makefile.basic` and the `backends/name/test` directory contains the test program for the given backend. - -For example, the simplest way to compile the static version of the library and the test program for PostgreSQL is: - -```console -cd src/core -make -f Makefile.basic -cd ../backends/postgresql -make -f Makefile.basic -cd test -make -f Makefile.basic -``` - -For each backend and its test program, the `Makefile.basic`s contain the variables that can have values specific to the given environment - they usually name the include and library paths. -These variables are placed at the beginning of the `Makefile.basic`s. -Please review their values in case of any compilation problems. - -The Makefiles for test programs can be a good starting point to find out correct compiler and linker options. ## Building with Conan @@ -291,12 +239,11 @@ In the example above, regression tests for the sample Empty backend and SQLite 3 ## Using library -CMake build produces set of shared and static libraries for SOCI core and backends separately. -On Unix, for example, `build/lib` directory will consist of the static libraries named like `libsoci_core.a`, `libsoci_sqlite3.a` and shared libraries with names like `libsoci_core.so.4.0.0`, `libsoci_sqlite3.so.4.0.0`, and so on. +CMake build produces set separate libraries for SOCI's core and all enabled backends. -If your project also uses CMake, you can simply use `find_package(Soci)` to check for SOCI availability and `target_link_libraries()` to link with the SOCI libraries available under the names `Soci::core` and `Soci::` (or `Soci::_static` if you prefer linking statically) and ensure that SOCI headers can be included (i.e. there is no need to use `target_include_directories()` explicitly). An example of a very simple CMake-based project using SOCI is provided in the `examples/connect` directory. +If your project also uses CMake, you can simply use `find_package(SOCI)` to check for SOCI availability and `target_link_libraries()` to link with the `SOCI::soci` target. An example of a very simple CMake-based project using SOCI is provided in the `examples/connect` directory. -Alternatively, you can add SOCI as a subdirectory to your project and include it via `add_subdirectory()`. As before, `target_link_libraries()` is used to link with the SOCI libraries available under the same names `Soci::core` and `Soci::` as above. An example of this can be found in the directory `examples/subdir-include`. +Alternatively, you can add SOCI as a subdirectory to your project and include it via `add_subdirectory()`. As before, `target_link_libraries()` is used to link with the `SOCI::soci` target. An example of this can be found in the directory `examples/subdir-include`. If you don't use CMake but want to use SOCI in your program, you need to specify the paths to the SOCI headers and libraries in your build configuration and to tell the linker to link against the libraries you want to use in your program. diff --git a/examples/connect/CMakeLists.txt b/examples/connect/CMakeLists.txt index c315cc91f..a5fefb808 100644 --- a/examples/connect/CMakeLists.txt +++ b/examples/connect/CMakeLists.txt @@ -7,20 +7,28 @@ # This is a very simple example of using SOCI in a CMake-based project. -cmake_minimum_required(VERSION 2.8 FATAL_ERROR) +cmake_minimum_required(VERSION 3.10...3.31 FATAL_ERROR) project(SOCIExampleConnect) -find_package(Soci REQUIRED) +# Note: SOCI versions before 4.1 rely on hand-written FindSOCI.cmake files to be +# present in downstream projects as SOCI didn't use to ship a config file. +# This is changed in 4.1 thanks to which the desired database backends can +# be specified as components. Known component names are +# - Empty +# - DB2 +# - Firebird +# - MySQL +# - ODBC +# - Oracle +# - PostgreSQL +# - SQLite3 +# note that some components may still be undefined if the corresponding library is +# not included in the SOCI version installed on your system. +find_package(SOCI 4.1 COMPONENTS Empty REQUIRED) add_executable(connect connect.cpp) -# Note that depending on the SOCI library automatically pulls in the required -# SOCI compilation options too, i.e. there is no need to explicitly use -# target_include_directories(). -# -# Linking with just soci_core is enough when using shared libraries, as the -# required backends will be loaded dynamically during run-time, but when using -# static libraries you would need to link with all the soci_ libraries -# needed too. -target_link_libraries(connect PRIVATE SOCI::soci_core) +# Note that linking to SOCI::soci is enough to inherit +# all of SOCI's dependencies, include directories, etc. +target_link_libraries(connect PRIVATE SOCI::soci) diff --git a/examples/subdir-include/CMakeLists.txt b/examples/subdir-include/CMakeLists.txt index 6861bc560..dd7992a13 100644 --- a/examples/subdir-include/CMakeLists.txt +++ b/examples/subdir-include/CMakeLists.txt @@ -2,15 +2,37 @@ # when placing SOCI in a subdirectory lib/soci/ of your project. # For this example, the SOCI backend called Empty is used. -cmake_minimum_required(VERSION 2.8 FATAL_ERROR) +cmake_minimum_required(VERSION 3.23 FATAL_ERROR) project(SOCIExampleSubdirectoryInclude) set(SOCI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/soci) # All compile options need to be set before the SOCI directory gets included. -# The backend you want to use needs to be enabled here. -option(SOCI_EMPTY "Build the sample backend called Empty" ON) +# The backend you want to use needs to be enabled here. Available options are +# - SOCI_DB2 +# - SOCI_EMPTY +# - SOCI_FIREBIRD +# - SOCI_MYSQL +# - SOCI_ODBC +# - SOCI_ORACLE +# - SOCI_POSTGRESQL +# - SOCI_SQLITE3 +# each of these options can be set to "ON" or "OFF" or to +# "AUTO" (the default) in which case the backend is included only +# if all of its dependencies are satisfied. If not, the backend +# is disabled but no error is emitted (which is what would happen +# in this case if the backend was set to "ON"). +set(SOCI_EMPTY ON CACHE INTERNAL "" FORCE) + +# In order to not run into cross-platform issues, the **top-level** project +# should define these variables to ensure all build artefacts (of a given kind) +# end up in the same place. +if (PROJECT_IS_TOP_LEVEL) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") +endif() # This line needs to be changed to include the directory you placed SOCI in, e.g. # add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/soci ${SOCI_BINARY_DIR}) @@ -18,12 +40,8 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${SOCI_BINARY_DIR}) add_executable(subdir_include subdir-include.cpp) -# Link the soci_ libraries you want to use here. -# There is no need to explicitly use target_include_directories() for the -# main headers or the generated header (soci/soci-config.h), because both -# are automatically added as part of the Soci::core target. +# Link to SOCI (SOCI::soci will resolve all requested dependencies automatically) target_link_libraries(subdir_include PRIVATE - Soci::core - Soci::empty + SOCI::soci ) diff --git a/include/soci/callbacks.h b/include/soci/callbacks.h index 85825ad1b..95ffe5690 100644 --- a/include/soci/callbacks.h +++ b/include/soci/callbacks.h @@ -8,6 +8,8 @@ #ifndef SOCI_CALLBACKS_H_INCLUDED #define SOCI_CALLBACKS_H_INCLUDED +#include + namespace soci { @@ -16,9 +18,11 @@ class session; // Simple callback interface for reporting failover events. // The meaning of each operation is intended to be portable, // but the behaviour details and parameters can be backend-specific. -class SOCI_DECL failover_callback +class failover_callback { public: + failover_callback() = default; + virtual ~failover_callback() = default; // Called when the failover operation has started, // after discovering connectivity problems. @@ -27,15 +31,15 @@ class SOCI_DECL failover_callback // Called after successful failover and creating a new connection; // the sql parameter denotes the new connection and allows the user // to replay any initial sequence of commands (like session configuration). - virtual void finished(session & /* sql */) {} + virtual void finished(session& /* sql */) {} // Called when the attempt to reconnect failed, // if the user code sets the retry parameter to true, // then new connection will be attempted; // the newTarget connection string is a hint that can be ignored // by external means. - virtual void failed(bool & /* out */ /* retry */, - std::string & /* out */ /* newTarget */) {} + virtual void failed(bool& /* out */ /* retry */, + std::string& /* out */ /* newTarget */) {} // Called when there was a failure that prevents further failover attempts. virtual void aborted() {} diff --git a/include/soci/mysql/soci-mysql.h b/include/soci/mysql/soci-mysql.h index e9dc17e76..83203c98e 100644 --- a/include/soci/mysql/soci-mysql.h +++ b/include/soci/mysql/soci-mysql.h @@ -19,29 +19,16 @@ #include #include -#ifdef _WIN32 -#include // SOCKET -#endif // _WIN32 - -// Some version of mysql.h contain trailing comma in an enum declaration that -// trigger -Wpedantic, so suppress it as there is nothing to be done about it -// using the macros defined in our private soci-compiler.h header, that we can -// only include when building SOCI itself. -#ifdef SOCI_MYSQL_SOURCE - #include "soci-compiler.h" -#endif - -#ifdef SOCI_GCC_WARNING_SUPPRESS - SOCI_GCC_WARNING_SUPPRESS(pedantic) -#endif +#ifdef SOCI_MYSQL_DIRECT_INCLUDE #include // MySQL Client #include // MySQL Error codes - -#ifdef SOCI_GCC_WARNING_RESTORE - SOCI_GCC_WARNING_RESTORE(pedantic) +#else +#include // MySQL Client +#include // MySQL Error codes #endif + #include diff --git a/include/soci/soci-config.h.in b/include/soci/soci-config.h.in deleted file mode 100644 index 77fff775d..000000000 --- a/include/soci/soci-config.h.in +++ /dev/null @@ -1,16 +0,0 @@ -// -// Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// - -#ifndef SOCICONFIG_H_INCLUDED -#define SOCICONFIG_H_INCLUDED - -// -// SOCI has been build with support for: -// -@CONFIGURED_VARIABLES@ - -#endif // SOCICONFIG_H_INCLUDED diff --git a/include/soci/soci-platform.h b/include/soci/soci-platform.h index 3f94cb57b..3172584b4 100644 --- a/include/soci/soci-platform.h +++ b/include/soci/soci-platform.h @@ -21,7 +21,7 @@ #include #include -#include "soci/soci-config.h" // for SOCI_HAVE_CXX11 +#include "soci/soci-config.h" #if defined(_MSC_VER) #define LL_FMT_FLAGS "I64" @@ -169,6 +169,8 @@ private: \ // Here the problem is that MSVC complains about unreachable code in this case // (but only in release builds, where optimizations are enabled), while other // compilers complain about missing return statement without it. +// Note: this macro is no longer used in SOCI's codebase. It is only retained +// in case downstream code is depending on it. #if defined(_MSC_VER) && defined(NDEBUG) #define SOCI_DUMMY_RETURN(x) #else diff --git a/include/soci/version.h b/include/soci/version.h index b13caa3dd..1a3ac7315 100644 --- a/include/soci/version.h +++ b/include/soci/version.h @@ -10,10 +10,8 @@ #ifndef SOCI_VERSION_HPP #define SOCI_VERSION_HPP -// When updating the version here, don't forget to update it in CMakeLists.txt! - // -// Caution, this is the only SOCI header that is guarenteed +// Caution, this is the only SOCI header that is guaranteed // to change with every SOCI release, including this header // will cause a recompile every time a new SOCI version is // released. diff --git a/scripts/ci/build_empty.sh b/scripts/ci/build_empty.sh index b27a31e08..d189e8416 100755 --- a/scripts/ci/build_empty.sh +++ b/scripts/ci/build_empty.sh @@ -13,17 +13,24 @@ run_cmake_for_empty() .. } -run_cmake_for_example() +build_example() { - cmake "../examples/$1" + cmake -S "../examples/$1" -B "$1" + cmake --build "$1" } +run_cmake_for_empty +run_make + if [[ "$BUILD_EXAMPLES" == "YES" ]]; then - run_cmake_for_example subdir-include - run_make -else - run_cmake_for_empty - run_make + # This example simulates SOCI sources being embedded in the project dir + build_example subdir-include + + # Install previously built SOCI library on the system + sudo make install + + # This example simulates SOCI being installed on the target system + build_example connect fi # Test release branch packaging and building from the package diff --git a/scripts/ci/build_odbc.sh b/scripts/ci/build_odbc.sh index 0d64965c4..66d1b1412 100755 --- a/scripts/ci/build_odbc.sh +++ b/scripts/ci/build_odbc.sh @@ -11,7 +11,9 @@ if test ! -d ${ODBC_TEST}; then exit 1 fi +# Disable ASAN -> see https://github.com/SOCI/soci/issues/1008 cmake ${SOCI_DEFAULT_CMAKE_OPTIONS} \ + -DSOCI_ASAN=OFF \ -DSOCI_ODBC=ON \ .. diff --git a/scripts/ci/build_oracle.sh b/scripts/ci/build_oracle.sh index a5e235fcc..95d537a3f 100755 --- a/scripts/ci/build_oracle.sh +++ b/scripts/ci/build_oracle.sh @@ -6,7 +6,6 @@ source ${SOCI_SOURCE_DIR}/scripts/ci/common.sh cmake ${SOCI_DEFAULT_CMAKE_OPTIONS} \ - -DWITH_BOOST=OFF \ -DSOCI_ORACLE=ON \ -DSOCI_ORACLE_TEST_CONNSTR:STRING="service=localhost/XE user=travis password=travis" \ .. diff --git a/scripts/ci/common.sh b/scripts/ci/common.sh index 19efd16cf..226622ada 100644 --- a/scripts/ci/common.sh +++ b/scripts/ci/common.sh @@ -47,20 +47,20 @@ esac builddir="${SOCI_SOURCE_DIR}/_build" # These options are used for all builds. -SOCI_COMMON_CMAKE_OPTIONS=' +SOCI_COMMON_CMAKE_OPTIONS=" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=ON -DSOCI_ENABLE_WERROR=ON - -DSOCI_STATIC=OFF -DSOCI_TESTS=ON -' + -DCMAKE_UNITY_BUILD=$SOCI_ENABLE_UNITY_BUILD +" if [ -n "${SOCI_CXXSTD}" ]; then SOCI_COMMON_CMAKE_OPTIONS="$SOCI_COMMON_CMAKE_OPTIONS -DCMAKE_CXX_STANDARD=${SOCI_CXXSTD}" fi -if [ -n "${WITH_BOOST}" ]; then - SOCI_COMMON_CMAKE_OPTIONS="$SOCI_COMMON_CMAKE_OPTIONS -DWITH_BOOST=${WITH_BOOST}" +if [ -n "${SOCI_BUILD_STATIC}" ]; then + SOCI_COMMON_CMAKE_OPTIONS="${SOCI_COMMON_CMAKE_OPTIONS} -DSOCI_SHARED=OFF" fi # These options are defaults and used by most builds, but not Valgrind one. diff --git a/scripts/ci/install_firebird.sh b/scripts/ci/install_firebird.sh index 7cc3b2eec..774464416 100755 --- a/scripts/ci/install_firebird.sh +++ b/scripts/ci/install_firebird.sh @@ -18,7 +18,7 @@ EOF ) ;; - jammy | focal | bionic) + jammy | focal | bionic | noble) firebird_version=3.0 firebird_server_package=firebird3.0-server firebird_server_service=firebird3.0 diff --git a/scripts/ci/test_odbc.sh b/scripts/ci/test_odbc.sh index ebc011a85..27fa608c1 100755 --- a/scripts/ci/test_odbc.sh +++ b/scripts/ci/test_odbc.sh @@ -8,4 +8,4 @@ source ${SOCI_SOURCE_DIR}/scripts/ci/common.sh # Exclude the tests which can't be run due to the absence of ODBC drivers (MS # SQL and MySQL). -LSAN_OPTIONS=suppressions=${SOCI_SOURCE_DIR}/scripts/suppress_odbc.txt run_test -E 'soci_odbc_test_m.sql' +LSAN_OPTIONS=suppressions=${SOCI_SOURCE_DIR}/scripts/suppress_odbc.txt run_test -E 'soci_odbc_m.sql_test' diff --git a/soci-config.cmake.in b/soci-config.cmake.in new file mode 100644 index 000000000..0aac3e20d --- /dev/null +++ b/soci-config.cmake.in @@ -0,0 +1,161 @@ +@PACKAGE_INIT@ + + +# Auto-generated stub to handle component-wise dependencies +set(__dep_soci_comps "@SOCI_DEPENDENCY_SOCI_COMPONENTS@") +set(__dep_names "@SOCI_DEPENDENCY_NAMES@") +set(__dep_dep_targets "@SOCI_DEPENDENCY_TARGETS@") +set(__dep_required "@SOCI_DEPENDENCY_REQUIRED@") +set(__dep_macro_names "@SOCI_DEPENDENCY_MACRO_NAMES@") +set(__dep_components "@SOCI_DEPENDENCY_COMPONENTS@") + + +set(__prev_module_path "${CMAKE_MODULE_PATH}") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/find_package_files/") + + +if (NOT DEFINED SOCI_FIND_COMPONENTS OR SOCI_FIND_COMPONENTS STREQUAL "") + # Use all available SOCI components + set(SOCI_FIND_COMPONENTS "${__dep_soci_comps}") + list(REMOVE_DUPLICATES SOCI_FIND_COMPONENTS) + list(TRANSFORM SOCI_FIND_COMPONENTS REPLACE "SOCI::" "") +endif() + +# Ensure that the Core target is always included (and as first component) +list(REMOVE_ITEM SOCI_FIND_COMPONENTS Core) +list(INSERT SOCI_FIND_COMPONENTS 0 Core) + + +list(LENGTH __dep_soci_comps __list_size) +foreach (__item IN ITEMS __dep_names __dep_dep_targets __dep_required __dep_macro_names __dep_components) + list(LENGTH ${__item} __current_size) + if (NOT (__list_size EQUAL __current_size)) + message(FATAL_ERROR "SociConfig is invalid -> dependency lists have different sizes") + endif() +endforeach() +unset(__current_size) + +math(EXPR __list_size "${__list_size} - 1") + +foreach(__comp IN LISTS SOCI_FIND_COMPONENTS) + if (NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/SOCI${__comp}Targets.cmake") + set(SOCI_FOUND FALSE) + set(SOCI_NOT_FOUND_MESSAGE "'${__comp}' is not a known SOCI component") + continue() + endif() + + # Handle component-specific dependencies + set(__link_targets) + set(__define_macros) + set(__skip_dependency FALSE) + foreach (__i RANGE ${__list_size}) + list(GET __dep_soci_comps ${__i} __dep_comp) + if (__dep_comp MATCHES "::${__comp}$") + # This entry matches the current component + list(GET __dep_names ${__i} __dep) + list(GET __dep_dep_targets ${__i} __targets) + list(GET __dep_required ${__i} __required) + list(GET __dep_macro_names ${__i} __macros) + list(GET __dep_components ${__i} __components) + + # Split list-valued entries to become actual lists + string(REPLACE "|" ";" __targets "${__targets}") + string(REPLACE "|" ";" __macros "${__macros}") + string(REPLACE "|" ";" __components "${__components}") + + set(__already_found) + foreach (__tgt IN LISTS __targets) + if (TARGET ${__tgt}) + set(__already_found ON) + else() + set(__already_found OFF) + break() + endif() + endforeach() + + if (__already_found) + continue() + endif() + + if (__components) + set(__components COMPONENTS ${__components}) + endif() + + if (${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) + set(__quiet "QUIET") + else() + set(__quiet "") + endif() + + find_package( + ${__dep} + ${__components} + ${__quiet} + ) + + if (NOT ${__dep}_FOUND) + if (__required) + set(SOCI_FOUND FALSE) + set(SOCI_NOT_FOUND_MESSAGE "Unmet dependency '${__dep}' for SOCI component '${__comp}'") + set(__skip_dependency TRUE) + endif() + continue() + endif() + + list(APPEND __link_targets ${__targets}) + list(APPEND __define_macros ${__macros}) + endif() + endforeach() + unset(__i) + + if (__skip_dependency) + continue() + endif() + + include("${CMAKE_CURRENT_LIST_DIR}/SOCI${__comp}Targets.cmake") + + set_property( + TARGET SOCI::${__comp} + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES "${__link_targets}" + ) + if (__define_macros) + set_property( + TARGET SOCI::${__comp} + APPEND + PROPERTY INTERFACE_COMPILE_DEFINITIONS "${__define_macros}" + ) + endif() + + set(${CMAKE_FIND_PACKAGE_NAME}_${__comp}_FOUND ON) +endforeach() +unset(__comp) + + +unset(__dep_soci_comps) +unset(__dep_names) +unset(__dep_dep_targets) +unset(__dep_required) +unset(__dep_macro_names) +unset(__dep_components) + + +check_required_components(SOCI) + +if (NOT DEFINED SOCI_FOUND OR SOCI_FOUND) + add_library(soci_interface INTERFACE) + + foreach (__comp IN LISTS SOCI_FIND_COMPONENTS) + target_link_libraries(soci_interface INTERFACE SOCI::${__comp}) + endforeach() + + add_library(SOCI::soci ALIAS soci_interface) + + if (NOT SOCI_FIND_QUIETLY) + list(JOIN SOCI_FIND_COMPONENTS ", " __components) + message(STATUS "Found SOCI: ${CMAKE_CURRENT_LIST_FILE} (found version \"@PROJECT_VERSION@\") found components: ${__components}") + endif() +endif() + +set(CMAKE_MODULE_PATH "${__prev_module_path}") +unset(__prev_module_path) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 472ae864c..4c0c4c865 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,14 +1,110 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -include_directories(${SOCI_SOURCE_DIR}/include/private) +add_library(soci_interface INTERFACE) +add_library(SOCI::soci ALIAS soci_interface) + +set(SOCI_GENERATED_INCLUDES_DIR "${CMAKE_BINARY_DIR}/include") +file(MAKE_DIRECTORY "${SOCI_GENERATED_INCLUDES_DIR}/soci") add_subdirectory(core) add_subdirectory(backends) + + +############################################################################### +# platform-dependent settings +############################################################################### + +include(CheckTypeSize) +check_type_size(long SOCI_SIZEOF_LONG LANGUAGE CXX) + +soci_are_types_same(TYPES "int64_t" "long" OUTPUT_VARIABLE SOCI_INT64_T_IS_LONG) +soci_are_types_same(TYPES "int8_t" "char" OUTPUT_VARIABLE SOCI_INT8_T_IS_CHAR) + +include(CheckCXXSourceCompiles) +check_cxx_source_compiles( + " + __attribute__ (( visibility(\"default\") )) int f1() { return 0; } + __attribute__ (( visibility(\"hidden\") )) int f2() { return 1; } + + int main(int argc, char* argv[]) { f1(); f2(); return 0; } + " + SOCI_VISIBILITY_ATTRIBUTE_SUPPORTED +) + + +# Generate the soci-config.h file + +set(CONFIG_LINES "#ifndef SOCI_SOCICONFIG_H_INCLUDED" "#define SOCI_SOCICONFIG_H_INCLUDED" "") + +set(CONFIG_VARS + SOCI_EMPTY + SOCI_DB2 + SOCI_FIREBIRD + SOCI_MYSQL + SOCI_ODBC + SOCI_ORACLE + SOCI_POSTGRESQL + SOCI_SQLITE3 + SOCI_VISIBILITY_ATTRIBUTE_SUPPORTED + SOCI_SIZEOF_LONG + SOCI_INT64_T_IS_LONG + SOCI_INT8_T_IS_CHAR +) +set(CONFIG_MACROS + SOCI_HAVE_EMPTY + SOCI_HAVE_DB2 + SOCI_HAVE_FIREBIRD + SOCI_HAVE_MYSQL + SOCI_HAVE_ODBC + SOCI_HAVE_ORACLE + SOCI_HAVE_POSTGRESQL + SOCI_HAVE_SQLITE3 + SOCI_HAVE_VISIBILITY_SUPPORT + SOCI_SIZEOF_LONG + SOCI_INT64_T_IS_LONG + SOCI_INT8_T_IS_CHAR +) + +list(LENGTH CONFIG_MACROS N_CONFIGS) +math(EXPR LAST_CONFIG_IDX "${N_CONFIGS} - 1") + +foreach (I RANGE ${LAST_CONFIG_IDX}) + list(GET CONFIG_VARS ${I} CURRENT_VAR) + list(GET CONFIG_MACROS ${I} CURRENT_MACRO) + + if (${CURRENT_VAR}) + if ("${${CURRENT_VAR}}" MATCHES "[0-9]+") + list(APPEND CONFIG_LINES "#define ${CURRENT_MACRO} ${${CURRENT_VAR}}") + else() + # Assume this is a boolean flag + list(APPEND CONFIG_LINES "#define ${CURRENT_MACRO} 1") + endif() + else() + list(APPEND CONFIG_LINES "/* #define ${CURRENT_MACRO} */") + endif() + list(APPEND CONFIG_LINES "") +endforeach() + +list(APPEND CONFIG_LINES "#endif") + +list(JOIN CONFIG_LINES "\n" CONFIG_CONTENT) + +string(MD5 CONFIG_CONTENT_HASH "${CONFIG_CONTENT}") +if (EXISTS "${SOCI_GENERATED_INCLUDES_DIR}/soci/soci-config.h") + file(MD5 "${SOCI_GENERATED_INCLUDES_DIR}/soci/soci-config.h" CONFIG_FILE_HASH) +else() + set(CONFIG_FILE_HASH 0) +endif() + +# Only overwrite the soci-config.h file if the generated content is different from the +# file's content in order to avoid needless rebuilding +if (NOT (CONFIG_CONTENT_HASH STREQUAL CONFIG_FILE_HASH)) + file(WRITE "${SOCI_GENERATED_INCLUDES_DIR}/soci/soci-config.h" "${CONFIG_CONTENT}") +endif() + +# Append the generated config header to the public headers of the core target +target_sources(soci_core + PUBLIC + FILE_SET headers TYPE HEADERS + BASE_DIRS "${SOCI_GENERATED_INCLUDES_DIR}" + FILES + "${SOCI_GENERATED_INCLUDES_DIR}/soci/soci-config.h" +) diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt index 871e151ef..950d89a01 100644 --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -1,50 +1,80 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -colormsg(_HIBLUE_ "Configuring SOCI backend libraries:") - -# First, we'll investigate what can be found from database engines -foreach(dep ${SOCI_BACKENDS_DB_DEPENDENCIES}) - string(TOUPPER ${dep} depUP) - if (WITH_${depUP}) - find_package(${dep}) - endif() - if(${dep}_FOUND OR ${depUP}_FOUND) - set(${depUP}_FOUND ON) - else() - set(${depUP}_FOUND OFF) - endif() - set(SOCI_HAVE_${depUP} OFF CACHE INTERNAL "${depUP} backend") -endforeach() +set(SOCI_EXISTING_BACKENDS + "DB2" + "Empty" + "Firebird" + "MySQL" + "ODBC" + "Oracle" + "PostgreSQL" + "SQLite3" + CACHE INTERNAL "" FORCE +) +set(ENABLED_BACKENDS "") + +foreach(CURRENT_BACKEND IN LISTS SOCI_EXISTING_BACKENDS) + string(TOUPPER "${CURRENT_BACKEND}" CURRENT_BACKEND_UPPER) + string(TOLOWER "${CURRENT_BACKEND}" CURRENT_BACKEND_LOWER) + + set(CURRENT_ENABLED_VAR "SOCI_${CURRENT_BACKEND_UPPER}") + set( + CURRENT_DESCRIPTION + "Whether to include the '${CURRENT_BACKEND}' backend. Can be a boolean value or 'AUTO' indicating that it shall be included unless its dependencies can't be satisfied." + ) + + # Add option to enable/disable the current backend. Note: if the cache variable already exists + # (e.g. because it has been specified on the command line), this will NOT overwrite the + # explicitly specified value + set(${CURRENT_ENABLED_VAR} "AUTO" CACHE STRING "${CURRENT_DESCRIPTION}") + + + # Backwards compatibility with the old cmake setup that used WITH_* variables + # These are now only defined if the user specified them. + if (DEFINED WITH_${CURRENT_BACKEND_UPPER}) + message(DEPRECATION "Use of the WITH_${CURRENT_BACKEND_UPPER} option is deprecated - use the new ${CURRENT_ENABLED_VAR} instead") + if (WITH_${CURRENT_BACKEND_UPPER} AND ${CURRENT_ENABLED_VAR}) + # Overwrite the new-style enable-option unless that was set to disable the current backend + # (Note that non-empty string - in particular "AUTO" - also convert to a true expression). + # However, the legacy behavior was to only include the backend, if its dependencies are met, + # so we set to AUTO rather than ON. + set(${CURRENT_ENABLED_VAR} "AUTO" CACHE STRING "${CURRENT_DESCRIPTION}" FORCE) + endif() + # Delete the legacy variable from cache + unset(WITH_${CURRENT_BACKEND_UPPER} CACHE) + endif() + + + # Convert the value of the current backend's include flag to uppercase + string(TOUPPER "${${CURRENT_ENABLED_VAR}}" UPPER_VALUE) + set(${CURRENT_ENABLED_VAR} "${UPPER_VALUE}" CACHE STRING "${CURRENT_DESCRIPTION}" FORCE) -# get all files in backends -file(GLOB backend_dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *) - -# empty backend always on by default -option(SOCI_EMPTY "Build empty backend" ON) -if(SOCI_EMPTY) - set(WITH_EMPTY ON) - set(EMPTY_FOUND ON) -endif() - -# enable only found backends -foreach(dir ${backend_dirs}) - if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir}) - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt) - string(TOUPPER ${dir} dirUP) - if(${dirUP}_FOUND AND WITH_${dirUP}) - add_subdirectory(${dir}) - set(SOCI_HAVE_${dirUP} ON CACHE INTERNAL "${dirUP} backend") - endif() - endif() - endif() + + # Internal variable indicating whether the current backend's include mode is AUTO + set(CURRENT_AUTO_VAR "SOCI_${CURRENT_BACKEND_UPPER}_AUTO") + set(${CURRENT_AUTO_VAR} OFF) + + + if (${CURRENT_ENABLED_VAR} STREQUAL "AUTO") + set(${CURRENT_AUTO_VAR} ON) + # Convert include status to ON as the AUTO status is kept track of separately + set(${CURRENT_ENABLED_VAR} ON CACHE STRING "${CURRENT_DESCRIPTION}" FORCE) + elseif(${CURRENT_ENABLED_VAR} MATCHES "^(ON|OFF|TRUE|FALSE|YES|NO|[YN01])$") + set(INCLUDE_CURRENT_BACKEND ${${CURRENT_ENABLED_VAR}}) + else() + message(FATAL_ERROR "Invalid value '${${CURRENT_ENABLED_VAR}}' for option '${CURRENT_ENABLED_VAR}'") + endif() + + + if (${CURRENT_ENABLED_VAR}) + add_subdirectory(${CURRENT_BACKEND_LOWER}) + + # Verify that the backend hasn't been disabled (happens if include mode is AUTO and there are + # unmet dependencies. + if (${CURRENT_ENABLED_VAR}) + list(APPEND ENABLED_BACKENDS "${CURRENT_BACKEND}") + endif() + endif() endforeach() -message(STATUS "") +set(SOCI_ENABLED_BACKENDS "${ENABLED_BACKENDS}" CACHE INTERNAL "" FORCE) +message(STATUS "Enabled SOCI backends are: ${ENABLED_BACKENDS}") + diff --git a/src/backends/db2/CMakeLists.txt b/src/backends/db2/CMakeLists.txt index 7913d7920..ee1a07df1 100644 --- a/src/backends/db2/CMakeLists.txt +++ b/src/backends/db2/CMakeLists.txt @@ -1,14 +1,39 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2011 Denis Chapligin -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -soci_backend(DB2 - DEPENDS DB2 - DESCRIPTION "SOCI backend for DB2" AUTHORS "Denis Chapligin" - MAINTAINERS "Denis Chapligin") +include(soci_define_backend_target) + +if (SOCI_DB2_AUTO) + set(DEPENDENCY_MODE "DISABLE") +else() + set(DEPENDENCY_MODE "ERROR") +endif() + +soci_define_backend_target( + BACKEND_NAME "DB2" + TARGET_NAME "soci_db2" + ALIAS_NAME "DB2" + DEPENDENCIES + "DB2 YIELDS DB2::DB2" + REQUIRED_COMPONENTS SOCI::Core + SOURCE_FILES + "blob.cpp" + "factory.cpp" + "row-id.cpp" + "session.cpp" + "standard-into-type.cpp" + "standard-use-type.cpp" + "statement.cpp" + "vector-into-type.cpp" + "vector-use-type.cpp" + HEADER_FILES + "${PROJECT_SOURCE_DIR}/include/soci/db2/soci-db2.h" + PRIVATE_INCLUDE_DIRS + "${PROJECT_SOURCE_DIR}/include/private" + FIND_PACKAGE_FILES + "${PROJECT_SOURCE_DIR}/cmake/find_modules/FindDB2.cmake" + MISSING_DEPENDENCY_BEHAVIOR "${DEPENDENCY_MODE}" + ENABLED_VARIABLE "SOCI_DB2" +) + +if (NOT SOCI_DB2) + return() +endif() + diff --git a/src/backends/empty/CMakeLists.txt b/src/backends/empty/CMakeLists.txt index b09185b58..4a141fb8b 100644 --- a/src/backends/empty/CMakeLists.txt +++ b/src/backends/empty/CMakeLists.txt @@ -1,14 +1,30 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -soci_backend(Empty - DESCRIPTION "SOCI backend skeleton for new backends development" - AUTHORS "Maciej Sobczak, Stephen Hutton" - MAINTAINERS "Maciej Sobczak") +include(soci_define_backend_target) + +if (SOCI_EMPTY_AUTO) + set(DEPENDENCY_MODE "DISABLE") +else() + set(DEPENDENCY_MODE "ERROR") +endif() + +soci_define_backend_target( + BACKEND_NAME "Empty" + TARGET_NAME "soci_empty" + ALIAS_NAME "Empty" + REQUIRED_COMPONENTS SOCI::Core + SOURCE_FILES + "blob.cpp" + "factory.cpp" + "row-id.cpp" + "session.cpp" + "standard-into-type.cpp" + "standard-use-type.cpp" + "statement.cpp" + "vector-into-type.cpp" + "vector-use-type.cpp" + MISSING_DEPENDENCY_BEHAVIOR "${DEPENDENCY_MODE}" + ENABLED_VARIABLE "SOCI_EMPTY" +) + +if (NOT SOCI_EMPTY) + return() +endif() diff --git a/src/backends/empty/Makefile.basic b/src/backends/empty/Makefile.basic deleted file mode 100644 index 7fe0f9107..000000000 --- a/src/backends/empty/Makefile.basic +++ /dev/null @@ -1,88 +0,0 @@ -# The following variable is specific to this backend and its correct -# values might depend on your environment - feel free to set it accordingly. - -EMPTYINCLUDEDIR = - -# The rest of the Makefile is indepentent of the target environment. - -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -CXXFLAGSSO = ${CXXFLAGS} -fPIC -INCLUDEDIRS = -I../../core ${EMPTYINCLUDEDIR} - - -OBJECTS = blob.o factory.o row-id.o session.o standard-into-type.o \ - standard-use-type.o statement.o vector-into-type.o vector-use-type.o - -OBJECTSSO = blob-s.o factory-s.o row-id-s.o session-s.o \ - standard-into-type-s.o standard-use-type-s.o statement-s.o \ - vector-into-type-s.o vector-use-type-s.o - - -libsoci_empty.a : ${OBJECTS} - ar rv $@ $? - rm *.o - - -blob.o : blob.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -factory.o : factory.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -row-id.o : row-id.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -session.o : session.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-into-type.o : standard-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-use-type.o : standard-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -statement.o : statement.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-into-type.o : vector-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-use-type.o : vector-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - - -shared : ${OBJECTSSO} - ${COMPILER} -shared -o libsoci_empty.so ${OBJECTSSO} - rm *.o - -blob-s.o : blob.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -factory-s.o : factory.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -row-id-s.o : row-id.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -session-s.o : session.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-into-type-s.o : standard-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-use-type-s.o : standard-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -statement-s.o : statement.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-into-type-s.o : vector-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-use-type-s.o : vector-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - - -clean : - rm -f libsoci_empty.a libsoci_empty.so diff --git a/src/backends/firebird/CMakeLists.txt b/src/backends/firebird/CMakeLists.txt index cbf702813..6076cb643 100644 --- a/src/backends/firebird/CMakeLists.txt +++ b/src/backends/firebird/CMakeLists.txt @@ -1,16 +1,45 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2013 Viacheslav Naydenov -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +include(soci_define_backend_target) + +option(SOCI_FIREBIRD_EMBEDDED "Use the embedded version of Firebird" OFF) +if (SOCI_FIREBIRD_EMBEDDED) + set(Firebird_SEARCH_EMBEDDED ON) +endif() + +if (SOCI_FIREBIRD_AUTO) + set(DEPENDENCY_MODE "DISABLE") +else() + set(DEPENDENCY_MODE "ERROR") +endif() + +soci_define_backend_target( + BACKEND_NAME "Firebird" + TARGET_NAME "soci_firebird" + ALIAS_NAME "Firebird" + DEPENDENCIES + "Firebird YIELDS Firebird::Firebird" + REQUIRED_COMPONENTS SOCI::Core + SOURCE_FILES + "blob.cpp" + "common.cpp" + "error-firebird.cpp" + "factory.cpp" + "session.cpp" + "standard-into-type.cpp" + "standard-use-type.cpp" + "statement.cpp" + "vector-into-type.cpp" + "vector-use-type.cpp" + HEADER_FILES + "${PROJECT_SOURCE_DIR}/include/soci/firebird/soci-firebird.h" + PRIVATE_INCLUDE_DIRS + "${PROJECT_SOURCE_DIR}/include/private" + FIND_PACKAGE_FILES + "${PROJECT_SOURCE_DIR}/cmake/find_modules/FindFirebird.cmake" + MISSING_DEPENDENCY_BEHAVIOR "${DEPENDENCY_MODE}" + ENABLED_VARIABLE "SOCI_FIREBIRD" +) + +if (NOT SOCI_FIREBIRD) + return() +endif() -soci_backend(Firebird - DEPENDS Firebird - DESCRIPTION "SOCI backend for Firebird" - AUTHORS "RafaƂ Bobrowski" - MAINTAINERS "Viacheslav Naydenov") diff --git a/src/backends/firebird/Makefile.basic b/src/backends/firebird/Makefile.basic deleted file mode 100644 index 5c0ffd15c..000000000 --- a/src/backends/firebird/Makefile.basic +++ /dev/null @@ -1,101 +0,0 @@ -# The following variable is specific to this backend and its correct -# values might depend on your environment - feel free to set it accordingly. - -FIREBIRDINCLUDEDIR = -I/usr/local/firebird/include - -# The rest of the Makefile is indepentent of the target environment. - -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -CXXFLAGSSO = ${CXXFLAGS} -fPIC -INCLUDEDIRS = -I../../core ${FIREBIRDINCLUDEDIR} - -OBJECTS = blob.o factory.o row-id.o session.o standard-into-type.o \ - standard-use-type.o statement.o vector-into-type.o vector-use-type.o \ - error-firebird.o common.o - -OBJECTSSO = blob-s.o factory-s.o row-id-s.o session-s.o \ - standard-into-type-s.o standard-use-type-s.o statement-s.o \ - vector-into-type-s.o vector-use-type-s.o error-firebird-s.o common-s.o - -FIREBIRDLIBS = -lfbclient -lpthread - -libsoci_firebird.a : ${OBJECTS} - ar rv $@ $? - rm *.o - -soci-firebird.o : soci-firebird.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -blob.o : blob.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -error-firebird.o : error-firebird.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -common.o : common.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -factory.o : factory.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -row-id.o : row-id.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -session.o : session.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-into-type.o : standard-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-use-type.o : standard-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -statement.o : statement.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-into-type.o : vector-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-use-type.o : vector-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -shared : ${OBJECTSSO} - ${COMPILER} -shared -o libsoci_firebird.so ${OBJECTSSO} ${FIREBIRDLIBS} - rm *.o - -blob-s.o : blob.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -error-firebird-s.o : error-firebird.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -common-s.o : common.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -factory-s.o : factory.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -row-id-s.o : row-id.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -session-s.o : session.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-into-type-s.o : standard-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-use-type-s.o : standard-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -statement-s.o : statement.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-into-type-s.o : vector-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-use-type-s.o : vector-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -clean : - rm -f *.o libsoci_firebird.a libsoci_firebird.so diff --git a/src/backends/mysql/CMakeLists.txt b/src/backends/mysql/CMakeLists.txt index b2dcc9ceb..d60280730 100644 --- a/src/backends/mysql/CMakeLists.txt +++ b/src/backends/mysql/CMakeLists.txt @@ -1,15 +1,39 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -soci_backend(MySQL - DEPENDS MySQL - DESCRIPTION "SOCI backend for MySQL" - AUTHORS "Pawel Aleksander Fedorynski" - MAINTAINERS "Pawel Aleksander Fedorynski") +include(soci_define_backend_target) + +if (SOCI_MYSQL_AUTO) + set(DEPENDENCY_MODE "DISABLE") +else() + set(DEPENDENCY_MODE "ERROR") +endif() + +soci_define_backend_target( + BACKEND_NAME "MySQL" + TARGET_NAME "soci_mysql" + ALIAS_NAME "MySQL" + DEPENDENCIES + "MySQL YIELDS MySQL::MySQL" + REQUIRED_COMPONENTS SOCI::Core + SOURCE_FILES + "blob.cpp" + "common.cpp" + "factory.cpp" + "row-id.cpp" + "session.cpp" + "standard-into-type.cpp" + "standard-use-type.cpp" + "statement.cpp" + "vector-into-type.cpp" + "vector-use-type.cpp" + HEADER_FILES + "${PROJECT_SOURCE_DIR}/include/soci/mysql/soci-mysql.h" + PRIVATE_INCLUDE_DIRS + "${PROJECT_SOURCE_DIR}/include/private" + FIND_PACKAGE_FILES + "${PROJECT_SOURCE_DIR}/cmake/find_modules/FindMySQL.cmake" + MISSING_DEPENDENCY_BEHAVIOR "${DEPENDENCY_MODE}" + ENABLED_VARIABLE "SOCI_MYSQL" +) + +if (NOT SOCI_MYSQL) + return() +endif() diff --git a/src/backends/mysql/Makefile.basic b/src/backends/mysql/Makefile.basic deleted file mode 100644 index 0073fadd3..000000000 --- a/src/backends/mysql/Makefile.basic +++ /dev/null @@ -1,97 +0,0 @@ -# The following variables are specific to this backend and their correct -# values might depend on your environment - feel free to set it accordingly. - -MYSQLLIBDIR = -L/usr/lib/mysql -MYSQLLIBS = -lmysqlclient -lz -MYSQLINCLUDEDIR = -I/usr/include/mysql - -# The rest of the Makefile is independent of the target environment. - -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -CXXFLAGSSO = ${CXXFLAGS} -fPIC -INCLUDEDIRS = -I../../core ${MYSQLINCLUDEDIR} - - -OBJECTS = blob.o factory.o row-id.o session.o standard-into-type.o \ - standard-use-type.o statement.o vector-into-type.o vector-use-type.o \ - common.o - - -OBJECTSSO = blob-s.o factory-s.o row-id-s.o session-s.o \ - standard-into-type-s.o standard-use-type-s.o statement-s.o \ - vector-into-type-s.o vector-use-type-s.o common-s.o - - -libsoci_mysql.a : ${OBJECTS} - ar rv $@ $? - rm *.o - - -blob.o : blob.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -common.o : common.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -factory.o : factory.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -row-id.o : row-id.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -session.o : session.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-into-type.o : standard-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-use-type.o : standard-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -statement.o : statement.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-into-type.o : vector-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-use-type.o : vector-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -shared : ${OBJECTSSO} - ${COMPILER} -shared -o libsoci_mysql.so ${OBJECTSSO} - rm *.o - -blob-s.o : blob.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -common-s.o : common.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -factory-s.o : factory.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -row-id-s.o : row-id.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -session-s.o : session.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-into-type-s.o : standard-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-use-type-s.o : standard-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -statement-s.o : statement.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-into-type-s.o : vector-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-use-type-s.o : vector-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - - -clean : - rm -f libsoci_mysql.a libsoci_mysql.so diff --git a/src/backends/odbc/CMakeLists.txt b/src/backends/odbc/CMakeLists.txt index ce0195393..273c383f2 100644 --- a/src/backends/odbc/CMakeLists.txt +++ b/src/backends/odbc/CMakeLists.txt @@ -1,15 +1,36 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -soci_backend(ODBC - DEPENDS ODBC - DESCRIPTION "SOCI backend for ODBC" - AUTHORS "Maciej Sobczak, Stephen Hutton, David Courtney" - MAINTAINERS "Vadim Zeitlin, Mateusz Loskot, Maciej Sobczak") +include(soci_define_backend_target) + +if (SOCI_ODBC_AUTO) + set(DEPENDENCY_MODE "DISABLE") +else() + set(DEPENDENCY_MODE "ERROR") +endif() + +soci_define_backend_target( + BACKEND_NAME "ODBC" + TARGET_NAME "soci_odbc" + ALIAS_NAME "ODBC" + DEPENDENCIES + "ODBC YIELDS ODBC::ODBC" + REQUIRED_COMPONENTS SOCI::Core + SOURCE_FILES + "blob.cpp" + "factory.cpp" + "row-id.cpp" + "session.cpp" + "standard-into-type.cpp" + "standard-use-type.cpp" + "statement.cpp" + "vector-into-type.cpp" + "vector-use-type.cpp" + HEADER_FILES + "${PROJECT_SOURCE_DIR}/include/soci/odbc/soci-odbc.h" + PRIVATE_INCLUDE_DIRS + "${PROJECT_SOURCE_DIR}/include/private" + MISSING_DEPENDENCY_BEHAVIOR "${DEPENDENCY_MODE}" + ENABLED_VARIABLE "SOCI_ODBC" +) + +if (NOT SOCI_ODBC) + return() +endif() diff --git a/src/backends/odbc/Makefile.basic b/src/backends/odbc/Makefile.basic deleted file mode 100644 index 5082f914f..000000000 --- a/src/backends/odbc/Makefile.basic +++ /dev/null @@ -1,89 +0,0 @@ -# The following variable is specific to this backend and its correct -# values might depend on your environment - feel free to set it accordingly. - -ODBCINCLUDEDIR = -I/usr/include - -# The rest of the Makefile is indepentent of the target environment. - -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -CXXFLAGSSO = ${CXXFLAGS} -fPIC -INCLUDEDIRS = -I../../core ${ODBCINCLUDEDIR} - - -OBJECTS = blob.o factory.o row-id.o session.o standard-into-type.o \ - standard-use-type.o statement.o vector-into-type.o vector-use-type.o - -OBJECTSSO = blob-s.o factory-s.o row-id-s.o session-s.o \ - standard-into-type-s.o standard-use-type-s.o statement-s.o \ - vector-into-type-s.o vector-use-type-s.o - - -libsoci_odbc.a : ${OBJECTS} - ar rv $@ $? - ranlib $@ - rm *.o - - -blob.o : blob.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -factory.o : factory.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -row-id.o : row-id.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -session.o : session.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-into-type.o : standard-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-use-type.o : standard-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -statement.o : statement.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-into-type.o : vector-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-use-type.o : vector-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - - -shared : ${OBJECTSSO} - ${COMPILER} -shared -o libsoci_odbc.so ${OBJECTSSO} - rm *.o - -blob-s.o : blob.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -factory-s.o : factory.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -row-id-s.o : row-id.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -session-s.o : session.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-into-type-s.o : standard-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-use-type-s.o : standard-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -statement-s.o : statement.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-into-type-s.o : vector-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-use-type-s.o : vector-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - - -clean : - rm -f libsoci_odbc.a libsoci_odbc.so diff --git a/src/backends/odbc/makefile.msvc b/src/backends/odbc/makefile.msvc deleted file mode 100644 index dcc5a96be..000000000 --- a/src/backends/odbc/makefile.msvc +++ /dev/null @@ -1,48 +0,0 @@ -# The following variable is specific to this backend and its correct -# values might depend on your environment - feel free to set it accordingly. - -ODBCINCLUDEDIR="C:\Program Files\Microsoft Platform SDK\Include" - -# The rest of the Makefile is indepentent of the target environment. - -COMPILER = cl -CXXFLAGS = /nologo /EHsc /D_CRT_SECURE_NO_DEPRECATE -INCLUDEDIRS = /I..\..\core /I$(ODBCINCLUDEDIR) - -OBJECTS = blob.obj factory.obj row-id.obj session.obj standard-into-type.obj \ - standard-use-type.obj statement.obj vector-into-type.obj \ - vector-use-type.obj - -soci-odbc.lib : $(OBJECTS) - lib /NOLOGO /OUT:$@ $? - del *.obj - -blob.obj : blob.cpp - $(COMPILER) /c $? $(CXXFLAGS) $(INCLUDEDIRS) - -factory.obj : factory.cpp - $(COMPILER) /c $? $(CXXFLAGS) $(INCLUDEDIRS) - -row-id.obj : row-id.cpp - $(COMPILER) /c $? $(CXXFLAGS) $(INCLUDEDIRS) - -session.obj : session.cpp - $(COMPILER) /c $? $(CXXFLAGS) $(INCLUDEDIRS) - -standard-into-type.obj : standard-into-type.cpp - $(COMPILER) /c $? $(CXXFLAGS) $(INCLUDEDIRS) - -standard-use-type.obj : standard-use-type.cpp - $(COMPILER) /c $? $(CXXFLAGS) $(INCLUDEDIRS) - -statement.obj : statement.cpp - $(COMPILER) /c $? $(CXXFLAGS) $(INCLUDEDIRS) - -vector-into-type.obj : vector-into-type.cpp - $(COMPILER) /c $? $(CXXFLAGS) $(INCLUDEDIRS) - -vector-use-type.obj : vector-use-type.cpp - $(COMPILER) /c $? $(CXXFLAGS) $(INCLUDEDIRS) - -clean : - del soci-odbc.lib soci-odbc.dll diff --git a/src/backends/oracle/CMakeLists.txt b/src/backends/oracle/CMakeLists.txt index 632ca6179..13d930be7 100644 --- a/src/backends/oracle/CMakeLists.txt +++ b/src/backends/oracle/CMakeLists.txt @@ -1,15 +1,39 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -soci_backend(Oracle - DEPENDS Oracle - DESCRIPTION "SOCI backend for Oracle 10+" - AUTHORS "Maciej Sobczak, Stephen Hutton" - MAINTAINERS "Maciej Sobczak") +include(soci_define_backend_target) + +if (SOCI_ORACLE_AUTO) + set(DEPENDENCY_MODE "DISABLE") +else() + set(DEPENDENCY_MODE "ERROR") +endif() + +soci_define_backend_target( + BACKEND_NAME "Oracle" + TARGET_NAME "soci_oracle" + ALIAS_NAME "Oracle" + DEPENDENCIES + "Oracle YIELDS Oracle::Oracle" + REQUIRED_COMPONENTS SOCI::Core + SOURCE_FILES + "blob.cpp" + "error.cpp" + "factory.cpp" + "row-id.cpp" + "session.cpp" + "standard-into-type.cpp" + "standard-use-type.cpp" + "statement.cpp" + "vector-into-type.cpp" + "vector-use-type.cpp" + HEADER_FILES + "${PROJECT_SOURCE_DIR}/include/soci/oracle/soci-oracle.h" + PRIVATE_INCLUDE_DIRS + "${PROJECT_SOURCE_DIR}/include/private" + FIND_PACKAGE_FILES + "${PROJECT_SOURCE_DIR}/cmake/find_modules/FindOracle.cmake" + MISSING_DEPENDENCY_BEHAVIOR "${DEPENDENCY_MODE}" + ENABLED_VARIABLE "SOCI_ORACLE" +) + +if (NOT SOCI_ORACLE) + return() +endif() diff --git a/src/backends/oracle/Makefile.basic b/src/backends/oracle/Makefile.basic deleted file mode 100644 index 31b861f5e..000000000 --- a/src/backends/oracle/Makefile.basic +++ /dev/null @@ -1,95 +0,0 @@ -# The following variable is specific to this backend and its correct -# values might depend on your environment - feel free to set it accordingly. - -ORACLEINCLUDEDIR = -I${ORACLE_HOME}/rdbms/public - -# The rest of the Makefile is indepentent of the target environment. - -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -CXXFLAGSSO = ${CXXFLAGS} -fPIC -INCLUDEDIRS = -I../../../include -I../../../include/private ${ORACLEINCLUDEDIR} - -OBJECTS = blob.o factory.o row-id.o session.o standard-into-type.o \ - standard-use-type.o statement.o vector-into-type.o vector-use-type.o \ - error.o - -OBJECTSSO = blob-s.o factory-s.o row-id-s.o session-s.o \ - standard-into-type-s.o standard-use-type-s.o statement-s.o \ - vector-into-type-s.o vector-use-type-s.o error-s.o - -libsoci_oracle.a : ${OBJECTS} - ar rv $@ $? - rm *.o - -soci-oracle.o : soci-oracle.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -blob.o : blob.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -error.o : error.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -factory.o : factory.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -row-id.o : row-id.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -session.o : session.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-into-type.o : standard-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-use-type.o : standard-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -statement.o : statement.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-into-type.o : vector-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-use-type.o : vector-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - - -shared : ${OBJECTSSO} - ${COMPILER} -shared -o libsoci_oracle.so ${OBJECTSSO} - rm *.o - -blob-s.o : blob.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -error-s.o : error.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -factory-s.o : factory.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -row-id-s.o : row-id.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -session-s.o : session.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-into-type-s.o : standard-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -standard-use-type-s.o : standard-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -statement-s.o : statement.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-into-type-s.o : vector-into-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - -vector-use-type-s.o : vector-use-type.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGSSO} ${INCLUDEDIRS} - - -clean : - rm -f *.o libsoci_oracle.a libsoci_oracle.so diff --git a/src/backends/postgresql/CMakeLists.txt b/src/backends/postgresql/CMakeLists.txt index 3debd3aa0..08c2bd7d1 100644 --- a/src/backends/postgresql/CMakeLists.txt +++ b/src/backends/postgresql/CMakeLists.txt @@ -1,32 +1,49 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +include(soci_define_backend_target) -include(CMakeDependentOption) +if (SOCI_POSTGRESQL_AUTO) + set(DEPENDENCY_MODE "DISABLE") +else() + set(DEPENDENCY_MODE "ERROR") +endif() + +soci_define_backend_target( + BACKEND_NAME "PostgreSQL" + TARGET_NAME "soci_postgresql" + ALIAS_NAME "PostgreSQL" + DEPENDENCIES + "PostgreSQL YIELDS PostgreSQL::PostgreSQL" + REQUIRED_COMPONENTS SOCI::Core + SOURCE_FILES + "blob.cpp" + "error.cpp" + "factory.cpp" + "row-id.cpp" + "session.cpp" + "standard-into-type.cpp" + "standard-use-type.cpp" + "statement.cpp" + "vector-into-type.cpp" + "vector-use-type.cpp" + HEADER_FILES + "${PROJECT_SOURCE_DIR}/include/soci/postgresql/soci-postgresql.h" + PRIVATE_INCLUDE_DIRS + "${PROJECT_SOURCE_DIR}/include/private" + MISSING_DEPENDENCY_BEHAVIOR "${DEPENDENCY_MODE}" + ENABLED_VARIABLE "SOCI_POSTGRESQL" +) + +if (NOT SOCI_POSTGRESQL) + return() +endif() option(SOCI_POSTGRESQL_NO_LO64 "Do not use lo_xxx64() functions for compatibility with PostgreSQL < 9.3" - OFF) - + OFF +) if (POSTGRESQL_VERSION VERSION_LESS "9.3.0") set(SOCI_POSTGRESQL_NO_LO64 ON CACHE BOOL "Avoid using lo_xxx64() functions" FORCE) endif() -if(SOCI_POSTGRESQL_NO_LO64) - add_definitions(-DSOCI_POSTGRESQL_NO_LO64=1) +if (SOCI_POSTGRESQL_NO_LO64) + target_compile_definitions(soci_postgresql INTERFACE SOCI_POSTGRESQL_NO_LO64) endif() - -soci_backend(PostgreSQL - DEPENDS PostgreSQL - DESCRIPTION "SOCI backend for PostgreSQL" - AUTHORS "Maciej Sobczak, Stephen Hutton" - MAINTAINERS "Mateusz Loskot") - -boost_report_value(SOCI_POSTGRESQL_NO_LO64) diff --git a/src/backends/postgresql/Makefile.basic b/src/backends/postgresql/Makefile.basic deleted file mode 100644 index 473abfffd..000000000 --- a/src/backends/postgresql/Makefile.basic +++ /dev/null @@ -1,114 +0,0 @@ -# The following variable is specific to this backend and its correct -# values might depend on your environment - feel free to set it accordingly. - -PGSQLINCLUDEDIR = -I/usr/include/postgresql -PGSQLLIBDIR = -L/usr/lib -PGSQLLIBS = -lpq - -# The rest of the Makefile is indepentent of the target environment. - -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -SHARED_CXXFLAGS = ${CXXFLAGS} -fPIC -INCLUDEDIRS = -I../../../include -I../../../include/private ${PGSQLINCLUDEDIR} - -SHARED_LIBDIRS = ${PGSQLLIBDIR} -SHARED_LIBS = ${PGSQLLIBS} ../../core/libsoci_core.a - -UNAME = $(shell uname) -ifeq ($(UNAME),Darwin) - SHARED_LINK_FLAGS = -dynamiclib -flat_namespace -undefined suppress -else - SHARED_LINK_FLAGS = -shared -endif - - -OBJECTS = blob.o error.o factory.o row-id.o session.o standard-into-type.o \ - standard-use-type.o statement.o vector-into-type.o vector-use-type.o \ - common.o - -SHARED_OBJECTS = blob-s.o error-s.o factory-s.o row-id-s.o session-s.o \ - standard-into-type-s.o standard-use-type-s.o statement-s.o \ - vector-into-type-s.o vector-use-type-s.o common-s.o - - -libsoci_postgresql.a : ${OBJECTS} - ar rv $@ $? - rm *.o - - -blob.o : blob.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -error.o : error.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -common.o : ../../core/common.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -factory.o : factory.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -row-id.o : row-id.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -session.o : session.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-into-type.o : standard-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-use-type.o : standard-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -statement.o : statement.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-into-type.o : vector-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-use-type.o : vector-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - - -shared : ${SHARED_OBJECTS} - ${COMPILER} ${SHARED_LINK_FLAGS} -o libsoci_postgresql.so \ - ${SHARED_OBJECTS} ${SHARED_LIBDIRS} ${SHARED_LIBS} - rm *.o - -blob-s.o : blob.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -error-s.o : error.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGS} ${INCLUDEDIRS} - -common-s.o : ../../core/common.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -factory-s.o : factory.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -row-id-s.o : row-id.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -session-s.o : session.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -standard-into-type-s.o : standard-into-type.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -standard-use-type-s.o : standard-use-type.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -statement-s.o : statement.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -vector-into-type-s.o : vector-into-type.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -vector-use-type-s.o : vector-use-type.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - - -clean : - rm -f libsoci_postgresql.a libsoci_postgresql.so diff --git a/src/backends/sqlite3/CMakeLists.txt b/src/backends/sqlite3/CMakeLists.txt index cd90b7ae2..1bb28fb2a 100644 --- a/src/backends/sqlite3/CMakeLists.txt +++ b/src/backends/sqlite3/CMakeLists.txt @@ -1,16 +1,37 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +include(soci_define_backend_target) -soci_backend(SQLite3 - DEPENDS SQLite3 - DESCRIPTION "SOCI backend for SQLite 3" - AUTHORS "Maciej Sobczak, Stephen Hutton, David Courtney" - MAINTAINERS "Maciej Sobczak, Mateusz Loskot") +if (SOCI_SQLITE3_AUTO) + set(DEPENDENCY_MODE "DISABLE") +else() + set(DEPENDENCY_MODE "ERROR") +endif() + +soci_define_backend_target( + BACKEND_NAME "SQLite3" + TARGET_NAME "soci_sqlite3" + ALIAS_NAME "SQLite3" + DEPENDENCIES + "SQLite3 YIELDS SQLite::SQLite3" + REQUIRED_COMPONENTS SOCI::Core + SOURCE_FILES + "blob.cpp" + "error.cpp" + "factory.cpp" + "row-id.cpp" + "session.cpp" + "standard-into-type.cpp" + "standard-use-type.cpp" + "statement.cpp" + "vector-into-type.cpp" + "vector-use-type.cpp" + HEADER_FILES + "${PROJECT_SOURCE_DIR}/include/soci/sqlite3/soci-sqlite3.h" + PRIVATE_INCLUDE_DIRS + "${PROJECT_SOURCE_DIR}/include/private" + MISSING_DEPENDENCY_BEHAVIOR "${DEPENDENCY_MODE}" + ENABLED_VARIABLE "SOCI_SQLITE3" +) + +if (NOT SOCI_SQLITE3) + return() +endif() diff --git a/src/backends/sqlite3/Makefile.basic b/src/backends/sqlite3/Makefile.basic deleted file mode 100644 index 6594dd31e..000000000 --- a/src/backends/sqlite3/Makefile.basic +++ /dev/null @@ -1,114 +0,0 @@ -# The following variable is specific to this backend and its correct -# values might depend on your environment - feel free to set it accordingly. - -SQLITE3INCLUDEDIR = -I/usr/include -SQLITE3LIBDIR = -L/usr/lib -SQLITE3LIBS = -lsqlite3 - -# The rest of the Makefile is indepentent of the target environment. - -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -SHARED_CXXFLAGS = ${CXXFLAGS} -fPIC -INCLUDEDIRS = -I../../../include -I../../../include/private ${SQLITE3INCLUDEDIR} - -SHARED_LIBDIRS = ${SQLITE3LIBDIR} -SHARED_LIBS = ${SQLITE3LIBS} ../../core/libsoci_core.a - -UNAME = $(shell uname) -ifeq ($(UNAME),Darwin) - SHARED_LINK_FLAGS = -dynamiclib -flat_namespace -undefined suppress -else - SHARED_LINK_FLAGS = -shared -endif - - -OBJECTS = blob.o error.o factory.o row-id.o session.o standard-into-type.o \ - standard-use-type.o statement.o vector-into-type.o vector-use-type.o \ - common.o - -SHARED_OBJECTS = blob-s.o factory-s.o row-id-s.o session-s.o \ - standard-into-type-s.o standard-use-type-s.o statement-s.o \ - vector-into-type-s.o vector-use-type-s.o common-s.o - - -libsoci_sqlite3.a : ${OBJECTS} - ar rv $@ $? - rm *.o - - -blob.o : blob.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -error.o : error.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -common.o : common.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -factory.o : factory.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -row-id.o : row-id.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -session.o : session.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-into-type.o : standard-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -standard-use-type.o : standard-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -statement.o : statement.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-into-type.o : vector-into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -vector-use-type.o : vector-use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - - -shared : ${SHARED_OBJECTS} - ${COMPILER} ${SHARED_LINK_FLAGS} -o libsoci_sqlite3.so \ - ${SHARED_OBJECTS} ${SHARED_LIBDIRS} ${SHARED_LIBS} - rm *.o - -blob-s.o : blob.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -error-s.o : error.cpp - ${COMPILER} -c -o $@ $? ${CXXFLAGS} ${INCLUDEDIRS} - -common-s.o : common.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -factory-s.o : factory.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -row-id-s.o : row-id.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -session-s.o : session.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -standard-into-type-s.o : standard-into-type.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -standard-use-type-s.o : standard-use-type.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -statement-s.o : statement.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -vector-into-type-s.o : vector-into-type.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - -vector-use-type-s.o : vector-use-type.cpp - ${COMPILER} -c -o $@ $? ${SHARED_CXXFLAGS} ${INCLUDEDIRS} - - -clean : - rm -f libsoci_sqlite3.a libsoci_sqlite3.so diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 0158da227..a8e82923b 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,151 +1,146 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2009-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -colormsg(_HIBLUE_ "Configuring SOCI core library:") - -include(CMakePackageConfigHelpers) - -# Set INCLUDE_DIRECTORIES -get_directory_property(SOCI_CORE_INCLUDE_DIRS INCLUDE_DIRECTORIES) -list(APPEND SOCI_CORE_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}) -set_directory_properties(PROPERTIES - INCLUDE_DIRECTORIES "${SOCI_CORE_INCLUDE_DIRS}") - -# Configure backend loader to also use default install directory. -configure_file(soci_backends_config.h.in - ${CMAKE_CURRENT_BINARY_DIR}/soci_backends_config.h) - -# Core source files -file(GLOB SOCI_CORE_HEADERS ${SOCI_SOURCE_DIR}/include/soci/*.h) -file(GLOB SOCI_CORE_SOURCES *.cpp) - -# Group source files for IDE source explorers (e.g. Visual Studio) -source_group("Header Files" FILES ${SOCI_CORE_HEADERS}) -source_group("Source Files" FILES ${SOCI_CORE_SOURCES}) -source_group("CMake Files" FILES CMakeLists.txt) - -# Core targets configuration -string(TOLOWER "${PROJECT_NAME}" PROJECTNAMEL) -#this command will update parent scope variable -set(SOCI_CORE_TARGET ${PROJECTNAMEL}_core PARENT_SCOPE) -set(SOCI_CORE_TARGET ${PROJECTNAMEL}_core) - -soci_target_output_name(${SOCI_CORE_TARGET} SOCI_CORE_TARGET_OUTPUT_NAME) - -# -# Core shared library -# +include(GNUInstallDirs) + +set(SOCI_LIB_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}soci_" CACHE STRING "Specifies prefix for the lib directory") +set(SOCI_LIB_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE STRING "Specifies suffix for the lib directory") +set(SOCI_DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}" CACHE STRING "Specifies suffix for the library file in debug mode") + + +find_package(Threads REQUIRED) + +add_library(soci_core + ${SOCI_LIB_TYPE} + "backend-loader.cpp" + "blob.cpp" + "common.cpp" + "connection-parameters.cpp" + "connection-pool.cpp" + "error.cpp" + "into-type.cpp" + "logger.cpp" + "once-temp-type.cpp" + "prepare-temp-type.cpp" + "procedure.cpp" + "ref-counted-prepare-info.cpp" + "ref-counted-statement.cpp" + "row.cpp" + "rowid.cpp" + "session.cpp" + "soci-simple.cpp" + "statement.cpp" + "transaction.cpp" + "unicode.cpp" + "use-type.cpp" + "values.cpp" +) + +add_library(SOCI::Core ALIAS soci_core) + +set_target_properties( + soci_core PROPERTIES + SOVERSION ${PROJECT_VERSION_MAJOR} + VERSION ${PROJECT_VERSION} + EXPORT_NAME Core +) + +# We have to explicitly list all public header files in order for them to get +# installed properly. This will automatically set the BASE_DIR up as an include +# directory for the target wrapped in a BUILD_INTERFACE generator expression. +# Note that we only add the general, public SOCI headers here. Backend-specific +# headers are added by the respective backend target. +file(GLOB SOCI_HEADER_FILES LIST_DIRECTORIES false CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/include/soci/*.h*") +target_sources(soci_core + PUBLIC + FILE_SET headers TYPE HEADERS + BASE_DIRS "${PROJECT_SOURCE_DIR}/include/" + FILES "${SOCI_HEADER_FILES}" +) + +target_include_directories(soci_core + PUBLIC + "$" + PRIVATE + "${PROJECT_SOURCE_DIR}/include/soci" + "${PROJECT_SOURCE_DIR}/include/private" +) + if (SOCI_SHARED) - add_library(${SOCI_CORE_TARGET} SHARED ${SOCI_CORE_HEADERS} ${SOCI_CORE_SOURCES}) - add_library(Soci::core ALIAS ${SOCI_CORE_TARGET}) - - target_link_libraries(${SOCI_CORE_TARGET} ${SOCI_CORE_DEPS_LIBS}) - - if(WIN32) - set_target_properties(${SOCI_CORE_TARGET} - PROPERTIES - DEFINE_SYMBOL SOCI_DLL - OUTPUT_NAME "${SOCI_CORE_TARGET_OUTPUT_NAME}" - VERSION ${SOCI_VERSION} - CLEAN_DIRECT_OUTPUT 1) - else() - set_target_properties(${SOCI_CORE_TARGET} - PROPERTIES - VERSION ${SOCI_VERSION} - SOVERSION ${SOCI_SOVERSION} - INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib - CLEAN_DIRECT_OUTPUT 1) - endif() - - target_include_directories(${SOCI_CORE_TARGET} - PUBLIC - $ - $ - $ + target_compile_definitions(soci_core + PUBLIC + # Define the macro SOCI_DLL on Windows + $,SOCI_DLL,> ) - endif() -# This adds definitions to all build configurations. SOCI_DEBUG_POSTFIX is passed to soci library -add_definitions(-DSOCI_LIB_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}soci_" - -DSOCI_LIB_SUFFIX="${CMAKE_SHARED_LIBRARY_SUFFIX}" - -DSOCI_DEBUG_POSTFIX="${CMAKE_DEBUG_POSTFIX}") - -# -# Core static library -# -if (SOCI_STATIC) - set(SOCI_CORE_TARGET_STATIC ${SOCI_CORE_TARGET}_static) - - add_library(${SOCI_CORE_TARGET_STATIC} STATIC - ${SOCI_CORE_HEADERS} ${SOCI_CORE_SOURCES}) - add_library(Soci::core_static ALIAS ${SOCI_CORE_TARGET_STATIC}) - - # we still need to link against dl if we have it - target_link_libraries (${SOCI_CORE_TARGET_STATIC} - ${SOCI_CORE_DEPS_LIBS} - ) - - set_target_properties(${SOCI_CORE_TARGET_STATIC} - PROPERTIES - OUTPUT_NAME ${SOCI_CORE_TARGET_OUTPUT_NAME} - PREFIX "lib" - CLEAN_DIRECT_OUTPUT 1) - - target_include_directories(${SOCI_CORE_TARGET_STATIC} - PUBLIC - $ - $ - $ - ) - +# First try and find Boost with the date_time component. If it succeeds, the second search doesn't have any +# effect. If it failed, retry searching only for Boost without the date_time component and use that, if found. +soci_public_dependency( + NAME Boost + DEP_TARGETS Boost::boost Boost::date_time Boost::disable_autolinking + COMPONENTS date_time + MACRO_NAMES SOCI_HAVE_BOOST SOCI_HAVE_BOOST_DATE_TIME + TARGET SOCI::Core +) +soci_public_dependency( + NAME Boost + DEP_TARGETS Boost::boost Boost::disable_autolinking + MACRO_NAMES SOCI_HAVE_BOOST + TARGET SOCI::Core +) + +target_link_libraries(soci_core + PUBLIC + $ + PRIVATE + Threads::Threads + ${CMAKE_DL_LIBS} +) + +if (WIN32) + set(ABI_VERSION "${PROJECT_VERSION_MAJOR}_${PROJECT_VERSION_MINOR}") +elseif(UNIX) + # Use SOVERSION, which is only the major version + set(ABI_VERSION "${PROJECT_VERSION_MAJOR}") endif() - - - -# -# Core installation -# -install(FILES ${SOCI_CORE_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECTNAMEL}) - -if (SOCI_SHARED) - install(TARGETS ${SOCI_CORE_TARGET} - EXPORT SOCI - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +cmake_path( + ABSOLUTE_PATH SOCI_INSTALL_LIBDIR + BASE_DIRECTORY "${CMAKE_INSTALL_PREFIX}" + OUTPUT_VARIABLE SOCI_INSTALL_FULL_LIBDIR +) + +target_compile_definitions(soci_core + PRIVATE + DEFAULT_BACKENDS_PATH="${SOCI_INSTALL_FULL_LIBDIR}" + SOCI_LIB_PREFIX="${SOCI_LIB_PREFIX}" + SOCI_LIB_SUFFIX="${SOCI_LIB_SUFFIX}" + SOCI_DEBUG_POSTFIX="${SOCI_DEBUG_POSTFIX}" +) +if (DEFINED ABI_VERSION) + target_compile_definitions(soci_core + PRIVATE + SOCI_ABI_VERSION="${ABI_VERSION}" + ) endif() -if (SOCI_STATIC) - install(TARGETS ${SOCI_CORE_TARGET_STATIC} - EXPORT SOCI - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -endif() -install(EXPORT SOCI NAMESPACE SOCI:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SOCI FILE SOCITargets.cmake) -configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/resources/SOCIConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/SOCIConfig.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SOCI) -write_basic_package_version_file(SOCIConfigVersion.cmake VERSION ${SOCI_VERSION} COMPATIBILITY SameMajorVersion) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/SOCIConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/SOCIConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SOCI) - -# -# Core configuration summary -# -boost_report_value(SOCI_CORE_TARGET) -boost_report_value(SOCI_CORE_TARGET_OUTPUT_NAME) -boost_report_value(SOCI_CORE_DEPS_LIBS) -boost_report_value(SOCI_CORE_INCLUDE_DIRS) -boost_report_value(WITH_BOOST) -soci_report_directory_property(COMPILE_DEFINITIONS) - -message(STATUS "") +install( + TARGETS soci_core + EXPORT SOCICoreTargets + RUNTIME DESTINATION "${SOCI_INSTALL_BINDIR}" + COMPONENT soci_runtime + LIBRARY DESTINATION "${SOCI_INSTALL_LIBDIR}" + COMPONENT soci_runtime + NAMELINK_COMPONENT soci_development + ARCHIVE DESTINATION "${SOCI_INSTALL_LIBDIR}" + COMPONENT soci_development + FILE_SET headers DESTINATION "${SOCI_INSTALL_INCLUDEDIR}" + COMPONENT soci_development +) +# Generate and install a targets file +install( + EXPORT SOCICoreTargets + DESTINATION "${SOCI_INSTALL_CMAKEDIR}" + FILE SOCICoreTargets.cmake + NAMESPACE SOCI:: + COMPONENT soci_development +) diff --git a/src/core/Makefile.basic b/src/core/Makefile.basic deleted file mode 100644 index bd5f78d86..000000000 --- a/src/core/Makefile.basic +++ /dev/null @@ -1,94 +0,0 @@ -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -INCLUDEDIRS = -I../../include -I../../include/private - -BACKENDLOADERDEFS = -DSOCI_LIB_PREFIX=\"libsoci_\" -DSOCI_LIB_SUFFIX=\".so\" - -OBJS = session.o statement.o row.o values.o \ - into-type.o use-type.o \ - blob.o rowid.o procedure.o ref-counted-prepare-info.o ref-counted-statement.o \ - once-temp-type.o prepare-temp-type.o error.o transaction.o backend-loader.o \ - connection-pool.o connection-parameters.o soci-simple.o - - -libsoci_core.a : generated ${OBJS} - ar rv $@ ${OBJS} - rm *.o - -shared : generated ${OBJS} - ${COMPILER} -fPIC -c ${OBJS} ${CXXFLAGS} ${INCLUDEDIRS} - ${COMPILER} -shared -o libsoci_core.so ${OBJS} - rm *.o - -generated : ../../include/soci/soci-config.h ../../include/private/soci_backends_config.h - -# Note: this file is generated without any configured variables, -# full configuration fill is generated by CMake. -../../include/soci/soci-config.h : ../../include/soci/soci-config.h.in - grep -v CONFIGURED_VARIABLES $? > $@ - -# Note: this file is generated with a basic search path, -# full backends search path is generated by CMake. -../../include/private/soci_backends_config.h : soci_backends_config.h.in - echo '#define DEFAULT_BACKENDS_PATH "."' > $@ - -session.o : session.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -statement.o : statement.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -row.o : row.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -values.o : values.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -into-type.o : into-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -use-type.o : use-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -blob.o : blob.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -error.o : error.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -rowid.o : rowid.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -procedure.o : procedure.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -ref-counted-prepare-info.o : ref-counted-prepare-info.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -ref-counted-statement.o : ref-counted-statement.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -once-temp-type.o : once-temp-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -prepare-temp-type.o : prepare-temp-type.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -transaction.o : transaction.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -backend-loader.o : backend-loader.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${BACKENDLOADERDEFS} ${INCLUDEDIRS} - -connection-pool.o : connection-pool.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -connection-parameters.o : connection-parameters.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - -soci-simple.o : soci-simple.cpp - ${COMPILER} -c $? ${CXXFLAGS} ${INCLUDEDIRS} - - -clean : - rm -f libsoci_core.a libsoci_core.so ../../include/private/soci_backends_config.h diff --git a/src/core/backend-loader.cpp b/src/core/backend-loader.cpp index 54220685b..79dd18ad7 100644 --- a/src/core/backend-loader.cpp +++ b/src/core/backend-loader.cpp @@ -18,8 +18,6 @@ #include #endif -#include "soci_backends_config.h" - using namespace soci; using namespace soci::dynamic_backends; @@ -77,11 +75,7 @@ std::string get_this_dynlib_path() } // unnamed namespace -#ifdef _UNICODE #define DLOPEN(x) LoadLibraryA(x) -#else -#define DLOPEN(x) LoadLibrary(x) -#endif #define DLCLOSE(x) FreeLibrary(x) #define DLSYM(x, y) GetProcAddress(x, y) diff --git a/src/core/logger.cpp b/src/core/logger.cpp index 5ff47eb24..696d9e8a6 100644 --- a/src/core/logger.cpp +++ b/src/core/logger.cpp @@ -15,7 +15,7 @@ namespace // anonymous { // Helper to throw from not implemented logger_impl methods. -void throw_not_supported() +[[noreturn]] void throw_not_supported() { throw soci_error("Legacy method not supported by this logger."); } @@ -61,15 +61,11 @@ void logger_impl::set_stream(std::ostream *) std::ostream * logger_impl::get_stream() const { throw_not_supported(); - - SOCI_DUMMY_RETURN(NULL); } std::string logger_impl::get_last_query() const { throw_not_supported(); - - SOCI_DUMMY_RETURN(std::string()); } std::string logger_impl::get_last_query_context() const diff --git a/src/core/session.cpp b/src/core/session.cpp index a303d0c5c..5d617b84b 100644 --- a/src/core/session.cpp +++ b/src/core/session.cpp @@ -26,9 +26,6 @@ namespace soci }; } // soci -namespace // anonymous -{ - void ensureConnected(session_backend * backEnd) { if (backEnd == NULL) @@ -46,7 +43,7 @@ class standard_logger_impl : public logger_impl logStream_ = NULL; } - virtual void start_query(std::string const & query) + virtual void start_query(std::string const & query) override { logger_impl::start_query(query); @@ -58,23 +55,23 @@ class standard_logger_impl : public logger_impl lastQuery_ = query; } - virtual void set_stream(std::ostream * s) + virtual void set_stream(std::ostream * s) override { logStream_ = s; } - virtual std::ostream * get_stream() const + virtual std::ostream * get_stream() const override { return logStream_; } - virtual std::string get_last_query() const + virtual std::string get_last_query() const override { return lastQuery_; } private: - virtual logger_impl* do_clone() const + virtual logger_impl* do_clone() const override { return new standard_logger_impl; } @@ -83,8 +80,6 @@ class standard_logger_impl : public logger_impl std::string lastQuery_; }; -} // namespace anonymous - session::session() : once(this), prepare(this), logger_(new standard_logger_impl) diff --git a/src/core/soci_backends_config.h.in b/src/core/soci_backends_config.h.in deleted file mode 100644 index b6c1d9f29..000000000 --- a/src/core/soci_backends_config.h.in +++ /dev/null @@ -1,12 +0,0 @@ -// -// Copyright (C) 2011 Alex Ott -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -#ifndef SOCI_BACKENDS_CONFIG_H -#define SOCI_BACKENDS_CONFIG_H - -#define DEFAULT_BACKENDS_PATH "@CMAKE_INSTALL_FULL_LIBDIR@" - -#endif // SOCI_BACKENDS_CONFIG_H diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index aec5e4cb2..e6f507ca4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,48 +1,15 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### -colormsg(_HIBLUE_ "Configuring SOCI tests:") +add_subdirectory(common) -# This works around a problem when building in C++11 mode with clang (see #984). -add_definitions(-DCATCH_CONFIG_CPP11_NO_SHUFFLE) -if(MSVC) - add_compile_options(/bigobj /utf-8) -endif() +foreach (CURRENT_BACKEND IN LISTS SOCI_ENABLED_BACKENDS) + string(TOUPPER "${CURRENT_BACKEND}" CURRENT_BACKEND_UPPER) + string(TOLOWER "${CURRENT_BACKEND}" CURRENT_BACKEND_LOWER) -include_directories( - ${SOCI_SOURCE_DIR}/include/private - ${CMAKE_CURRENT_SOURCE_DIR}) + set(SOCI_${CURRENT_BACKEND_UPPER}_SKIP_TESTS OFF CACHE BOOL "Whether to skip tests for backend '${CURRENT_BACKEND}'") -# This library is used by all test executables. -# It's always static for simplicity, even when using shared SOCI libraries. -add_library(soci_tests_common STATIC - common/test-main.cpp - common/test-boost.cpp - common/test-common.cpp - common/test-connparams.cpp - common/test-custom.cpp - common/test-dynamic.cpp - common/test-lob.cpp - common/test-manual.cpp - common/test-rowset.cpp - test-assert.h - test-context.h - test-myint.h) + if (NOT SOCI_${CURRENT_BACKEND_UPPER}_SKIP_TESTS) + add_subdirectory(${CURRENT_BACKEND_LOWER}) + endif() +endforeach() -add_subdirectory(empty) -add_subdirectory(db2) -add_subdirectory(firebird) -add_subdirectory(mysql) -add_subdirectory(odbc) -add_subdirectory(oracle) -add_subdirectory(postgresql) -add_subdirectory(sqlite3) diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt new file mode 100644 index 000000000..53460fe89 --- /dev/null +++ b/tests/common/CMakeLists.txt @@ -0,0 +1,42 @@ + +add_library(soci_tests_common + STATIC + "test-boost.cpp" + "test-common.cpp" + "test-connparams.cpp" + "test-custom.cpp" + "test-dynamic.cpp" + "test-lob.cpp" + "test-main.cpp" + "test-manual.cpp" + "test-rowset.cpp" + "test-unicode.cpp" +) + +# Catch headers are sensitive when it comes to being included in different +# contexts and this can lead to issues with all functionality to actually +# running the tests i.e. the main function. +# Therefore, we have to make sure that the main file is not included in +# a unity build. +set_source_files_properties("test-main.cpp" + PROPERTIES + SKIP_UNITY_BUILD_INCLUSION TRUE +) + +# Required to work around build issues with C++11 and Clang (see https://github.com/SOCI/soci/issues/984) +target_compile_definitions(soci_tests_common + PUBLIC + CATCH_CONFIG_CPP11_NO_SHUFFLE +) + +target_link_libraries(soci_tests_common + PUBLIC + soci_compiler_interface + SOCI::Core +) + +target_include_directories(soci_tests_common + PUBLIC + "${PROJECT_SOURCE_DIR}/include/private" + "${PROJECT_SOURCE_DIR}/tests" +) diff --git a/tests/db2/CMakeLists.txt b/tests/db2/CMakeLists.txt index 940d9f814..31cff62b0 100644 --- a/tests/db2/CMakeLists.txt +++ b/tests/db2/CMakeLists.txt @@ -1,16 +1,11 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +add_executable(soci_db2_tests + "test-db2.cpp" +) +target_link_libraries(soci_db2_tests PRIVATE soci_tests_common SOCI::DB2) -soci_backend_test( - BACKEND DB2 - DEPENDS DB2 - SOURCE test-db2.cpp - CONNSTR "DSN=SAMPLE;Uid=db2inst1;Pwd=db2inst1;autocommit=off") +set(SOCI_DB2_TEST_CONNSTR "DSN=SAMPLE;Uid=db2inst1;Pwd=db2inst1;autocommit=off" CACHE STRING "The connection string to use for DB2 tests") + +add_test( + NAME soci_db2_tests + COMMAND soci_db2_tests "${SOCI_DB2_TEST_CONNSTR}" "--invisibles" +) diff --git a/tests/empty/CMakeLists.txt b/tests/empty/CMakeLists.txt index 9d945a5f1..58920627d 100644 --- a/tests/empty/CMakeLists.txt +++ b/tests/empty/CMakeLists.txt @@ -1,18 +1,11 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +add_executable(soci_empty_tests + "test-empty.cpp" +) +target_link_libraries(soci_empty_tests PRIVATE soci_tests_common SOCI::Empty) -soci_backend_test( - BACKEND Empty - SOURCE test-empty.cpp - # We only run these tests from the empty backend test, as they don't use - # database at all. - ../common/test-unicode.cpp - CONNSTR "dummy") +set(SOCI_EMPTY_TEST_CONNSTR "dummy" CACHE STRING "The connection string to use for Empty tests") + +add_test( + NAME soci_empty_tests + COMMAND soci_empty_tests "${SOCI_EMPTY_TEST_CONNSTR}" "--invisibles" +) diff --git a/tests/firebird/CMakeLists.txt b/tests/firebird/CMakeLists.txt index e5989190a..5f51afc4e 100644 --- a/tests/firebird/CMakeLists.txt +++ b/tests/firebird/CMakeLists.txt @@ -1,16 +1,11 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +add_executable(soci_firebird_tests + "test-firebird.cpp" +) +target_link_libraries(soci_firebird_tests PRIVATE soci_tests_common SOCI::Firebird) -soci_backend_test( - BACKEND Firebird - DEPENDS Firebird - SOURCE test-firebird.cpp - CONNSTR "service=/tmp/soci_test.fdb user=SYSDBA password=masterkey") +set(SOCI_FIREBIRD_TEST_CONNSTR "service=/tmp/soci_test.fdb user=SYSDBA password=masterkey" CACHE STRING "The connection string to use for Firebird tests") + +add_test( + NAME soci_firebird_tests + COMMAND soci_firebird_tests "${SOCI_FIREBIRD_TEST_CONNSTR}" "--invisibles" +) diff --git a/tests/mysql/CMakeLists.txt b/tests/mysql/CMakeLists.txt index 9bd760e45..9510f6fb1 100644 --- a/tests/mysql/CMakeLists.txt +++ b/tests/mysql/CMakeLists.txt @@ -1,16 +1,11 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +add_executable(soci_mysql_tests + "test-mysql.cpp" +) +target_link_libraries(soci_mysql_tests PRIVATE soci_tests_common SOCI::MySQL) -soci_backend_test( - BACKEND MySQL - DEPENDS MySQL - SOURCE test-mysql.cpp - CONNSTR "db=soci_test") +set(SOCI_MYSQL_TEST_CONNSTR "db=soci_test" CACHE STRING "The connection string to use for MySQL tests") + +add_test( + NAME soci_mysql_tests + COMMAND soci_mysql_tests "${SOCI_MYSQL_TEST_CONNSTR}" "--invisibles" +) diff --git a/tests/odbc/CMakeLists.txt b/tests/odbc/CMakeLists.txt index 0791a88f8..4e3579544 100644 --- a/tests/odbc/CMakeLists.txt +++ b/tests/odbc/CMakeLists.txt @@ -1,69 +1,85 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### - -if (WIN32) - # MDBTools driver seems unreliable - soci_backend_test( - NAME access - BACKEND ODBC - DEPENDS ODBC - SOURCE test-odbc-access.cpp - CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-access.dsn") -else() - message(STATUS "MS Access test disabled on non-Windows platform") -endif() - set(MSSQL_VER $ENV{MSSQL_VER}) if (NOT MSSQL_VER) # Use the same value that was used before by default. set(MSSQL_VER "2014") endif() -configure_file("test-mssql.dsn.in" "test-mssql.dsn" @ONLY) - -soci_backend_test( - NAME mssql - BACKEND ODBC - DEPENDS ODBC - SOURCE test-odbc-mssql.cpp - CONNSTR "FILEDSN=${CMAKE_CURRENT_BINARY_DIR}/test-mssql.dsn") - -soci_backend_test( - NAME mysql - BACKEND ODBC - DEPENDS ODBC - SOURCE test-odbc-mysql.cpp - CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-mysql.dsn") +configure_file("test-mssql.dsn.in" "${CMAKE_CURRENT_BINARY_DIR}/test-mssql.dsn" @ONLY) + + +if (WIN32) + add_executable(soci_odbc_ms_access_tests + "test-odbc-access.cpp" + ) + target_link_libraries(soci_odbc_ms_access_tests PRIVATE soci_tests_common SOCI::ODBC) + + set(SOCI_ODBC_TEST_ACCESS_CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-access.dsn" CACHE STRING "Connection string for the ODBC MS Access test") + + add_test( + NAME soci_odbc_ms_access_tests + COMMAND soci_odbc_ms_access_tests "${SOCI_ODBC_TEST_ACCESS_CONNSTR}" "--invisibles" + ) +endif() + + +add_executable(soci_odbc_mssql_tests + "test-odbc-mssql.cpp" +) +target_link_libraries(soci_odbc_mssql_tests PRIVATE soci_tests_common SOCI::ODBC) + +set(SOCI_ODBC_TEST_MSSQL_CONNSTR "FILEDSN=${CMAKE_CURRENT_BINARY_DIR}/test-mssql.dsn" CACHE STRING "Connection string for the ODBC MSSQL test") + +add_test( + NAME soci_odbc_mssql_tests + COMMAND soci_odbc_mssql_tests "${SOCI_ODBC_TEST_MSSQL_CONNSTR}" "--invisibles" +) + + +add_executable(soci_odbc_mysql_tests + "test-odbc-mysql.cpp" +) +target_link_libraries(soci_odbc_mysql_tests PRIVATE soci_tests_common SOCI::ODBC) + +set(SOCI_ODBC_TEST_MYSQL_CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-mysql.dsn" CACHE STRING "Connection string for the ODBC MySQL test") + +add_test( + NAME soci_odbc_mysql_tests + COMMAND soci_odbc_mysql_tests "${SOCI_ODBC_TEST_MYSQL_CONNSTR}" "--invisibles" +) + if(WIN32) set(TEST_PGSQL_DSN "test-postgresql-win64.dsn") else() set(TEST_PGSQL_DSN "test-postgresql.dsn") endif() -soci_backend_test( - NAME postgresql - BACKEND ODBC - DEPENDS ODBC - SOURCE test-odbc-postgresql.cpp - CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/${TEST_PGSQL_DSN}") + +add_executable(soci_odbc_postgresql_tests + "test-odbc-postgresql.cpp" +) +target_link_libraries(soci_odbc_postgresql_tests PRIVATE soci_tests_common SOCI::ODBC) + +set(SOCI_ODBC_TEST_POSTGRESQL_CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/${TEST_PGSQL_DSN}" CACHE STRING "Connection string for the ODBC PostgreSQL test") + +add_test( + NAME soci_odbc_postgresql_tests + COMMAND soci_odbc_postgresql_tests "${SOCI_ODBC_TEST_POSTGRESQL_CONNSTR}" "--invisibles" +) + # TODO: DB2 backend is tested by Travis CI on dedicated VM, separate from ODBC, # in order to test DB2 with ODBC, it would be best to install DB2 driver only. # if (NOT $ENV{TRAVIS}) option(WITH_ODBC_TEST_DB2 "Build ODBC DB2 test" OFF) if (WITH_ODBC_TEST_DB2) - soci_backend_test( - NAME db2 - BACKEND ODBC - SOURCE test-odbc-db2.cpp - CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-db2.dsn") -else() - message(STATUS "ODBC DB2 test disabled.") + add_executable(soci_odbc_db2_tests + "test-odbc-db2.cpp" + ) + target_link_libraries(osoci_dbc_db2_tests PRIVATE soci_tests_common SOCI::ODBC) + + set(SOCI_ODBC_TEST_DB2_CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-db2.dsn" CACHE STRING "Connection string for the ODBC DB2 test") + + add_test( + NAME soci_odbc_db2_tests + COMMAND soci_odbc_db2_tests "${SOCI_ODBC_TEST_DB2_CONNSTR}" "--invisibles" + ) endif() diff --git a/tests/oracle/CMakeLists.txt b/tests/oracle/CMakeLists.txt index 290111d1c..39819b956 100644 --- a/tests/oracle/CMakeLists.txt +++ b/tests/oracle/CMakeLists.txt @@ -1,16 +1,11 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +add_executable(soci_oracle_tests + "test-oracle.cpp" +) +target_link_libraries(soci_oracle_tests PRIVATE soci_tests_common SOCI::Oracle) -soci_backend_test( - BACKEND Oracle - DEPENDS Oracle - SOURCE test-oracle.cpp - CONNSTR "service=orcl user=scott password=tiger") +set(SOCI_ORACLE_TEST_CONNSTR "service=orcl user=scott password=tiger" CACHE STRING "The connection string to use for Oracle tests") + +add_test( + NAME soci_oracle_tests + COMMAND soci_oracle_tests "${SOCI_ORACLE_TEST_CONNSTR}" "--invisibles" +) diff --git a/tests/oracle/Makefile.basic b/tests/oracle/Makefile.basic deleted file mode 100644 index 11c3e24cd..000000000 --- a/tests/oracle/Makefile.basic +++ /dev/null @@ -1,13 +0,0 @@ -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -INCLUDEDIRS = -I../../include -I../../include/private -I.. \ - -I${ORACLE_HOME}/rdbms/public -LIBDIRS = -L../../src/core -L../../src/backends/oracle -L${ORACLE_HOME}/lib -LIBS = -lsoci_core -lsoci_oracle -ldl -lclntsh -locci -lnnz11 - -test-oracle : test-oracle.cpp - ${COMPILER} $? -o $@ ${INCLUDEDIRS} ${LIBDIRS} ${LIBS} - - -clean : - rm -f test-oracle diff --git a/tests/postgresql/CMakeLists.txt b/tests/postgresql/CMakeLists.txt index 02b4d535d..7e1b02c68 100644 --- a/tests/postgresql/CMakeLists.txt +++ b/tests/postgresql/CMakeLists.txt @@ -1,16 +1,11 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +add_executable(soci_postgresql_tests + "test-postgresql.cpp" +) +target_link_libraries(soci_postgresql_tests PRIVATE soci_tests_common SOCI::PostgreSQL) -soci_backend_test( - BACKEND PostgreSQL - DEPENDS PostgreSQL - SOURCE test-postgresql.cpp - CONNSTR "dbname=soci_test") +set(SOCI_POSTGRESQL_TEST_CONNSTR "dbname=soci_test" CACHE STRING "The connection string to use for PostgreSQL tests") + +add_test( + NAME soci_postgresql_tests + COMMAND soci_postgresql_tests "${SOCI_POSTGRESQL_TEST_CONNSTR}" "--invisibles" +) diff --git a/tests/postgresql/Makefile.basic b/tests/postgresql/Makefile.basic deleted file mode 100644 index 145347c35..000000000 --- a/tests/postgresql/Makefile.basic +++ /dev/null @@ -1,12 +0,0 @@ -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -INCLUDEDIRS = -I../../include -I../../include/private -I.. -I/usr/include/postgresql -LIBDIRS = -L../../src/core -L../../src/backends/postgresql -L/usr/lib/x86_64-linux-gnu -LIBS = -lsoci_postgresql -lsoci_core -ldl -lpq - -test-postgresql : test-postgresql.cpp - ${COMPILER} $? -o $@ ${INCLUDEDIRS} ${LIBDIRS} ${LIBS} - - -clean : - rm -f test-postgresql diff --git a/tests/sqlite3/CMakeLists.txt b/tests/sqlite3/CMakeLists.txt index 6d8bee49b..288bef28c 100644 --- a/tests/sqlite3/CMakeLists.txt +++ b/tests/sqlite3/CMakeLists.txt @@ -1,16 +1,11 @@ -############################################################################### -# -# This file is part of CMake configuration for SOCI library -# -# Copyright (C) 2010-2013 Mateusz Loskot -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) -# -############################################################################### +add_executable(soci_sqlite3_tests + "test-sqlite3.cpp" +) +target_link_libraries(soci_sqlite3_tests PRIVATE soci_tests_common SOCI::SQLite3) -soci_backend_test( - BACKEND SQLite3 - DEPENDS SQLite3 - SOURCE test-sqlite3.cpp - CONNSTR ":memory:") +set(SOCI_SQLITE3_TEST_CONNSTR ":memory:" CACHE STRING "The connection string to use for SQLite3 tests") + +add_test( + NAME soci_sqlite3_tests + COMMAND soci_sqlite3_tests "${SOCI_SQLITE3_TEST_CONNSTR}" "--invisibles" +) diff --git a/tests/sqlite3/Makefile.basic b/tests/sqlite3/Makefile.basic deleted file mode 100644 index 697d67404..000000000 --- a/tests/sqlite3/Makefile.basic +++ /dev/null @@ -1,12 +0,0 @@ -COMPILER = g++ -CXXFLAGS = -Wall -pedantic -Wno-long-long -INCLUDEDIRS = -I../../include -I../../include/private -I.. -I/usr/include/sqlite3 -LIBDIRS = -L../../src/core -L../../src/backends/sqlite3 -L/usr/lib/x86_64-linux-gnu -LIBS = -lsoci_sqlite3 -lsoci_core -ldl -lsqlite3 - -test-sqlite3 : test-sqlite3.cpp - ${COMPILER} $? -o $@ ${INCLUDEDIRS} ${LIBDIRS} ${LIBS} - - -clean : - rm -f test-sqlite3