Skip to content

Commit

Permalink
SQLITECPP_IN_EXTENSION option controlling linking and use of sqlite3e…
Browse files Browse the repository at this point in the history
…xt.h
  • Loading branch information
mlin committed Jan 23, 2021
1 parent f6b3225 commit d21b605
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,13 @@ endif ()
## Build provided copy of SQLite3 C library ##

option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON)
if (SQLITECPP_INTERNAL_SQLITE)
option(SQLITECPP_IN_EXTENSION "Use SQLiteCpp in the implementation of a SQLite3 loadable extension" OFF)
if(SQLITECPP_IN_EXTENSION)
# To use within a SQLite3 loadable extension, we must not target_link_libraries() SQLite3 itself; the
# host program will already have loaded it (possibly a statically-linked version) and we'll receive its
# API pointers via sqlite3_extension_init().
target_compile_definitions(SQLiteCpp PUBLIC SQLITECPP_IN_EXTENSION)
elseif (SQLITECPP_INTERNAL_SQLITE)
message(STATUS "Compile sqlite3 from source in subdirectory")
option(SQLITE_ENABLE_JSON1 "Enable JSON1 extension when building internal sqlite3 library." ON)
# build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package
Expand Down Expand Up @@ -285,7 +291,7 @@ else (SQLITECPP_INTERNAL_SQLITE)
target_link_libraries(SQLiteCpp PRIVATE ${sqlcipher_LIBRARY})
endif()
endif()
endif (SQLITECPP_INTERNAL_SQLITE)
endif (SQLITECPP_IN_EXTENSION)

# Link target with pthread and dl for Unix
if (UNIX)
Expand Down
5 changes: 5 additions & 0 deletions src/Backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

#include <SQLiteCpp/Exception.h>

#if !defined(SQLITECPP_IN_EXTENSION) || defined(SQLITE_CORE)
#include <sqlite3.h>
#else
#include <sqlite3ext.h>
extern "C" const sqlite3_api_routines *sqlite3_api;
#endif

namespace SQLite
{
Expand Down
5 changes: 5 additions & 0 deletions src/Column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
*/
#include <SQLiteCpp/Column.h>

#if !defined(SQLITECPP_IN_EXTENSION) || defined(SQLITE_CORE)
#include <sqlite3.h>
#else
#include <sqlite3ext.h>
extern "C" const sqlite3_api_routines *sqlite3_api;
#endif

#include <iostream>

Expand Down
6 changes: 6 additions & 0 deletions src/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
#include <SQLiteCpp/Exception.h>
#include <SQLiteCpp/Statement.h>

#if !defined(SQLITECPP_IN_EXTENSION) || defined(SQLITE_CORE)
#include <sqlite3.h>
#else
#include <sqlite3ext.h>
extern "C" const sqlite3_api_routines *sqlite3_api;
#endif

#include <fstream>
#include <string.h>

Expand Down
5 changes: 5 additions & 0 deletions src/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
*/
#include <SQLiteCpp/Exception.h>

#if !defined(SQLITECPP_IN_EXTENSION) || defined(SQLITE_CORE)
#include <sqlite3.h>
#else
#include <sqlite3ext.h>
extern "C" const sqlite3_api_routines *sqlite3_api;
#endif


namespace SQLite
Expand Down
5 changes: 5 additions & 0 deletions src/Statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
#include <SQLiteCpp/Assertion.h>
#include <SQLiteCpp/Exception.h>

#if !defined(SQLITECPP_IN_EXTENSION) || defined(SQLITE_CORE)
#include <sqlite3.h>
#else
#include <sqlite3ext.h>
extern "C" const sqlite3_api_routines *sqlite3_api;
#endif

namespace SQLite
{
Expand Down

0 comments on commit d21b605

Please sign in to comment.