Skip to content

Commit 8d372d1

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

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

CMakeLists.txt

Lines changed: 49 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,7 @@ 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 "Link UMF with HWLOC library statically (Windows+Release only)" OFF)
4046
option(UMF_DEVELOPER_MODE "Enable developer checks, treats warnings as errors"
4147
OFF)
4248
option(UMF_FORMAT_CODE_STYLE
@@ -83,6 +89,47 @@ else()
8389
message(FATAL_ERROR "Unknown OS type")
8490
endif()
8591

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

133-
include(CTest)
134-
include(CMakePackageConfigHelpers)
135-
include(GNUInstallDirs)
136-
find_package(PkgConfig)
137-
138180
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
139181
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
140182
set(CMAKE_UMF_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
@@ -179,7 +221,8 @@ if(WINDOWS)
179221
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
180222
# set PATH to DLLs on Windows
181223
set(DLL_PATH_LIST
182-
"PATH=path_list_append:${PROJECT_BINARY_DIR}/bin/$<CONFIG>")
224+
"${DLL_PATH_LIST};PATH=path_list_append:${PROJECT_BINARY_DIR}/bin/$<CONFIG>"
225+
)
183226
# add path to the proxy lib DLL
184227
set(DLL_PATH_LIST
185228
"${DLL_PATH_LIST};PATH=path_list_append:${PROJECT_BINARY_DIR}/src/proxy_lib"
@@ -190,14 +233,6 @@ if(WINDOWS)
190233
)
191234
endif()
192235

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-
201236
pkg_check_modules(TBB tbb)
202237
if(NOT TBB_FOUND)
203238
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

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
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})

0 commit comments

Comments
 (0)