Skip to content

Commit 854bd3a

Browse files
committed
Add SQLITECPP_FIND_SQLITE to disable find_package
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.
1 parent b6fcb54 commit 854bd3a

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,15 @@ endif ()
279279
## Build provided copy of SQLite3 C library ##
280280

281281
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 SQLite::SQLite3 cmake target must already exist." ON)
282283
if (SQLITECPP_INTERNAL_SQLITE)
283284
message(STATUS "Compile sqlite3 from source in subdirectory")
284285
option(SQLITE_ENABLE_RTREE "Enable RTree extension when building internal sqlite3 library." OFF)
285286
option(SQLITE_ENABLE_DBSTAT_VTAB "Enable DBSTAT read-only eponymous virtual table extension when building internal sqlite3 library." OFF)
286287
# build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package
287288
add_subdirectory(sqlite3)
288289
target_link_libraries(SQLiteCpp PUBLIC SQLite::SQLite3)
289-
else (SQLITECPP_INTERNAL_SQLITE)
290+
elseif (SQLITECPP_FIND_SQLITE)
290291
# When using the SQLite codec, we need to link against the sqlcipher lib & include <sqlcipher/sqlite3.h>
291292
# So this gets the lib & header, and links/includes everything
292293
if(SQLITE_HAS_CODEC)
@@ -332,7 +333,14 @@ else (SQLITECPP_INTERNAL_SQLITE)
332333
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT")
333334
endif()
334335
endif()
335-
endif (SQLITECPP_INTERNAL_SQLITE)
336+
else ()
337+
if (NOT TARGET SQLite::SQLite3)
338+
message(FATAL_ERROR "SQLITECPP_FIND_SQLITE=OFF requires a pre-existing SQLite::SQLite3 cmake target")
339+
endif()
340+
341+
message(STATUS "Using pre-existing SQLite::SQLite3 cmake target")
342+
target_link_libraries(SQLiteCpp PUBLIC SQLite::SQLite3)
343+
endif ()
336344

337345
## disable the optional support for std::filesystem (C++17)
338346
option(SQLITECPP_DISABLE_STD_FILESYSTEM "Disable the use of std::filesystem in SQLiteCpp." OFF)

0 commit comments

Comments
 (0)