mirror of
https://github.com/SOCI/soci.git
synced 2026-04-30 16:19:26 -05:00
@@ -31,16 +31,24 @@ if (WIN32)
|
||||
)
|
||||
endif()
|
||||
|
||||
# We want to use warning-related options only for C++ source files (this
|
||||
# excludes 3rdparty/sqlite3/sqlite3.c) and only when compiling SOCI itself and
|
||||
# not an application using it.
|
||||
set(soci_cxx_source "$<AND:$<BOOL:${PROJECT_IS_TOP_LEVEL}>,$<COMPILE_LANGUAGE:CXX>>")
|
||||
|
||||
if (MSVC)
|
||||
# Configure warnings
|
||||
target_compile_options(soci_compiler_interface
|
||||
INTERFACE
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:/W4>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:/we4266>"
|
||||
"$<${soci_cxx_source}:/W4>"
|
||||
"$<${soci_cxx_source}:/we4266>"
|
||||
)
|
||||
|
||||
if (SOCI_ENABLE_WERROR)
|
||||
target_compile_options(soci_compiler_interface INTERFACE "/WX")
|
||||
target_compile_options(soci_compiler_interface
|
||||
INTERFACE
|
||||
"$<${soci_cxx_source}:/WX>"
|
||||
)
|
||||
endif()
|
||||
|
||||
if (SOCI_LD)
|
||||
@@ -51,7 +59,10 @@ if (MSVC)
|
||||
else()
|
||||
|
||||
if (SOCI_ENABLE_WERROR)
|
||||
target_compile_options(soci_compiler_interface INTERFACE "-Werror")
|
||||
target_compile_options(soci_compiler_interface
|
||||
INTERFACE
|
||||
"$<${soci_cxx_source}:-Werror>"
|
||||
)
|
||||
endif()
|
||||
|
||||
if (SOCI_UBSAN)
|
||||
@@ -87,29 +98,29 @@ else()
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
if (NOT (CMAKE_SYSTEM_NAME MATCHES "FreeBSD"))
|
||||
target_compile_options(soci_compiler_interface INTERFACE "$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wno-variadic-macros>")
|
||||
target_compile_options(soci_compiler_interface INTERFACE "$<${soci_cxx_source}:-Wno-variadic-macros>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(SOCI_USE_STD_FLAGS ON)
|
||||
else()
|
||||
message(WARNING "Unknown toolset - using default flags to build SOCI")
|
||||
message(WARNING "Unknown toolset - using default flags to build SOCI")
|
||||
endif()
|
||||
|
||||
if (SOCI_USE_STD_FLAGS)
|
||||
target_compile_options(soci_compiler_interface
|
||||
INTERFACE
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-pedantic>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wno-error=parentheses>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wall>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wextra>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wpointer-arith>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wcast-align>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wcast-qual>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wfloat-equal>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Woverloaded-virtual>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wredundant-decls>"
|
||||
"$<$<BOOL:${PROJECT_IS_TOP_LEVEL}>:-Wno-long-long>"
|
||||
"$<${soci_cxx_source}:-pedantic>"
|
||||
"$<${soci_cxx_source}:-Wno-error=parentheses>"
|
||||
"$<${soci_cxx_source}:-Wall>"
|
||||
"$<${soci_cxx_source}:-Wextra>"
|
||||
"$<${soci_cxx_source}:-Wpointer-arith>"
|
||||
"$<${soci_cxx_source}:-Wcast-align>"
|
||||
"$<${soci_cxx_source}:-Wcast-qual>"
|
||||
"$<${soci_cxx_source}:-Wfloat-equal>"
|
||||
"$<${soci_cxx_source}:-Woverloaded-virtual>"
|
||||
"$<${soci_cxx_source}:-Wredundant-decls>"
|
||||
"$<${soci_cxx_source}:-Wno-long-long>"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -67,6 +67,11 @@ function(soci_define_backend_target)
|
||||
string(TOUPPER "${DEFINE_BACKEND_NAME}" BACKEND_UPPER)
|
||||
set(DEFINE_BACKEND_ENABLED_VARIABLE "SOCI_${BACKEND_UPPER}")
|
||||
|
||||
# Skip looking for dependencies if built-in version is preferred.
|
||||
if (${SOCI_${BACKEND_UPPER}_BUILTIN})
|
||||
unset(DEFINE_BACKEND_DEPENDENCIES)
|
||||
endif()
|
||||
|
||||
foreach(CURRENT_DEP_SPEC IN LISTS DEFINE_BACKEND_DEPENDENCIES)
|
||||
if (NOT "${CURRENT_DEP_SPEC}" MATCHES "^([a-zA-Z0-9_:-;]+) YIELDS ([a-zA-Z0-9_:-;]+)$")
|
||||
message(FATAL_ERROR "Invalid format for dependency specification in '${CURRENT_DEP_SPEC}'")
|
||||
@@ -90,7 +95,6 @@ function(soci_define_backend_target)
|
||||
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_NAME}'")
|
||||
break()
|
||||
else()
|
||||
message(FATAL_ERROR "Unspecified handling of unmet dependency")
|
||||
|
||||
@@ -92,6 +92,9 @@ When it comes to enabling specific backends, SOCI supports three distinct option
|
||||
* `OFF`: Disable the backend.
|
||||
* `ON`: Enables the backend. If one or more of its dependencies are unmet, error and abort configuration.
|
||||
|
||||
SQLite backend is special, as it may use the built-in SQLite library if the system version is not found, see its documentation below for more details.
|
||||
|
||||
|
||||
#### Empty (sample backend)
|
||||
|
||||
* `SOCI_EMPTY` - Enabler - Enables the [sample backend](backends/index.md) called Empty. Always ON by default.
|
||||
@@ -146,7 +149,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. 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` - 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_BUILTIN` can be set to `OFF` to prevent this from happening, i.e. force using system version only, or, on the contrary, set to `ON` to always use the built-in version, even if SQLite3 library is available on the system.
|
||||
* `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.
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ else()
|
||||
set(DEPENDENCY_MODE "ERROR")
|
||||
endif()
|
||||
|
||||
# This variable is specific to this backend and allows to either force or
|
||||
# disable using the built-in copy of SQLite3.
|
||||
set(SOCI_SQLITE3_BUILTIN "" CACHE STRING "Prefer, or forbid, using the built-in SQLite3 library")
|
||||
|
||||
soci_define_backend_target(
|
||||
NAME "SQLite3"
|
||||
TARGET_NAME "soci_sqlite3"
|
||||
@@ -35,28 +39,37 @@ 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?")
|
||||
set(SQLITE3_DIRECTORY "${PROJECT_SOURCE_DIR}/3rdparty/sqlite3")
|
||||
set(SQLITE3_SOURCE_FILE "${SQLITE3_DIRECTORY}/sqlite3.c")
|
||||
|
||||
# But if it wasn't, use our built-in version, after checking that it is
|
||||
# available, and if we're allowed to use it.
|
||||
if (NOT "${SOCI_SQLITE3_BUILTIN}" STREQUAL "OFF")
|
||||
if (NOT EXISTS ${SQLITE3_SOURCE_FILE})
|
||||
message(WARNING "SQLite3 not found and built-in version not available, have you cloned SOCI repository with --recurse-submodules?")
|
||||
else()
|
||||
set(SOCI_SQLITE3_USE_BUILTIN ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT SOCI_SQLITE3_USE_BUILTIN)
|
||||
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"
|
||||
)
|
||||
if ("${SOCI_SQLITE3_BUILTIN}" STREQUAL "ON")
|
||||
message(STATUS "Using built-in version of SQLite3")
|
||||
else()
|
||||
message(STATUS "Falling back on built-in version of SQLite3")
|
||||
endif()
|
||||
|
||||
target_link_libraries(soci_sqlite3
|
||||
target_sources(soci_sqlite3
|
||||
PRIVATE
|
||||
soci_sqlite3_builtin
|
||||
${SQLITE3_SOURCE_FILE}
|
||||
)
|
||||
target_include_directories(soci_sqlite3
|
||||
PRIVATE
|
||||
${SQLITE3_DIRECTORY}
|
||||
)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user