Skip to content

Commit d74ec06

Browse files
committed
CMake tweaks for non-sqlcipher key support
The `SQLITE_HAS_CODEC` option currently does two separate things: it enables usage of the key API, and it forces searching for sqlcipher headers when finding SQLite. When attempting to use an alternative to sqlcipher (such as sqlite-ee or sqlite-multiple-ciphers) the former is wanted, and the latter is absolutely not wanted. The previous commit allows working around the sqlcipher search by simply bypassing the find process entirely and allowing a parent project to set up SQLite3::SQLite however it wants. That, combined with SQLITE_HAS_CODEC=ON, allows using SQLiteCpp with encryption API with some alternative to sqlcipher. This commit adds some small "niceness" updates: - make the SQLITE_HAS_CODEC compile definition PRIVATE as it only affects internal code in Database.cpp and does not require propagation to linking code. (Building sqlcipher itself requires this definition, but SQLiteCpp does not support building sqlcipher, it only finds an already-built one). - sqlite3_key_v2 is not actually required or used (and appears to be sqlcipher-specific), but sqlite3_rekey is. (`sqlite3_key` and `sqlite3_rekey` are supported by all of sqlcipher, sqlite-mc, and sqlite-ee). - SQLITE_HAS_CODEC combined with SQLITECPP_INTERNAL_SQLITE will not compile as the internal version is stock sqlite3, and this adds a check and fatal error if attempting that configuration.
1 parent 8b816df commit d74ec06

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,12 @@ if (SQLITE_ENABLE_ASSERT_HANDLER)
228228
target_compile_definitions(SQLiteCpp PUBLIC SQLITECPP_ENABLE_ASSERT_HANDLER)
229229
endif (SQLITE_ENABLE_ASSERT_HANDLER)
230230

231-
option(SQLITE_HAS_CODEC "Enable database encryption API. Not available in the public release of SQLite." OFF)
231+
option(SQLITE_HAS_CODEC "Enables usage of the Database key() and rekey() methods. Requires a custom SQLite providing the key API such as sqlcipher/sql-ee/sqlite-multi-ciphers" OFF)
232232
if (SQLITE_HAS_CODEC)
233-
# Enable database encryption API. Requires implementations of sqlite3_key & sqlite3_key_v2.
234-
# Eg. SQLCipher (libsqlcipher-dev) is an SQLite extension that provides 256 bit AES encryption of database files.
235-
target_compile_definitions(SQLiteCpp PUBLIC SQLITE_HAS_CODEC)
233+
# Enable database encryption API. Requires implementations of sqlite3_key & sqlite3_rekey.
234+
# SQLCipher, SQLite Multiple Ciphers, and the commercial SQLite Encryption Extensions provide
235+
# these API functions for encrypting a database.
236+
target_compile_definitions(SQLiteCpp PRIVATE SQLITE_HAS_CODEC)
236237
endif (SQLITE_HAS_CODEC)
237238

238239
option(SQLITE_USE_LEGACY_STRUCT "Fallback to forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)" OFF)
@@ -279,8 +280,12 @@ endif ()
279280
## Build provided copy of SQLite3 C library ##
280281

281282
option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON)
282-
option(SQLITECPP_FIND_SQLITE "Attempt to find SQLite via find_package (requires SQLITECPP_INTERNAL_SQLITE=OFF). If disabled then a SQLite3::SQLite cmake target must already exist." ON)
283+
option(SQLITECPP_FIND_SQLITE "Attempt to find SQLite (or sqlcipher, with SQLITE_HAS_CODEC) automatically. Requires SQLITECPP_INTERNAL_SQLITE=OFF. If disabled then a SQLite3::SQLite cmake target must already exist." ON)
283284
if (SQLITECPP_INTERNAL_SQLITE)
285+
if (SQLITE_HAS_CODEC)
286+
message(FATAL_ERROR "Internal sqlite3 source does not support SQLITE_HAS_CODEC")
287+
endif()
288+
284289
message(STATUS "Compile sqlite3 from source in subdirectory")
285290
option(SQLITE_ENABLE_RTREE "Enable RTree extension when building internal sqlite3 library." OFF)
286291
option(SQLITE_ENABLE_DBSTAT_VTAB "Enable DBSTAT read-only eponymous virtual table extension when building internal sqlite3 library." OFF)

meson_options.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
option('SQLITE_ENABLE_COLUMN_METADATA', type: 'boolean', value: false, description: 'Enable Column::getColumnOriginName(). Require support from sqlite3 library.')
55
## Enable the user definition of a assertion_failed() handler (default to false, easier to handler for beginners).
66
option('SQLITE_ENABLE_ASSERT_HANDLER', type: 'boolean', value: false, description: 'Enable the user definition of a assertion_failed() handler.')
7-
## Enable database encryption API. Requires implementations of sqlite3_key & sqlite3_key_v2.
8-
## Eg. SQLCipher (libsqlcipher-dev) is an SQLite extension that provides 256 bit AES encryption of database files.
7+
## Enable database encryption API. Requires implementations of sqlite3_key & sqlite3_rekey.
8+
## SQLCipher, SQLite Multiple Ciphers, and the commercial SQLite Encryption Extensions provide
9+
## these API functions for encrypting a database.
910
option('SQLITE_HAS_CODEC', type: 'boolean', value: false, description: 'Enable database encryption API. Not available in the public release of SQLite.')
1011
## Force forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)
1112
option('SQLITE_USE_LEGACY_STRUCT', type: 'boolean', value: false, description: 'Fallback to forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)')

0 commit comments

Comments
 (0)