Skip to content

Commit daffca6

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

File tree

3 files changed

+63
-10
lines changed

3 files changed

+63
-10
lines changed

.github/workflows/basic.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
--build-type ${{matrix.build_type}}
154154
--disjoint-pool
155155
--jemalloc-pool
156-
${{ matrix.install_tbb == 'ON' && matrix.disable_hwloc != 'ON' && '--proxy' || '' }}
156+
${{ matrix.install_tbb == 'ON' && matrix.disable_hwloc != 'ON' && matrix.link_hwloc_statically != 'ON' && '--proxy' || '' }}
157157
--umf-version ${{env.UMF_VERSION}}
158158
${{ matrix.shared_library == 'ON' && '--shared-library' || '' }}
159159
@@ -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 autoconf automake libtool
353353

354354
- name: Configure build
355355
run: >
@@ -376,6 +376,6 @@ jobs:
376376
--build-type ${{env.BUILD_TYPE}}
377377
--disjoint-pool
378378
--jemalloc-pool
379-
--proxy
379+
${{ matrix.link_hwloc_statically != 'ON' && '--proxy' || '' }}
380380
--umf-version ${{env.UMF_VERSION}}
381381
--shared-library

CMakeLists.txt

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ option(UMF_BUILD_EXAMPLES "Build UMF examples" ON)
4848
option(UMF_BUILD_FUZZTESTS "Build UMF fuzz tests" OFF)
4949
option(UMF_BUILD_GPU_EXAMPLES "Build UMF GPU examples" OFF)
5050
option(UMF_DEVELOPER_MODE "Enable additional developer checks" OFF)
51-
option(UMF_LINK_HWLOC_STATICALLY
52-
"Link UMF with HWLOC library statically (Windows+Release only)" OFF)
51+
option(
52+
UMF_LINK_HWLOC_STATICALLY
53+
"Link UMF with HWLOC library statically (supported for Linux, MacOS and Release build on Windows)"
54+
OFF)
5355
option(UMF_FORMAT_CODE_STYLE
5456
"Add clang, cmake, and black -format-check and -format-apply targets"
5557
OFF)
@@ -110,10 +112,11 @@ if(NOT UMF_LINK_HWLOC_STATICALLY)
110112
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
111113
)
112114
endif()
113-
else()
114-
if(NOT WINDOWS)
115-
message(FATAL_ERROR "hwloc can be statically linked only on Windows")
116-
endif()
115+
# add PATH to DLL on Windows
116+
set(DLL_PATH_LIST
117+
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
118+
)
119+
elseif(WINDOWS)
117120
include(FetchContent)
118121
set(HWLOC_ENABLE_TESTING OFF)
119122
set(HWLOC_SKIP_LSTOPO ON)
@@ -134,6 +137,55 @@ else()
134137
set(LIBHWLOC_LIBRARY_DIRS
135138
${hwloc_targ_BINARY_DIR}/Release;${hwloc_targ_BINARY_DIR}/Debug)
136139

140+
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
141+
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
142+
message(STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS}")
143+
else()
144+
include(FetchContent)
145+
FetchContent_Declare(
146+
hwloc_targ
147+
GIT_REPOSITORY "https://github.com/open-mpi/hwloc.git"
148+
GIT_TAG hwloc-2.10.0)
149+
150+
FetchContent_GetProperties(hwloc_targ)
151+
if(NOT hwloc_targ_POPULATED)
152+
FetchContent_MakeAvailable(hwloc_targ)
153+
endif()
154+
155+
add_custom_command(
156+
COMMAND ./autogen.sh
157+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
158+
OUTPUT ${hwloc_targ_SOURCE_DIR}/configure)
159+
add_custom_command(
160+
COMMAND
161+
./configure --prefix=${hwloc_targ_BINARY_DIR} --enable-static=yes
162+
--enable-shared=no --disable-libxml2 --disable-levelzero
163+
CFLAGS=-fPIC CXXFLAGS=-fPIC
164+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
165+
OUTPUT ${hwloc_targ_SOURCE_DIR}/Makefile
166+
DEPENDS ${hwloc_targ_SOURCE_DIR}/configure)
167+
add_custom_command(
168+
COMMAND make
169+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
170+
OUTPUT ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la
171+
DEPENDS ${hwloc_targ_SOURCE_DIR}/Makefile)
172+
add_custom_command(
173+
COMMAND make install
174+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
175+
OUTPUT ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a
176+
DEPENDS ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la)
177+
178+
add_custom_target(hwloc_prod
179+
DEPENDS ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
180+
add_library(hwloc INTERFACE)
181+
target_link_libraries(hwloc
182+
INTERFACE ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
183+
add_dependencies(hwloc hwloc_prod)
184+
185+
set(LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR}/lib)
186+
set(LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR}/include)
187+
set(LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
188+
137189
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
138190
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
139191
message(STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS}")

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ add_umf_test(
267267
# tests for the proxy library
268268
if(UMF_PROXY_LIB_ENABLED
269269
AND UMF_BUILD_SHARED_LIBRARY
270-
AND NOT UMF_DISABLE_HWLOC)
270+
AND NOT UMF_DISABLE_HWLOC
271+
AND NOT UMF_LINK_HWLOC_STATICALLY)
271272
add_umf_test(
272273
NAME proxy_lib_basic
273274
SRCS ${BA_SOURCES_FOR_TEST} test_proxy_lib.cpp

0 commit comments

Comments
 (0)