Make sqlite support optional (compile-time)

This commit is contained in:
Luke Dashjr 2020-10-15 13:50:00 +00:00
parent 711ddce943
commit 7b54d768e1
6 changed files with 48 additions and 5 deletions

View file

@ -128,6 +128,12 @@ AC_ARG_ENABLE([wallet],
[enable_wallet=$enableval],
[enable_wallet=yes])
AC_ARG_WITH([sqlite],
[AS_HELP_STRING([--with-sqlite=yes|no|auto],
[enable sqlite wallet support (default: auto, i.e., enabled if wallet is enabled and sqlite is found)])],
[use_sqlite=$withval],
[use_sqlite=auto])
AC_ARG_WITH([miniupnpc],
[AS_HELP_STRING([--with-miniupnpc],
[enable UPNP (default is yes if libminiupnpc is found)])],
@ -1224,7 +1230,24 @@ if test x$enable_wallet != xno; then
fi
dnl Check for sqlite3
PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.17], , [AC_MSG_ERROR([sqlite3 not found.])])
if test "x$use_sqlite" != "xno"; then
PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.17], [have_sqlite=yes], [have_sqlite=no])
fi
AC_MSG_CHECKING([whether to build wallet with support for sqlite])
if test "x$use_sqlite" = "xno"; then
use_sqlite=no
elif test "x$have_sqlite" = "xno"; then
if test "x$use_sqlite" = "xyes"; then
AC_MSG_ERROR([sqlite support requested but cannot be built. Use --without-sqlite])
fi
use_sqlite=no
else
if test x$use_sqlite != xno; then
AC_DEFINE([USE_SQLITE],[1],[Define if sqlite support should be compiled in])
use_sqlite=yes
fi
fi
AC_MSG_RESULT([$use_sqlite])
fi
dnl Check for libminiupnpc (optional)
@ -1578,6 +1601,7 @@ AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
AM_CONDITIONAL([TARGET_LINUX], [test x$TARGET_OS = xlinux])
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
AM_CONDITIONAL([USE_SQLITE], [test "x$use_sqlite" = "xyes"])
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
@ -1643,6 +1667,7 @@ AC_SUBST(AVX2_CXXFLAGS)
AC_SUBST(SHANI_CXXFLAGS)
AC_SUBST(ARM_CRC_CXXFLAGS)
AC_SUBST(LIBTOOL_APP_LDFLAGS)
AC_SUBST(USE_SQLITE)
AC_SUBST(USE_UPNP)
AC_SUBST(USE_QRCODE)
AC_SUBST(BOOST_LIBS)
@ -1718,6 +1743,9 @@ echo "Options used to compile and link:"
echo " boost process = $ax_cv_boost_process"
echo " multiprocess = $build_multiprocess"
echo " with wallet = $enable_wallet"
if test "x$enable_wallet" != "xno"; then
echo " with sqlite = $use_sqlite"
fi
echo " with gui / qt = $bitcoin_enable_qt"
if test x$bitcoin_enable_qt != xno; then
echo " with qr = $use_qr"

View file

@ -46,7 +46,7 @@ Optional dependencies:
libqrencode | QR codes in GUI | Optional for generating QR codes (only needed when GUI enabled)
univalue | Utility | JSON parsing and encoding (bundled version will be used unless --with-system-univalue passed to configure)
libzmq3 | ZMQ notification | Optional, allows generating ZMQ notifications (requires ZMQ version >= 4.0.0)
sqlite3 | SQLite DB | Wallet storage (only needed when wallet enabled)
sqlite3 | SQLite DB | Optional, wallet storage (only needed when wallet enabled)
For the versions used, see [dependencies.md](dependencies.md)

View file

@ -34,7 +34,7 @@ Some dependencies are not needed in all configurations. The following are some f
#### Options passed to `./configure`
* MiniUPnPc is not needed with `--with-miniupnpc=no`.
* Berkeley DB is not needed with `--disable-wallet`.
* SQLite is not needed with `--disable-wallet`.
* SQLite is not needed with `--disable-wallet` or `--without-sqlite`.
* Qt is not needed with `--without-gui`.
* If the qrencode dependency is absent, QR support won't be added. To force an error when that happens, pass `--with-qrencode`.
* ZeroMQ is needed only with the `--with-zmq` option.

View file

@ -356,7 +356,7 @@ endif
# wallet: shared between bitcoind and bitcoin-qt, but only linked
# when wallet enabled
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(SQLITE_CFLAGS)
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_wallet_a_SOURCES = \
interfaces/wallet.cpp \
@ -372,13 +372,16 @@ libbitcoin_wallet_a_SOURCES = \
wallet/rpcwallet.cpp \
wallet/salvage.cpp \
wallet/scriptpubkeyman.cpp \
wallet/sqlite.cpp \
wallet/wallet.cpp \
wallet/walletdb.cpp \
wallet/walletutil.cpp \
wallet/coinselection.cpp \
$(BITCOIN_CORE_H)
if USE_SQLITE
libbitcoin_wallet_a_SOURCES += wallet/sqlite.cpp
endif
libbitcoin_wallet_tool_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_wallet_tool_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_wallet_tool_a_SOURCES = \

View file

@ -15,7 +15,9 @@
#include <util/time.h>
#include <util/translation.h>
#include <wallet/bdb.h>
#ifdef USE_SQLITE
#include <wallet/sqlite.h>
#endif
#include <wallet/wallet.h>
#include <atomic>
@ -1012,6 +1014,7 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
if (ExistsBerkeleyDatabase(path)) {
format = DatabaseFormat::BERKELEY;
}
#ifdef USE_SQLITE
if (ExistsSQLiteDatabase(path)) {
if (format) {
error = Untranslated(strprintf("Failed to load database path '%s'. Data is in ambiguous format.", path.string()));
@ -1020,6 +1023,7 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
}
format = DatabaseFormat::SQLITE;
}
#endif
} else if (options.require_existing) {
error = Untranslated(strprintf("Failed to load database path '%s'. Path does not exist.", path.string()));
status = DatabaseStatus::FAILED_NOT_FOUND;
@ -1048,9 +1052,13 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
// Format is not set when a db doesn't already exist, so use the format specified by the options if it is set.
if (!format && options.require_format) format = options.require_format;
#ifdef USE_SQLITE
if (format && format == DatabaseFormat::SQLITE) {
return MakeSQLiteDatabase(path, options, status, error);
}
#else
assert(format != DatabaseFormat::SQLITE);
#endif
return MakeBerkeleyDatabase(path, options, status, error);
}

View file

@ -8,7 +8,11 @@
#include <util/system.h>
bool ExistsBerkeleyDatabase(const fs::path& path);
#ifdef USE_SQLITE
bool ExistsSQLiteDatabase(const fs::path& path);
#else
# define ExistsSQLiteDatabase(path) (false)
#endif
fs::path GetWalletDir()
{