From 0e1fe2d89e76340909852d261f0b9125a826da41 Mon Sep 17 00:00:00 2001 From: Pansysk75 Date: Mon, 17 Jun 2024 16:06:30 -0500 Subject: [PATCH] Fix Boost fetch --- CMakeLists.txt | 4 ++ cmake/HPX_FetchBoost.cmake | 102 +++++++++++++++++++++++++++++ cmake/HPX_SetupBoost.cmake | 94 +++++--------------------- cmake/templates/HPXConfig.cmake.in | 16 +++-- cmake/templates/HPXMacros.cmake.in | 3 + 5 files changed, 137 insertions(+), 82 deletions(-) create mode 100644 cmake/HPX_FetchBoost.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4eeebf15fc7b..e24535e59843 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/HPX_FetchBoost.cmake b/cmake/HPX_FetchBoost.cmake new file mode 100644 index 000000000000..be536f44f8e9 --- /dev/null +++ b/cmake/HPX_FetchBoost.cmake @@ -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 +) diff --git a/cmake/HPX_SetupBoost.cmake b/cmake/HPX_SetupBoost.cmake index 7560311b8285..12d5869df846 100644 --- a/cmake/HPX_SetupBoost.cmake +++ b/cmake/HPX_SetupBoost.cmake @@ -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) @@ -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) @@ -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 @@ -182,4 +123,5 @@ if(NOT TARGET hpx_dependencies_boost) target_link_libraries( hpx_dependencies_boost INTERFACE Boost::disable_autolinking ) + endif() diff --git a/cmake/templates/HPXConfig.cmake.in b/cmake/templates/HPXConfig.cmake.in index 5c2c7260f96e..d6a486009920 100644 --- a/cmake/templates/HPXConfig.cmake.in +++ b/cmake/templates/HPXConfig.cmake.in @@ -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__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__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) diff --git a/cmake/templates/HPXMacros.cmake.in b/cmake/templates/HPXMacros.cmake.in index a3dd7a5f8e13..5fc64e329fc8 100644 --- a/cmake/templates/HPXMacros.cmake.in +++ b/cmake/templates/HPXMacros.cmake.in @@ -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()