Skip to content

Commit

Permalink
Merge pull request #6611 from srinivasyadav18/fix_hwloc_fc
Browse files Browse the repository at this point in the history
Fix Hwloc fetch content
  • Loading branch information
hkaiser authored Feb 24, 2025
2 parents 095711b + b0a7204 commit e8cde1b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,10 @@ include(HPX_SetupAsio)

# Find all allocators which are currently supported.
include(HPX_SetupAllocator)

if(HPX_WITH_FETCH_HWLOC)
set(HPX_HWLOC_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/hwloc_installed)
endif()
include(HPX_SetupHwloc)

# reset external source lists
Expand Down
12 changes: 12 additions & 0 deletions cmake/HPX_FindHwloc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2025 Srinivas Yadav Singanaboina
#
# 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)

find_package(Hwloc)
if(NOT Hwloc_FOUND)
hpx_error(
"Hwloc could not be found, please specify Hwloc_ROOT to point to the correct location"
)
endif()
25 changes: 17 additions & 8 deletions cmake/HPX_SetupHwloc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Copyright (c) 2017 Abhimanyu Rawat
# Copyright (c) 2017 Google
# Copyright (c) 2017 Taeguk Kwon
# Copyright (c) 2025 Srinivas Yadav Singanaboina
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -44,11 +45,14 @@ else()
)
if(NOT HWLoc_POPULATED)
fetchcontent_populate(HWLoc)
set(HPX_HWLOC_BUILD_DIR_INSTALLATION_PATH
"${FETCHCONTENT_BASE_DIR}/hwloc_installed"
)
if(NOT Hwloc_BUILD_INSTALLED)
execute_process(
COMMAND
sh -c
"cd ${FETCHCONTENT_BASE_DIR}/hwloc-src && ./configure --prefix=${FETCHCONTENT_BASE_DIR}/hwloc-installed && make -j && make install"
"cd ${FETCHCONTENT_BASE_DIR}/hwloc-src && ./configure --prefix=${HPX_HWLOC_BUILD_DIR_INSTALLATION_PATH} && make -j && make install"
)
set(Hwloc_BUILD_INSTALLED
TRUE
Expand All @@ -59,8 +63,8 @@ else()
"HWLoc is installed at ${FETCHCONTENT_BASE_DIR}/hwloc-installed"
)
endif()
set(HWLOC_ROOT ${HPX_HWLOC_BUILD_DIR_INSTALLATION_PATH})
endif()
set(HWLOC_ROOT "${FETCHCONTENT_BASE_DIR}/hwloc-installed")
set(Hwloc_INCLUDE_DIR
${HWLOC_ROOT}/include
CACHE INTERNAL ""
Expand Down Expand Up @@ -107,15 +111,14 @@ else()
${HWLOC_ROOT}/lib/libhwloc.dll.a
CACHE INTERNAL ""
)
file(GLOB HWLOC_DLL ${HWLOC_ROOT}/bin/libhwloc*.dll)
else()
hpx_error(
"Building HWLOC as part of HPX' configuration process is not supported on this platform"
)
endif() # End hwloc installation

add_library(Hwloc::hwloc INTERFACE IMPORTED)
target_include_directories(Hwloc::hwloc INTERFACE ${Hwloc_INCLUDE_DIR})
target_link_libraries(Hwloc::hwloc INTERFACE ${Hwloc_LIBRARY})
find_package(Hwloc)

if(HPX_WITH_FETCH_HWLOC AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
if(RUNTIME_OUTPUT_DIRECTORY)
Expand All @@ -124,15 +127,21 @@ else()
set(EXE_DIRECTORY_PATH "${CMAKE_BINARY_DIR}/$<CONFIG>/bin/")
endif()

set(DLL_PATH "${HWLOC_ROOT}/bin/libhwloc-15.dll")
message("Copying ${HWLOC_DLL} to ${EXE_DIRECTORY_PATH}")
add_custom_target(
HwlocDLL ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${EXE_DIRECTORY_PATH}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DLL_PATH}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${HWLOC_DLL}
${EXE_DIRECTORY_PATH}
)
install(FILES ${DLL_PATH} DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${HWLOC_DLL} DESTINATION ${CMAKE_INSTALL_BINDIR})
add_hpx_pseudo_target(HwlocDLL)
add_dependencies(Hwloc::hwloc HwlocDLL)
endif()

install(
DIRECTORY ${HWLOC_ROOT}/
DESTINATION ${HPX_HWLOC_INSTALL_PATH}
COMPONENT core
)
endif()
12 changes: 10 additions & 2 deletions cmake/templates/HPXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,16 @@ include(HPX_SetupThreads)
include(HPX_SetupHIP)

# Hwloc
set(HPX_HWLOC_ROOT "@Hwloc_ROOT@")
include(HPX_SetupHwloc)
if(HPX_WITH_FETCH_HWLOC)
if(EXISTS ${HPX_PREFIX}/_deps/hwloc_installed)
set(Hwloc_ROOT ${HPX_PREFIX}/_deps/hwloc_installed)
else()
set(Hwloc_ROOT "@HPX_HWLOC_INSTALL_PATH@")
endif()
else()
set(Hwloc_ROOT "@Hwloc_ROOT@")
endif()
include(HPX_FindHwloc)

# Papi
set(HPX_PAPI_ROOT "@Papi_ROOT@")
Expand Down

0 comments on commit e8cde1b

Please sign in to comment.