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()