mirror of
https://github.com/allankoechke/soci.git
synced 2026-11-30 10:58:24 +00:00
Build SQLite3 ourselves if it's not otherwise available
Use sources from the submodule to create soci_sqlite3_builtin library. Recommend cloning with --recurse-submodule to ensure that the submodule is available and update AppVeyor CI to initialize submodules too. Add "BUILTIN" dependency mode to soci_define_backend_target() and use it for SQLite3 backend. Note that because SQLite3 source is C, and not C++, this language needs to be explicitly added to CMake project() function, otherwise C files are just silently ignored. This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
@@ -14,7 +14,7 @@ project(SOCI
|
||||
VERSION ${SOCI_VERSION}
|
||||
DESCRIPTION "C++ database access library"
|
||||
HOMEPAGE_URL "https://soci.sourceforge.net/"
|
||||
LANGUAGES CXX
|
||||
LANGUAGES C CXX
|
||||
)
|
||||
|
||||
include(soci_utils)
|
||||
|
||||
@@ -75,6 +75,7 @@ install:
|
||||
# Ensure we have a recent cmake version available
|
||||
- choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
|
||||
- refreshenv
|
||||
- git submodule update --init
|
||||
|
||||
before_build:
|
||||
# dirty little hack - remove sh from Git to make generator happy
|
||||
|
||||
@@ -9,7 +9,7 @@ include(soci_utils)
|
||||
# BACKEND_NAME <name> Name of the backend
|
||||
# ENABLED_VARIABLE <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 <behavior> What to do if a dependency is not found. Valid values are "ERROR" and "DISABLE"
|
||||
# MISSING_DEPENDENCY_BEHAVIOR <behavior> What to do if a dependency is not found. Valid values are "ERROR", "DISABLE" and "BUILTIN".
|
||||
# TARGET_NAME <target> Name of the CMake target that shall be created for this backend
|
||||
# DEPENDENCIES <spec1> [... <specN>] List of dependency specifications. Each specification has to be a single
|
||||
# argument (single string) following the syntax
|
||||
@@ -58,6 +58,9 @@ function(soci_define_backend_target)
|
||||
set(ERROR_ON_MISSING_DEPENDENCY ON)
|
||||
elseif(DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR STREQUAL "DISABLE")
|
||||
set(DISABLE_ON_MISSING_DEPENDENCY ON)
|
||||
elseif(DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR STREQUAL "BUILTIN")
|
||||
set(REQUIRE_FLAG "QUIET")
|
||||
set(BUILTIN_ON_MISSING_DEPENDENCY ON)
|
||||
else()
|
||||
message(FATAL_ERROR "Invalid value '${DEFINE_BACKEND_MISSING_DEPENDENCY_BEHAVIOR}' for option 'MISSING_DEPENDENCY_BEHAVIOR'")
|
||||
endif()
|
||||
@@ -88,22 +91,29 @@ function(soci_define_backend_target)
|
||||
get_property(DESCRIPTION CACHE "${DEFINE_BACKEND_ENABLED_VARIABLE}" PROPERTY HELPSTRING)
|
||||
set(${DEFINE_BACKEND_ENABLED_VARIABLE} OFF CACHE STRING "${DESCRIPTION}" FORCE)
|
||||
return()
|
||||
elseif(BUILTIN_ON_MISSING_DEPENDENCY)
|
||||
message(STATUS "Falling back on built-in version of '${CURRENT_DEP}' for SOCI backend '${DEFINE_BACKEND_BACKEND_NAME}'")
|
||||
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}'")
|
||||
else()
|
||||
# This is wasteful, but do it again without "QUIET" flag to show the result if it succeeded.
|
||||
if (REQUIRE_FLAG STREQUAL "QUIET")
|
||||
find_package(${CURRENT_DEP_SEARCH})
|
||||
endif()
|
||||
endforeach()
|
||||
if (CURRENT_DEP_DEFINES)
|
||||
set(MACRO_NAMES_ARG "MACRO_NAMES ${CURRENT_DEP_DEFINES}")
|
||||
|
||||
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"
|
||||
)
|
||||
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()
|
||||
|
||||
|
||||
|
||||
@@ -6,32 +6,11 @@ SOCI backend for accessing SQLite 3 database.
|
||||
|
||||
### Supported Versions
|
||||
|
||||
The SOCI SQLite3 backend is supported for use with SQLite3 >= 3.1
|
||||
|
||||
### Tested Platforms
|
||||
|
||||
|SQLite3|OS|Compiler|
|
||||
|--- |--- |--- |
|
||||
|3.12.1|Windows Server 2016|MSVC++ 14.1|
|
||||
|3.12.1|Windows Server 2012 R2|MSVC++ 14.0|
|
||||
|3.12.1|Windows Server 2012 R2|MSVC++ 12.0|
|
||||
|3.12.1|Windows Server 2012 R2|MSVC++ 11.0|
|
||||
|3.12.1|Windows Server 2012 R2|Mingw-w64/GCC 4.8|
|
||||
|3.7.9|Ubuntu 12.04|g++ 4.6.3|
|
||||
|3.4.0|Windows XP|(cygwin) g++ 3.4.4|
|
||||
|3.4.0|Windows XP|Visual C++ 2005 Express Edition|
|
||||
|3.3.8|Windows XP|Visual C++ 2005 Professional|
|
||||
|3.5.2|Mac OS X 10.5|g++ 4.0.1|
|
||||
|3.3.4|Ubuntu 5.1|g++ 4.0.2|
|
||||
|3.3.4|Windows XP|(cygwin) g++ 3.3.4|
|
||||
|3.3.4|Windows XP|Visual C++ 2005 Express Edition|
|
||||
|3.2.1|Linux i686 2.6.10-gentoo-r6|g++ 3.4.5|
|
||||
|3.1.3|Mac OS X 10.4|g++ 4.0.1|
|
||||
|3.24.0|macOS High Sierra 10.13.5|AppleClang 9.1.0.9020039|
|
||||
The oldest tested SQLite3 version that SOCI was tested with was 3.1.3 and the latest tested version is 3.49.1. Due to high degree of SQLite3 backwards compatibility, it is likely that newer versions can work as well.
|
||||
|
||||
### Required Client Libraries
|
||||
|
||||
The SOCI SQLite3 backend requires SQLite3's `libsqlite3` client library.
|
||||
The SOCI SQLite3 backend uses `libsqlite3` client library if available or the built-in version of SQLite3 included in the SOCI source code if this library cannot be found.
|
||||
|
||||
### Connecting to the Database
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ where X.Y.Z is the version number. Unpack the archive.
|
||||
You can always clone SOCI from the Git repository:
|
||||
|
||||
```console
|
||||
git clone git://github.com/SOCI/soci.git
|
||||
git clone --recurse-submodules git://github.com/SOCI/soci.git
|
||||
```
|
||||
|
||||
## Building with CMake
|
||||
@@ -145,7 +145,7 @@ Furthermore, the `MYSQL_DIR` _environment variable_ can be set to the MySQL inst
|
||||
|
||||
#### SQLite 3
|
||||
|
||||
* `SOCI_SQLITE3` - Enabler - Enables the [SQLite3](backends/sqlite3.md) backend.
|
||||
* `SOCI_SQLITE3` - Enabler - Enables the [SQLite3](backends/sqlite3.md) backend. Note that, unlike with all the other backends, if SQLite3 library is not found, built-in version of SQLite3 is used instead of the backend being disabled.
|
||||
* `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.
|
||||
|
||||
|
||||
@@ -31,7 +31,24 @@
|
||||
namespace sqlite_api
|
||||
{
|
||||
|
||||
#include <sqlite3.h>
|
||||
// Don't include sqlite3.h from outside SOCI: this header might not be
|
||||
// available when using built-in SQLite3 as we don't install it in this case.
|
||||
#ifdef SOCI_SQLITE3_SOURCE
|
||||
#include <sqlite3.h>
|
||||
#else // !SOCI_SQLITE3_SOURCE
|
||||
// We need just a couple of forward declarations to make this header itself
|
||||
// compile.
|
||||
struct sqlite3;
|
||||
struct sqlite3_stmt;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
typedef __int64 sqlite3_int64;
|
||||
typedef unsigned __int64 sqlite3_uint64;
|
||||
#else
|
||||
typedef long long int sqlite3_int64;
|
||||
typedef unsigned long long int sqlite3_uint64;
|
||||
#endif
|
||||
#endif // SOCI_SQLITE3_SOURCE/!SOCI_SQLITE3_SOURCE
|
||||
|
||||
} // namespace sqlite_api
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
include(soci_define_backend_target)
|
||||
|
||||
if (SOCI_SQLITE3_AUTO)
|
||||
set(DEPENDENCY_MODE "DISABLE")
|
||||
# Unlike most other backends, we can fall back on using the built-in
|
||||
# version of SQLite3 if the system version is not found.
|
||||
set(DEPENDENCY_MODE "BUILTIN")
|
||||
else()
|
||||
set(DEPENDENCY_MODE "ERROR")
|
||||
endif()
|
||||
@@ -32,3 +34,31 @@ soci_define_backend_target(
|
||||
if (NOT SOCI_SQLITE3)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# If SQLite3 was found, this target must have been created.
|
||||
if (NOT TARGET SQLite::SQLite3)
|
||||
# But if it wasn't, use our built-in version, after checking that it is
|
||||
# available.
|
||||
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/3rdparty/sqlite3/sqlite3.c")
|
||||
message(WARNING "SQLite3 not found and built-in version not available, have you cloned SOCI repository with --recurse-submodules?")
|
||||
|
||||
get_property(DESCRIPTION CACHE SOCI_SQLITE3 PROPERTY HELPSTRING)
|
||||
set(SOCI_SQLITE3 OFF CACHE STRING "${DESCRIPTION}" FORCE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
add_library(soci_sqlite3_builtin)
|
||||
target_sources(soci_sqlite3_builtin
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/3rdparty/sqlite3/sqlite3.c"
|
||||
)
|
||||
target_include_directories(soci_sqlite3_builtin
|
||||
PUBLIC
|
||||
"${PROJECT_SOURCE_DIR}/3rdparty/sqlite3"
|
||||
)
|
||||
|
||||
target_link_libraries(soci_sqlite3
|
||||
PRIVATE
|
||||
soci_sqlite3_builtin
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -107,7 +107,7 @@ organization where all Git repositories are available.</p>
|
||||
|
||||
<p>The main Git repository with SOCI source code can be cloned with:</p>
|
||||
<pre>
|
||||
$ git clone git://github.com/SOCI/soci.git
|
||||
$ git clone --recurse-submodules git://github.com/SOCI/soci.git
|
||||
</pre>
|
||||
|
||||
<p>The <a href="https://github.com/SOCI/soci/issues">Issues</a> tracker is open
|
||||
|
||||
Reference in New Issue
Block a user