Skip to content

Commit 88d39e0

Browse files
igchorKFilipek
andcommitted
Add option to link with hwloc statically on linux
Co-authored-by: Krzysztof Filipek <[email protected]>
1 parent 9a96626 commit 88d39e0

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

.github/workflows/basic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ jobs:
349349
run: python3 -m pip install -r third_party/requirements.txt
350350

351351
- name: Install hwloc
352-
run: brew install hwloc jemalloc tbb
352+
run: brew install hwloc jemalloc tbb automake
353353

354354
- name: Configure build
355355
run: >

CMakeLists.txt

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ if(NOT UMF_LINK_HWLOC_STATICALLY)
110110
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
111111
)
112112
endif()
113-
else()
114-
if(NOT WINDOWS)
115-
message(FATAL_ERROR "hwloc can be statically linked only on Windows")
116-
endif()
113+
# add PATH to DLL on Windows
114+
set(DLL_PATH_LIST
115+
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
116+
)
117+
elseif(WINDOWS)
117118
include(FetchContent)
118119
set(HWLOC_ENABLE_TESTING OFF)
119120
set(HWLOC_SKIP_LSTOPO ON)
@@ -137,6 +138,46 @@ else()
137138
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
138139
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
139140
message(STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS}")
141+
else()
142+
include(FetchContent)
143+
FetchContent_Declare(
144+
hwloc_targ
145+
GIT_REPOSITORY "https://github.com/open-mpi/hwloc.git"
146+
GIT_TAG hwloc-2.10.0)
147+
148+
FetchContent_GetProperties(hwloc_targ)
149+
if(NOT hwloc_targ_POPULATED)
150+
FetchContent_MakeAvailable(hwloc_targ)
151+
endif()
152+
153+
add_custom_command(
154+
COMMAND ./autogen.sh
155+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
156+
OUTPUT ${hwloc_targ_SOURCE_DIR}/configure)
157+
add_custom_command(
158+
COMMAND
159+
./configure --prefix=${hwloc_targ_BINARY_DIR} --enable-static=yes
160+
--enable-shared=no --disable-libxml2 --disable-levelzero
161+
CFLAGS=-fPIC CXXFLAGS=-fPIC
162+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
163+
OUTPUT ${hwloc_targ_SOURCE_DIR}/Makefile
164+
DEPENDS ${hwloc_targ_SOURCE_DIR}/configure)
165+
add_custom_command(
166+
COMMAND make
167+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
168+
OUTPUT ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la
169+
DEPENDS ${hwloc_targ_SOURCE_DIR}/Makefile)
170+
add_custom_command(
171+
COMMAND make install
172+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
173+
OUTPUT ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a
174+
DEPENDS ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la)
175+
176+
add_custom_target(hwloc DEPENDS ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
177+
178+
set(LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR}/lib)
179+
set(LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR}/include)
180+
set(LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
140181
endif()
141182

142183
# This build type check is not possible on Windows when CMAKE_BUILD_TYPE is not

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ elseif(MACOSX)
132132
endif()
133133

134134
if(UMF_BUILD_SHARED_LIBRARY)
135-
if(NOT UMF_DISABLE_HWLOC)
135+
if(NOT UMF_DISABLE_HWLOC AND NOT UMF_LINK_HWLOC_STATICALLY)
136136
set(HWLOC_LIB hwloc)
137137
endif()
138138
add_umf_library(

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ add_umf_test(
271271
# tests for the proxy library
272272
if(UMF_PROXY_LIB_ENABLED
273273
AND UMF_BUILD_SHARED_LIBRARY
274-
AND NOT UMF_DISABLE_HWLOC)
274+
AND NOT UMF_DISABLE_HWLOC
275+
AND NOT UMF_LINK_HWLOC_STATICALLY)
275276
add_umf_test(
276277
NAME proxy_lib_basic
277278
SRCS ${BA_SOURCES_FOR_TEST} test_proxy_lib.cpp

0 commit comments

Comments
 (0)