@@ -41,6 +41,7 @@ endif()
4141include (CTest)
4242include (CMakePackageConfigHelpers)
4343include (GNUInstallDirs)
44+ include (FetchContent)
4445find_package (PkgConfig)
4546
4647# --------------------------------------------------------------------------- #
@@ -162,7 +163,6 @@ else()
162163 set (UMF_JEMALLOC_TAG 5.3.0)
163164 endif ()
164165
165- include (FetchContent)
166166 message (
167167 STATUS
168168 "Will fetch jemalloc from ${UMF_JEMALLOC_REPO} (tag: ${UMF_JEMALLOC_TAG} )"
@@ -257,126 +257,95 @@ else()
257257 if (NOT UMF_LINK_HWLOC_STATICALLY)
258258 pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
259259 if (NOT LIBHWLOC_FOUND)
260- find_package (LIBHWLOC 2.3.0 REQUIRED hwloc)
260+ find_package (LIBHWLOC 2.3.0 COMPONENTS hwloc)
261+ if (LIBHWLOC_LIBRARIES)
262+ set (LIBHWLOC_AVAILABLE TRUE )
263+ endif ()
261264 endif ()
262265
263- # add PATH to DLL on Windows
264- set (DLL_PATH_LIST
265- "${DLL_PATH_LIST} ;PATH=path_list_append:${LIBHWLOC_DLL_DIRS} " )
266- elseif (WINDOWS)
267- include (FetchContent)
268- set (HWLOC_ENABLE_TESTING OFF )
269- set (HWLOC_SKIP_LSTOPO ON )
270- set (HWLOC_SKIP_TOOLS ON )
266+ if (LIBHWLOC_AVAILABLE OR LIBHWLOC_FOUND)
267+ # add PATH to DLL on Windows
268+ set (DLL_PATH_LIST
269+ "${DLL_PATH_LIST} ;PATH=path_list_append:${LIBHWLOC_DLL_DIRS} " )
270+ message (STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES} " )
271+ else ()
272+ set (UMF_LINK_HWLOC_STATICALLY ON )
273+ endif ()
274+ endif ()
271275
276+ if (UMF_LINK_HWLOC_STATICALLY)
272277 message (
273278 STATUS
274279 "Will fetch hwloc from ${UMF_HWLOC_REPO} (tag: ${UMF_HWLOC_TAG} )"
275280 )
276281
277- FetchContent_Declare(
278- hwloc_targ
279- GIT_REPOSITORY ${UMF_HWLOC_REPO}
280- GIT_TAG ${UMF_HWLOC_TAG}
281- SOURCE_SUBDIR contrib/windows-cmake/ FIND_PACKAGE_ARGS)
282- FetchContent_MakeAvailable(hwloc_targ)
283-
284- message (STATUS "hwloc CMAKE_GENERATOR: ${CMAKE_GENERATOR} " )
282+ if (WINDOWS)
283+ set (HWLOC_ENABLE_TESTING OFF )
284+ set (HWLOC_SKIP_LSTOPO ON )
285+ set (HWLOC_SKIP_TOOLS ON )
286+
287+ FetchContent_Declare(
288+ hwloc_targ
289+ GIT_REPOSITORY ${UMF_HWLOC_REPO}
290+ GIT_TAG ${UMF_HWLOC_TAG}
291+ SOURCE_SUBDIR contrib/windows-cmake/)
292+ FetchContent_MakeAvailable(hwloc_targ)
293+
294+ set (HWLOC_LIB_PATH "" )
295+ if (CMAKE_GENERATOR STREQUAL "NMake Makefiles" )
296+ set (HWLOC_LIB_PATH "${hwloc_targ_BINARY_DIR} /hwloc.lib" )
297+ else ()
298+ set (HWLOC_LIB_PATH "${hwloc_targ_BINARY_DIR} /lib/hwloc.lib" )
299+ endif ()
300+
301+ get_filename_component (LIBHWLOC_LIBRARY_DIRS ${HWLOC_LIB_PATH}
302+ DIRECTORY )
303+ set (LIBHWLOC_LIBRARIES ${HWLOC_LIB_PATH} )
304+ set (LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR} /include )
305+ else () # not Windows
306+ FetchContent_Declare(
307+ hwloc_targ
308+ GIT_REPOSITORY ${UMF_HWLOC_REPO}
309+ GIT_TAG ${UMF_HWLOC_TAG} )
310+ FetchContent_MakeAvailable(hwloc_targ)
285311
286- if (CMAKE_GENERATOR STREQUAL "Ninja" OR CMAKE_GENERATOR STREQUAL
287- "Unix Makefiles" )
288312 add_custom_command (
289- COMMAND ${CMAKE_COMMAND}
290- -DCMAKE_INSTALL_PREFIX=${hwloc_targ_BINARY_DIR} -B build
291- WORKING_DIRECTORY
292- ${hwloc_targ_SOURCE_DIR} /contrib/windows-cmake/
293- OUTPUT
294- ${hwloc_targ_SOURCE_DIR} /contrib/windows-cmake/CMakeCache.txt
295- )
313+ COMMAND ./autogen.sh
314+ WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
315+ OUTPUT ${hwloc_targ_SOURCE_DIR} /configure)
296316 add_custom_command (
297- COMMAND ${CMAKE_COMMAND} --build build
298- WORKING_DIRECTORY
299- ${hwloc_targ_SOURCE_DIR} /contrib/windows-cmake/
300- OUTPUT
301- ${hwloc_targ_SOURCE_DIR} /contrib/windows-cmake/build /lib/hwloc.lib
302- DEPENDS
303- ${hwloc_targ_SOURCE_DIR} /contrib/windows-cmake/CMakeCache.txt
304- )
317+ COMMAND
318+ ./configure --prefix =${hwloc_targ_BINARY_DIR}
319+ --enable-static =yes --enable-shared=no --disable-libxml2
320+ --disable-pci --disable-levelzero --disable-opencl
321+ --disable-cuda --disable-nvml --disable-libudev
322+ --disable-rsmi CFLAGS=-fPIC CXXFLAGS=-fPIC
323+ WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
324+ OUTPUT ${hwloc_targ_SOURCE_DIR} /Makefile
325+ DEPENDS ${hwloc_targ_SOURCE_DIR} /configure)
305326 add_custom_command (
306- COMMAND ${CMAKE_COMMAND} --build build --target INSTALL
307- WORKING_DIRECTORY
308- ${hwloc_targ_SOURCE_DIR} /contrib/windows-cmake/
309- OUTPUT ${hwloc_targ_BINARY_DIR} /lib/hwloc.lib
310- DEPENDS
311- ${hwloc_targ_SOURCE_DIR} /contrib/windows-cmake/build /lib/hwloc.lib
312- )
327+ COMMAND make
328+ WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
329+ OUTPUT ${hwloc_targ_SOURCE_DIR} /lib/libhwloc.la
330+ DEPENDS ${hwloc_targ_SOURCE_DIR} /Makefile)
331+ add_custom_command (
332+ COMMAND make install
333+ WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
334+ OUTPUT ${hwloc_targ_BINARY_DIR} /lib/libhwloc.a
335+ DEPENDS ${hwloc_targ_SOURCE_DIR} /lib/libhwloc.la)
336+
313337 add_custom_target (hwloc_prod
314- DEPENDS ${hwloc_targ_BINARY_DIR} /lib/hwloc.lib)
338+ DEPENDS ${hwloc_targ_BINARY_DIR} /lib/libhwloc.a)
339+ add_library (hwloc INTERFACE )
315340 target_link_libraries (
316- hwloc INTERFACE ${hwloc_targ_BINARY_DIR} /lib/hwloc.lib )
341+ hwloc INTERFACE ${hwloc_targ_BINARY_DIR} /lib/libhwloc.a )
317342 add_dependencies (hwloc hwloc_prod)
318343
319344 set (LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR} /lib)
320- set (LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR} /lib/hwloc.lib)
321- elseif (CMAKE_GENERATOR STREQUAL "NMake Makefiles" )
322- set (LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR} /)
323- set (LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR} /hwloc.lib)
324- else ()
325- set (LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR} /$<CONFIG>)
326- set (LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR} /$<CONFIG>/hwloc.lib)
345+ set (LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR} /include )
346+ set (LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR} /lib/libhwloc.a)
327347 endif ()
328-
329- set (LIBHWLOC_INCLUDE_DIRS
330- ${hwloc_targ_SOURCE_DIR} /include ;${hwloc_targ_BINARY_DIR} /include )
331- else ()
332- include (FetchContent)
333- message (
334- STATUS
335- "Will fetch hwloc from ${UMF_HWLOC_REPO} (tag: ${UMF_HWLOC_TAG} )"
336- )
337-
338- FetchContent_Declare(
339- hwloc_targ
340- GIT_REPOSITORY ${UMF_HWLOC_REPO}
341- GIT_TAG ${UMF_HWLOC_TAG} )
342- FetchContent_MakeAvailable(hwloc_targ)
343-
344- add_custom_command (
345- COMMAND ./autogen.sh
346- WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
347- OUTPUT ${hwloc_targ_SOURCE_DIR} /configure)
348- add_custom_command (
349- COMMAND
350- ./configure --prefix =${hwloc_targ_BINARY_DIR}
351- --enable-static =yes --enable-shared=no --disable-libxml2
352- --disable-pci --disable-levelzero --disable-opencl
353- --disable-cuda --disable-nvml --disable-libudev --disable-rsmi
354- CFLAGS=-fPIC CXXFLAGS=-fPIC
355- WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
356- OUTPUT ${hwloc_targ_SOURCE_DIR} /Makefile
357- DEPENDS ${hwloc_targ_SOURCE_DIR} /configure)
358- add_custom_command (
359- COMMAND make
360- WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
361- OUTPUT ${hwloc_targ_SOURCE_DIR} /lib/libhwloc.la
362- DEPENDS ${hwloc_targ_SOURCE_DIR} /Makefile)
363- add_custom_command (
364- COMMAND make install
365- WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
366- OUTPUT ${hwloc_targ_BINARY_DIR} /lib/libhwloc.a
367- DEPENDS ${hwloc_targ_SOURCE_DIR} /lib/libhwloc.la)
368-
369- add_custom_target (hwloc_prod
370- DEPENDS ${hwloc_targ_BINARY_DIR} /lib/libhwloc.a)
371- add_library (hwloc INTERFACE )
372- target_link_libraries (hwloc
373- INTERFACE ${hwloc_targ_BINARY_DIR} /lib/libhwloc.a)
374- add_dependencies (hwloc hwloc_prod)
375-
376- set (LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR} /lib)
377- set (LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR} /include )
378- set (LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR} /lib/libhwloc.a)
379- endif ()
348+ endif () # UMF_LINK_HWLOC_STATICALLY
380349
381350 message (STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES} " )
382351 message (STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS} " )
@@ -388,7 +357,7 @@ else()
388357endif ()
389358
390359if (hwloc_targ_SOURCE_DIR)
391- # apply security patch for HWLOC
360+ # Apply security patch for HWLOC
392361 execute_process (
393362 COMMAND git apply ${PROJECT_SOURCE_DIR} /cmake/fix_coverity_issues.patch
394363 WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
@@ -406,8 +375,6 @@ endif()
406375# Fetch L0 loader only if needed i.e.: if building L0 provider is ON and L0
407376# headers are not provided by the user (via setting UMF_LEVEL_ZERO_INCLUDE_DIR).
408377if (UMF_BUILD_LEVEL_ZERO_PROVIDER AND (NOT UMF_LEVEL_ZERO_INCLUDE_DIR))
409- include (FetchContent)
410-
411378 set (LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git" )
412379 set (LEVEL_ZERO_LOADER_TAG v1.20.2)
413380
@@ -436,8 +403,6 @@ endif()
436403# Fetch CUDA only if needed i.e.: if building CUDA provider is ON and CUDA
437404# headers are not provided by the user (via setting UMF_CUDA_INCLUDE_DIR).
438405if (UMF_BUILD_CUDA_PROVIDER AND (NOT UMF_CUDA_INCLUDE_DIR))
439- include (FetchContent)
440-
441406 set (CUDA_REPO
442407 "https://gitlab.com/nvidia/headers/cuda-individual/cudart.git" )
443408 set (CUDA_TAG cuda-12.5.1)
0 commit comments