Skip to content

Commit 57a6e2e

Browse files
committed
cmake: Build bitcoin-qt executable
1 parent 30f6429 commit 57a6e2e

File tree

4 files changed

+387
-1
lines changed

4 files changed

+387
-1
lines changed

CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)
6767
include(CMakeDependentOption)
6868
# When adding a new option, end the <help_text> with a full stop for consistency.
6969
option(BUILD_DAEMON "Build bitcoind executable." ON)
70+
option(BUILD_GUI "Build bitcoin-qt executable." OFF)
7071
option(BUILD_CLI "Build bitcoin-cli executable." ON)
7172

7273
option(BUILD_TESTS "Build test_bitcoin executable." ON)
@@ -143,6 +144,17 @@ endif()
143144

144145
cmake_dependent_option(ENABLE_EXTERNAL_SIGNER "Enable external signer support." ON "NOT WIN32" OFF)
145146

147+
if(BUILD_GUI)
148+
set(qt_components Core Gui Widgets LinguistTools)
149+
if(ENABLE_WALLET)
150+
list(APPEND qt_components Network)
151+
endif()
152+
find_package(Qt5 5.11.3 MODULE REQUIRED
153+
COMPONENTS ${qt_components}
154+
)
155+
unset(qt_components)
156+
endif()
157+
146158
option(BUILD_BENCH "Build bench_bitcoin executable." OFF)
147159
option(BUILD_FUZZ_BINARY "Build fuzz binary." OFF)
148160
cmake_dependent_option(BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF "NOT MSVC" OFF)
@@ -178,6 +190,7 @@ if(BUILD_FOR_FUZZING)
178190
set(BUILD_TX OFF)
179191
set(BUILD_UTIL OFF)
180192
set(BUILD_WALLET_TOOL OFF)
193+
set(BUILD_GUI OFF)
181194
set(ENABLE_EXTERNAL_SIGNER OFF)
182195
set(WITH_NATPMP OFF)
183196
set(WITH_MINIUPNPC OFF)
@@ -337,7 +350,7 @@ endif()
337350
include(AddBoostIfNeeded)
338351
add_boost_if_needed()
339352

340-
if(BUILD_DAEMON OR BUILD_CLI OR BUILD_TESTS OR BUILD_BENCH OR BUILD_FUZZ_BINARY)
353+
if(BUILD_DAEMON OR BUILD_GUI OR BUILD_CLI OR BUILD_TESTS OR BUILD_BENCH OR BUILD_FUZZ_BINARY)
341354
find_package(Libevent 2.1.8 MODULE REQUIRED)
342355
endif()
343356

@@ -460,6 +473,7 @@ message("Configure summary")
460473
message("=================")
461474
message("Executables:")
462475
message(" bitcoind ............................ ${BUILD_DAEMON}")
476+
message(" bitcoin-qt (GUI) .................... ${BUILD_GUI}")
463477
message(" bitcoin-cli ......................... ${BUILD_CLI}")
464478
message(" bitcoin-tx .......................... ${BUILD_TX}")
465479
message(" bitcoin-util ........................ ${BUILD_UTIL}")

cmake/module/FindQt5.cmake

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright (c) 2024-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+
#[=======================================================================[
6+
FindQt5
7+
-------
8+
9+
Finds the Qt 5 headers and libraries.
10+
11+
This is a wrapper around find_package() command that:
12+
- facilitates searching in various build environments
13+
- prints a standard log message
14+
15+
#]=======================================================================]
16+
17+
set(_qt_homebrew_prefix)
18+
if(CMAKE_HOST_APPLE)
19+
find_program(HOMEBREW_EXECUTABLE brew)
20+
if(HOMEBREW_EXECUTABLE)
21+
execute_process(
22+
COMMAND ${HOMEBREW_EXECUTABLE} --prefix qt@5
23+
OUTPUT_VARIABLE _qt_homebrew_prefix
24+
ERROR_QUIET
25+
OUTPUT_STRIP_TRAILING_WHITESPACE
26+
)
27+
endif()
28+
endif()
29+
30+
# Save CMAKE_FIND_ROOT_PATH_MODE_LIBRARY state.
31+
unset(_qt_find_root_path_mode_library_saved)
32+
if(DEFINED CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
33+
set(_qt_find_root_path_mode_library_saved ${CMAKE_FIND_ROOT_PATH_MODE_LIBRARY})
34+
endif()
35+
36+
# The Qt config files internally use find_library() calls for all
37+
# dependencies to ensure their availability. In turn, the find_library()
38+
# inspects the well-known locations on the file system; therefore, it must
39+
# be able to find platform-specific system libraries, for example:
40+
# /usr/x86_64-w64-mingw32/lib/libm.a or /usr/arm-linux-gnueabihf/lib/libm.a.
41+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
42+
43+
find_package(Qt5 ${Qt5_FIND_VERSION}
44+
COMPONENTS ${Qt5_FIND_COMPONENTS}
45+
HINTS ${_qt_homebrew_prefix}
46+
PATH_SUFFIXES Qt5 # Required on OpenBSD systems.
47+
)
48+
unset(_qt_homebrew_prefix)
49+
50+
# Restore CMAKE_FIND_ROOT_PATH_MODE_LIBRARY state.
51+
if(DEFINED _qt_find_root_path_mode_library_saved)
52+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ${_qt_find_root_path_mode_library_saved})
53+
unset(_qt_find_root_path_mode_library_saved)
54+
else()
55+
unset(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
56+
endif()
57+
58+
include(FindPackageHandleStandardArgs)
59+
find_package_handle_standard_args(Qt5
60+
REQUIRED_VARS Qt5_DIR
61+
VERSION_VAR Qt5_VERSION
62+
)
63+
64+
foreach(component IN LISTS Qt5_FIND_COMPONENTS ITEMS "")
65+
mark_as_advanced(Qt5${component}_DIR)
66+
endforeach()

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ if(BUILD_UTIL)
344344
endif()
345345

346346

347+
if(BUILD_GUI)
348+
add_subdirectory(qt)
349+
endif()
350+
351+
347352
add_subdirectory(test/util)
348353
if(BUILD_BENCH)
349354
add_subdirectory(bench)

0 commit comments

Comments
 (0)