Skip to content

Commit ff2f574

Browse files
committed
Merge #77: cmake: Build bitcoin-qt executable
7f4babc fixup! ci: Test CMake edge cases (Hennadii Stepanov) de62901 fixup! cmake: Add vcpkg manifest file (Hennadii Stepanov) 923d883 msvc: Fix building with vcpkg's Qt packages (Hennadii Stepanov) b342887 cmake: Build `bitcoin-qt` executable (Hennadii Stepanov) 2609377 fixup! build: Generate `share/toolchain.cmake` in depends (Hennadii Stepanov) adcb895 Revert "build, qt: Do not install *.prl files" (Hennadii Stepanov) Pull request description: A new configuration option `WITH_GUI` has been added. Its valid values are `AUTO`, `Qt5`, `OFF`. Top commit has no ACKs. Tree-SHA512: 3d32fa0ae4d51b772c5721d3035660c6b29e500ebc7add3e2a97e1bfde704aa20c989b5a8ee46e8622fa9f6dd2277de59f98c1cd1d9e525b44650d74a8b20c44
2 parents 3659fca + 7f4babc commit ff2f574

File tree

11 files changed

+250
-13
lines changed

11 files changed

+250
-13
lines changed

.github/workflows/cmake.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,17 @@ jobs:
259259
packages: 'clang-14 g++-multilib'
260260
c_compiler: 'clang-14 -m32'
261261
cxx_compiler: 'clang++-14 -m32'
262-
depends_options: 'NO_QT=1'
262+
depends_options: ''
263263
configure_options: '-DWERROR=ON'
264264
- name: 'MinGW-w64'
265265
triplet: 'x86_64-w64-mingw32'
266266
packages: 'g++-mingw-w64-x86-64-posix'
267-
depends_options: 'NO_QT=1'
267+
depends_options: ''
268268
exe_extension: '.exe'
269269
- name: 'MinGW-w64, debug'
270270
triplet: 'x86_64-w64-mingw32'
271271
packages: 'g++-mingw-w64-x86-64-posix'
272-
depends_options: 'NO_QT=1 DEBUG=1'
272+
depends_options: 'DEBUG=1'
273273
configure_options: '-DCMAKE_BUILD_TYPE=Debug'
274274
cache_suffix: '-debug'
275275
exe_extension: '.exe'
@@ -392,6 +392,9 @@ jobs:
392392
# to avoid linker errors when using vcpkg in the manifest mode.
393393
# See: https://github.com/bitcoin/bitcoin/pull/28934
394394
Add-Content -Path "$env:VCPKG_ROOT\triplets\x64-windows-static.cmake" -Value "set(VCPKG_PLATFORM_TOOLSET_VERSION $env:VCToolsVersion)"
395+
# Skip debug configuration to speed up build and minimize cache size.
396+
Add-Content -Path "$env:VCPKG_ROOT\triplets\x64-windows.cmake" -Value "set(VCPKG_BUILD_TYPE release)"
397+
Add-Content -Path "$env:VCPKG_ROOT\triplets\x64-windows-static.cmake" -Value "set(VCPKG_BUILD_TYPE release)"
395398
396399
- name: Restore vcpkg binary cache
397400
uses: actions/cache/restore@v3
@@ -453,7 +456,7 @@ jobs:
453456
env:
454457
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
455458
run: |
456-
brew install ccache cmake pkg-config boost libevent berkeley-db@4 libnatpmp miniupnpc zeromq tree
459+
brew install ccache cmake pkg-config boost libevent berkeley-db@4 qt@5 libnatpmp miniupnpc zeromq tree
457460
echo "CCACHE_DIR=${{ runner.temp }}/ccache" >> "$GITHUB_ENV"
458461
459462
- name: CMake version

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ else()
290290
unset(debug_flags)
291291
endif()
292292

293+
include(cmake/optional_qt.cmake)
294+
293295
include(cmake/optional.cmake)
294296

295297
# Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
@@ -396,6 +398,7 @@ message("Wallet support:")
396398
message(" SQLite, descriptor wallets .......... ${WITH_SQLITE}")
397399
message(" Berkeley DB, legacy wallets ......... ${WITH_BDB}")
398400
message("Optional packages:")
401+
message(" GUI ................................. ${WITH_GUI}")
399402
message(" NAT-PMP ............................. ${WITH_NATPMP}")
400403
message(" UPnP ................................ ${WITH_MINIUPNPC}")
401404
message(" ZeroMQ .............................. ${WITH_ZMQ}")

cmake/optional_qt.cmake

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2023-present The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://opensource.org/license/mit/.
4+
5+
set(WITH_GUI "AUTO" CACHE STRING "Build GUI ([AUTO], Qt5, OFF)")
6+
set(with_gui_values AUTO Qt5 OFF)
7+
if(NOT WITH_GUI IN_LIST with_gui_values)
8+
message(FATAL_ERROR "WITH_GUI value is \"${WITH_GUI}\", but must be one of \"AUTO\", \"Qt5\" or \"OFF\".")
9+
endif()
10+
11+
if(WITH_GUI)
12+
set(QT_NO_CREATE_VERSIONLESS_FUNCTIONS ON)
13+
set(QT_NO_CREATE_VERSIONLESS_TARGETS ON)
14+
15+
if(BREW_COMMAND)
16+
execute_process(
17+
COMMAND ${BREW_COMMAND} --prefix qt@5
18+
OUTPUT_VARIABLE qt5_brew_prefix
19+
ERROR_QUIET
20+
OUTPUT_STRIP_TRAILING_WHITESPACE
21+
)
22+
endif()
23+
24+
if(WITH_GUI STREQUAL "AUTO")
25+
# The PATH_SUFFIXES option is required on OpenBSD systems.
26+
find_package(QT NAMES Qt5
27+
COMPONENTS Core
28+
HINTS ${qt5_brew_prefix}
29+
PATH_SUFFIXES Qt5
30+
)
31+
if(QT_FOUND)
32+
set(WITH_GUI Qt${QT_VERSION_MAJOR})
33+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
34+
enable_language(OBJCXX)
35+
set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
36+
set(CMAKE_OBJCXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
37+
set(CMAKE_OBJCXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
38+
set(CMAKE_OBJCXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
39+
endif()
40+
else()
41+
message(WARNING "Qt not found, disabling.\n"
42+
"To skip this warning check, use \"-DWITH_GUI=OFF\".\n")
43+
set(WITH_GUI OFF)
44+
endif()
45+
endif()
46+
endif()

depends/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ $(host_prefix)/share/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_
266266
-e 's|@host_arch@|$(host_arch)|' \
267267
-e 's|@CC@|$(host_CC)|' \
268268
-e 's|@CXX@|$(host_CXX)|' \
269+
-e 's|@OSX_SDK@|$(OSX_SDK)|' \
269270
-e 's|@AR@|$(host_AR)|' \
270271
-e 's|@RANLIB@|$(host_RANLIB)|' \
271272
-e 's|@STRIP@|$(host_STRIP)|' \

depends/packages/qt.mk

+4-3
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,14 @@ define $(package)_build_cmds
280280
$(MAKE)
281281
endef
282282

283+
# TODO: Investigate whether specific targets can be used here to minimize the amount of files/components installed.
283284
define $(package)_stage_cmds
284-
$(MAKE) -C qtbase/src INSTALL_ROOT=$($(package)_staging_dir) $(addsuffix -install_subtargets,$(addprefix sub-,$($(package)_qt_libs))) && \
285-
$(MAKE) -C qttools/src/linguist INSTALL_ROOT=$($(package)_staging_dir) $(addsuffix -install_subtargets,$(addprefix sub-,$($(package)_linguist_tools))) && \
285+
$(MAKE) -C qtbase INSTALL_ROOT=$($(package)_staging_dir) install && \
286+
$(MAKE) -C qttools INSTALL_ROOT=$($(package)_staging_dir) install && \
286287
$(MAKE) -C qttranslations INSTALL_ROOT=$($(package)_staging_dir) install_subtargets
287288
endef
288289

289290
define $(package)_postprocess_cmds
290-
rm -rf native/mkspecs/ native/lib/ lib/cmake/ && \
291+
rm -rf doc/ native/lib/ && \
291292
rm -f lib/lib*.la
292293
endef

depends/patches/qt/qt.pro

-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ cache(, super)
33

44
!QTDIR_build: cache(CONFIG, add, $$list(QTDIR_build))
55

6-
prl = no_install_prl
7-
CONFIG += $$prl
8-
cache(CONFIG, add stash, prl)
9-
106
TEMPLATE = subdirs
117
SUBDIRS = qtbase qttools qttranslations
128

depends/toolchain.cmake.in

+9-1
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@ set(PKG_CONFIG_PATH "@depends_prefix@/lib/pkgconfig")
9191
set(PKG_CONFIG_LIBDIR "${PKG_CONFIG_PATH}")
9292
set(QT_TRANSLATIONS_DIR "@depends_prefix@/translations")
9393

94+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE)
95+
# The find_package(Qt ...) function internally uses find_library()
96+
# calls for all dependencies to ensure their availability.
97+
# In turn, the find_library() inspects the well-known locations
98+
# on the file system; therefore, a hint is required.
99+
set(CMAKE_FRAMEWORK_PATH "@OSX_SDK@/System/Library/Frameworks")
100+
endif()
101+
94102
if(NOT WITH_GUI AND "@no_qt@" STREQUAL "1")
95-
set(WITH_GUI "no" CACHE STRING "")
103+
set(WITH_GUI OFF CACHE STRING "")
96104
endif()
97105

98106
if(NOT WITH_QRENCODE AND "@no_qr@" STREQUAL "1")

src/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ if(BUILD_UTIL)
327327
endif()
328328

329329

330+
if(WITH_GUI)
331+
add_subdirectory(qt)
332+
endif()
333+
334+
330335
add_subdirectory(test/util)
331336
if(BUILD_BENCH)
332337
add_subdirectory(bench)

src/qt/CMakeLists.txt

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Copyright (c) 2023-present The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://opensource.org/license/mit/.
4+
5+
# See:
6+
# - https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html
7+
# - https://doc.qt.io/qt-5/cmake-manual.html
8+
9+
set(CMAKE_AUTOMOC ON)
10+
set(CMAKE_AUTORCC ON)
11+
set(CMAKE_AUTOUIC ON)
12+
set(CMAKE_AUTOUIC_SEARCH_PATHS forms)
13+
14+
set(qt_minimum_required_version 5.11.3)
15+
16+
set(qt_components Core Gui Widgets Network LinguistTools)
17+
18+
if(CMAKE_CROSSCOMPILING)
19+
# The find_package(Qt ...) function internally uses find_library()
20+
# calls for all dependencies to ensure their availability.
21+
# In turn, the find_library() inspects the well-known locations
22+
# on the file system; therefore, it must be able to find
23+
# platform-specific system libraries, for example:
24+
# /usr/x86_64-w64-mingw32/lib/libm.a or /usr/arm-linux-gnueabihf/lib/libm.a.
25+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
26+
endif()
27+
28+
find_package(Qt5 ${qt_minimum_required_version} REQUIRED
29+
COMPONENTS ${qt_components}
30+
HINTS ${qt5_brew_prefix}
31+
PATH_SUFFIXES Qt5 # Required on OpenBSD systems.
32+
)
33+
unset(qt_components)
34+
message(STATUS "Found Qt: ${Qt5_DIR} (found suitable version \"${Qt5_VERSION}\", minimum required is \"${qt_minimum_required_version}\")")
35+
unset(qt_minimum_required_version)
36+
37+
# TODO: The file(GLOB ...) command should be replaced with an explicit
38+
# file list. Such a change must be synced with the corresponding change
39+
# to https://github.com/bitcoin-core/bitcoin-maintainer-tools/blob/main/update-translations.py
40+
file(GLOB ts_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} locale/*.ts)
41+
set_source_files_properties(${ts_files} PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/locale)
42+
qt5_add_translation(qm_files ${ts_files})
43+
44+
configure_file(bitcoin_locale.qrc bitcoin_locale.qrc COPYONLY)
45+
46+
add_library(bitcoinqt STATIC EXCLUDE_FROM_ALL
47+
bantablemodel.cpp
48+
bitcoin.cpp
49+
bitcoinaddressvalidator.cpp
50+
bitcoinamountfield.cpp
51+
bitcoingui.cpp
52+
bitcoinunits.cpp
53+
clientmodel.cpp
54+
csvmodelwriter.cpp
55+
guiutil.cpp
56+
initexecutor.cpp
57+
intro.cpp
58+
modaloverlay.cpp
59+
networkstyle.cpp
60+
notificator.cpp
61+
optionsdialog.cpp
62+
optionsmodel.cpp
63+
peertablemodel.cpp
64+
peertablesortproxy.cpp
65+
platformstyle.cpp
66+
qvalidatedlineedit.cpp
67+
qvaluecombobox.cpp
68+
rpcconsole.cpp
69+
splashscreen.cpp
70+
trafficgraphwidget.cpp
71+
utilitydialog.cpp
72+
$<$<PLATFORM_ID:Windows>:winshutdownmonitor.cpp>
73+
$<$<PLATFORM_ID:Darwin>:macdockiconhandler.mm>
74+
$<$<PLATFORM_ID:Darwin>:macnotificationhandler.mm>
75+
$<$<PLATFORM_ID:Darwin>:macos_appnap.mm>
76+
bitcoin.qrc
77+
${CMAKE_CURRENT_BINARY_DIR}/bitcoin_locale.qrc
78+
)
79+
target_compile_definitions(bitcoinqt
80+
PUBLIC
81+
QT_NO_KEYWORDS
82+
QT_USE_QSTRINGBUILDER
83+
)
84+
target_include_directories(bitcoinqt
85+
PUBLIC
86+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
87+
)
88+
target_link_libraries(bitcoinqt
89+
PUBLIC
90+
Qt5::Widgets
91+
PRIVATE
92+
core_interface
93+
bitcoin_cli
94+
leveldb
95+
Boost::headers
96+
$<TARGET_NAME_IF_EXISTS:NATPMP::NATPMP>
97+
$<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
98+
$<$<PLATFORM_ID:Darwin>:-framework\ AppKit>
99+
$<$<CXX_COMPILER_ID:MSVC>:shlwapi>
100+
)
101+
102+
if(ENABLE_WALLET)
103+
target_sources(bitcoinqt
104+
PRIVATE
105+
addressbookpage.cpp
106+
addresstablemodel.cpp
107+
askpassphrasedialog.cpp
108+
coincontroldialog.cpp
109+
coincontroltreewidget.cpp
110+
createwalletdialog.cpp
111+
editaddressdialog.cpp
112+
openuridialog.cpp
113+
overviewpage.cpp
114+
paymentserver.cpp
115+
psbtoperationsdialog.cpp
116+
qrimagewidget.cpp
117+
receivecoinsdialog.cpp
118+
receiverequestdialog.cpp
119+
recentrequeststablemodel.cpp
120+
sendcoinsdialog.cpp
121+
sendcoinsentry.cpp
122+
signverifymessagedialog.cpp
123+
transactiondesc.cpp
124+
transactiondescdialog.cpp
125+
transactionfilterproxy.cpp
126+
transactionoverviewwidget.cpp
127+
transactionrecord.cpp
128+
transactiontablemodel.cpp
129+
transactionview.cpp
130+
walletcontroller.cpp
131+
walletframe.cpp
132+
walletmodel.cpp
133+
walletmodeltransaction.cpp
134+
walletview.cpp
135+
)
136+
target_link_libraries(bitcoinqt
137+
PRIVATE
138+
bitcoin_wallet
139+
Qt5::Network
140+
)
141+
endif()
142+
143+
if(CMAKE_CROSSCOMPILING)
144+
target_compile_definitions(bitcoinqt PRIVATE QT_STATICPLUGIN)
145+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND TARGET Qt5::QXcbIntegrationPlugin)
146+
target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_XCB)
147+
elseif(WIN32 AND TARGET Qt5::QWindowsIntegrationPlugin AND TARGET Qt5::QWindowsVistaStylePlugin)
148+
target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_WINDOWS)
149+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND TARGET Qt5::QCocoaIntegrationPlugin AND TARGET Qt5::QMacStylePlugin)
150+
target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_COCOA)
151+
endif()
152+
endif()
153+
154+
add_executable(bitcoin-qt
155+
main.cpp
156+
../init/bitcoin-qt.cpp
157+
)
158+
159+
target_link_libraries(bitcoin-qt
160+
core_interface
161+
bitcoinqt
162+
bitcoin_node
163+
)
164+
165+
if(WIN32)
166+
set_target_properties(bitcoin-qt PROPERTIES WIN32_EXECUTABLE TRUE)
167+
endif()
168+
169+
install(TARGETS bitcoin-qt
170+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
171+
COMPONENT GUI
172+
)

src/qt/winshutdownmonitor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <QString>
1111
#include <functional>
1212

13-
#include <windef.h> // for HWND
13+
#include <windows.h>
1414

1515
#include <QAbstractNativeEventFilter>
1616

vcpkg.json

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"libevent",
1212
"miniupnpc",
1313
"sqlite3",
14+
"qt5-base",
15+
"qt5-tools",
1416
"zeromq"
1517
]
1618
}

0 commit comments

Comments
 (0)