From 34d3833d1d9d36b1a8300734f0444323ef559ea7 Mon Sep 17 00:00:00 2001 From: Pansysk75 Date: Wed, 11 Sep 2024 15:02:44 -0500 Subject: [PATCH] Use find_package to locate HPX-installed Boost --- cmake/HPX_SetupBoost.cmake | 54 ++++++++++++++++-------------- cmake/templates/HPXConfig.cmake.in | 31 +++++++++++------ cmake/templates/HPXMacros.cmake.in | 2 +- 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/cmake/HPX_SetupBoost.cmake b/cmake/HPX_SetupBoost.cmake index 05f5cfcd5614..261cb6630c76 100644 --- a/cmake/HPX_SetupBoost.cmake +++ b/cmake/HPX_SetupBoost.cmake @@ -82,15 +82,16 @@ if(NOT TARGET hpx_dependencies_boost) unset(BOOST_ROOT CACHE) endif() - if(NOT HPX_WITH_FETCH_BOOST) + if((NOT HPX_WITH_FETCH_BOOST) OR HPX_FIND_PACKAGE) + set(Boost_MINIMUM_VERSION "1.71" CACHE INTERNAL "1.71" FORCE ) find_package( - Boost ${Boost_MINIMUM_VERSION} NO_POLICY_SCOPE MODULE REQUIRED - COMPONENTS ${__boost_libraries} + Boost ${Boost_MINIMUM_VERSION} NO_POLICY_SCOPE REQUIRED + COMPONENTS ${__boost_libraries} HINTS ${HPX_BOOST_ROOT} ) add_library(hpx_dependencies_boost INTERFACE IMPORTED) @@ -104,29 +105,26 @@ if(NOT TARGET hpx_dependencies_boost) endforeach() elseif(NOT TARGET Boost::boost AND NOT HPX_FIND_PACKAGE) - # set(HPX_WITH_BOOST_VERSION "1.84.0") - # hpx_info( - # "HPX_WITH_FETCH_BOOST=${HPX_WITH_FETCH_BOOST}, Boost v${HPX_WITH_BOOST_VERSION} will be fetched using CMake's FetchContent" - # ) + # Fetch Boost using CMake's FetchContent + + if(NOT HPX_WITH_BOOST_VERSION) + set(HPX_WITH_BOOST_VERSION "1.86.0") + endif() + + hpx_info( + "HPX_WITH_FETCH_BOOST=${HPX_WITH_FETCH_BOOST}, Boost v${HPX_WITH_BOOST_VERSION} will be fetched using CMake's FetchContent" + ) + include(FetchContent) fetchcontent_declare( Boost - URL https://github.com/boostorg/boost/releases/download/boost-1.85.0/boost-1.85.0-cmake.tar.gz + URL https://github.com/boostorg/boost/releases/download/boost-${HPX_WITH_BOOST_VERSION}/boost-${HPX_WITH_BOOST_VERSION}-cmake.tar.xz TLS_VERIFY true DOWNLOAD_EXTRACT_TIMESTAMP true ) - set(BOOST_INCLUDE_LIBRARIES ${__boost_libraries}) - set(BOOST_SKIP_INSTALL_RULES OFF) - - # Use Populate + add_subdirectory instead of MakeAvailable, as we need - # EXCLUDE_FROM_ALL so that we only configure the boost libraries we need - fetchcontent_getproperties(Boost) - if(NOT boost_POPULATED) - fetchcontent_populate(Boost) - add_subdirectory(${boost_SOURCE_DIR} ${boost_BINARY_DIR} EXCLUDE_FROM_ALL) - endif() - + # Need to explicitly list header-only dependencies, since Cmake-Boost has + # installs each library's headers individually, as opposed to b2-built Boost. set(__boost_libraries ${__boost_libraries} accumulators @@ -145,12 +143,18 @@ if(NOT TARGET hpx_dependencies_boost) spirit variant ) + + set(BOOST_INCLUDE_LIBRARIES ${__boost_libraries}) + set(BOOST_SKIP_INSTALL_RULES OFF) + + fetchcontent_makeavailable(Boost) + + add_library(hpx_dependencies_boost INTERFACE) + list(TRANSFORM __boost_libraries PREPEND "boost_" OUTPUT_VARIABLE __boost_libraries_prefixed ) - add_library(hpx_dependencies_boost INTERFACE) - target_link_libraries( hpx_dependencies_boost INTERFACE ${__boost_libraries_prefixed} ) @@ -164,15 +168,13 @@ if(NOT TARGET hpx_dependencies_boost) install( EXPORT HPXBoostTarget FILE HPXBoostTarget.cmake - NAMESPACE Boost:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${HPX_PACKAGE_NAME} ) export( - TARGETS hpx_dependencies_boost - NAMESPACE Boost:: - FILE "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}/HPXBoostTarget.cmake" - ) + TARGETS hpx_dependencies_boost + FILE "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}/HPXBoostTarget.cmake" + ) endif() diff --git a/cmake/templates/HPXConfig.cmake.in b/cmake/templates/HPXConfig.cmake.in index 3c5161690bde..ba64cfb6c96d 100644 --- a/cmake/templates/HPXConfig.cmake.in +++ b/cmake/templates/HPXConfig.cmake.in @@ -91,6 +91,26 @@ if("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") endif() endif() +if(HPX_WITH_FETCH_BOOST) + # Boost has been installed alongside HPX + # Let HPX_SetupBoost find it + set(HPX_BOOST_ROOT "${CMAKE_CURRENT_LIST_DIR}/../") + include(HPX_SetupBoost) + include(HPX_SetupBoostFilesystem) + include(HPX_SetupBoostIostreams) +else() + # Boost Separate boost targets to be unarily linked to some modules + set(HPX_BOOST_ROOT "@Boost_ROOT@") + # By default Boost_ROOT is set to HPX_BOOST_ROOT (not necessary for PAPI or + # HWLOC cause we are specifying HPX__ROOT as an HINT to find_package) + if(NOT Boost_ROOT AND NOT "$ENV{BOOST_ROOT}") + set(Boost_ROOT ${HPX_BOOST_ROOT}) + endif() + include(HPX_SetupBoost) + include(HPX_SetupBoostFilesystem) + include(HPX_SetupBoostIostreams) +endif() + include("${CMAKE_CURRENT_LIST_DIR}/HPXInternalTargets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/HPXTargets.cmake") @@ -156,17 +176,6 @@ include(HPX_SetupAllocator) include(HPX_SetupThreads) -# Boost Separate boost targets to be unarily linked to some modules -set(HPX_BOOST_ROOT "@Boost_ROOT@") -# By default Boost_ROOT is set to HPX_BOOST_ROOT (not necessary for PAPI or -# HWLOC cause we are specifying HPX__ROOT as an HINT to find_package) -if(NOT Boost_ROOT AND NOT "$ENV{BOOST_ROOT}") - set(Boost_ROOT ${HPX_BOOST_ROOT}) -endif() -include(HPX_SetupBoost) -include(HPX_SetupBoostFilesystem) -include(HPX_SetupBoostIostreams) - # HIP include(HPX_SetupHIP) diff --git a/cmake/templates/HPXMacros.cmake.in b/cmake/templates/HPXMacros.cmake.in index a3dd7a5f8e13..518aced7c4f9 100644 --- a/cmake/templates/HPXMacros.cmake.in +++ b/cmake/templates/HPXMacros.cmake.in @@ -88,7 +88,7 @@ function(hpx_check_compiler_compatibility) endfunction() function(hpx_check_boost_compatibility) - if(HPX_IGNORE_BOOST_COMPATIBILITY) + if(HPX_IGNORE_BOOST_COMPATIBILITY OR HPX_WITH_FETCH_BOOST) return() endif() if(NOT DEFINED Boost_ROOT)