Skip to content

Commit b57e557

Browse files
wenju-heclaude
andauthored
Propagate CMAKE_SYSROOT/gcc-toolchain into hwloc's autotools CC/CXX (#1597)
PR #1585 forwards CC=${CMAKE_C_COMPILER}/CXX=${CMAKE_CXX_COMPILER} into hwloc's ExternalProject_Add autogen.sh/configure invocation, but those are bare compiler paths with no notion of CMAKE_SYSROOT or CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN. When UMF_LINK_HWLOC_STATICALLY is combined with a sysroot- or toolchain-file-pinned compiler, hwloc still ends up built against the host's headers/libs instead of the sysroot's, which can produce ABI mismatches (e.g. undefined glibc symbols) at final link time. CC/CXX are passed to autotools as space-separated "compiler [flags...]" strings (the same convention as CC="ccache gcc"), so --sysroot and --gcc-toolchain can be appended directly without needing wrapper scripts or touching CMAKE_C_COMPILER/CMAKE_CXX_COMPILER themselves. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 2c4fd67 commit b57e557

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,25 @@ if(UMF_LINK_HWLOC_STATICALLY)
329329
# ./configure invocation below, so hwloc would otherwise be built with
330330
# the ambient host compiler instead of the one CMake was configured to
331331
# use (e.g. a sysroot- or toolchain-file-pinned compiler), causing an
332-
# ABI mismatch against the rest of the build.
332+
# ABI mismatch against the rest of the build. CC/CXX are passed as
333+
# space-separated "compiler [flags...]" strings (like CC="ccache gcc"),
334+
# so --sysroot/--gcc-toolchain can be appended directly; make
335+
# word-splits them unquoted when invoking the compiler.
336+
set(UMF_HWLOC_CC "${CMAKE_C_COMPILER}")
337+
set(UMF_HWLOC_CXX "${CMAKE_CXX_COMPILER}")
338+
if(CMAKE_SYSROOT)
339+
string(APPEND UMF_HWLOC_CC " --sysroot=${CMAKE_SYSROOT}")
340+
string(APPEND UMF_HWLOC_CXX " --sysroot=${CMAKE_SYSROOT}")
341+
endif()
342+
if(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN)
343+
string(APPEND UMF_HWLOC_CC
344+
" --gcc-toolchain=${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}")
345+
endif()
346+
if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
347+
string(APPEND UMF_HWLOC_CXX
348+
" --gcc-toolchain=${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
349+
endif()
350+
333351
ExternalProject_Add(
334352
hwloc_targ
335353
PREFIX ${hwloc_targ_PREFIX}
@@ -338,11 +356,11 @@ if(UMF_LINK_HWLOC_STATICALLY)
338356
UPDATE_DISCONNECTED TRUE
339357
PATCH_COMMAND git apply
340358
${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
359+
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env "CC=${UMF_HWLOC_CC}"
360+
"CXX=${UMF_HWLOC_CXX}" <SOURCE_DIR>/autogen.sh
343361
COMMAND
344-
${CMAKE_COMMAND} -E env CC=${CMAKE_C_COMPILER}
345-
CXX=${CMAKE_CXX_COMPILER} <SOURCE_DIR>/configure
362+
${CMAKE_COMMAND} -E env "CC=${UMF_HWLOC_CC}"
363+
"CXX=${UMF_HWLOC_CXX}" <SOURCE_DIR>/configure
346364
--prefix=<INSTALL_DIR> --enable-static=yes --enable-shared=no
347365
--disable-libxml2 --disable-pci --disable-levelzero
348366
--disable-opencl --disable-cuda --disable-nvml --disable-libudev

0 commit comments

Comments
 (0)