Skip to content

Commit 2e09eeb

Browse files
authored
Merge pull request #534 from KFilipek/static_linking
Add static linking option
2 parents 3b00603 + ac1c9db commit 2e09eeb

File tree

5 files changed

+136
-21
lines changed

5 files changed

+136
-21
lines changed

.github/workflows/basic.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,76 @@ jobs:
228228
--umf-version ${{env.UMF_VERSION}}
229229
${{ matrix.shared_library == 'ON' && '--shared-library' || ''}}
230230
231+
windows-dynamic_build_hwloc:
232+
name: "Windows dynamic UMF + static hwloc"
233+
env:
234+
BUILD_DIR : "${{github.workspace}}/build/${{matrix.build_type}}"
235+
strategy:
236+
matrix:
237+
build_type: [Release]
238+
239+
runs-on: 'windows-2022'
240+
241+
steps:
242+
- name: Checkout
243+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
244+
245+
- name: Configure build
246+
run: >
247+
cmake
248+
-B ${{env.BUILD_DIR}}
249+
-DUMF_BUILD_SHARED_LIBRARY=ON
250+
-DUMF_BUILD_EXAMPLES=OFF
251+
-DUMF_FORMAT_CODE_STYLE=OFF
252+
-DUMF_DEVELOPER_MODE=ON
253+
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
254+
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
255+
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
256+
-DUMF_TESTS_FAIL_ON_SKIP=ON
257+
-DUMF_LINK_HWLOC_STATICALLY=ON
258+
259+
- name: Build UMF
260+
run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $Env:NUMBER_OF_PROCESSORS
261+
262+
- name: Run tests
263+
working-directory: ${{env.BUILD_DIR}}
264+
run: ctest -C ${{matrix.build_type}} --output-on-failure --test-dir test
265+
266+
windows-static_build_hwloc:
267+
name: "Windows static UMF + static hwloc"
268+
env:
269+
BUILD_DIR : "${{github.workspace}}/build/${{matrix.build_type}}"
270+
strategy:
271+
matrix:
272+
build_type: [Release]
273+
274+
runs-on: 'windows-2022'
275+
276+
steps:
277+
- name: Checkout
278+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
279+
280+
- name: Configure build
281+
run: >
282+
cmake
283+
-B ${{env.BUILD_DIR}}
284+
-DUMF_BUILD_SHARED_LIBRARY=OFF
285+
-DUMF_BUILD_EXAMPLES=OFF
286+
-DUMF_FORMAT_CODE_STYLE=OFF
287+
-DUMF_DEVELOPER_MODE=ON
288+
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
289+
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
290+
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
291+
-DUMF_TESTS_FAIL_ON_SKIP=ON
292+
-DUMF_LINK_HWLOC_STATICALLY=ON
293+
294+
- name: Build UMF
295+
run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $Env:NUMBER_OF_PROCESSORS
296+
297+
- name: Run tests
298+
working-directory: ${{env.BUILD_DIR}}
299+
run: ctest -C ${{matrix.build_type}} --output-on-failure --test-dir test
300+
231301
macos-build:
232302
name: MacOS
233303
strategy:

CMakeLists.txt

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ set(UMF_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
1414
list(APPEND CMAKE_MODULE_PATH "${UMF_CMAKE_SOURCE_DIR}/cmake")
1515
include(${UMF_CMAKE_SOURCE_DIR}/cmake/helpers.cmake)
1616

17+
include(CTest)
18+
include(CMakePackageConfigHelpers)
19+
include(GNUInstallDirs)
20+
find_package(PkgConfig)
21+
1722
# CMAKE_PROJECT_VERSION[_MAJOR|_MINOR|_PATCH] variables are set via 'project'
1823
# command. They cannot contain any "pre-release" part, though. We use custom
1924
# "UMF_SRC_VERSION" to store more accurate (source) version - this var should be
@@ -39,6 +44,8 @@ option(UMF_BUILD_EXAMPLES "Build UMF examples" ON)
3944
option(UMF_BUILD_FUZZTESTS "Build UMF fuzz tests" OFF)
4045
option(UMF_BUILD_GPU_EXAMPLES "Build UMF GPU examples" OFF)
4146
option(UMF_DEVELOPER_MODE "Enable additional developer checks" OFF)
47+
option(UMF_LINK_HWLOC_STATICALLY
48+
"Link UMF with HWLOC library statically (Windows+Release only)" OFF)
4249
option(UMF_FORMAT_CODE_STYLE
4350
"Add clang, cmake, and black -format-check and -format-apply targets"
4451
OFF)
@@ -83,6 +90,44 @@ else()
8390
message(FATAL_ERROR "Unknown OS type")
8491
endif()
8592

93+
if(NOT UMF_LINK_HWLOC_STATICALLY)
94+
pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
95+
if(NOT LIBHWLOC_FOUND)
96+
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
97+
endif()
98+
# add PATH to DLL on Windows
99+
set(DLL_PATH_LIST
100+
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
101+
)
102+
else()
103+
if(NOT WINDOWS)
104+
message(FATAL_ERROR "hwloc can be statically linked only on Windows")
105+
endif()
106+
include(FetchContent)
107+
set(HWLOC_ENABLE_TESTING OFF)
108+
set(HWLOC_SKIP_LSTOPO ON)
109+
set(HWLOC_SKIP_TOOLS ON)
110+
FetchContent_Declare(
111+
hwloc_targ
112+
GIT_REPOSITORY "https://github.com/open-mpi/hwloc.git"
113+
GIT_TAG hwloc-2.10.0
114+
SOURCE_SUBDIR contrib/windows-cmake/ FIND_PACKAGE_ARGS)
115+
116+
FetchContent_GetProperties(hwloc_targ)
117+
if(NOT hwloc_targ_POPULATED)
118+
FetchContent_MakeAvailable(hwloc_targ)
119+
endif()
120+
121+
set(LIBHWLOC_INCLUDE_DIRS
122+
${hwloc_targ_SOURCE_DIR}/include;${hwloc_targ_BINARY_DIR}/include)
123+
set(LIBHWLOC_LIBRARY_DIRS
124+
${hwloc_targ_BINARY_DIR}/Release;${hwloc_targ_BINARY_DIR}/Debug)
125+
126+
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
127+
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
128+
message(STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS}")
129+
endif()
130+
86131
# This build type check is not possible on Windows when CMAKE_BUILD_TYPE is not
87132
# set, because in this case the build type is determined after a CMake
88133
# configuration is done (at the build time)
@@ -130,11 +175,6 @@ foreach(option_name ${OPTIONS_REQUIRING_CXX})
130175
endif()
131176
endforeach()
132177

133-
include(CTest)
134-
include(CMakePackageConfigHelpers)
135-
include(GNUInstallDirs)
136-
find_package(PkgConfig)
137-
138178
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
139179
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
140180
set(CMAKE_UMF_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
@@ -186,7 +226,8 @@ if(WINDOWS)
186226
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
187227
# set PATH to DLLs on Windows
188228
set(DLL_PATH_LIST
189-
"PATH=path_list_append:${PROJECT_BINARY_DIR}/bin/$<CONFIG>")
229+
"${DLL_PATH_LIST};PATH=path_list_append:${PROJECT_BINARY_DIR}/bin/$<CONFIG>"
230+
)
190231
# add path to the proxy lib DLL
191232
set(DLL_PATH_LIST
192233
"${DLL_PATH_LIST};PATH=path_list_append:${PROJECT_BINARY_DIR}/src/proxy_lib"
@@ -197,14 +238,6 @@ if(WINDOWS)
197238
)
198239
endif()
199240

200-
pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
201-
if(NOT LIBHWLOC_FOUND)
202-
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
203-
endif()
204-
# add PATH to DLL on Windows
205-
set(DLL_PATH_LIST
206-
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin")
207-
208241
pkg_check_modules(TBB tbb)
209242
if(NOT TBB_FOUND)
210243
find_package(TBB OPTIONAL_COMPONENTS tbb)
@@ -240,10 +273,17 @@ if(WINDOWS)
240273
# In MSVC builds, there is no way to determine the actual build type during
241274
# the CMake configuration step. Therefore, this message is printed in all
242275
# MSVC builds.
243-
message(
244-
STATUS
245-
"The proxy library will be built, however it is supported only in the Release build on Windows"
246-
)
276+
if(UMF_LINK_HWLOC_STATICALLY)
277+
message(
278+
STATUS
279+
"The proxy library will be disabled - static linkage with hwloc is not supported yet"
280+
)
281+
else()
282+
message(
283+
STATUS
284+
"The proxy library will be built, however it is supported only in the Release build on Windows"
285+
)
286+
endif()
247287
endif()
248288
if(UMF_PROXY_LIB_BASED_ON_POOL STREQUAL SCALABLE)
249289
if(UMF_POOL_SCALABLE_ENABLED)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ List of options provided by CMake:
127127
| USE_MSAN | Enable MemorySanitizer checks | ON/OFF | OFF |
128128
| USE_VALGRIND | Enable Valgrind instrumentation | ON/OFF | OFF |
129129
| USE_GCOV | Enable gcov support (Linux only) | ON/OFF | OFF |
130+
| UMF_LINK_HWLOC_STATICALLY | Link UMF with HWLOC library statically (Windows+Release only) | ON/OFF | OFF |
130131

131132
## Architecture: memory pools and providers
132133

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set(EXAMPLE_NAME umf_example_basic)
1818
add_umf_executable(
1919
NAME ${EXAMPLE_NAME}
2020
SRCS basic/basic.c
21-
LIBS umf)
21+
LIBS umf hwloc)
2222

2323
target_include_directories(
2424
${EXAMPLE_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils

src/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ if(UMF_BUILD_SHARED_LIBRARY)
115115
NAME umf
116116
TYPE SHARED
117117
SRCS ${UMF_SOURCES}
118-
LIBS ${UMF_LIBS}
118+
LIBS ${UMF_LIBS} hwloc
119119
LINUX_MAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libumf.map
120120
WINDOWS_DEF_FILE ${CMAKE_CURRENT_BINARY_DIR}/libumf.def)
121121
set(UMF_PRIVATE_COMPILE_DEFINITIONS ${UMF_PRIVATE_COMPILE_DEFINITIONS}
@@ -133,6 +133,10 @@ else()
133133
LIBS ${UMF_LIBS})
134134
endif()
135135

136+
if(UMF_LINK_HWLOC_STATICALLY)
137+
add_dependencies(umf hwloc)
138+
endif()
139+
136140
target_link_directories(umf PRIVATE ${UMF_PRIVATE_LIBRARY_DIRS})
137141

138142
target_compile_definitions(umf PRIVATE ${UMF_PRIVATE_COMPILE_DEFINITIONS})
@@ -176,6 +180,6 @@ install(TARGETS umf EXPORT ${PROJECT_NAME}-targets)
176180

177181
add_subdirectory(pool)
178182

179-
if(UMF_PROXY_LIB_ENABLED)
183+
if(UMF_PROXY_LIB_ENABLED AND NOT UMF_LINK_HWLOC_STATICALLY)
180184
add_subdirectory(proxy_lib)
181185
endif()

0 commit comments

Comments
 (0)