Skip to content

Commit 148a837

Browse files
authored
Merge pull request #641 from igchor/hwloc_static
Add option to link statically with hwloc on linux
2 parents 9a96626 + b32b89a commit 148a837

File tree

3 files changed

+86
-11
lines changed

3 files changed

+86
-11
lines changed

.github/workflows/basic.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
level_zero_provider: ['ON']
2525
install_tbb: ['ON']
2626
disable_hwloc: ['OFF']
27+
link_hwloc_statically: ['OFF']
2728
include:
2829
- os: 'ubuntu-20.04'
2930
build_type: Release
@@ -71,12 +72,19 @@ jobs:
7172
level_zero_provider: 'ON'
7273
install_tbb: 'OFF'
7374
- os: 'ubuntu-22.04'
74-
build_type: Release
75+
build_type: Debug
7576
compiler: {c: gcc, cxx: g++}
7677
shared_library: 'ON'
7778
level_zero_provider: 'ON'
7879
install_tbb: 'ON'
7980
disable_hwloc: 'ON'
81+
- os: 'ubuntu-22.04'
82+
build_type: Release
83+
compiler: {c: gcc, cxx: g++}
84+
shared_library: 'ON'
85+
level_zero_provider: 'ON'
86+
install_tbb: 'ON'
87+
link_hwloc_statically: 'ON'
8088
runs-on: ${{matrix.os}}
8189

8290
steps:
@@ -131,6 +139,7 @@ jobs:
131139
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
132140
-DUMF_TESTS_FAIL_ON_SKIP=ON
133141
-DUMF_DISABLE_HWLOC=${{matrix.disable_hwloc}}
142+
-DUMF_LINK_HWLOC_STATICALLY=${{matrix.link_hwloc_statically}}
134143
135144
- name: Build UMF
136145
run: cmake --build ${{env.BUILD_DIR}} -j $(nproc)
@@ -153,7 +162,7 @@ jobs:
153162
--build-type ${{matrix.build_type}}
154163
--disjoint-pool
155164
--jemalloc-pool
156-
${{ matrix.install_tbb == 'ON' && matrix.disable_hwloc != 'ON' && '--proxy' || '' }}
165+
${{ matrix.install_tbb == 'ON' && matrix.disable_hwloc != 'ON' && matrix.link_hwloc_statically != 'ON' && '--proxy' || '' }}
157166
--umf-version ${{env.UMF_VERSION}}
158167
${{ matrix.shared_library == 'ON' && '--shared-library' || '' }}
159168

CMakeLists.txt

Lines changed: 73 additions & 8 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)
@@ -98,6 +100,14 @@ else()
98100
message(FATAL_ERROR "Unknown OS type")
99101
endif()
100102

103+
if(NOT DEFINED UMF_HWLOC_REPO)
104+
set(UMF_HWLOC_REPO "https://github.com/open-mpi/hwloc.git")
105+
endif()
106+
107+
if(NOT DEFINED UMF_HWLOC_TAG)
108+
set(UMF_HWLOC_TAG hwloc-2.10.0)
109+
endif()
110+
101111
if(NOT UMF_LINK_HWLOC_STATICALLY)
102112
if(NOT UMF_DISABLE_HWLOC)
103113
pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
@@ -110,18 +120,22 @@ if(NOT UMF_LINK_HWLOC_STATICALLY)
110120
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
111121
)
112122
endif()
113-
else()
114-
if(NOT WINDOWS)
115-
message(FATAL_ERROR "hwloc can be statically linked only on Windows")
116-
endif()
123+
# add PATH to DLL on Windows
124+
set(DLL_PATH_LIST
125+
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
126+
)
127+
elseif(WINDOWS)
117128
include(FetchContent)
118129
set(HWLOC_ENABLE_TESTING OFF)
119130
set(HWLOC_SKIP_LSTOPO ON)
120131
set(HWLOC_SKIP_TOOLS ON)
132+
133+
message(STATUS "Will fetch hwloc from ${UMF_HWLOC_REPO}")
134+
121135
FetchContent_Declare(
122136
hwloc_targ
123-
GIT_REPOSITORY "https://github.com/open-mpi/hwloc.git"
124-
GIT_TAG hwloc-2.10.0
137+
GIT_REPOSITORY ${UMF_HWLOC_REPO}
138+
GIT_TAG ${UMF_HWLOC_TAG}
125139
SOURCE_SUBDIR contrib/windows-cmake/ FIND_PACKAGE_ARGS)
126140

127141
FetchContent_GetProperties(hwloc_targ)
@@ -134,6 +148,57 @@ else()
134148
set(LIBHWLOC_LIBRARY_DIRS
135149
${hwloc_targ_BINARY_DIR}/Release;${hwloc_targ_BINARY_DIR}/Debug)
136150

151+
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
152+
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
153+
message(STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS}")
154+
else()
155+
include(FetchContent)
156+
message(STATUS "Will fetch hwloc from ${UMF_HWLOC_REPO}")
157+
158+
FetchContent_Declare(
159+
hwloc_targ
160+
GIT_REPOSITORY ${UMF_HWLOC_REPO}
161+
GIT_TAG ${UMF_HWLOC_TAG})
162+
163+
FetchContent_GetProperties(hwloc_targ)
164+
if(NOT hwloc_targ_POPULATED)
165+
FetchContent_MakeAvailable(hwloc_targ)
166+
endif()
167+
168+
add_custom_command(
169+
COMMAND ./autogen.sh
170+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
171+
OUTPUT ${hwloc_targ_SOURCE_DIR}/configure)
172+
add_custom_command(
173+
COMMAND
174+
./configure --prefix=${hwloc_targ_BINARY_DIR} --enable-static=yes
175+
--enable-shared=no --disable-libxml2 --disable-levelzero
176+
CFLAGS=-fPIC CXXFLAGS=-fPIC
177+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
178+
OUTPUT ${hwloc_targ_SOURCE_DIR}/Makefile
179+
DEPENDS ${hwloc_targ_SOURCE_DIR}/configure)
180+
add_custom_command(
181+
COMMAND make
182+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
183+
OUTPUT ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la
184+
DEPENDS ${hwloc_targ_SOURCE_DIR}/Makefile)
185+
add_custom_command(
186+
COMMAND make install
187+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
188+
OUTPUT ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a
189+
DEPENDS ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la)
190+
191+
add_custom_target(hwloc_prod
192+
DEPENDS ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
193+
add_library(hwloc INTERFACE)
194+
target_link_libraries(hwloc
195+
INTERFACE ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
196+
add_dependencies(hwloc hwloc_prod)
197+
198+
set(LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR}/lib)
199+
set(LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR}/include)
200+
set(LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
201+
137202
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
138203
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
139204
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
@@ -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)