Skip to content

Commit a0ecaa3

Browse files
committed
Add static linking option
1 parent 2a0dc99 commit a0ecaa3

File tree

5 files changed

+125
-16
lines changed

5 files changed

+125
-16
lines changed

.github/workflows/basic.yml

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

CMakeLists.txt

Lines changed: 46 additions & 14 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
@@ -37,6 +42,8 @@ option(UMF_BUILD_BENCHMARKS "Build UMF benchmarks" OFF)
3742
option(UMF_BUILD_BENCHMARKS_MT "Build UMF multithreaded benchmarks" OFF)
3843
option(UMF_BUILD_EXAMPLES "Build UMF examples" ON)
3944
option(UMF_BUILD_GPU_EXAMPLES "Build UMF GPU examples" OFF)
45+
option(UMF_LINK_HWLOC_STATICALLY
46+
"Link UMF with HWLOC library statically (Windows+Release only)" OFF)
4047
option(UMF_DEVELOPER_MODE "Enable developer checks, treats warnings as errors"
4148
OFF)
4249
option(UMF_FORMAT_CODE_STYLE
@@ -83,6 +90,43 @@ 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/
115+
FIND_PACKAGE_ARGS)
116+
117+
FetchContent_GetProperties(hwloc_targ)
118+
if(NOT hwloc_targ_POPULATED)
119+
FetchContent_MakeAvailable(hwloc_targ)
120+
endif()
121+
122+
set(LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_SOURCE_DIR}/include;${hwloc_targ_BINARY_DIR}/include)
123+
set(LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_SOURCE_DIR}/Release;${hwloc_targ_SOURCE_DIR}/Debug)
124+
125+
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
126+
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
127+
message(STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS}")
128+
endif()
129+
86130
# This build type check is not possible on Windows when CMAKE_BUILD_TYPE is not
87131
# set, because in this case the build type is determined after a CMake
88132
# configuration is done (at the build time)
@@ -130,11 +174,6 @@ foreach(option_name ${OPTIONS_REQUIRING_CXX})
130174
endif()
131175
endforeach()
132176

133-
include(CTest)
134-
include(CMakePackageConfigHelpers)
135-
include(GNUInstallDirs)
136-
find_package(PkgConfig)
137-
138177
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
139178
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
140179
set(CMAKE_UMF_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
@@ -179,7 +218,8 @@ if(WINDOWS)
179218
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
180219
# set PATH to DLLs on Windows
181220
set(DLL_PATH_LIST
182-
"PATH=path_list_append:${PROJECT_BINARY_DIR}/bin/$<CONFIG>")
221+
"${DLL_PATH_LIST};PATH=path_list_append:${PROJECT_BINARY_DIR}/bin/$<CONFIG>"
222+
)
183223
# add path to the proxy lib DLL
184224
set(DLL_PATH_LIST
185225
"${DLL_PATH_LIST};PATH=path_list_append:${PROJECT_BINARY_DIR}/src/proxy_lib"
@@ -190,14 +230,6 @@ if(WINDOWS)
190230
)
191231
endif()
192232

193-
pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
194-
if(NOT LIBHWLOC_FOUND)
195-
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
196-
endif()
197-
# add PATH to DLL on Windows
198-
set(DLL_PATH_LIST
199-
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin")
200-
201233
pkg_check_modules(TBB tbb)
202234
if(NOT TBB_FOUND)
203235
find_package(TBB OPTIONAL_COMPONENTS tbb)

README.md

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

130131
## Architecture: memory pools and providers
131132

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ else()
131131
LIBS ${UMF_LIBS})
132132
endif()
133133

134+
if(UMF_LINK_HWLOC_STATICALLY)
135+
add_dependencies(umf hwloc)
136+
endif()
137+
134138
target_link_directories(umf PRIVATE ${UMF_PRIVATE_LIBRARY_DIRS})
135139

136140
target_compile_definitions(umf PRIVATE ${UMF_PRIVATE_COMPILE_DEFINITIONS})
@@ -174,6 +178,6 @@ install(TARGETS umf EXPORT ${PROJECT_NAME}-targets)
174178

175179
add_subdirectory(pool)
176180

177-
if(UMF_PROXY_LIB_ENABLED)
181+
if(UMF_PROXY_LIB_ENABLED AND NOT UMF_LINK_HWLOC_STATICALLY)
178182
add_subdirectory(proxy_lib)
179183
endif()

0 commit comments

Comments
 (0)