Skip to content

Commit 975d673

Browse files
committed
cmake: Build test_bitcoin-qt executable
1 parent 10fcc66 commit 975d673

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ if(WITH_QRENCODE)
152152
endif()
153153

154154
cmake_dependent_option(WITH_DBUS "Enable DBus support." ON "CMAKE_SYSTEM_NAME STREQUAL \"Linux\" AND BUILD_GUI" OFF)
155+
cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_GUI;BUILD_TESTS" OFF)
155156
if(BUILD_GUI)
156157
set(qt_components Core Gui Widgets LinguistTools)
157158
if(ENABLE_WALLET)
@@ -161,6 +162,9 @@ if(BUILD_GUI)
161162
list(APPEND qt_components DBus)
162163
set(USE_DBUS TRUE)
163164
endif()
165+
if(BUILD_GUI_TESTS)
166+
list(APPEND qt_components Test)
167+
endif()
164168
find_package(Qt5 5.11.3 MODULE REQUIRED
165169
COMPONENTS ${qt_components}
166170
)
@@ -208,6 +212,7 @@ if(BUILD_FOR_FUZZING)
208212
set(WITH_MINIUPNPC OFF)
209213
set(WITH_ZMQ OFF)
210214
set(BUILD_TESTS OFF)
215+
set(BUILD_GUI_TESTS OFF)
211216
set(BUILD_BENCH OFF)
212217
set(BUILD_FUZZ_BINARY ON)
213218

@@ -506,6 +511,7 @@ message(" QR code (GUI) ....................... ${WITH_QRENCODE}")
506511
message(" DBus (GUI, Linux only) .............. ${WITH_DBUS}")
507512
message("Tests:")
508513
message(" test_bitcoin ........................ ${BUILD_TESTS}")
514+
message(" test_bitcoin-qt ..................... ${BUILD_GUI_TESTS}")
509515
message(" bench_bitcoin ....................... ${BUILD_BENCH}")
510516
message(" fuzz binary ......................... ${BUILD_FUZZ_BINARY}")
511517
message("")

src/qt/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ if(WIN32)
243243
set_target_properties(bitcoin-qt PROPERTIES WIN32_EXECUTABLE TRUE)
244244
endif()
245245

246+
if(BUILD_GUI_TESTS)
247+
add_subdirectory(test)
248+
endif()
249+
246250

247251
# Gets sources to be parsed to gather translatable strings.
248252
function(get_translatable_sources var)

src/qt/test/CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
add_executable(test_bitcoin-qt
6+
apptests.cpp
7+
optiontests.cpp
8+
rpcnestedtests.cpp
9+
test_main.cpp
10+
uritests.cpp
11+
util.cpp
12+
../../init/bitcoin-qt.cpp
13+
)
14+
15+
target_link_libraries(test_bitcoin-qt
16+
core_interface
17+
bitcoinqt
18+
test_util
19+
bitcoin_node
20+
Boost::headers
21+
Qt5::Test
22+
)
23+
24+
import_plugins(test_bitcoin-qt)
25+
26+
if(ENABLE_WALLET)
27+
target_sources(test_bitcoin-qt
28+
PRIVATE
29+
addressbooktests.cpp
30+
wallettests.cpp
31+
../../wallet/test/wallet_test_fixture.cpp
32+
)
33+
endif()
34+
35+
if(NOT QT_IS_STATIC)
36+
add_custom_command(
37+
TARGET test_bitcoin-qt POST_BUILD
38+
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_PROPERTY:Qt5::QMinimalIntegrationPlugin,LOCATION_$<UPPER_CASE:$<CONFIG>>> $<TARGET_FILE_DIR:test_bitcoin-qt>/plugins/platforms
39+
VERBATIM
40+
)
41+
endif()
42+
43+
add_test(NAME test_bitcoin-qt
44+
COMMAND test_bitcoin-qt
45+
)
46+
if(WIN32 AND VCPKG_TARGET_TRIPLET)
47+
# On Windows, vcpkg configures Qt with `-opengl dynamic`, which makes
48+
# the "minimal" platform plugin unusable due to internal Qt bugs.
49+
set_tests_properties(test_bitcoin-qt PROPERTIES
50+
ENVIRONMENT "QT_QPA_PLATFORM=windows"
51+
)
52+
endif()
53+
54+
install(TARGETS test_bitcoin-qt
55+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
56+
)

0 commit comments

Comments
 (0)