Skip to content

Commit

Permalink
Merge #198: cmake: Consistent build option naming
Browse files Browse the repository at this point in the history
79c3c89 cmake: Group port mapping in summary (Hennadii Stepanov)
18abbb9 cmake: Rework wallet report in summary (Hennadii Stepanov)
7c151e7 cmake: Rename option `WITH_EXTERNAL_SIGNER` to `ENABLE_EXTERNAL_SIGNER` (Hennadii Stepanov)
41a2159 cmake: Rename build option `THREADLOCAL` to `ENABLE_THREADLOCAL` (Hennadii Stepanov)
bed5fea cmake: Rename build option `MULTIPROCESS` to `WITH_MULTIPROCESS` (Hennadii Stepanov)
9d6ebf4 cmake: Rename build option `HARDENING` to `ENABLE_HARDENING` (Hennadii Stepanov)
576251f cmake: Rename build option `FUZZ` to `ENABLE_FUZZ` (Hennadii Stepanov)
2a8aba3 cmake: Rename build option `CCACHE` to `WITH_CCACHE` (Hennadii Stepanov)

Pull request description:

  Based on #194 (comment).

  ### The build option naming convention

  1. `BUILD_*` options control what binaries and libraries are built.

  2. `ENABLE_*` options control what features are turned on.
  If a feature is fully implemented in a standalone binary, a `BUILD_*` option should be used. For example, `BUILD_GUI`.

  3. `WITH_*` options control what dependencies are turned on (internally, a CMake command `find_*` is used).

  ---

  The resulted build option set being presented in the CMake GUI tool looks as follows:

  ![image](https://github.com/hebasto/bitcoin/assets/32963518/10e3f241-6649-437d-a698-d57ed14501b1)

  An example of the configure summary:
  ```
  Configure summary
  =================
  Executables:
    bitcoind ............................ ON
    bitcoin-node (multiprocess) ......... OFF
    bitcoin-qt (GUI) .................... OFF
    bitcoin-gui (GUI, multiprocess) ..... OFF
    bitcoin-cli ......................... ON
    bitcoin-tx .......................... ON
    bitcoin-util ........................ ON
    bitcoin-wallet ...................... ON
    bitcoin-chainstate (experimental) ... OFF
    libbitcoinkernel (experimental) ..... OFF
  Optional features:
    wallet support ...................... ON
     - descriptor wallets (SQLite) ...... ON
     - legacy wallets (Berkeley DB) ..... OFF
    external signer ..................... ON
    port mapping:
     - using NAT-PMP .................... OFF
     - using UPnP ....................... OFF
    ZeroMQ .............................. OFF
    USDT tracing ........................ OFF
    QR code (GUI) ....................... OFF
    DBus (GUI, Linux only) .............. OFF
  Tests:
    test_bitcoin ........................ ON
    test_bitcoin-qt ..................... OFF
    bench_bitcoin ....................... ON
    fuzz binary ......................... ON

  ...
  ```

  Closes #194.

Top commit has no ACKs.

Tree-SHA512: 21ab517502c11b92e7c173e9390311c470d481fd533671dc9445f4673dfedf76b96ff09dfa52d3c93dcc64e97c561d3ef75c70f7dc0ca513d7d6ff3cfff7368e
  • Loading branch information
hebasto committed May 22, 2024
2 parents bae096a + 79c3c89 commit d9ba536
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 48 deletions.
54 changes: 31 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ if(WITH_BDB)
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)
option(HARDENING "Attempt to harden the resulting executables." ON)
option(ENABLE_THREADLOCAL "Enable features that depend on the C++ thread_local keyword (currently just thread names in debug logs)." ON)
option(ENABLE_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)
tristate_option(WITH_CCACHE "Use ccache for compiling." "if ccache is found." AUTO)

option(WITH_NATPMP "Enable NAT-PMP." OFF)
if(WITH_NATPMP)
Expand Down Expand Up @@ -141,8 +141,7 @@ if(WITH_USDT)
find_package(USDT MODULE REQUIRED)
endif()

cmake_dependent_option(WITH_EXTERNAL_SIGNER "Enable external signer support." ON "NOT WIN32" OFF)
set(ENABLE_EXTERNAL_SIGNER ${WITH_EXTERNAL_SIGNER})
cmake_dependent_option(ENABLE_EXTERNAL_SIGNER "Enable external signer support." ON "NOT WIN32" OFF)

cmake_dependent_option(WITH_QRENCODE "Enable QR code support." ON "BUILD_GUI" OFF)
if(WITH_QRENCODE)
Expand All @@ -155,8 +154,8 @@ endif()

cmake_dependent_option(WITH_DBUS "Enable DBus support." ON "CMAKE_SYSTEM_NAME STREQUAL \"Linux\" AND BUILD_GUI" OFF)

option(MULTIPROCESS "Build multiprocess bitcoin-node, bitcoin-wallet, and bitcoin-gui executables in addition to monolithic bitcoind and bitcoin-qt executables. Requires libmultiprocess library. Experimental." OFF)
if(MULTIPROCESS)
option(WITH_MULTIPROCESS "Build multiprocess bitcoin-node and bitcoin-gui executables in addition to monolithic bitcoind and bitcoin-qt executables. Requires libmultiprocess library. Experimental." OFF)
if(WITH_MULTIPROCESS)
find_package(Libmultiprocess CONFIG REQUIRED)
find_package(LibmultiprocessGen CONFIG REQUIRED)
endif()
Expand All @@ -165,7 +164,7 @@ option(BUILD_TESTS "Build test_bitcoin executable." ON)
cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_GUI;BUILD_TESTS" OFF)
option(BUILD_BENCH "Build bench_bitcoin executable." ON)
option(BUILD_FUZZ_BINARY "Build fuzz binary." ON)
cmake_dependent_option(FUZZ "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF "NOT MSVC" OFF)
cmake_dependent_option(ENABLE_FUZZ "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF "NOT MSVC" OFF)

option(INSTALL_MAN "Install man pages." ON)

Expand Down Expand Up @@ -206,8 +205,8 @@ target_link_libraries(core_base_interface INTERFACE
)
target_link_libraries(core_interface INTERFACE core_base_interface)

if(FUZZ)
message(WARNING "FUZZ=ON will disable all other targets and force BUILD_FUZZ_BINARY=ON.")
if(ENABLE_FUZZ)
message(WARNING "ENABLE_FUZZ=ON will disable all other targets and force BUILD_FUZZ_BINARY=ON.")
set(BUILD_DAEMON OFF)
set(BUILD_CLI OFF)
set(BUILD_TX OFF)
Expand All @@ -216,7 +215,7 @@ if(FUZZ)
set(BUILD_KERNEL_LIB OFF)
set(BUILD_WALLET_TOOL OFF)
set(BUILD_GUI OFF)
set(WITH_EXTERNAL_SIGNER OFF)
set(ENABLE_EXTERNAL_SIGNER OFF)
set(WITH_NATPMP OFF)
set(WITH_MINIUPNPC OFF)
set(WITH_ZMQ OFF)
Expand Down Expand Up @@ -495,7 +494,7 @@ try_append_cxx_flags("-fno-extended-identifiers" TARGET core_base_interface SKIP
# -fstack-reuse=none for all gcc builds. (Only gcc understands this flag).
try_append_cxx_flags("-fstack-reuse=none" TARGET core_base_interface)

if(HARDENING)
if(ENABLE_HARDENING)
add_library(hardening_interface INTERFACE)
target_link_libraries(core_base_interface INTERFACE hardening_interface)
if(MSVC)
Expand Down Expand Up @@ -604,21 +603,30 @@ message("Configure summary")
message("=================")
message("Executables:")
message(" bitcoind ............................ ${BUILD_DAEMON}")
message(" bitcoin-qt .......................... ${BUILD_GUI}")
message(" bitcoin-node (multiprocess) ......... ${WITH_MULTIPROCESS}")
message(" bitcoin-qt (GUI) .................... ${BUILD_GUI}")
if(BUILD_GUI AND WITH_MULTIPROCESS)
set(bitcoin_gui_status ON)
else()
set(bitcoin_gui_status OFF)
endif()
message(" bitcoin-gui (GUI, multiprocess) ..... ${bitcoin_gui_status}")
message(" bitcoin-cli ......................... ${BUILD_CLI}")
message(" bitcoin-tx .......................... ${BUILD_TX}")
message(" bitcoin-util ........................ ${BUILD_UTIL}")
message(" bitcoin-wallet ...................... ${BUILD_WALLET_TOOL}")
message(" bitcoin-chainstate (experimental) ... ${BUILD_UTIL_CHAINSTATE}")
message(" libbitcoinkernel (experimental) ..... ${BUILD_KERNEL_LIB}")
message("Wallet support:")
message(" SQLite, descriptor wallets .......... ${WITH_SQLITE}")
message(" Berkeley DB, legacy wallets ......... ${WITH_BDB}")
message("Optional packages:")
message(" external signer ..................... ${WITH_EXTERNAL_SIGNER}")
message(" multiprocess ........................ ${MULTIPROCESS}")
message(" NAT-PMP ............................. ${WITH_NATPMP}")
message(" UPnP ................................ ${WITH_MINIUPNPC}")
message("Optional features:")
message(" wallet support ...................... ${ENABLE_WALLET}")
if(ENABLE_WALLET)
message(" - descriptor wallets (SQLite) ...... ${WITH_SQLITE}")
message(" - legacy wallets (Berkeley DB) ..... ${WITH_BDB}")
endif()
message(" external signer ..................... ${ENABLE_EXTERNAL_SIGNER}")
message(" port mapping:")
message(" - using NAT-PMP .................... ${WITH_NATPMP}")
message(" - using UPnP ....................... ${WITH_MINIUPNPC}")
message(" ZeroMQ .............................. ${WITH_ZMQ}")
message(" USDT tracing ........................ ${WITH_USDT}")
message(" QR code (GUI) ....................... ${WITH_QRENCODE}")
Expand Down Expand Up @@ -647,9 +655,9 @@ message("Common link options ................... ${common_link_options}")
message("Linker flags for executables .......... ${CMAKE_EXE_LINKER_FLAGS} ${APPEND_LDFLAGS}")
message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS} ${APPEND_LDFLAGS}")
print_config_flags()
message("Attempt to harden executables ......... ${HARDENING}")
message("Attempt to harden executables ......... ${ENABLE_HARDENING}")
message("Treat compiler warnings as errors ..... ${WERROR}")
message("Use ccache for compiling .............. ${CCACHE}")
message("Use ccache for compiling .............. ${WITH_CCACHE}")
message("\n")
if(configure_warnings)
message(" ******\n")
Expand Down
6 changes: 3 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"WITH_MINIUPNPC": "ON",
"WITH_ZMQ": "ON",
"WERROR": "ON",
"CCACHE": "ON"
"WITH_CCACHE": "ON"
}
},
{
Expand All @@ -26,7 +26,7 @@
"rhs": "Linux"
},
"cacheVariables": {
"WITH_EXTERNAL_SIGNER": "ON",
"ENABLE_EXTERNAL_SIGNER": "ON",
"WITH_USDT": "ON"
}
},
Expand All @@ -41,7 +41,7 @@
},
"cacheVariables": {
"BUILD_GUI": "ON",
"WITH_EXTERNAL_SIGNER": "ON"
"ENABLE_EXTERNAL_SIGNER": "ON"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion ci/test/00_setup_env_native_tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export RUN_FUNCTIONAL_TESTS=false
export RUN_FUZZ_TESTS=false
export RUN_TIDY=true
export GOAL="install"
export BITCOIN_CONFIG="-DWARN_INCOMPATIBLE_BDB=OFF -DHARDENING=OFF \
export BITCOIN_CONFIG="-DWARN_INCOMPATIBLE_BDB=OFF -DENABLE_HARDENING=OFF \
-DCMAKE_C_COMPILER=clang-${TIDY_LLVM_V} -DCMAKE_CXX_COMPILER=clang++-${TIDY_LLVM_V} \
-DCMAKE_C_FLAGS_RELWITHDEBINFO='-O0 -g0' -DCMAKE_CXX_FLAGS_RELWITHDEBINFO='-O0 -g0'"
export CCACHE_MAXSIZE=200M
2 changes: 1 addition & 1 deletion ci/test/03_test_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ if [ -n "$ANDROID_TOOLS_URL" ]; then
exit 0
fi

BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DWITH_EXTERNAL_SIGNER=ON -DCMAKE_INSTALL_PREFIX=$BASE_OUTDIR"
BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DENABLE_EXTERNAL_SIGNER=ON -DCMAKE_INSTALL_PREFIX=$BASE_OUTDIR"

if [[ "${RUN_TIDY}" == "true" ]]; then
BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
Expand Down
2 changes: 1 addition & 1 deletion cmake/module/AddThreadsIfNeeded.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function(add_threads_if_needed)
- https://github.com/bitcoin/bitcoin/pull/16059
- https://groups.google.com/d/msg/bsdmailinglist/22ncTZAbDp4/Dii_pII5AwAJ
]=]
elseif(THREADLOCAL)
elseif(ENABLE_THREADLOCAL)
target_compile_definitions(core_interface INTERFACE
"$<$<COMPILE_FEATURES:cxx_thread_local>:HAVE_THREAD_LOCAL>"
)
Expand Down
2 changes: 1 addition & 1 deletion cmake/module/Maintenance.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function(add_maintenance_targets)
VERBATIM
)

if(HARDENING)
if(ENABLE_HARDENING)
add_custom_target(check-security
COMMAND ${CMAKE_COMMAND} -E echo "Checking binary security..."
COMMAND ${PYTHON_COMMAND} ${CMAKE_SOURCE_DIR}/contrib/devtools/security-check.py ${executables}
Expand Down
16 changes: 8 additions & 8 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Optional features and packages.

if(CCACHE)
if(WITH_CCACHE)
set(ccache_hints)
if(MSVC AND EXISTS "$ENV{ChocolateyInstall}")
# Bypass a shim executable provided by Chocolatey.
Expand All @@ -19,7 +19,7 @@ if(CCACHE)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
# ccache >= 4.8 requires compile batching turned off that is available since CMake 3.24.
# See https://github.com/ccache/ccache/wiki/MS-Visual-Studio
set(CCACHE ON)
set(WITH_CCACHE ON)
file(COPY_FILE ${CCACHE_COMMAND} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT)
list(APPEND CMAKE_VS_GLOBALS
"CLToolExe=cl.exe"
Expand All @@ -30,20 +30,20 @@ if(CCACHE)
# By default Visual Studio generators will use /Zi which is not compatible
# with ccache, so tell Visual Studio to use /Z7 instead.
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")
elseif(CCACHE STREQUAL "AUTO")
elseif(WITH_CCACHE STREQUAL "AUTO")
message(WARNING "ccache requested and found, but CMake >= 3.24 is required to use it properly. Disabling.\n"
"To skip ccache check, use \"-DCCACHE=OFF\".\n")
set(CCACHE OFF)
"To skip ccache check, use \"-DWITH_CCACHE=OFF\".\n")
set(WITH_CCACHE OFF)
else()
message(FATAL_ERROR "ccache requested and found, but CMake >= 3.24 is required to use it properly.")
endif()
else()
set(CCACHE ON)
set(WITH_CCACHE ON)
list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_COMMAND})
list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_COMMAND})
endif()
elseif(CCACHE STREQUAL "AUTO")
set(CCACHE OFF)
elseif(WITH_CCACHE STREQUAL "AUTO")
set(WITH_CCACHE OFF)
else()
message(FATAL_ERROR "ccache requested, but not found.")
endif()
Expand Down
2 changes: 1 addition & 1 deletion contrib/guix/libexec/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ mkdir -p "$DISTSRC"
env CFLAGS="${HOST_CFLAGS}" CXXFLAGS="${HOST_CXXFLAGS}" LDFLAGS="${HOST_LDFLAGS}" \
cmake -S . -B build \
--toolchain "${BASEPREFIX}/${HOST}/toolchain.cmake" \
-DCCACHE=OFF \
-DWITH_CCACHE=OFF \
${CONFIGFLAGS}

# Build Bitcoin Core
Expand Down
8 changes: 4 additions & 4 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ else()
endif()

if("@no_harden@")
set(HARDENING OFF CACHE BOOL "")
set(ENABLE_HARDENING OFF CACHE BOOL "")
else()
set(HARDENING ON CACHE BOOL "")
set(ENABLE_HARDENING ON CACHE BOOL "")
endif()

if("@multiprocess@" STREQUAL "1")
set(MULTIPROCESS ON CACHE BOOL "")
set(WITH_MULTIPROCESS ON CACHE BOOL "")
set(LibmultiprocessGen_DIR "${CMAKE_FIND_ROOT_PATH}/native/lib/cmake/LibmultiprocessGen" CACHE PATH "")
else()
set(MULTIPROCESS OFF CACHE BOOL "")
set(WITH_MULTIPROCESS OFF CACHE BOOL "")
endif()
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ add_dependencies(bitcoin_clientversion generate_build_info)
add_subdirectory(crypto)
add_subdirectory(univalue)
add_subdirectory(util)
if(MULTIPROCESS)
if(WITH_MULTIPROCESS)
add_subdirectory(ipc)
endif()

Expand Down Expand Up @@ -276,7 +276,7 @@ if(BUILD_DAEMON)
)
list(APPEND installable_targets bitcoind)
endif()
if(MULTIPROCESS)
if(WITH_MULTIPROCESS)
add_executable(bitcoin-node
bitcoind.cpp
init/bitcoin-node.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ if(WIN32)
set_target_properties(bitcoin-qt PROPERTIES WIN32_EXECUTABLE TRUE)
endif()

if(MULTIPROCESS)
if(WITH_MULTIPROCESS)
add_executable(bitcoin-gui
main.cpp
../init/bitcoin-gui.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ if(ENABLE_WALLET)
add_subdirectory(${PROJECT_SOURCE_DIR}/src/wallet/test wallet)
endif()

if(MULTIPROCESS)
if(WITH_MULTIPROCESS)
add_library(bitcoin_ipc_test STATIC EXCLUDE_FROM_ALL
ipc_test.cpp
)
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function(create_test_config)
set_configure_variable(BUILD_DAEMON BUILD_BITCOIND)
set_configure_variable(BUILD_FUZZ_BINARY ENABLE_FUZZ_BINARY)
set_configure_variable(WITH_ZMQ ENABLE_ZMQ)
set_configure_variable(WITH_EXTERNAL_SIGNER ENABLE_EXTERNAL_SIGNER)
set_configure_variable(ENABLE_EXTERNAL_SIGNER ENABLE_EXTERNAL_SIGNER)
set_configure_variable(WITH_USDT ENABLE_USDT_TRACEPOINTS)

configure_file(config.ini.in config.ini @ONLY)
Expand Down

0 comments on commit d9ba536

Please sign in to comment.