From f2dbb17de3b6da7f17962578b4c2a9d5a419bd11 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 8 Jul 2023 19:27:47 +0100 Subject: [PATCH] [FIXUP] for "cmake: Build `test_bitcoin` executable" The vcpkg package manager has a separated `boost-test` package, and it is more robust to test its headers explicitly. --- cmake/module/AddBoostIfNeeded.cmake | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cmake/module/AddBoostIfNeeded.cmake b/cmake/module/AddBoostIfNeeded.cmake index 48c50a00243d8..32b4abdd18fcb 100644 --- a/cmake/module/AddBoostIfNeeded.cmake +++ b/cmake/module/AddBoostIfNeeded.cmake @@ -28,5 +28,28 @@ function(add_boost_if_needed) add_library(Boost::headers ALIAS Boost::boost) endif() + if(BUILD_TESTS) + include(CheckCXXSourceCompiles) + set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR}) + check_cxx_source_compiles(" + #define BOOST_TEST_MAIN + #include + " HAVE_BOOST_INCLUDED_UNIT_TEST_H + ) + if(NOT HAVE_BOOST_INCLUDED_UNIT_TEST_H) + message(FATAL_ERROR "Building test_bitcoin executable requested but boost/test/included/unit_test.hpp header not available.") + endif() + + check_cxx_source_compiles(" + #define BOOST_TEST_MAIN + #include + #include + " HAVE_BOOST_UNIT_TEST_H + ) + if(NOT HAVE_BOOST_UNIT_TEST_H) + message(FATAL_ERROR "Building test_bitcoin executable requested but boost/test/unit_test.hpp header not available.") + endif() + endif() + mark_as_advanced(Boost_INCLUDE_DIR) endfunction()