From fa34d9965d622e91fd113068cc630ec729b00e3b Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:07:08 +0000 Subject: [PATCH] cmake: Build `bitcoin-qt` executable --- CMakeLists.txt | 3 + cmake/optional_qt.cmake | 46 ++++++++++++ depends/packages/qt.mk | 8 +-- src/CMakeLists.txt | 5 ++ src/qt/CMakeLists.txt | 153 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 cmake/optional_qt.cmake create mode 100644 src/qt/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ce1ff726876f..969d48f806ac8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,6 +239,8 @@ else() unset(debug_flags) endif() +include(cmake/optional_qt.cmake) + include(cmake/optional.cmake) # Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review. @@ -345,6 +347,7 @@ message("Wallet support:") message(" SQLite, descriptor wallets .......... ${WITH_SQLITE}") message(" Berkeley DB, legacy wallets ......... ${WITH_BDB}") message("Optional packages:") +message(" GUI ................................. ${WITH_GUI}") message(" NAT-PMP ............................. ${WITH_NATPMP}") message(" UPnP ................................ ${WITH_MINIUPNPC}") message(" ZeroMQ .............................. ${WITH_ZMQ}") diff --git a/cmake/optional_qt.cmake b/cmake/optional_qt.cmake new file mode 100644 index 0000000000000..bf46f8413b13b --- /dev/null +++ b/cmake/optional_qt.cmake @@ -0,0 +1,46 @@ +# 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) + + if(BREW_COMMAND) + execute_process( + COMMAND ${BREW_COMMAND} --prefix qt@5 + OUTPUT_VARIABLE qt5_brew_prefix + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + 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) + endif() + endif() +endif() diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 99511362b7892..de5dbdb3c41ed 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -281,12 +281,12 @@ define $(package)_build_cmds endef define $(package)_stage_cmds - $(MAKE) -C qtbase/src INSTALL_ROOT=$($(package)_staging_dir) $(addsuffix -install_subtargets,$(addprefix sub-,$($(package)_qt_libs))) && \ - $(MAKE) -C qttools/src/linguist INSTALL_ROOT=$($(package)_staging_dir) $(addsuffix -install_subtargets,$(addprefix sub-,$($(package)_linguist_tools))) && \ + $(MAKE) -C qtbase INSTALL_ROOT=$($(package)_staging_dir) install && \ + $(MAKE) -C qttools INSTALL_ROOT=$($(package)_staging_dir) install && \ $(MAKE) -C qttranslations INSTALL_ROOT=$($(package)_staging_dir) install_subtargets endef define $(package)_postprocess_cmds - rm -rf native/mkspecs/ native/lib/ lib/cmake/ && \ - rm -f lib/lib*.la lib/*.prl plugins/*/*.prl + rm -rf doc/ native/lib/ && \ + rm -f lib/lib*.la endef diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 087cf4b641b19..44b83f83002ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -327,6 +327,11 @@ if(BUILD_UTIL) endif() +if(WITH_GUI) + add_subdirectory(qt) +endif() + + add_subdirectory(test/util) if(BUILD_BENCH) add_subdirectory(bench) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt new file mode 100644 index 0000000000000..8a43cafa81382 --- /dev/null +++ b/src/qt/CMakeLists.txt @@ -0,0 +1,153 @@ +# 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/. + +# See: +# - https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html +# - https://doc.qt.io/qt-5/cmake-manual.html + +set(CMAKE_AUTOMOC ON) +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) +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) + +file(GLOB ts_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} locale/*.ts) +set_source_files_properties(${ts_files} PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/locale) +qt5_add_translation(qm_files ${ts_files}) + +configure_file(bitcoin_locale.qrc bitcoin_locale.qrc COPYONLY) + +add_library(bitcoinqt STATIC EXCLUDE_FROM_ALL + bantablemodel.cpp + bitcoin.cpp + bitcoinaddressvalidator.cpp + bitcoinamountfield.cpp + bitcoingui.cpp + bitcoinunits.cpp + clientmodel.cpp + csvmodelwriter.cpp + guiutil.cpp + initexecutor.cpp + intro.cpp + modaloverlay.cpp + networkstyle.cpp + notificator.cpp + optionsdialog.cpp + optionsmodel.cpp + peertablemodel.cpp + peertablesortproxy.cpp + platformstyle.cpp + qvalidatedlineedit.cpp + qvaluecombobox.cpp + rpcconsole.cpp + splashscreen.cpp + trafficgraphwidget.cpp + utilitydialog.cpp + $<$:winshutdownmonitor.cpp> + $<$:macdockiconhandler.mm> + $<$:macnotificationhandler.mm> + $<$:macos_appnap.mm> + bitcoin.qrc + ${CMAKE_CURRENT_BINARY_DIR}/bitcoin_locale.qrc +) +target_compile_definitions(bitcoinqt + PUBLIC + QT_NO_KEYWORDS + QT_USE_QSTRINGBUILDER +) +target_include_directories(bitcoinqt + PUBLIC + $ +) +target_link_libraries(bitcoinqt + PUBLIC + Qt5::Widgets + PRIVATE + core_interface + bitcoin_cli + leveldb + Boost::headers + $ + $ + $<$:shlwapi> +) + +if(ENABLE_WALLET) + target_sources(bitcoinqt + PRIVATE + addressbookpage.cpp + addresstablemodel.cpp + askpassphrasedialog.cpp + coincontroldialog.cpp + coincontroltreewidget.cpp + createwalletdialog.cpp + editaddressdialog.cpp + openuridialog.cpp + overviewpage.cpp + paymentserver.cpp + psbtoperationsdialog.cpp + qrimagewidget.cpp + receivecoinsdialog.cpp + receiverequestdialog.cpp + recentrequeststablemodel.cpp + sendcoinsdialog.cpp + sendcoinsentry.cpp + signverifymessagedialog.cpp + transactiondesc.cpp + transactiondescdialog.cpp + transactionfilterproxy.cpp + transactionoverviewwidget.cpp + transactionrecord.cpp + transactiontablemodel.cpp + transactionview.cpp + walletcontroller.cpp + walletframe.cpp + walletmodel.cpp + walletmodeltransaction.cpp + walletview.cpp + ) + target_link_libraries(bitcoinqt + PRIVATE + bitcoin_wallet + Qt5::Network + ) +endif() + +if(CMAKE_CROSSCOMPILING) + target_compile_definitions(bitcoinqt PRIVATE QT_STATICPLUGIN) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND TARGET Qt5::QXcbIntegrationPlugin) + target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_XCB) + elseif(WIN32 AND TARGET Qt5::QWindowsIntegrationPlugin AND TARGET Qt5::QWindowsVistaStylePlugin) + target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_WINDOWS) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND TARGET Qt5::QCocoaIntegrationPlugin AND TARGET Qt5::QMacStylePlugin) + target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_COCOA) + endif() +endif() + +add_executable(bitcoin-qt + main.cpp + ../init/bitcoin-qt.cpp +) + +target_link_libraries(bitcoin-qt + core_interface + bitcoinqt + bitcoin_node +) + +install(TARGETS bitcoin-qt + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT GUI +)