Skip to content

Commit

Permalink
cmake: Build bitcoin-qt executable
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Aug 16, 2024
1 parent 30f6429 commit 57a6e2e
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 1 deletion.
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)
include(CMakeDependentOption)
# When adding a new option, end the <help_text> with a full stop for consistency.
option(BUILD_DAEMON "Build bitcoind executable." ON)
option(BUILD_GUI "Build bitcoin-qt executable." OFF)
option(BUILD_CLI "Build bitcoin-cli executable." ON)

option(BUILD_TESTS "Build test_bitcoin executable." ON)
Expand Down Expand Up @@ -143,6 +144,17 @@ endif()

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

if(BUILD_GUI)
set(qt_components Core Gui Widgets LinguistTools)
if(ENABLE_WALLET)
list(APPEND qt_components Network)
endif()
find_package(Qt5 5.11.3 MODULE REQUIRED
COMPONENTS ${qt_components}
)
unset(qt_components)
endif()

option(BUILD_BENCH "Build bench_bitcoin executable." OFF)
option(BUILD_FUZZ_BINARY "Build fuzz binary." OFF)
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)
Expand Down Expand Up @@ -178,6 +190,7 @@ if(BUILD_FOR_FUZZING)
set(BUILD_TX OFF)
set(BUILD_UTIL OFF)
set(BUILD_WALLET_TOOL OFF)
set(BUILD_GUI OFF)
set(ENABLE_EXTERNAL_SIGNER OFF)
set(WITH_NATPMP OFF)
set(WITH_MINIUPNPC OFF)
Expand Down Expand Up @@ -337,7 +350,7 @@ endif()
include(AddBoostIfNeeded)
add_boost_if_needed()

if(BUILD_DAEMON OR BUILD_CLI OR BUILD_TESTS OR BUILD_BENCH OR BUILD_FUZZ_BINARY)
if(BUILD_DAEMON OR BUILD_GUI OR BUILD_CLI OR BUILD_TESTS OR BUILD_BENCH OR BUILD_FUZZ_BINARY)
find_package(Libevent 2.1.8 MODULE REQUIRED)
endif()

Expand Down Expand Up @@ -460,6 +473,7 @@ message("Configure summary")
message("=================")
message("Executables:")
message(" bitcoind ............................ ${BUILD_DAEMON}")
message(" bitcoin-qt (GUI) .................... ${BUILD_GUI}")
message(" bitcoin-cli ......................... ${BUILD_CLI}")
message(" bitcoin-tx .......................... ${BUILD_TX}")
message(" bitcoin-util ........................ ${BUILD_UTIL}")
Expand Down
66 changes: 66 additions & 0 deletions cmake/module/FindQt5.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) 2024-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

#[=======================================================================[
FindQt5
-------
Finds the Qt 5 headers and libraries.
This is a wrapper around find_package() command that:
- facilitates searching in various build environments
- prints a standard log message
#]=======================================================================]

set(_qt_homebrew_prefix)
if(CMAKE_HOST_APPLE)
find_program(HOMEBREW_EXECUTABLE brew)
if(HOMEBREW_EXECUTABLE)
execute_process(
COMMAND ${HOMEBREW_EXECUTABLE} --prefix qt@5
OUTPUT_VARIABLE _qt_homebrew_prefix
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
endif()

# Save CMAKE_FIND_ROOT_PATH_MODE_LIBRARY state.
unset(_qt_find_root_path_mode_library_saved)
if(DEFINED CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
set(_qt_find_root_path_mode_library_saved ${CMAKE_FIND_ROOT_PATH_MODE_LIBRARY})
endif()

# The Qt config files internally use find_library() calls for all
# dependencies to ensure their availability. In turn, the find_library()
# inspects the well-known locations on the file system; therefore, it must
# be able to find platform-specific system libraries, for example:
# /usr/x86_64-w64-mingw32/lib/libm.a or /usr/arm-linux-gnueabihf/lib/libm.a.
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)

find_package(Qt5 ${Qt5_FIND_VERSION}
COMPONENTS ${Qt5_FIND_COMPONENTS}
HINTS ${_qt_homebrew_prefix}
PATH_SUFFIXES Qt5 # Required on OpenBSD systems.
)
unset(_qt_homebrew_prefix)

# Restore CMAKE_FIND_ROOT_PATH_MODE_LIBRARY state.
if(DEFINED _qt_find_root_path_mode_library_saved)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ${_qt_find_root_path_mode_library_saved})
unset(_qt_find_root_path_mode_library_saved)
else()
unset(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Qt5
REQUIRED_VARS Qt5_DIR
VERSION_VAR Qt5_VERSION
)

foreach(component IN LISTS Qt5_FIND_COMPONENTS ITEMS "")
mark_as_advanced(Qt5${component}_DIR)
endforeach()
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ if(BUILD_UTIL)
endif()


if(BUILD_GUI)
add_subdirectory(qt)
endif()


add_subdirectory(test/util)
if(BUILD_BENCH)
add_subdirectory(bench)
Expand Down
Loading

0 comments on commit 57a6e2e

Please sign in to comment.