diff --git a/CMakeLists.txt b/CMakeLists.txt index 915bb321c6cf1e..67dd54de511589 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,11 @@ tristate_option(WITH_USDT "if sys/sdt.h is found." AUTO ) +tristate_option(WITH_EXTERNAL_SIGNER + "Enable external signer support." + "if Boost.Process is found." + AUTO +) option(BUILD_TESTS "Build test_bitcoin executable." ON) option(BUILD_BENCH "Build bench_bitcoin executable." ON) @@ -399,6 +404,7 @@ message(" SQLite, descriptor wallets .......... ${WITH_SQLITE}") message(" Berkeley DB, legacy wallets ......... ${WITH_BDB}") message("Optional packages:") message(" GUI ................................. ${WITH_GUI}") +message(" external signer ..................... ${WITH_EXTERNAL_SIGNER}") message(" NAT-PMP ............................. ${WITH_NATPMP}") message(" UPnP ................................ ${WITH_MINIUPNPC}") message(" ZeroMQ .............................. ${WITH_ZMQ}") diff --git a/cmake/bitcoin-config.h.in b/cmake/bitcoin-config.h.in index ebbb97562cdb01..23033593867043 100644 --- a/cmake/bitcoin-config.h.in +++ b/cmake/bitcoin-config.h.in @@ -215,4 +215,7 @@ /* Define if Berkeley DB (BDB) support should be compiled in. */ #cmakedefine USE_BDB +/* Define if external signer support is enabled. */ +#cmakedefine ENABLE_EXTERNAL_SIGNER + #endif //BITCOIN_CONFIG_H diff --git a/cmake/module/AddBoostIfNeeded.cmake b/cmake/module/AddBoostIfNeeded.cmake index 179887d24bb153..ead1e0b7a25ee2 100644 --- a/cmake/module/AddBoostIfNeeded.cmake +++ b/cmake/module/AddBoostIfNeeded.cmake @@ -19,6 +19,7 @@ function(add_boost_if_needed) set(Boost_NO_BOOST_CMAKE ON) find_package(Boost 1.73.0 REQUIRED) + mark_as_advanced(Boost_INCLUDE_DIR) set_target_properties(Boost::headers PROPERTIES IMPORTED_GLOBAL TRUE) target_compile_definitions(Boost::headers INTERFACE # We don't use multi_index serialization. @@ -48,5 +49,51 @@ function(add_boost_if_needed) endif() endif() - mark_as_advanced(Boost_INCLUDE_DIR) + if(WITH_EXTERNAL_SIGNER) + include(CheckCXXSourceCompiles) + set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR}) + set(CMAKE_REQUIRED_FLAGS "${working_compiler_werror_flag}") + # Boost 1.78 requires the following workaround. + # See: https://github.com/boostorg/process/issues/235 + string(APPEND CMAKE_REQUIRED_FLAGS " -Wno-error=narrowing") + check_cxx_source_compiles(" + #define BOOST_PROCESS_USE_STD_FS + #include + #include + + int main() + { + namespace bp = boost::process; + bp::opstream stdin_stream; + bp::ipstream stdout_stream; + bp::child c(\"dummy\", bp::std_out > stdout_stream, bp::std_err > stdout_stream, bp::std_in < stdin_stream); + stdin_stream << std::string{\"test\"} << std::endl; + if (c.running()) c.terminate(); + c.wait(); + c.exit_code(); + } + " HAVE_BOOST_PROCESS + ) + if(HAVE_BOOST_PROCESS) + if(WIN32) + # Boost Process for Windows uses Boost ASIO. Boost ASIO performs + # pre-main init of Windows networking libraries, which we do not + # want. + set(WITH_EXTERNAL_SIGNER OFF PARENT_SCOPE) + set(ENABLE_EXTERNAL_SIGNER OFF PARENT_SCOPE) + else() + set(WITH_EXTERNAL_SIGNER ON PARENT_SCOPE) + set(ENABLE_EXTERNAL_SIGNER ON PARENT_SCOPE) + target_compile_definitions(Boost::headers INTERFACE + BOOST_PROCESS_USE_STD_FS + ) + endif() + elseif(WITH_EXTERNAL_SIGNER STREQUAL "AUTO") + set(WITH_EXTERNAL_SIGNER OFF PARENT_SCOPE) + set(ENABLE_EXTERNAL_SIGNER OFF PARENT_SCOPE) + else() + message(FATAL_ERROR "External signing is not supported for this Boost version.") + endif() + endif() + endfunction()