Skip to content

Commit fa34d99

Browse files
committed
cmake: Build bitcoin-qt executable
1 parent e36222a commit fa34d99

File tree

5 files changed

+211
-4
lines changed

5 files changed

+211
-4
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ else()
239239
unset(debug_flags)
240240
endif()
241241

242+
include(cmake/optional_qt.cmake)
243+
242244
include(cmake/optional.cmake)
243245

244246
# Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
@@ -345,6 +347,7 @@ message("Wallet support:")
345347
message(" SQLite, descriptor wallets .......... ${WITH_SQLITE}")
346348
message(" Berkeley DB, legacy wallets ......... ${WITH_BDB}")
347349
message("Optional packages:")
350+
message(" GUI ................................. ${WITH_GUI}")
348351
message(" NAT-PMP ............................. ${WITH_NATPMP}")
349352
message(" UPnP ................................ ${WITH_MINIUPNPC}")
350353
message(" ZeroMQ .............................. ${WITH_ZMQ}")

cmake/optional_qt.cmake

Lines changed: 46 additions & 0 deletions
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/packages/qt.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,12 @@ define $(package)_build_cmds
281281
endef
282282

283283
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))) && \
284+
$(MAKE) -C qtbase INSTALL_ROOT=$($(package)_staging_dir) install && \
285+
$(MAKE) -C qttools INSTALL_ROOT=$($(package)_staging_dir) install && \
286286
$(MAKE) -C qttranslations INSTALL_ROOT=$($(package)_staging_dir) install_subtargets
287287
endef
288288

289289
define $(package)_postprocess_cmds
290-
rm -rf native/mkspecs/ native/lib/ lib/cmake/ && \
291-
rm -f lib/lib*.la lib/*.prl plugins/*/*.prl
290+
rm -rf doc/ native/lib/ && \
291+
rm -f lib/lib*.la
292292
endef

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
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

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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+
find_package(Qt5 ${qt_minimum_required_version} REQUIRED
18+
COMPONENTS ${qt_components}
19+
HINTS ${qt5_brew_prefix}
20+
PATH_SUFFIXES Qt5 # Required on OpenBSD systems.
21+
)
22+
unset(qt_components)
23+
message(STATUS "Found Qt: ${Qt5_DIR} (found suitable version \"${Qt5_VERSION}\", minimum required is \"${qt_minimum_required_version}\")")
24+
unset(qt_minimum_required_version)
25+
26+
file(GLOB ts_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} locale/*.ts)
27+
set_source_files_properties(${ts_files} PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/locale)
28+
qt5_add_translation(qm_files ${ts_files})
29+
30+
configure_file(bitcoin_locale.qrc bitcoin_locale.qrc COPYONLY)
31+
32+
add_library(bitcoinqt STATIC EXCLUDE_FROM_ALL
33+
bantablemodel.cpp
34+
bitcoin.cpp
35+
bitcoinaddressvalidator.cpp
36+
bitcoinamountfield.cpp
37+
bitcoingui.cpp
38+
bitcoinunits.cpp
39+
clientmodel.cpp
40+
csvmodelwriter.cpp
41+
guiutil.cpp
42+
initexecutor.cpp
43+
intro.cpp
44+
modaloverlay.cpp
45+
networkstyle.cpp
46+
notificator.cpp
47+
optionsdialog.cpp
48+
optionsmodel.cpp
49+
peertablemodel.cpp
50+
peertablesortproxy.cpp
51+
platformstyle.cpp
52+
qvalidatedlineedit.cpp
53+
qvaluecombobox.cpp
54+
rpcconsole.cpp
55+
splashscreen.cpp
56+
trafficgraphwidget.cpp
57+
utilitydialog.cpp
58+
$<$<PLATFORM_ID:Windows>:winshutdownmonitor.cpp>
59+
$<$<PLATFORM_ID:Darwin>:macdockiconhandler.mm>
60+
$<$<PLATFORM_ID:Darwin>:macnotificationhandler.mm>
61+
$<$<PLATFORM_ID:Darwin>:macos_appnap.mm>
62+
bitcoin.qrc
63+
${CMAKE_CURRENT_BINARY_DIR}/bitcoin_locale.qrc
64+
)
65+
target_compile_definitions(bitcoinqt
66+
PUBLIC
67+
QT_NO_KEYWORDS
68+
QT_USE_QSTRINGBUILDER
69+
)
70+
target_include_directories(bitcoinqt
71+
PUBLIC
72+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
73+
)
74+
target_link_libraries(bitcoinqt
75+
PUBLIC
76+
Qt5::Widgets
77+
PRIVATE
78+
core_interface
79+
bitcoin_cli
80+
leveldb
81+
Boost::headers
82+
$<TARGET_NAME_IF_EXISTS:NATPMP::NATPMP>
83+
$<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
84+
$<$<CXX_COMPILER_ID:MSVC>:shlwapi>
85+
)
86+
87+
if(ENABLE_WALLET)
88+
target_sources(bitcoinqt
89+
PRIVATE
90+
addressbookpage.cpp
91+
addresstablemodel.cpp
92+
askpassphrasedialog.cpp
93+
coincontroldialog.cpp
94+
coincontroltreewidget.cpp
95+
createwalletdialog.cpp
96+
editaddressdialog.cpp
97+
openuridialog.cpp
98+
overviewpage.cpp
99+
paymentserver.cpp
100+
psbtoperationsdialog.cpp
101+
qrimagewidget.cpp
102+
receivecoinsdialog.cpp
103+
receiverequestdialog.cpp
104+
recentrequeststablemodel.cpp
105+
sendcoinsdialog.cpp
106+
sendcoinsentry.cpp
107+
signverifymessagedialog.cpp
108+
transactiondesc.cpp
109+
transactiondescdialog.cpp
110+
transactionfilterproxy.cpp
111+
transactionoverviewwidget.cpp
112+
transactionrecord.cpp
113+
transactiontablemodel.cpp
114+
transactionview.cpp
115+
walletcontroller.cpp
116+
walletframe.cpp
117+
walletmodel.cpp
118+
walletmodeltransaction.cpp
119+
walletview.cpp
120+
)
121+
target_link_libraries(bitcoinqt
122+
PRIVATE
123+
bitcoin_wallet
124+
Qt5::Network
125+
)
126+
endif()
127+
128+
if(CMAKE_CROSSCOMPILING)
129+
target_compile_definitions(bitcoinqt PRIVATE QT_STATICPLUGIN)
130+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND TARGET Qt5::QXcbIntegrationPlugin)
131+
target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_XCB)
132+
elseif(WIN32 AND TARGET Qt5::QWindowsIntegrationPlugin AND TARGET Qt5::QWindowsVistaStylePlugin)
133+
target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_WINDOWS)
134+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND TARGET Qt5::QCocoaIntegrationPlugin AND TARGET Qt5::QMacStylePlugin)
135+
target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_COCOA)
136+
endif()
137+
endif()
138+
139+
add_executable(bitcoin-qt
140+
main.cpp
141+
../init/bitcoin-qt.cpp
142+
)
143+
144+
target_link_libraries(bitcoin-qt
145+
core_interface
146+
bitcoinqt
147+
bitcoin_node
148+
)
149+
150+
install(TARGETS bitcoin-qt
151+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
152+
COMPONENT GUI
153+
)

0 commit comments

Comments
 (0)