Skip to content

Commit

Permalink
cmake: Add MULTIPROCESS option
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Mar 18, 2024
1 parent 2b2edb3 commit a1d7e1b
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ tristate_option(WITH_EXTERNAL_SIGNER
AUTO
)
tristate_option(WITH_QRENCODE "Enable QR code support." "if libqrencode is found." AUTO)
tristate_option(MULTIPROCESS "Build multiprocess bitcoin-node, bitcoin-wallet, and bitcoin-gui executables in addition to monolithic bitcoind and bitcoin-qt executables. Requires libmultiprocess library. Experimental." "if libmultiprocess is found." OFF)

option(BUILD_TESTS "Build test_bitcoin executable." ON)
cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_TESTS" OFF)
Expand Down Expand Up @@ -484,6 +485,7 @@ if(WITH_GUI)
message(" QR code (GUI) ....................... ${WITH_QRENCODE}")
endif()
message(" external signer ..................... ${WITH_EXTERNAL_SIGNER}")
message(" multiprocess ........................ ${MULTIPROCESS}")
message(" NAT-PMP ............................. ${WITH_NATPMP}")
message(" UPnP ................................ ${WITH_MINIUPNPC}")
message(" ZeroMQ .............................. ${WITH_ZMQ}")
Expand Down
31 changes: 31 additions & 0 deletions cmake/module/GenerateMPCode.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

function(target_capnp_sources target)
foreach(capnp_file IN LISTS ARGN)
add_custom_command(
OUTPUT ${capnp_file}.c++ ${capnp_file}.h ${capnp_file}.proxy-client.c++ ${capnp_file}.proxy-types.h ${capnp_file}.proxy-server.c++ ${capnp_file}.proxy-types.c++ ${capnp_file}.proxy.h
COMMAND ${MPGEN_PREFIX}/bin/mpgen ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file}
DEPENDS ${capnp_file}
VERBATIM
)
target_sources(${target}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.c++
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-client.c++
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-server.c++
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-types.c++
)
endforeach()

target_include_directories(${target}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
)

target_link_libraries(${target}
PRIVATE
PkgConfig::libmultiprocess
)
endfunction()
14 changes: 14 additions & 0 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,17 @@ if(WITH_GUI AND WITH_QRENCODE)
message(FATAL_ERROR "libqrencode requested, but not found.")
endif()
endif()

if(MULTIPROCESS)
# TODO: Switch to find_package() command.
include(CrossPkgConfig)
cross_pkg_check_modules(libmultiprocess libmultiprocess IMPORTED_TARGET)
if(libmultiprocess_FOUND)
set(MULTIPROCESS ON)
set(MPGEN_PREFIX "${libmultiprocess_PREFIX}" CACHE PATH "libmultiprocess codegen tool prefix.")
elseif(MULTIPROCESS STREQUAL "AUTO")
set(MULTIPROCESS OFF)
else()
message(FATAL_ERROR "\"-DMULTIPROCESS=ON\" specified, but libmultiprocess library was not found.")
endif()
endif()
1 change: 1 addition & 0 deletions depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ $(host_prefix)/share/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_
-e 's|@no_natpmp@|$(NO_NATPMP)|' \
-e 's|@no_usdt@|$(NO_USDT)|' \
-e 's|@no_harden@|$(NO_HARDEN)|' \
-e 's|@multiprocess@|$(MULTIPROCESS)|' \
$< > $@
touch $@

Expand Down
9 changes: 9 additions & 0 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,12 @@ endif()
if(NOT HARDENING AND "@no_harden@" STREQUAL "1")
set(HARDENING OFF CACHE STRING "Attempt to harden the resulting executables.")
endif()

if("@multiprocess@" STREQUAL "1")
if(NOT MULTIPROCESS)
set(MULTIPROCESS ON CACHE STRING "Build multiprocess bitcoin-node, bitcoin-wallet, and bitcoin-gui executables in addition to monolithic bitcoind and bitcoin-qt executables. Requires libmultiprocess library. Experimental.")
endif()
if(NOT MPGEN_PREFIX)
set(MPGEN_PREFIX "${CMAKE_FIND_ROOT_PATH}/native" CACHE PATH "libmultiprocess codegen tool prefix.")
endif()
endif()
16 changes: 16 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ add_dependencies(bitcoin_clientversion generate_build_info)
add_subdirectory(crypto)
add_subdirectory(univalue)
add_subdirectory(util)
if(MULTIPROCESS)
add_subdirectory(ipc)
endif()


add_library(bitcoin_consensus_sources INTERFACE)
Expand Down Expand Up @@ -277,6 +280,19 @@ if(BUILD_DAEMON)
)
list(APPEND installable_targets bitcoind)
endif()
if(MULTIPROCESS)
add_executable(bitcoin-node
bitcoind.cpp
init/bitcoin-node.cpp
)
target_link_libraries(bitcoin-node
core_interface
bitcoin_node
bitcoin_ipc
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
)
list(APPEND installable_targets bitcoin-node)
endif()


add_library(bitcoin_cli STATIC EXCLUDE_FROM_ALL
Expand Down
17 changes: 17 additions & 0 deletions src/ipc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

add_library(bitcoin_ipc STATIC EXCLUDE_FROM_ALL
capnp/protocol.cpp
interfaces.cpp
process.cpp
)

include(GenerateMPCode)
target_capnp_sources(bitcoin_ipc capnp/echo.capnp capnp/init.capnp)

target_link_libraries(bitcoin_ipc
PRIVATE
core_interface
)
22 changes: 20 additions & 2 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,30 @@ target_link_libraries(bitcoin-qt
)

import_plugins(bitcoin-qt)

set(installable_targets bitcoin-qt)
if(WIN32)
set_target_properties(bitcoin-qt PROPERTIES WIN32_EXECUTABLE TRUE)
endif()

install(TARGETS bitcoin-qt
if(MULTIPROCESS)
add_executable(bitcoin-gui
main.cpp
../init/bitcoin-gui.cpp
)
target_link_libraries(bitcoin-gui
core_interface
bitcoinqt
bitcoin_node
bitcoin_ipc
)
import_plugins(bitcoin-gui)
list(APPEND installable_targets bitcoin-gui)
if(WIN32)
set_target_properties(bitcoin-gui PROPERTIES WIN32_EXECUTABLE TRUE)
endif()
endif()

install(TARGETS ${installable_targets}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT GUI
)
Expand Down
21 changes: 21 additions & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ if(ENABLE_WALLET)
endif()
endif()

if(MULTIPROCESS)
add_library(bitcoin_ipc_test STATIC EXCLUDE_FROM_ALL
ipc_test.cpp
)

include(GenerateMPCode)
target_capnp_sources(bitcoin_ipc_test ipc_test.capnp)

target_link_libraries(bitcoin_ipc_test
PRIVATE
core_interface
univalue
)

target_sources(test_bitcoin
PRIVATE
ipc_tests.cpp
)
target_link_libraries(test_bitcoin bitcoin_ipc_test)
endif()

install(TARGETS test_bitcoin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

0 comments on commit a1d7e1b

Please sign in to comment.