Skip to content

Commit

Permalink
cmake [KILL 3-STATE]: Make WITH_GUI binary option w/ default OFF
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed May 1, 2024
1 parent 3c26fec commit 784fa3f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 89 deletions.
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)
# Configurable options.
# When adding a new option, end the <help_text> 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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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}")
Expand All @@ -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}")
Expand Down
62 changes: 62 additions & 0 deletions cmake/module/FindQt5.cmake
Original file line number Diff line number Diff line change
@@ -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
)
51 changes: 0 additions & 51 deletions cmake/optional_qt.cmake

This file was deleted.

10 changes: 5 additions & 5 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
48 changes: 21 additions & 27 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 784fa3f

Please sign in to comment.