Generalized cmake sqlite & key api to allow easier use of SQLite Multiple Ciphers #532
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have recently been working on a project that is looking to use SQLite Multiple Ciphers rather than sqlite (or sqlcipher), and stumbled into some CMake inflexibility in SQLiteCpp that makes this difficult to achieve:
SQLiteCpp's cmake only supports "build internal sqlite" or "use find_package". This has been a bit of a nuissance for me before, requiring this workaround before
add_directory(SQLiteCpp):Basically: setting a bunch of cache variables to make the
find_package(SQLite)inside SQLiteCpp short-circuit itself and return immediately, so that thetarget_link_libraries(SQLiteCpp PUBLIC SQLite3::SQLite)links to what I already set up.This was a bit gross, but it worked, with plain SQLite3.
The
SQLITE_HAS_CODECoption forces a pkg-config search for sqlcipher. I am not using sqlcipher, and so this is obviously not what I want. I could go make a fake package config file to short circuit that search, but that feels like yet another layer of hacks.An alternative hack to make this work was to set cmake's SQLITE_HAS_CODEC=OFF but then, after the add_directory, modifying the SQLiteCpp target to add
-DSQLITE_HAS_CODECto bypass the sqlcipher search but still actually enable the key API. I.e. adding these to the above hacks:This works, but again feels quite dirty.
This PR
Hence this PR: this adds an "escape hatch" to the cmake code so that I can tell SQLiteCpp to let me worry about SQLite3 via a SQLite3::SQLite pre-existing target, and then lets the
SQLITE_USE_CIPHERcmake option be usable for this case.With this:
The PR also makes some closely related changes to this part of the cmake code:
sqlite3_key_v2function and addsqlite3_rekeyfunction