Skip to content

Commit

Permalink
Centralized backend list; AsAvailable->AUTO
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl committed Jan 9, 2025
1 parent af92da7 commit 3588900
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 37 deletions.
88 changes: 60 additions & 28 deletions src/backends/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,74 @@
set(SOCI_EMPTY ${PROJECT_IS_TOP_LEVEL} CACHE STRING "Include the 'empty' backend. Can be bool-valued or one of 'Enabled', 'Disabled' and 'AsAvailable'")
set(SOCI_EXISTING_BACKENDS
"Empty"

set(SOCI_DB2 "AsAvailable" CACHE STRING "Include the 'DB2' backend. Can be bool-valued or one of 'Enabled', 'Disabled' and 'AsAvailable'")
set(SOCI_FIREBIRD "AsAvailable" CACHE STRING "Include the 'Firebird' backend. Can be bool-valued or one of 'Enabled', 'Disabled' and 'AsAvailable'")
set(SOCI_MYSQL "AsAvailable" CACHE STRING "Include the 'MySQL' backend. Can be bool-valued or one of 'Enabled', 'Disabled' and 'AsAvailable'")
set(SOCI_ODBC "AsAvailable" CACHE STRING "Include the 'ODBC' backend. Can be bool-valued or one of 'Enabled', 'Disabled' and 'AsAvailable'")
set(SOCI_ORACLE "AsAvailable" CACHE STRING "Include the 'Oracle' backend. Can be bool-valued or one of 'Enabled', 'Disabled' and 'AsAvailable'")
set(SOCI_POSTGRESQL "AsAvailable" CACHE STRING "Include the 'Postgresql' backend. Can be bool-valued or one of 'Enabled', 'Disabled' and 'AsAvailable'")
set(SOCI_SQLITE3 "AsAvailable" CACHE STRING "Include the 'SQLite3' backend. Can be bool-valued or one of 'Enabled', 'Disabled' and 'AsAvailable'")
"DB2"
"Firebird"
"MySQL"
"ODBC"
"Oracle"
"PostgreSQL"
"SQLite3"
)
set(SOCI_ENABLED_BACKENDS "")

foreach(CURRENT_BACKEND IN LISTS SOCI_EXISTING_BACKENDS)
string(TOUPPER "${CURRENT_BACKEND}" CURRENT_BACKEND_UPPER)
string(TOLOWER "${CURRENT_BACKEND}" CURRENT_BACKEND_LOWER)

foreach(CURRENT IN ITEMS "db2" "empty" "firebird" "mysql" "odbc" "oracle" "postgresql" "sqlite3")
string(TOUPPER "${CURRENT}" CURRENT_UPPER)
set(CURRENT_ENABLED_VAR "SOCI_${CURRENT_BACKEND_UPPER}")

# 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
"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."
)

# 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_UPPER})
message(DEPRECATION "Use of the WITH_${CURRENT_UPPER} option is deprecated - use the new SOCI_${CURRENT_UPPER} instead")
set(SOCI_${CURRENT_UPPER} "${WITH_${CURRENT_UPPER}}" CACHE STRING "")
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 "" FORCE)
endif()
# Delete the legacy variable from cache
unset(WITH_${CURRENT_UPPER} CACHE)
unset(WITH_${CURRENT_BACKEND_UPPER} CACHE)
endif()

set(SOCI_${CURRENT_UPPER}_AS_AVAILABLE OFF CACHE INTERNAL "" FORCE)

if (SOCI_${CURRENT_UPPER} STREQUAL "Enabled")
set(SOCI_${CURRENT_UPPER} ON CACHE BOOL "" FORCE)
elseif(SOCI_${CURRENT_UPPER} STREQUAL "Disabled")
set(SOCI_${CURRENT_UPPER} OFF CACHE BOOL "" FORCE)
elseif(SOCI_${CURRENT_UPPER} STREQUAL "AsAvailable")
set(SOCI_${CURRENT_UPPER} ON CACHE BOOL "" FORCE)
set(SOCI_${CURRENT_UPPER}_AS_AVAILABLE ON CACHE INTERNAL "" FORCE)
elseif(SOCI_${CURRENT_UPPER} MATCHES "[Oo][Nn]|[Oo][Ff][Ff]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[Yy][Ee][Ss]|[Nn][Oo]|[YyNn01]")
# Do nothing - these are already booleans

# 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 CACHE INTERNAL "" FORCE)

# Convert the value of the current backend's include flag to uppercase
string(TOUPPER "${${CURRENT_ENABLED_VAR}}" ${CURRENT_ENABLED_VAR})

set(INCLUDE_CURRENT_BACKEND OFF)
if (${CURRENT_ENABLED_VAR} STREQUAL "AUTO")
set(INCLUDE_CURRENT_BACKEND ON)
set(${CURRENT_AUTO_VAR} ON)
elseif(${CURRENT_ENABLED_VAR} MATCHES "^(ON|OFF|TRUE|FALSE|YES|NO|[YN01])$")
set(INCLUDE_CURRENT_BACKEND ${${CURRENT_ENABLED_VAR}})
else()
message(FATAL_ERROR "Unsupported value '${SOCI_${CURRENT_UPPER}}' for option SOCI_${CURRENT_UPPER}")
message(FATAL_ERROR "Invalid value '${${CURRENT_ENABLED_VAR}}' for option '${CURRENT_ENABLED_VAR}'")
endif()

if (SOCI_${CURRENT_UPPER})
add_subdirectory(${CURRENT})
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 SOCI_ENABLED_BACKENDS "${CURRENT_BACKEND}")
endif()
endif()
endforeach()

2 changes: 1 addition & 1 deletion src/backends/db2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (SOCI_DB2_AS_AVAILABLE)
if (SOCI_DB2_AUTO)
set(REQUIRED_FLAG "")
else()
set(REQUIRED_FLAG "REQUIRED")
Expand Down
2 changes: 1 addition & 1 deletion src/backends/firebird/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
option(SOCI_FIREBIRD_EMBEDDED "Use the embedded version of Firebird" OFF)

if (SOCI_FIREBIRD_AS_AVAILABLE)
if (SOCI_FIREBIRD_AUTO)
set(REQUIRED_FLAG "")
else()
set(REQUIRED_FLAG "REQUIRED")
Expand Down
2 changes: 1 addition & 1 deletion src/backends/mysql/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (SOCI_MYSQL_AS_AVAILABLE)
if (SOCI_MYSQL_AUTO)
set(REQUIRED_FLAG "")
else()
set(REQUIRED_FLAG "REQUIRED")
Expand Down
2 changes: 1 addition & 1 deletion src/backends/odbc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (SOCI_ODBC_AS_AVAILABLE)
if (SOCI_ODBC_AUTO)
set(REQUIRED_FLAG "")
else()
set(REQUIRED_FLAG "REQUIRED")
Expand Down
2 changes: 1 addition & 1 deletion src/backends/oracle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (SOCI_ORACLE_AS_AVAILABLE)
if (SOCI_ORACLE_AUTO)
set(REQUIRED_FLAG "")
else()
set(REQUIRED_FLAG "REQUIRED")
Expand Down
2 changes: 1 addition & 1 deletion src/backends/postgresql/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (SOCI_POSTGRESQL_AS_AVAILABLE)
if (SOCI_POSTGRESQL_AUTO)
set(REQUIRED_FLAG "")
else()
set(REQUIRED_FLAG "REQUIRED")
Expand Down
2 changes: 1 addition & 1 deletion src/backends/sqlite3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (SOCI_SQLITE3_AS_AVAILABLE)
if (SOCI_SQLITE3_AUTO)
set(REQUIRED_FLAG "")
else()
set(REQUIRED_FLAG "REQUIRED")
Expand Down
7 changes: 5 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
add_subdirectory(common)


foreach (CURRENT_BACKEND IN ITEMS "db2" "empty" "firebird" "mysql" "odbc" "oracle" "postgresql" "sqlite3")
foreach (CURRENT_BACKEND IN LISTS SOCI_ENABLED_BACKENDS)
string(TOUPPER "${CURRENT_BACKEND}" CURRENT_BACKEND_UPPER)
string(TOLOWER "${CURRENT_BACKEND}" CURRENT_BACKEND_LOWER)

if (SOCI_${CURRENT_BACKEND_UPPER} AND NOT SOCI_${CURRENT_BACKEND_UPPER}_DO_NOT_TEST)
set(SOCI_${CURRENT_BACKEND_UPPER}_SKIP_TESTS OFF CACHE BOOL "Whether to skip tests for backend '${CURRENT_BACKEND}'")

if (NOT SOCI_${CURRENT_BACKEND_UPPER}_SKIP_TESTS)
add_subdirectory(${CURRENT_BACKEND})
endif()
endforeach()
Expand Down

0 comments on commit 3588900

Please sign in to comment.