Skip to content

Commit

Permalink
[cmake] Handle FindBoost.cmake deprecation
Browse files Browse the repository at this point in the history
Summary:
See https://cmake.org/cmake/help/latest/policy/CMP0167.html.

Starting with cmake 3.30 the FindBoost.cmake module is no longer provided and we should use the BoostConfig.cmake provided by Boost. But this file is only available since Boost 1.70.
Work around this by trying the config first then fall back to the module. There are cases where this will fail, e.g. Boost 1.64 (our current minimum) with cmake 3.30 but it's unlikely to have a system with both such a recent cmake and such an old Boost. Also there is no solution to this problem.

Test Plan:
  ninja check
Run the GUIX builds

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D17431
  • Loading branch information
Fabcien committed Dec 31, 2024
1 parent e5d8664 commit e2f5b0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions cmake/modules/NativeExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,27 @@ function(non_native_target_link_libraries TARGET LIB VERSION)
endforeach()
endfunction()

function(non_native_target_link_headers_only TARGET LIB VERSION)
function(non_native_target_link_boost_headers_only TARGET VERSION)
# Drop dependency during native builds
if(__IS_NATIVE_BUILD)
return()
endif()

# Header only libraries have imported targets with no associated component
find_package(${LIB} ${VERSION} REQUIRED)
foreach(COMPONENT ${ARGN})
target_link_libraries(${TARGET} ${LIB}::${COMPONENT})
endforeach()
# Starting with cmake 3.30, FindBoost is no longer provided. Boost provides
# a configuration file since v1.70 so this fallback can be removed if we
# enforce this Boost version or greater.
# find_package(Boost ${VERSION} COMPONENTS headers CONFIG)
if(NOT Boost_FOUND)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.30)
cmake_policy(SET CMP0167 OLD)
endif()
# Header only library have an imported target but no associated
# component
find_package(Boost ${VERSION} QUIET REQUIRED)
endif()

message(STATUS "Found Boost component headers: ${Boost_INCLUDE_DIRS} (found suitable version \"${Boost_VERSION}\", minimum required is \"${VERSION}\")")
target_link_libraries(${TARGET} Boost::headers)
endfunction()

# It is imperative that NATIVE_BUILD_DIR be in the cache.
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,10 @@ endmacro()
link_event(util event)

macro(link_boost_headers_only TARGET)
non_native_target_link_headers_only(${TARGET} Boost 1.64 ${ARGN})
non_native_target_link_boost_headers_only(${TARGET} 1.64)
endmacro()

link_boost_headers_only(util headers)
link_boost_headers_only(util)
target_compile_definitions(util PUBLIC BOOST_NO_CXX98_FUNCTION_BASE)

set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down

0 comments on commit e2f5b0b

Please sign in to comment.