Skip to content

Commit

Permalink
Use find_package to locate HPX-installed Boost
Browse files Browse the repository at this point in the history
  • Loading branch information
Pansysk75 committed Sep 11, 2024
1 parent 6d436e0 commit 34d3833
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
54 changes: 28 additions & 26 deletions cmake/HPX_SetupBoost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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}
)
Expand All @@ -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()

Expand Down
31 changes: 20 additions & 11 deletions cmake/templates/HPXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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_<lib>_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")

Expand Down Expand Up @@ -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_<lib>_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)

Expand Down
2 changes: 1 addition & 1 deletion cmake/templates/HPXMacros.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 34d3833

Please sign in to comment.