Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HPX_WITH_FETCH_BOOST #6511

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,10 @@ endif()
include(HPX_SetupThreads)

# Setup our required Boost libraries.
if(HPX_WITH_FETCH_BOOST)
include(HPX_FetchBoost)
include(${CMAKE_BINARY_DIR}/hpx_boost_root.cmake)
endif()
include(HPX_SetupBoost)
include(HPX_SetupBoostFilesystem)
include(HPX_SetupBoostIostreams)
Expand Down
102 changes: 102 additions & 0 deletions cmake/HPX_FetchBoost.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Copyright (c) 2024 Panos Syskakis
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

# Fetches Boost using CMake's FetchContent and builds it.
# Installs Boost alongside HPX and creates a file that, when included, will point find_package to that Boost installation

set(__boost_libraries "")
if(HPX_PARCELPORT_LIBFABRIC_WITH_LOGGING
OR HPX_PARCELPORT_LIBFABRIC_WITH_DEV_MODE
)
set(__boost_libraries ${__boost_libraries} log log_setup date_time chrono
thread
)
endif()

if(HPX_WITH_GENERIC_CONTEXT_COROUTINES)
# if context is needed, we should still link with boost thread and chrono
set(__boost_libraries ${__boost_libraries} context thread chrono)
endif()

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"
)
include(FetchContent)
fetchcontent_declare(
Boost
URL https://github.com/boostorg/boost/releases/download/boost-${HPX_WITH_BOOST_VERSION}/boost-${HPX_WITH_BOOST_VERSION}.tar.gz
TLS_VERIFY true
DOWNLOAD_EXTRACT_TIMESTAMP true
)

if(NOT Boost_POPULATED)
fetchcontent_populate(Boost)
endif()

if(NOT _HPX_IS_FETCHED_BOOST_BUILT)
set(boost_with_libraries "--with-libraries=headers")

if(__boost_libraries)
list(JOIN ${__boost_libraries} "," __boost_libraries_comma_sep)
set(boost_with_libraries
"${boost_with_libraries},${__boost_libraries_comma_sep}"
)
endif()

if(WIN32)
execute_process(
COMMAND
cmd /C
".\\bootstrap.bat --prefix=${boost_BINARY_DIR} ${boost_with_libraries} &&\
.\\b2 install cxxflags=/std:c++${HPX_CXX_STANDARD}"
WORKING_DIRECTORY "${boost_SOURCE_DIR}"
RESULT_VARIABLE _result
)
else()
execute_process(
COMMAND
sh -c
"./bootstrap.sh --prefix=${boost_BINARY_DIR} ${boost_with_libraries} &&\
./b2 install cxxflags=--std=c++${HPX_CXX_STANDARD}"
WORKING_DIRECTORY "${boost_SOURCE_DIR}"
RESULT_VARIABLE _result
)
endif()

if(NOT _result EQUAL 0)
hpx_error("Failed to build Boost")
endif()

set(_HPX_IS_FETCHED_BOOST_BUILT
ON
CACHE INTERNAL ""
)
endif()

# Copy the Boost build directory to the install directory as-is
install(
DIRECTORY "${boost_BINARY_DIR}/"
DESTINATION "${CMAKE_INSTALL_PREFIX}"
USE_SOURCE_PERMISSIONS
COMPONENT core
)

# Create a file on the build tree to point to the Boost build
file(WRITE "${CMAKE_BINARY_DIR}/hpx_boost_root.cmake"
"set(hpx_boost_root \"${boost_BINARY_DIR}\")"
)

# Create a file on the install tree to point to the Boost install
file(WRITE "${CMAKE_BINARY_DIR}/hpx_boost_root-install.cmake"
"set(hpx_boost_root \"${CMAKE_INSTALL_PREFIX}\")"
)

install(
FILES "${CMAKE_BINARY_DIR}/hpx_boost_root-install.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${HPX_PACKAGE_NAME}"
COMPONENT cmake
)
94 changes: 18 additions & 76 deletions cmake/HPX_SetupBoost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,25 @@
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

if(HPX_WITH_FETCH_BOOST)
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"
)
include(FetchContent)
fetchcontent_declare(
Boost
URL https://github.com/boostorg/boost/releases/download/boost-${HPX_WITH_BOOST_VERSION}/boost-${HPX_WITH_BOOST_VERSION}.tar.gz
TLS_VERIFY true
DOWNLOAD_EXTRACT_TIMESTAMP true
)
fetchcontent_populate(Boost)
set(HPX_WITH_BUILD_FETCHED_BOOST
"Execute process"
CACHE STRING "Used by command line tool to build fetched Boost"
)
set(HPX_WITH_BUILD_FETCHED_BOOST_CHECK
""
CACHE
STRING
"for internal use only, do not modify. Checks if fetched Boost is built"
)
# In case find_package(HPX) is called multiple times
if(NOT TARGET hpx_dependencies_boost)

if(NOT HPX_WITH_BUILD_FETCHED_BOOST STREQUAL
HPX_WITH_BUILD_FETCHED_BOOST_CHECK
set(__boost_libraries "")
if(HPX_PARCELPORT_LIBFABRIC_WITH_LOGGING
OR HPX_PARCELPORT_LIBFABRIC_WITH_DEV_MODE
)
if(WIN32)
execute_process(
COMMAND
cmd /C
"cd ${CMAKE_BINARY_DIR}\\_deps\\boost-src && .\\bootstrap.bat && .\\b2 headers cxxflags=/std:c++${HPX_CXX_STANDARD}"
)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
execute_process(
COMMAND
sh -c
"cd ${CMAKE_BINARY_DIR}/_deps/boost-src && ./bootstrap.sh --prefix=${CMAKE_BINARY_DIR}/_deps/boost-installed && ./b2 && ./b2 install --prefix=${CMAKE_BINARY_DIR}/_deps/boost-installed cxxflags=--std=c++${HPX_CXX_STANDARD}"
)
else()
execute_process(
COMMAND
sh -c
"cd ${CMAKE_BINARY_DIR}/_deps/boost-src && ./bootstrap.sh && ./b2 headers cxxflags=--std=c++${HPX_CXX_STANDARD}"
)
endif()
set(HPX_WITH_BUILD_FETCHED_BOOST_CHECK
${HPX_WITH_BUILD_FETCHED_BOOST}
CACHE
INTERNAL
"for internal use only, do not modify. Checks if fetched Boost is built"
set(__boost_libraries ${__boost_libraries} log log_setup date_time chrono
thread
)
endif()

set(Boost_DIR
"${CMAKE_BINARY_DIR}/_deps/boost-src"
CACHE INTERNAL ""
)
set(Boost_INCLUDE_DIR
"${CMAKE_BINARY_DIR}/_deps/boost-src"
CACHE INTERNAL ""
)
endif()
if(HPX_WITH_GENERIC_CONTEXT_COROUTINES)
# if context is needed, we should still link with boost thread and chrono
set(__boost_libraries ${__boost_libraries} context thread chrono)
endif()

list(REMOVE_DUPLICATES __boost_libraries)

# In case find_package(HPX) is called multiple times
if(NOT TARGET hpx_dependencies_boost)
# We first try to find the required minimum set of Boost libraries. This will
# also give us the version of the found boost installation
if(HPX_WITH_STATIC_LINKING)
Expand Down Expand Up @@ -98,6 +51,10 @@ if(NOT TARGET hpx_dependencies_boost)

set(Boost_NO_BOOST_CMAKE ON) # disable the search for boost-cmake

if(HPX_WITH_FETCH_BOOST AND NOT BOOST_ROOT AND NOT Boost_ROOT)
set(Boost_ROOT ${hpx_boost_root})
endif()

# Find the headers and get the version
find_package(Boost ${Boost_MINIMUM_VERSION} REQUIRED)
if(NOT Boost_VERSION_STRING)
Expand All @@ -106,22 +63,6 @@ if(NOT TARGET hpx_dependencies_boost)
)
endif()

set(__boost_libraries "")
if(HPX_PARCELPORT_LIBFABRIC_WITH_LOGGING
OR HPX_PARCELPORT_LIBFABRIC_WITH_DEV_MODE
)
set(__boost_libraries ${__boost_libraries} log log_setup date_time chrono
thread
)
endif()

if(HPX_WITH_GENERIC_CONTEXT_COROUTINES)
# if context is needed, we should still link with boost thread and chrono
set(__boost_libraries ${__boost_libraries} context thread chrono)
endif()

list(REMOVE_DUPLICATES __boost_libraries)

# compatibility with older CMake versions
if(BOOST_ROOT AND NOT Boost_ROOT)
set(Boost_ROOT
Expand Down Expand Up @@ -182,4 +123,5 @@ if(NOT TARGET hpx_dependencies_boost)
target_link_libraries(
hpx_dependencies_boost INTERFACE Boost::disable_autolinking
)

endif()
16 changes: 10 additions & 6 deletions cmake/templates/HPXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,16 @@ 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})
if(HPX_WITH_FETCH_BOOST)
include("${CMAKE_CURRENT_LIST_DIR}/hpx_boost_root-install.cmake")
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()
endif()
include(HPX_SetupBoost)
include(HPX_SetupBoostFilesystem)
Expand Down
3 changes: 3 additions & 0 deletions cmake/templates/HPXMacros.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ function(hpx_check_boost_compatibility)
if(HPX_IGNORE_BOOST_COMPATIBILITY)
return()
endif()
if(HPX_WITH_FETCH_BOOST)
return()
endif()
if(NOT DEFINED Boost_ROOT)
return()
endif()
Expand Down
Loading