3
3
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
4
5
5
cmake_minimum_required (VERSION 3.14.0 FATAL_ERROR )
6
- project (unified-memory-framework VERSION 0.1.0 LANGUAGES C )
6
+ project (
7
+ unified-memory-framework
8
+ VERSION 0.1.0
9
+ LANGUAGES C )
7
10
8
11
# Build Options
9
12
option (UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF )
10
13
option (UMF_BUILD_LEVEL_ZERO_PROVIDER "Build Level Zero memory provider" ON )
11
- option (UMF_BUILD_LIBUMF_POOL_DISJOINT "Build the libumf_pool_disjoint static library" OFF )
12
- option (UMF_BUILD_LIBUMF_POOL_JEMALLOC "Build the libumf_pool_jemalloc static library" OFF )
13
- option (UMF_BUILD_LIBUMF_POOL_SCALABLE "Build the libumf_pool_scalable static library" OFF )
14
+ option (UMF_BUILD_LIBUMF_POOL_DISJOINT
15
+ "Build the libumf_pool_disjoint static library" OFF )
16
+ option (UMF_BUILD_LIBUMF_POOL_JEMALLOC
17
+ "Build the libumf_pool_jemalloc static library" OFF )
18
+ option (UMF_BUILD_LIBUMF_POOL_SCALABLE
19
+ "Build the libumf_pool_scalable static library" OFF )
14
20
option (UMF_BUILD_TESTS "Build UMF tests" ON )
15
21
option (UMF_BUILD_GPU_TESTS "Build UMF GPU tests" OFF )
16
22
option (UMF_BUILD_BENCHMARKS "Build UMF benchmarks" OFF )
17
23
option (UMF_BUILD_BENCHMARKS_MT "Build UMF multithreaded benchmarks" OFF )
18
24
option (UMF_BUILD_EXAMPLES "Build UMF examples" ON )
19
25
option (UMF_ENABLE_POOL_TRACKING "Build UMF with pool tracking" ON )
20
- option (UMF_DEVELOPER_MODE "Enable developer checks, treats warnings as errors" OFF )
26
+ option (UMF_DEVELOPER_MODE "Enable developer checks, treats warnings as errors"
27
+ OFF )
21
28
option (UMF_FORMAT_CODE_STYLE "Format UMF code with clang-format" OFF )
22
29
option (USE_ASAN "Enable AddressSanitizer checks" OFF )
23
30
option (USE_UBSAN "Enable UndefinedBehaviorSanitizer checks" OFF )
@@ -26,32 +33,43 @@ option(USE_MSAN "Enable MemorySanitizer checks" OFF)
26
33
option (USE_VALGRIND "Enable Valgrind instrumentation" OFF )
27
34
28
35
# set UMF_PROXY_LIB_BASED_ON_POOL to one of: SCALABLE or JEMALLOC
29
- set (UMF_PROXY_LIB_BASED_ON_POOL SCALABLE CACHE STRING "A UMF pool the proxy library is based on (SCALABLE or JEMALLOC)" FORCE )
36
+ set (UMF_PROXY_LIB_BASED_ON_POOL
37
+ SCALABLE
38
+ CACHE STRING
39
+ "A UMF pool the proxy library is based on (SCALABLE or JEMALLOC)"
40
+ FORCE )
30
41
31
42
set (KNOWN_BUILD_TYPES Release Debug RelWithDebInfo MinSizeRel )
32
43
string (REPLACE ";" " " KNOWN_BUILD_TYPES_STR "${KNOWN_BUILD_TYPES} " )
33
44
34
45
if (NOT CMAKE_BUILD_TYPE )
35
- message (STATUS "No build type selected (CMAKE_BUILD_TYPE), defaulting to Release" )
46
+ message (
47
+ STATUS
48
+ "No build type selected (CMAKE_BUILD_TYPE), defaulting to Release" )
36
49
set (CMAKE_BUILD_TYPE "Release" )
37
50
else ()
38
51
message (STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE} " )
39
52
if (NOT CMAKE_BUILD_TYPE IN_LIST KNOWN_BUILD_TYPES )
40
- message (WARNING "Unusual build type was set (${CMAKE_BUILD_TYPE} ), please make sure it is a correct one. "
41
- "The following ones are supported by default: ${KNOWN_BUILD_TYPES_STR} ." )
53
+ message (
54
+ WARNING
55
+ "Unusual build type was set (${CMAKE_BUILD_TYPE} ), please make sure it is a correct one. "
56
+ "The following ones are supported by default: ${KNOWN_BUILD_TYPES_STR} ."
57
+ )
42
58
endif ()
43
59
endif ()
44
60
45
- set (CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE} " CACHE STRING "Choose the type of build, options are: ${KNOWN_BUILD_TYPES_STR} ..." FORCE )
61
+ set (CMAKE_BUILD_TYPE
62
+ "${CMAKE_BUILD_TYPE} "
63
+ CACHE STRING
64
+ "Choose the type of build, options are: ${KNOWN_BUILD_TYPES_STR} ..."
65
+ FORCE )
46
66
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${KNOWN_BUILD_TYPES} )
47
67
48
- # For using the options listed in the OPTIONS_REQUIRING_CXX variable
49
- # a C++17 compiler is required. Moreover, if these options are not set,
50
- # CMake will set up a strict C build, without C++ support.
51
- set (OPTIONS_REQUIRING_CXX
52
- "UMF_BUILD_TESTS"
53
- "UMF_BUILD_LIBUMF_POOL_DISJOINT"
54
- "UMF_BUILD_BENCHMARKS_MT" )
68
+ # For using the options listed in the OPTIONS_REQUIRING_CXX variable a C++17
69
+ # compiler is required. Moreover, if these options are not set, CMake will set
70
+ # up a strict C build, without C++ support.
71
+ set (OPTIONS_REQUIRING_CXX "UMF_BUILD_TESTS" "UMF_BUILD_LIBUMF_POOL_DISJOINT"
72
+ "UMF_BUILD_BENCHMARKS_MT" )
55
73
foreach (option_name ${OPTIONS_REQUIRING_CXX} )
56
74
if (${option_name} )
57
75
enable_language (CXX )
@@ -111,7 +129,7 @@ if(USE_TSAN)
111
129
endif ()
112
130
if (USE_MSAN )
113
131
message (WARNING "MemorySanitizer requires instrumented libraries to "
114
- "prevent reporting false-positives" )
132
+ "prevent reporting false-positives" )
115
133
add_sanitizer_flag (memory )
116
134
endif ()
117
135
@@ -121,43 +139,47 @@ add_library(umf_headers INTERFACE)
121
139
122
140
# Alias target to support FetchContent.
123
141
add_library (${PROJECT_NAME} ::headers ALIAS umf_headers )
124
- target_include_directories (umf_headers INTERFACE
125
- $< BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include>
126
- $< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} > )
142
+ target_include_directories (
143
+ umf_headers INTERFACE $< BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include>
144
+ $< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} > )
127
145
128
146
# Add the include directory and the headers target to the install.
129
- install (
130
- DIRECTORY "${PROJECT_SOURCE_DIR} /include/"
131
- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
147
+ install (DIRECTORY "${PROJECT_SOURCE_DIR} /include/"
148
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
132
149
133
- install (
134
- TARGETS umf_headers
135
- EXPORT ${PROJECT_NAME} -targets )
150
+ install (TARGETS umf_headers EXPORT ${PROJECT_NAME} -targets )
136
151
137
152
if (WINDOWS )
138
153
add_compile_definitions (_CRT_SECURE_NO_WARNINGS )
139
154
# set PATH to DLLs on Windows
140
- set (DLL_PATH_LIST "PATH=path_list_append:${PROJECT_BINARY_DIR} /bin/$<CONFIG>" )
155
+ set (DLL_PATH_LIST
156
+ "PATH=path_list_append:${PROJECT_BINARY_DIR} /bin/$<CONFIG>" )
141
157
# add path to the proxy lib DLL
142
- set (DLL_PATH_LIST "${DLL_PATH_LIST} ;PATH=path_list_append:${PROJECT_BINARY_DIR} /src/proxy_lib" )
158
+ set (DLL_PATH_LIST
159
+ "${DLL_PATH_LIST} ;PATH=path_list_append:${PROJECT_BINARY_DIR} /src/proxy_lib"
160
+ )
143
161
# MSVC implicitly adds $<CONFIG> to the output path
144
- set (DLL_PATH_LIST "${DLL_PATH_LIST} ;PATH=path_list_append:${PROJECT_BINARY_DIR} /src/proxy_lib/$<CONFIG>" )
162
+ set (DLL_PATH_LIST
163
+ "${DLL_PATH_LIST} ;PATH=path_list_append:${PROJECT_BINARY_DIR} /src/proxy_lib/$<CONFIG>"
164
+ )
145
165
endif ()
146
166
147
167
pkg_check_modules (LIBHWLOC hwloc )
148
168
if (NOT LIBHWLOC_FOUND )
149
169
find_package (LIBHWLOC REQUIRED hwloc )
150
170
endif ()
151
171
# add PATH to DLL on Windows
152
- set (DLL_PATH_LIST "${DLL_PATH_LIST} ;PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS} /../bin" )
172
+ set (DLL_PATH_LIST
173
+ "${DLL_PATH_LIST} ;PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS} /../bin" )
153
174
154
175
if (UMF_BUILD_LIBUMF_POOL_SCALABLE AND (LINUX OR WINDOWS ))
155
176
pkg_check_modules (TBB tbb )
156
177
if (NOT TBB_FOUND )
157
178
find_package (TBB REQUIRED tbb )
158
179
endif ()
159
180
# add PATH to DLL on Windows
160
- set (DLL_PATH_LIST "${DLL_PATH_LIST} ;PATH=path_list_append:${TBB_LIBRARY_DIRS} /../bin" )
181
+ set (DLL_PATH_LIST
182
+ "${DLL_PATH_LIST} ;PATH=path_list_append:${TBB_LIBRARY_DIRS} /../bin" )
161
183
endif ()
162
184
163
185
if (UMF_BUILD_LIBUMF_POOL_JEMALLOC AND (LINUX OR WINDOWS ))
@@ -166,32 +188,46 @@ if(UMF_BUILD_LIBUMF_POOL_JEMALLOC AND (LINUX OR WINDOWS))
166
188
find_package (JEMALLOC REQUIRED jemalloc )
167
189
endif ()
168
190
# add PATH to DLL on Windows
169
- set (DLL_PATH_LIST "${DLL_PATH_LIST} ;PATH=path_list_append:${JEMALLOC_LIBRARY_DIRS} /../bin" )
191
+ set (DLL_PATH_LIST
192
+ "${DLL_PATH_LIST} ;PATH=path_list_append:${JEMALLOC_LIBRARY_DIRS} /../bin"
193
+ )
170
194
endif ()
171
195
172
196
# set UMF_PROXY_LIB_ENABLED
173
197
if (LINUX OR WINDOWS )
174
198
# TODO: enable the proxy library in the Debug build on Windows
175
199
if (WINDOWS AND NOT (CMAKE_BUILD_TYPE STREQUAL "Release" ))
176
- message (STATUS "Disabling the proxy library, because it is supported only in the Release build on Windows (CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE} )" )
200
+ message (
201
+ STATUS
202
+ "Disabling the proxy library, because it is supported only in the Release build on Windows (CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE} )"
203
+ )
177
204
elseif (UMF_PROXY_LIB_BASED_ON_POOL STREQUAL SCALABLE )
178
205
if (UMF_BUILD_LIBUMF_POOL_SCALABLE )
179
206
set (UMF_PROXY_LIB_ENABLED ON )
180
207
set (PROXY_LIB_USES_SCALABLE_POOL ON )
181
208
set (PROXY_LIBS umf scalable_pool )
182
209
else ()
183
- message (STATUS "Disabling the proxy library, because UMF_PROXY_LIB_BASED_ON_POOL==SCALABLE but UMF_BUILD_LIBUMF_POOL_SCALABLE is OFF" )
210
+ message (
211
+ STATUS
212
+ "Disabling the proxy library, because UMF_PROXY_LIB_BASED_ON_POOL==SCALABLE but UMF_BUILD_LIBUMF_POOL_SCALABLE is OFF"
213
+ )
184
214
endif ()
185
215
elseif (UMF_PROXY_LIB_BASED_ON_POOL STREQUAL JEMALLOC )
186
216
if (UMF_BUILD_LIBUMF_POOL_JEMALLOC )
187
217
set (UMF_PROXY_LIB_ENABLED ON )
188
218
set (PROXY_LIB_USES_JEMALLOC_POOL ON )
189
219
set (PROXY_LIBS umf jemalloc_pool )
190
220
else ()
191
- message (STATUS "Disabling the proxy library, because UMF_PROXY_LIB_BASED_ON_POOL==JEMALLOC but UMF_BUILD_LIBUMF_POOL_JEMALLOC is OFF" )
221
+ message (
222
+ STATUS
223
+ "Disabling the proxy library, because UMF_PROXY_LIB_BASED_ON_POOL==JEMALLOC but UMF_BUILD_LIBUMF_POOL_JEMALLOC is OFF"
224
+ )
192
225
endif ()
193
226
else ()
194
- message (FATAL_ERROR "Proxy library: pool manager not chosen or set to a non-supported one (see UMF_PROXY_LIB_BASED_ON_POOL)" )
227
+ message (
228
+ FATAL_ERROR
229
+ "Proxy library: pool manager not chosen or set to a non-supported one (see UMF_PROXY_LIB_BASED_ON_POOL)"
230
+ )
195
231
endif ()
196
232
endif ()
197
233
@@ -205,7 +241,8 @@ if(UMF_BUILD_BENCHMARKS)
205
241
if (LINUX OR WINDOWS )
206
242
add_subdirectory (benchmark )
207
243
else ()
208
- message (FATAL_ERROR "benchmarks are supported on Linux and Windows only" )
244
+ message (
245
+ FATAL_ERROR "benchmarks are supported on Linux and Windows only" )
209
246
endif ()
210
247
endif ()
211
248
@@ -214,19 +251,21 @@ if(UMF_BUILD_EXAMPLES)
214
251
endif ()
215
252
216
253
if (UMF_FORMAT_CODE_STYLE )
217
- find_program (CLANG_FORMAT NAMES clang-format-15 clang-format-15.0 clang-format )
254
+ find_program (CLANG_FORMAT NAMES clang-format-15 clang-format-15.0
255
+ clang-format )
218
256
find_program (CMAKE_FORMAT NAMES cmake-format )
219
257
220
258
if (CLANG_FORMAT )
221
259
get_program_version_major_minor (${CLANG_FORMAT} CLANG_FORMAT_VERSION )
222
260
message (STATUS "Found clang-format: ${CLANG_FORMAT} "
223
261
"(version: ${CLANG_FORMAT_VERSION} )" )
224
262
225
- # Check if clang-format (in correct version) is available for code formatting.
263
+ # Check if clang-format (in correct version) is available for code
264
+ # formatting.
226
265
set (CLANG_FORMAT_REQUIRED "15.0" )
227
266
if (NOT (CLANG_FORMAT_VERSION VERSION_EQUAL CLANG_FORMAT_REQUIRED ))
228
267
message (FATAL_ERROR "Required clang-format version is "
229
- "${CLANG_FORMAT_REQUIRED} " )
268
+ "${CLANG_FORMAT_REQUIRED} " )
230
269
endif ()
231
270
endif ()
232
271
@@ -254,42 +293,53 @@ if(UMF_FORMAT_CODE_STYLE)
254
293
255
294
# Obtain files for clang-format check
256
295
set (format_glob )
257
- foreach (DIR IN ITEMS benchmark examples include src test )
258
- list (APPEND format_glob
296
+ foreach (
297
+ DIR IN
298
+ ITEMS benchmark
299
+ examples
300
+ include
301
+ src
302
+ test )
303
+ list (
304
+ APPEND
305
+ format_glob
259
306
"${DIR} /*.h"
260
307
"${DIR} /*.hpp"
261
308
"${DIR} /*.c"
262
309
"${DIR} /*.cpp"
263
310
"${DIR} /**/*.h"
264
311
"${DIR} /**/*.hpp"
265
312
"${DIR} /**/*.c"
266
- "${DIR} /**/*.cpp"
267
- )
313
+ "${DIR} /**/*.cpp" )
268
314
endforeach ()
269
315
file (GLOB_RECURSE format_list ${format_glob} )
270
316
271
317
message (STATUS "Adding clang-format-check and clang-format-apply make "
272
- "targets" )
273
-
274
- add_custom_target (clang-format-check
275
- COMMAND ${CLANG_FORMAT}
276
- --style=file
277
- --dry-run
278
- -Werror
279
- ${format_list}
318
+ "targets" )
319
+
320
+ add_custom_target (
321
+ clang-format-check
322
+ COMMAND ${CLANG_FORMAT} --style=file --dry-run -Werror ${format_list}
280
323
COMMENT "Check files formatting using clang-format" )
281
324
282
- add_custom_target (clang-format-apply
283
- COMMAND ${CLANG_FORMAT}
284
- --style=file
285
- --i
286
- ${format_list}
325
+ add_custom_target (
326
+ clang-format-apply
327
+ COMMAND ${CLANG_FORMAT} --style=file --i ${format_list}
287
328
COMMENT "Format files using clang-format" )
288
329
289
330
# Obtain files for cmake-format check
290
331
set (format_cmake_glob )
291
- foreach (DIR IN ITEMS examples cmake include src test benchmark )
292
- list (APPEND format_cmake_glob
332
+ foreach (
333
+ DIR IN
334
+ ITEMS examples
335
+ cmake
336
+ include
337
+ src
338
+ test
339
+ benchmark )
340
+ list (
341
+ APPEND
342
+ format_cmake_glob
293
343
"${DIR} /CMakeLists.txt"
294
344
"${DIR} /*.cmake"
295
345
"${DIR} /**/CMakeLists.txt"
@@ -299,7 +349,7 @@ if(UMF_FORMAT_CODE_STYLE)
299
349
list (APPEND format_cmake_list "${PROJECT_SOURCE_DIR} /CMakeLists.txt" )
300
350
301
351
message (STATUS "Adding cmake-format-check and cmake-format-apply make "
302
- "targets" )
352
+ "targets" )
303
353
304
354
add_custom_target (
305
355
cmake-format-check
@@ -335,8 +385,8 @@ install(FILES ${CMAKE_SOURCE_DIR}/LICENSE.TXT
335
385
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR} /doc/${PROJECT_NAME} /" )
336
386
337
387
# Add the list of installed targets to the install. This includes the namespace
338
- # which all installed targets will be prefixed with, e.g. for the headers
339
- # target users will depend on ${PROJECT_NAME}::headers.
388
+ # which all installed targets will be prefixed with, e.g. for the headers target
389
+ # users will depend on ${PROJECT_NAME}::headers.
340
390
install (
341
391
EXPORT ${PROJECT_NAME} -targets
342
392
FILE ${PROJECT_NAME} -targets.cmake
@@ -356,16 +406,12 @@ configure_package_config_file(
356
406
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} )
357
407
358
408
# Add the package files to the install.
359
- install (
360
- FILES
361
- ${PROJECT_BINARY_DIR} /cmake/${PROJECT_NAME}-config.cmake
362
- ${PROJECT_BINARY_DIR} /cmake/${PROJECT_NAME}-config-version.cmake
363
- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} )
409
+ install (FILES ${PROJECT_BINARY_DIR} /cmake/${PROJECT_NAME}-config.cmake
410
+ ${PROJECT_BINARY_DIR} /cmake/${PROJECT_NAME}-config-version.cmake
411
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} )
364
412
365
- configure_file (
366
- "${PROJECT_SOURCE_DIR} /cmake/cmake_uninstall.cmake.in"
367
- "${PROJECT_BINARY_DIR} /cmake_uninstall.cmake"
368
- IMMEDIATE @ONLY )
413
+ configure_file ("${PROJECT_SOURCE_DIR} /cmake/cmake_uninstall.cmake.in"
414
+ "${PROJECT_BINARY_DIR} /cmake_uninstall.cmake" IMMEDIATE @ONLY )
369
415
370
- add_custom_target (uninstall
371
- COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR} /cmake_uninstall.cmake )
416
+ add_custom_target (uninstall COMMAND ${CMAKE_COMMAND} -P
417
+ ${PROJECT_BINARY_DIR} /cmake_uninstall.cmake )
0 commit comments