From 2b4ad506ee9cd647eacaec8a2df2250fd2b68180 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 22 Apr 2024 19:56:05 +0100 Subject: [PATCH] cmake [KILL 3-STATE]: Switch `WITH_{SQLITE,BDB}` to boolean `WITH_BDB` default is `OFF`. --- CMakeLists.txt | 43 ++++++++++++++++++++++++++++++------- cmake/optional.cmake | 44 -------------------------------------- depends/toolchain.cmake.in | 18 ++++++++++------ 3 files changed, 47 insertions(+), 58 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92d5b44d7933ea..76aade513a1364 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,10 @@ set(CMAKE_CXX_EXTENSIONS OFF) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module) -# Configurable options. +#============================= +# Configurable options +#============================= +include(CMakeDependentOption) # When adding a new option, end the with a full stop for consistency. option(BUILD_DAEMON "Build bitcoind executable." ON) option(BUILD_CLI "Build bitcoin-cli executable." ON) @@ -67,13 +70,34 @@ option(BUILD_UTIL_CHAINSTATE "Build experimental bitcoin-chainstate executable." option(BUILD_KERNEL_LIB "Build experimental bitcoinkernel library." ${BUILD_UTIL_CHAINSTATE}) option(ENABLE_WALLET "Enable wallet." ON) -# TODO: These tri-state options will be removed and most features -# will become opt-in by default before merging into master. -include(TristateOption) -tristate_option(WITH_SQLITE "Enable SQLite wallet support." "if libsqlite3 is found." AUTO) -tristate_option(WITH_BDB "Enable Berkeley DB (BDB) wallet support." "if libdb_cxx is found." AUTO) -option(WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON) -include(CMakeDependentOption) +option(WITH_SQLITE "Enable SQLite wallet support." ${ENABLE_WALLET}) +if(WITH_SQLITE) + if(VCPKG_TARGET_TRIPLET) + # Use of the `unofficial::` namespace is a vcpkg package manager convention. + find_package(unofficial-sqlite3 CONFIG REQUIRED) + else() + find_package(SQLite3 3.7.17 REQUIRED) + endif() + set(USE_SQLITE ON) + set(ENABLE_WALLET ON) +endif() +option(WITH_BDB "Enable Berkeley DB (BDB) wallet support." OFF) +cmake_dependent_option(WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON "WITH_BDB" OFF) +if(WITH_BDB) + find_package(BerkeleyDB 4.8 MODULE REQUIRED) + set(USE_BDB ON) + set(ENABLE_WALLET ON) + if(NOT BerkeleyDB_VERSION VERSION_EQUAL 4.8) + message(WARNING "Found Berkeley DB (BDB) other than 4.8.\n" + "BDB (legacy) wallets opened by this build will not be portable!" + ) + if(WARN_INCOMPATIBLE_BDB) + message(WARNING "If this is intended, pass \"-DWARN_INCOMPATIBLE_BDB=OFF\".\n" + "Passing \"-DWITH_BDB=OFF\" will suppress this warning." + ) + endif() + endif() +endif() cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ON "ENABLE_WALLET" OFF) option(THREADLOCAL "Enable features that depend on the C++ thread_local keyword (currently just thread names in debug logs)." ON) @@ -81,6 +105,9 @@ option(HARDENING "Attempt to harden the resulting executables." ON) option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF) option(WERROR "Treat compiler warnings as errors." OFF) +# TODO: These tri-state options will be removed and most features +# will become opt-in by default before merging into master. +include(TristateOption) tristate_option(CCACHE "Use ccache for compiling." "if ccache is found." AUTO) option(WITH_NATPMP "Enable NAT-PMP." OFF) diff --git a/cmake/optional.cmake b/cmake/optional.cmake index 8452813cafb627..d74c50c9bd9e41 100644 --- a/cmake/optional.cmake +++ b/cmake/optional.cmake @@ -49,47 +49,3 @@ if(CCACHE) endif() mark_as_advanced(CCACHE_COMMAND) endif() - -if(ENABLE_WALLET) - if(WITH_SQLITE) - if(VCPKG_TARGET_TRIPLET) - # Use of the `unofficial::` namespace is a vcpkg package manager convention. - find_package(unofficial-sqlite3 CONFIG) - else() - find_package(SQLite3 3.7.17) - endif() - if(TARGET unofficial::sqlite3::sqlite3 OR TARGET SQLite::SQLite3) - set(WITH_SQLITE ON) - set(USE_SQLITE ON) - elseif(WITH_SQLITE STREQUAL "AUTO") - set(WITH_SQLITE OFF) - else() - message(FATAL_ERROR "SQLite requested, but not found.") - endif() - endif() - - if(WITH_BDB) - find_package(BerkeleyDB 4.8 MODULE) - if(BerkeleyDB_FOUND) - set(WITH_BDB ON) - set(USE_BDB ON) - if(NOT BerkeleyDB_VERSION VERSION_EQUAL 4.8) - message(WARNING "Found Berkeley DB (BDB) other than 4.8.") - if(WARN_INCOMPATIBLE_BDB) - message(WARNING "BDB (legacy) wallets opened by this build would not be portable!\n" - "If this is intended, pass \"-DWARN_INCOMPATIBLE_BDB=OFF\".\n" - "Passing \"-DWITH_BDB=OFF\" will suppress this warning.\n") - else() - message(WARNING "BDB (legacy) wallets opened by this build will not be portable!") - endif() - endif() - else() - message(WARNING "Berkeley DB (BDB) required for legacy wallet support, but not found.\n" - "Passing \"-DWITH_BDB=OFF\" will suppress this warning.\n") - set(WITH_BDB OFF) - endif() - endif() -else() - set(WITH_SQLITE OFF) - set(WITH_BDB OFF) -endif() diff --git a/depends/toolchain.cmake.in b/depends/toolchain.cmake.in index 8676b65f68a60b..da41489dc348e7 100644 --- a/depends/toolchain.cmake.in +++ b/depends/toolchain.cmake.in @@ -134,16 +134,22 @@ else() set(WITH_ZMQ ON CACHE BOOL "") endif() -if(NOT ENABLE_WALLET AND "@no_wallet@" STREQUAL "1") - set(ENABLE_WALLET OFF CACHE BOOL "Enable wallet.") +if("@no_wallet@") + set(ENABLE_WALLET OFF CACHE BOOL "") +else() + set(ENABLE_WALLET ON CACHE BOOL "") endif() -if(NOT WITH_BDB AND "@no_bdb@" STREQUAL "1") - set(WITH_BDB OFF CACHE STRING "Enable Berkeley DB (BDB) wallet support.") +if("@no_wallet@" OR "@no_bdb@") + set(WITH_BDB OFF CACHE BOOL "") +else() + set(WITH_BDB ON CACHE BOOL "") endif() -if(NOT WITH_SQLITE AND "@no_sqlite@" STREQUAL "1") - set(WITH_SQLITE OFF CACHE STRING "Enable SQLite wallet support.") +if("@no_wallet@" OR "@no_sqlite@") + set(WITH_SQLITE OFF CACHE BOOL "") +else() + set(WITH_SQLITE ON CACHE BOOL "") endif() if("@no_upnp@")