Skip to content

Commit 689318c

Browse files
committed
Merge bitcoin/bitcoin#32667: build: Find Boost in config mode
14653b8 build: Find Boost in config mode (Hennadii Stepanov) Pull request description: The `FindBoost` module has been removed by policy [CMP0167](https://cmake.org/cmake/help/latest/policy/CMP0167.html). ACKs for top commit: purpleKarrot: ACK 14653b8 Tree-SHA512: 5ec88647af83158f9bc04b41a3b72d4da7d84a7c81af351b8dac61cdf7f2f3b34bedd6ff164f21c229f2fd442918aaf21ba7c2c81c346b64de9032aae27b10ce
2 parents 4a3475a + 14653b8 commit 689318c

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

cmake/module/AddBoostIfNeeded.cmake

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,8 @@ function(add_boost_if_needed)
2929
endif()
3030
endif()
3131

32-
# We cannot rely on find_package(Boost ...) to work properly without
33-
# Boost_NO_BOOST_CMAKE set until we require a more recent Boost because
34-
# upstream did not ship proper CMake files until 1.82.0.
35-
# Until then, we rely on CMake's FindBoost module.
36-
# See: https://cmake.org/cmake/help/latest/policy/CMP0167.html
37-
if(POLICY CMP0167)
38-
cmake_policy(SET CMP0167 OLD)
39-
endif()
40-
set(Boost_NO_BOOST_CMAKE ON)
41-
find_package(Boost 1.73.0 REQUIRED)
42-
mark_as_advanced(Boost_INCLUDE_DIR)
32+
find_package(Boost 1.73.0 REQUIRED CONFIG)
33+
mark_as_advanced(Boost_INCLUDE_DIR boost_headers_DIR)
4334
set_target_properties(Boost::headers PROPERTIES IMPORTED_GLOBAL TRUE)
4435
target_compile_definitions(Boost::headers INTERFACE
4536
# We don't use multi_index serialization.
@@ -57,34 +48,24 @@ function(add_boost_if_needed)
5748
# older than 1.80.
5849
# See: https://github.com/boostorg/config/pull/430.
5950
set(CMAKE_REQUIRED_DEFINITIONS -DBOOST_NO_CXX98_FUNCTION_BASE)
60-
set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR})
61-
include(CMakePushCheckState)
62-
cmake_push_check_state()
63-
include(TryAppendCXXFlags)
51+
get_target_property(CMAKE_REQUIRED_INCLUDES Boost::headers INTERFACE_INCLUDE_DIRECTORIES)
6452
set(CMAKE_REQUIRED_FLAGS ${working_compiler_werror_flag})
6553
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
54+
include(CheckCXXSourceCompiles)
6655
check_cxx_source_compiles("
6756
#include <boost/config.hpp>
6857
" NO_DIAGNOSTICS_BOOST_NO_CXX98_FUNCTION_BASE
6958
)
70-
cmake_pop_check_state()
7159
if(NO_DIAGNOSTICS_BOOST_NO_CXX98_FUNCTION_BASE)
7260
target_compile_definitions(Boost::headers INTERFACE
7361
BOOST_NO_CXX98_FUNCTION_BASE
7462
)
75-
else()
76-
set(CMAKE_REQUIRED_DEFINITIONS)
7763
endif()
7864

7965
# Some package managers, such as vcpkg, vendor Boost.Test separately
8066
# from the rest of the headers, so we have to check for it individually.
8167
if(BUILD_TESTS AND DEFINED VCPKG_TARGET_TRIPLET)
82-
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DBOOST_TEST_NO_MAIN)
83-
include(CheckIncludeFileCXX)
84-
check_include_file_cxx(boost/test/included/unit_test.hpp HAVE_BOOST_INCLUDED_UNIT_TEST_H)
85-
if(NOT HAVE_BOOST_INCLUDED_UNIT_TEST_H)
86-
message(FATAL_ERROR "Building test_bitcoin executable requested but boost/test/included/unit_test.hpp header not available.")
87-
endif()
68+
find_package(boost_included_unit_test_framework ${Boost_VERSION} EXACT REQUIRED CONFIG)
8869
endif()
8970

9071
endfunction()

0 commit comments

Comments
 (0)