@@ -7,7 +7,8 @@ cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
77set (UMF_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
88
99list (APPEND CMAKE_MODULE_PATH "${UMF_CMAKE_SOURCE_DIR} /cmake" )
10- include (helpers)
10+ # Use full path of the helpers module (to omit potential conflicts with others)
11+ include (${UMF_CMAKE_SOURCE_DIR} /cmake/helpers.cmake)
1112
1213# We use semver aligned version, set via git tags. We parse git output to
1314# establih the version of UMF to be used in CMake, Win dll's, and within the
@@ -47,8 +48,10 @@ option(UMF_BUILD_EXAMPLES "Build UMF examples" ON)
4748option (UMF_BUILD_FUZZTESTS "Build UMF fuzz tests" OFF )
4849option (UMF_BUILD_GPU_EXAMPLES "Build UMF GPU examples" OFF )
4950option (UMF_DEVELOPER_MODE "Enable additional developer checks" OFF )
50- option (UMF_LINK_HWLOC_STATICALLY
51- "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 )
5255option (UMF_FORMAT_CODE_STYLE
5356 "Add clang, cmake, and black -format-check and -format-apply targets"
5457 OFF )
@@ -60,6 +63,10 @@ option(USE_TSAN "Enable ThreadSanitizer checks" OFF)
6063option (USE_MSAN "Enable MemorySanitizer checks" OFF )
6164option (USE_VALGRIND "Enable Valgrind instrumentation" OFF )
6265option (USE_GCOV "Enable gcov support" OFF )
66+ option (
67+ UMF_DISABLE_HWLOC
68+ "Disable features that requires hwloc (OS provider, memory targets, topolgy discovery)"
69+ OFF )
6370
6471# set UMF_PROXY_LIB_BASED_ON_POOL to one of: SCALABLE or JEMALLOC
6572set (KNOWN_PROXY_LIB_POOLS SCALABLE JEMALLOC)
@@ -93,27 +100,42 @@ else()
93100 message (FATAL_ERROR "Unknown OS type" )
94101endif ()
95102
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+
96111if (NOT UMF_LINK_HWLOC_STATICALLY)
97- pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
98- if (NOT LIBHWLOC_FOUND)
99- find_package (LIBHWLOC 2.3.0 REQUIRED hwloc)
112+ if (NOT UMF_DISABLE_HWLOC)
113+ pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
114+ if (NOT LIBHWLOC_FOUND)
115+ find_package (LIBHWLOC 2.3.0 REQUIRED hwloc)
116+ endif ()
117+
118+ # add PATH to DLL on Windows
119+ set (DLL_PATH_LIST
120+ "${DLL_PATH_LIST} ;PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS} /../bin"
121+ )
100122 endif ()
101123 # add PATH to DLL on Windows
102124 set (DLL_PATH_LIST
103125 "${DLL_PATH_LIST} ;PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS} /../bin"
104126 )
105- else ()
106- if (NOT WINDOWS)
107- message (FATAL_ERROR "hwloc can be statically linked only on Windows" )
108- endif ()
127+ elseif (WINDOWS AND NOT UMF_DISABLE_HWLOC)
109128 include (FetchContent)
110129 set (HWLOC_ENABLE_TESTING OFF )
111130 set (HWLOC_SKIP_LSTOPO ON )
112131 set (HWLOC_SKIP_TOOLS ON )
132+
133+ message (STATUS "Will fetch hwloc from ${UMF_HWLOC_REPO} " )
134+
113135 FetchContent_Declare(
114136 hwloc_targ
115- GIT_REPOSITORY "https://github.com/open-mpi/hwloc.git"
116- GIT_TAG hwloc-2.10.0
137+ GIT_REPOSITORY ${UMF_HWLOC_REPO}
138+ GIT_TAG ${UMF_HWLOC_TAG}
117139 SOURCE_SUBDIR contrib/windows-cmake/ FIND_PACKAGE_ARGS)
118140
119141 FetchContent_GetProperties(hwloc_targ)
@@ -126,6 +148,57 @@ else()
126148 set (LIBHWLOC_LIBRARY_DIRS
127149 ${hwloc_targ_BINARY_DIR} /Release;${hwloc_targ_BINARY_DIR} /Debug)
128150
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+ elseif (NOT UMF_DISABLE_HWLOC)
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+
129202 message (STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES} " )
130203 message (STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS} " )
131204 message (STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS} " )
@@ -317,6 +390,18 @@ else()
317390 )
318391endif ()
319392
393+ set (UMF_OPTIONAL_SYMBOLS_LINUX "" )
394+ set (UMF_OPTIONAL_SYMBOLS_WINDOWS "" )
395+
396+ # Conditional configuration for Level Zero provider
397+ if (UMF_BUILD_LEVEL_ZERO_PROVIDER)
398+ add_optional_symbol(umfLevelZeroMemoryProviderOps)
399+ endif ()
400+
401+ if (NOT UMF_DISABLE_HWLOC)
402+ add_optional_symbol(umfOsMemoryProviderOps)
403+ endif ()
404+
320405add_subdirectory (src)
321406
322407if (UMF_BUILD_TESTS)
@@ -328,20 +413,13 @@ if(UMF_BUILD_BENCHMARKS)
328413endif ()
329414
330415if (UMF_BUILD_EXAMPLES)
331- add_subdirectory (examples)
332- endif ()
333-
334- # Conditional configuration for Level Zero provider
335- if (UMF_BUILD_LEVEL_ZERO_PROVIDER)
336- set (OPTIONAL_SYMBOLS "umfLevelZeroMemoryProviderOps" )
337- else ()
338- set (OPTIONAL_SYMBOLS "" )
416+ if (NOT UMF_DISABLE_HWLOC)
417+ add_subdirectory (examples)
418+ else ()
419+ message (WARNING "Examples cannot be build - hwloc disabled" )
420+ endif ()
339421endif ()
340422
341- # Configure the DEF file based on whether Level Zero provider is built
342- configure_file ("${CMAKE_CURRENT_SOURCE_DIR} /src/libumf.def.in"
343- "${CMAKE_CURRENT_BINARY_DIR} /src/libumf.def" @ONLY)
344-
345423if (UMF_FORMAT_CODE_STYLE)
346424 find_program (CLANG_FORMAT NAMES clang-format-15 clang-format-15.0
347425 clang-format)
@@ -522,8 +600,10 @@ endif()
522600# Configure make install/uninstall and packages
523601# --------------------------------------------------------------------------- #
524602install (FILES ${CMAKE_SOURCE_DIR} /LICENSE.TXT
525- ${CMAKE_SOURCE_DIR} /third-party-programs.txt
526603 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR} /doc/${PROJECT_NAME} /" )
604+ install (
605+ FILES ${CMAKE_SOURCE_DIR} /licensing/third-party-programs.txt
606+ DESTINATION "${CMAKE_INSTALL_DATAROOTDIR} /doc/${PROJECT_NAME} /licensing/" )
527607
528608install (DIRECTORY examples DESTINATION "${CMAKE_INSTALL_DOCDIR} " )
529609
0 commit comments