From 784fa3f7fb99f7ee4e91145542cba4da9fd5cb99 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 1 May 2024 21:32:01 +0100 Subject: [PATCH] cmake [KILL 3-STATE]: Make WITH_GUI binary option w/ default OFF --- CMakeLists.txt | 10 +++--- cmake/module/FindQt5.cmake | 62 ++++++++++++++++++++++++++++++++++++++ cmake/optional_qt.cmake | 51 ------------------------------- depends/toolchain.cmake.in | 10 +++--- src/qt/CMakeLists.txt | 48 +++++++++++++---------------- 5 files changed, 92 insertions(+), 89 deletions(-) create mode 100644 cmake/module/FindQt5.cmake delete mode 100644 cmake/optional_qt.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 75f27da4c7170..65ee2c6508ca4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module) # Configurable options. # When adding a new option, end the with a full stop for consistency. option(BUILD_DAEMON "Build bitcoind executable." ON) +option(WITH_GUI "Build bitcoin-qt executable." OFF) option(BUILD_CLI "Build bitcoin-cli executable." ON) option(BUILD_TX "Build bitcoin-tx executable." ON) option(BUILD_UTIL "Build bitcoin-util executable." ON) @@ -116,7 +117,6 @@ tristate_option(WITH_USDT cmake_dependent_option(WITH_EXTERNAL_SIGNER "Enable external signer support." ON "NOT WIN32" OFF) set(ENABLE_EXTERNAL_SIGNER ${WITH_EXTERNAL_SIGNER}) -include(cmake/optional_qt.cmake) cmake_dependent_option(WITH_QRENCODE "Enable QR code support." ON "WITH_GUI" OFF) if(WITH_QRENCODE) find_package(PkgConfig REQUIRED) @@ -133,7 +133,7 @@ if(MULTIPROCESS) endif() option(BUILD_TESTS "Build test_bitcoin executable." ON) -cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_TESTS" OFF) +cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "WITH_GUI;BUILD_TESTS" OFF) option(BUILD_BENCH "Build bench_bitcoin executable." ON) cmake_dependent_option(BUILD_FUZZ_BINARY "Build fuzz binary." ON "NOT MSVC" OFF) cmake_dependent_option(FUZZ "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF "NOT MSVC" OFF) @@ -571,6 +571,7 @@ message("Configure summary") message("=================") message("Executables:") message(" bitcoind ............................ ${BUILD_DAEMON}") +message(" bitcoin-qt .......................... ${WITH_GUI}") message(" bitcoin-cli ......................... ${BUILD_CLI}") message(" bitcoin-tx .......................... ${BUILD_TX}") message(" bitcoin-util ........................ ${BUILD_UTIL}") @@ -581,16 +582,13 @@ message("Wallet support:") message(" SQLite, descriptor wallets .......... ${WITH_SQLITE}") message(" Berkeley DB, legacy wallets ......... ${WITH_BDB}") message("Optional packages:") -message(" GUI ................................. ${WITH_GUI}") -if(WITH_GUI) - message(" QR code (GUI) ....................... ${WITH_QRENCODE}") -endif() message(" external signer ..................... ${WITH_EXTERNAL_SIGNER}") message(" multiprocess ........................ ${MULTIPROCESS}") message(" NAT-PMP ............................. ${WITH_NATPMP}") message(" UPnP ................................ ${WITH_MINIUPNPC}") message(" ZeroMQ .............................. ${WITH_ZMQ}") message(" USDT tracing ........................ ${WITH_USDT}") +message(" QR code (GUI) ....................... ${WITH_QRENCODE}") message("Tests:") message(" test_bitcoin ........................ ${BUILD_TESTS}") message(" test_bitcoin-qt ..................... ${BUILD_GUI_TESTS}") diff --git a/cmake/module/FindQt5.cmake b/cmake/module/FindQt5.cmake new file mode 100644 index 0000000000000..cbf17f02af86c --- /dev/null +++ b/cmake/module/FindQt5.cmake @@ -0,0 +1,62 @@ +# Copyright (c) 2024-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +#[=======================================================================[ +FindQt5 +------- + +Finds the Qt 5 headers and libraries. + +This is a wrapper around find_package() command that: + - facilitates searching in various build environments + - prints a standard log message + +#]=======================================================================] + +set(_qt_homebrew_prefix) +if(CMAKE_HOST_APPLE) + find_program(HOMEBREW_EXECUTABLE brew) + if(HOMEBREW_EXECUTABLE) + execute_process( + COMMAND ${HOMEBREW_EXECUTABLE} --prefix qt@5 + OUTPUT_VARIABLE _qt_homebrew_prefix + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() +endif() + +# Save CMAKE_FIND_ROOT_PATH_MODE_LIBRARY state. +unset(_qt_find_root_path_mode_library_saved) +if(DEFINED CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) + set(_qt_find_root_path_mode_library_saved ${CMAKE_FIND_ROOT_PATH_MODE_LIBRARY}) +endif() + +# The Qt config files internally use find_library() calls for all +# dependencies to ensure their availability. In turn, the find_library() +# inspects the well-known locations on the file system; therefore, it must +# be able to find platform-specific system libraries, for example: +# /usr/x86_64-w64-mingw32/lib/libm.a or /usr/arm-linux-gnueabihf/lib/libm.a. +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) + +find_package(Qt5 ${Qt5_FIND_VERSION} + COMPONENTS ${Qt5_FIND_COMPONENTS} + HINTS ${_qt_homebrew_prefix} + PATH_SUFFIXES Qt5 # Required on OpenBSD systems. +) +unset(_qt_homebrew_prefix) + +# Restore CMAKE_FIND_ROOT_PATH_MODE_LIBRARY state. +if(DEFINED _qt_find_root_path_mode_library_saved) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ${_qt_find_root_path_mode_library_saved}) + unset(_qt_find_root_path_mode_library_saved) +else() + unset(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Qt5 + REQUIRED_VARS Qt5_DIR + VERSION_VAR Qt5_VERSION +) diff --git a/cmake/optional_qt.cmake b/cmake/optional_qt.cmake deleted file mode 100644 index 4d796e5eeb6fc..0000000000000 --- a/cmake/optional_qt.cmake +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (c) 2023-present The Bitcoin Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or https://opensource.org/license/mit/. - -set(WITH_GUI "AUTO" CACHE STRING "Build GUI ([AUTO], Qt5, OFF)") -set(with_gui_values AUTO Qt5 OFF) -if(NOT WITH_GUI IN_LIST with_gui_values) - message(FATAL_ERROR "WITH_GUI value is \"${WITH_GUI}\", but must be one of \"AUTO\", \"Qt5\" or \"OFF\".") -endif() - -if(WITH_GUI) - set(QT_NO_CREATE_VERSIONLESS_FUNCTIONS ON) - set(QT_NO_CREATE_VERSIONLESS_TARGETS ON) - - set(qt5_brew_prefix) - if(CMAKE_HOST_APPLE) - find_program(HOMEBREW_EXECUTABLE brew) - if(HOMEBREW_EXECUTABLE) - execute_process( - COMMAND ${HOMEBREW_EXECUTABLE} --prefix qt@5 - OUTPUT_VARIABLE qt5_brew_prefix - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - endif() - endif() - - if(WITH_GUI STREQUAL "AUTO") - # The PATH_SUFFIXES option is required on OpenBSD systems. - find_package(QT NAMES Qt5 - COMPONENTS Core - HINTS ${qt5_brew_prefix} - PATH_SUFFIXES Qt5 - ) - if(QT_FOUND) - set(WITH_GUI Qt${QT_VERSION_MAJOR}) - if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - enable_language(OBJCXX) - set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") - set(CMAKE_OBJCXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - set(CMAKE_OBJCXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - set(CMAKE_OBJCXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}") - endif() - else() - message(WARNING "Qt not found, disabling.\n" - "To skip this warning check, use \"-DWITH_GUI=OFF\".\n") - set(WITH_GUI OFF) - set(BUILD_GUI_TESTS OFF) - endif() - endif() -endif() diff --git a/depends/toolchain.cmake.in b/depends/toolchain.cmake.in index 1a6e6d9b99c9b..694078f3e1668 100644 --- a/depends/toolchain.cmake.in +++ b/depends/toolchain.cmake.in @@ -117,11 +117,11 @@ unset(pkg_config_path) set(PKG_CONFIG_ARGN --static) -# Ensure that the docstrings in the following `set(... CACHE ...)` -# commands match those in the root CMakeLists.txt file. - -if(NOT WITH_GUI AND "@no_qt@" STREQUAL "1") - set(WITH_GUI OFF CACHE STRING "Build GUI.") +# Set configuration options for the main build system. +if("@no_qt@") + set(WITH_GUI OFF CACHE BOOL "") +else() + set(WITH_GUI ON CACHE BOOL "") endif() if(NOT WITH_QRENCODE AND "@no_qr@" STREQUAL "1") diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index b528b4d68acfc..63a3212218945 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -2,6 +2,26 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or https://opensource.org/license/mit/. +set(qt_components Core Gui Widgets LinguistTools) +if(ENABLE_WALLET) + list(APPEND qt_components Network) +endif() +if(BUILD_GUI_TESTS) + list(APPEND qt_components Test) +endif() +find_package(Qt5 5.11.3 MODULE REQUIRED + COMPONENTS ${qt_components} +) +unset(qt_components) + +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + enable_language(OBJCXX) + set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + set(CMAKE_OBJCXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + set(CMAKE_OBJCXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + set(CMAKE_OBJCXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}") +endif() + function(import_plugins target) if(QT_IS_STATIC) set(plugins Qt5::QMinimalIntegrationPlugin) @@ -19,7 +39,7 @@ function(import_plugins target) endif() endfunction() -# See: +# For Qt-specific commands and variables, please consult: # - https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html # - https://doc.qt.io/qt-5/cmake-manual.html @@ -28,32 +48,6 @@ set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC_SEARCH_PATHS forms) -set(qt_minimum_required_version 5.11.3) - -set(qt_components Core Gui Widgets Network LinguistTools) -if(BUILD_GUI_TESTS) - list(APPEND qt_components Test) -endif() - -if(CMAKE_CROSSCOMPILING) - # The find_package(Qt ...) function internally uses find_library() - # calls for all dependencies to ensure their availability. - # In turn, the find_library() inspects the well-known locations - # on the file system; therefore, it must be able to find - # platform-specific system libraries, for example: - # /usr/x86_64-w64-mingw32/lib/libm.a or /usr/arm-linux-gnueabihf/lib/libm.a. - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) -endif() - -find_package(Qt5 ${qt_minimum_required_version} REQUIRED - COMPONENTS ${qt_components} - HINTS ${qt5_brew_prefix} - PATH_SUFFIXES Qt5 # Required on OpenBSD systems. -) -unset(qt_components) -message(STATUS "Found Qt: ${Qt5_DIR} (found suitable version \"${Qt5_VERSION}\", minimum required is \"${qt_minimum_required_version}\")") -unset(qt_minimum_required_version) - include(CMakePushCheckState) cmake_push_check_state(RESET) set(CMAKE_REQUIRED_LIBRARIES Qt5::Core)