Skip to content

Commit a190c7c

Browse files
Merge pull request #1585 from wenju-he/hwloc-external-project-add
Build hwloc via ExternalProject_Add instead of raw add_custom_command
2 parents a81e75d + fd1f68d commit a190c7c

1 file changed

Lines changed: 34 additions & 32 deletions

File tree

CMakeLists.txt

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -319,43 +319,43 @@ if(UMF_LINK_HWLOC_STATICALLY)
319319
"Either install it, or set UMF_LINK_HWLOC_STATICALLY=OFF and install hwloc >= 2.3.0 in your system."
320320
)
321321
endif()
322-
FetchContent_Declare(
322+
include(ExternalProject)
323+
324+
set(hwloc_targ_PREFIX ${CMAKE_BINARY_DIR}/hwloc_targ-prefix)
325+
set(hwloc_targ_SOURCE_DIR ${hwloc_targ_PREFIX}/src/hwloc_targ)
326+
set(hwloc_targ_BINARY_DIR ${hwloc_targ_PREFIX})
327+
328+
# CC/CXX/CFLAGS/CXXFLAGS are not forwarded by CMake into the autotools
329+
# ./configure invocation below, so hwloc would otherwise be built with
330+
# the ambient host compiler instead of the one CMake was configured to
331+
# use (e.g. a sysroot- or toolchain-file-pinned compiler), causing an
332+
# ABI mismatch against the rest of the build.
333+
ExternalProject_Add(
323334
hwloc_targ
335+
PREFIX ${hwloc_targ_PREFIX}
324336
GIT_REPOSITORY ${UMF_HWLOC_REPO}
325-
GIT_TAG ${UMF_HWLOC_TAG})
326-
FetchContent_MakeAvailable(hwloc_targ)
327-
328-
add_custom_command(
329-
COMMAND ./autogen.sh
330-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
331-
OUTPUT ${hwloc_targ_SOURCE_DIR}/configure)
332-
add_custom_command(
337+
GIT_TAG ${UMF_HWLOC_TAG}
338+
UPDATE_DISCONNECTED TRUE
339+
PATCH_COMMAND git apply
340+
${PROJECT_SOURCE_DIR}/cmake/fix_coverity_issues.patch
341+
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env CC=${CMAKE_C_COMPILER}
342+
CXX=${CMAKE_CXX_COMPILER} <SOURCE_DIR>/autogen.sh
333343
COMMAND
334-
./configure --prefix=${hwloc_targ_BINARY_DIR}
335-
--enable-static=yes --enable-shared=no --disable-libxml2
336-
--disable-pci --disable-levelzero --disable-opencl
337-
--disable-cuda --disable-nvml --disable-libudev --disable-rsmi
338-
CFLAGS=-fPIC CXXFLAGS=-fPIC
339-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
340-
OUTPUT ${hwloc_targ_SOURCE_DIR}/Makefile
341-
DEPENDS ${hwloc_targ_SOURCE_DIR}/configure)
342-
add_custom_command(
343-
COMMAND make
344-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
345-
OUTPUT ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la
346-
DEPENDS ${hwloc_targ_SOURCE_DIR}/Makefile)
347-
add_custom_command(
348-
COMMAND make install
349-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
350-
OUTPUT ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a
351-
DEPENDS ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la)
344+
${CMAKE_COMMAND} -E env CC=${CMAKE_C_COMPILER}
345+
CXX=${CMAKE_CXX_COMPILER} <SOURCE_DIR>/configure
346+
--prefix=<INSTALL_DIR> --enable-static=yes --enable-shared=no
347+
--disable-libxml2 --disable-pci --disable-levelzero
348+
--disable-opencl --disable-cuda --disable-nvml --disable-libudev
349+
--disable-rsmi CFLAGS=-fPIC CXXFLAGS=-fPIC
350+
BUILD_COMMAND make
351+
BUILD_IN_SOURCE TRUE
352+
INSTALL_COMMAND make install
353+
BUILD_BYPRODUCTS <INSTALL_DIR>/lib/libhwloc.a)
352354

353-
add_custom_target(hwloc_prod
354-
DEPENDS ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
355355
add_library(hwloc INTERFACE)
356356
target_link_libraries(hwloc
357357
INTERFACE ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
358-
add_dependencies(hwloc hwloc_prod)
358+
add_dependencies(hwloc hwloc_targ)
359359

360360
set(LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR}/lib)
361361
set(LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR}/include)
@@ -372,8 +372,10 @@ if(WINDOWS)
372372
message(STATUS " LIBHWLOC_DLL_DIRS = ${LIBHWLOC_DLL_DIRS}")
373373
endif()
374374

375-
if(hwloc_targ_SOURCE_DIR)
376-
# Apply security patch for HWLOC
375+
if(WINDOWS AND hwloc_targ_SOURCE_DIR)
376+
# Apply security patch for HWLOC. On non-Windows this is applied via
377+
# ExternalProject_Add's PATCH_COMMAND instead, since that source tree is
378+
# only populated at build time, not at configure time.
377379
execute_process(
378380
COMMAND git apply ${PROJECT_SOURCE_DIR}/cmake/fix_coverity_issues.patch
379381
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}

0 commit comments

Comments
 (0)