Skip to content

Commit fb4ed14

Browse files
Set up a CMake find module for hwloc so that the finding behavior can be overriden using hwloc_ROOT downstream.
1 parent c5c5753 commit fb4ed14

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cmake_minimum_required(VERSION 3.12...3.31)
22

3+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
4+
35
set(CMAKE_C_STANDARD 11)
46
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build using shared libraries.")
57

cmake/Findhwloc.cmake

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
find_path(hwloc_INCLUDE_DIR hwloc.h PATH_SUFFIXES include)
2+
find_library(hwloc_LIBRARY
3+
NAMES hwloc libhwloc
4+
PATH_SUFFIXES lib lib64 lib32)
5+
if("${hwloc_INCLUDE_DIR}" STREQUAL "hwloc_INCLUDE_DIR-NOTFOUND" OR "${hwloc_LIBRARY}" STREQUAL "hwloc_LIBRARY-NOTFOUND")
6+
set(hwloc_FOUND FALSE)
7+
else()
8+
set(hwloc_FOUND TRUE)
9+
endif()
10+
11+
if(CMAKE_VERSION VERSION_LESS "3.17.0")
12+
message("-- Found hwloc: ${hwloc_FOUND}")
13+
else()
14+
message(STATUS "Found hwloc: ${hwloc_FOUND}")
15+
endif()

src/CMakeLists.txt

+3-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ set(QTHREADS_HASHMAP hashmap CACHE STRING "Which hashmap implementation to use.
99
set(QTHREADS_DICT_TYPE shavit CACHE STRING "Which dictionary implementation to use. Valid values are \"shavit\", \"trie\", and \"simple\".")
1010
set(QTHREADS_TIMER_TYPE gettimeofday CACHE STRING "Which timer implementation to use. Valid values are \"clock_gettime\", \"mach\", \"gettimeofday\", and \"gethrtime\".")
1111
set(QTHREADS_CONTEXT_SWAP_IMPL fastcontext CACHE STRING "Which context swap implementation to use. Valid values are \"system\" and \"fastcontext\".")
12-
set(HWLOC_INSTALL_DIR /usr/local CACHE PATH "Install path for hwloc library")
1312
set(QTHREADS_HWLOC_GET_TOPOLOGY_FUNCTION "" CACHE STRING "function to get hwloc topology (otherwise uses hwloc_topology_init and hwloc_topology_load)")
1413
set(QTHREADS_GUARD_PAGES OFF CACHE BOOL "Whether or not to guard memory pages to help with debugging stack overflows. Default is OFF.")
1514
set(QTHREADS_CONDWAIT_QUEUE OFF CACHE BOOL "Use a waiting queue based on pthread condition variables instead of a spin-based queue for inter-thread communication. Default is OFF.")
@@ -79,13 +78,9 @@ target_include_directories(qthread
7978
set_target_properties(qthread PROPERTIES C_VISIBILITY_PRESET hidden)
8079
target_link_libraries(qthread PUBLIC Threads::Threads)
8180
if ("${QTHREADS_TOPOLOGY}" STREQUAL "hwloc" OR "${QTHREADS_TOPOLOGY}" STREQUAL "binders")
82-
find_path(HWLOC_INCLUDE_DIR NAMES hwloc.h HINTS ${HWLOC_INSTALL_DIR} PATH_SUFFIXES include)
83-
target_include_directories(qthread PRIVATE ${HWLOC_INCLUDE_DIR})
84-
find_library(HWLOC_LIBRARY
85-
NAMES hwloc libhwloc
86-
HINTS ${HWLOC_INSTALL_DIR}
87-
PATH_SUFFIXES lib lib64 lib32)
88-
target_link_libraries(qthread PUBLIC "${HWLOC_LIBRARY}")
81+
find_package(hwloc REQUIRED)
82+
target_include_directories(qthread PRIVATE "${hwloc_INCLUDE_DIR}")
83+
target_link_libraries(qthread PUBLIC "${hwloc_LIBRARY}")
8984
if ("${QTHREADS_TOPOLOGY}" STREQUAL "hwloc")
9085
target_compile_definitions(qthread PRIVATE USE_HWLOC_MEM_AFFINITY)
9186
endif()

0 commit comments

Comments
 (0)