Generalized cmake sqlite & key api to allow easier use of SQLite Multiple Ciphers#532
Open
jagerman wants to merge 2 commits intoSRombauts:masterfrom
Open
Generalized cmake sqlite & key api to allow easier use of SQLite Multiple Ciphers#532jagerman wants to merge 2 commits intoSRombauts:masterfrom
jagerman wants to merge 2 commits intoSRombauts:masterfrom
Conversation
Currently the SQLite3 code is quite limited, and really only has two options: - build bundled sqlite3 version - use find_package() to find it This commit adds an option to enable a third case: letting an external cmake project worry about finding or building and providing sqlite by setting `SQLITECPP_FIND_SQLITE` to `OFF`. This requires that the parent project has already set up some SQLite3::SQLite cmake target that SQLiteCpp can then simply use without trying to find anything. This is particularly useful when building a custom sqlite3 (such as SQLite3 Multiple Ciphers) which will not be found via `find_package`. Currently you can *somewhat* hack around this by setting a bunch of cache variables to make the find_package short-circuit, but that feels inelegant.
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.
Contributor
Author
|
(I did see PR #392, but the approach here seems considerably simpler by just letting the caller worry about it.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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