forked from osmhpi/pgasus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
303 lines (251 loc) · 10 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
if (POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()
include(GenerateExportHeader)
project(LibNumaCpp VERSION 0.0.0 LANGUAGES C CXX)
include(cmake/CppCheckTargets.cmake)
set(CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/cmake"
"${PROJECT_SOURCE_DIR}/3rdParty/sanitizers-cmake/cmake"
${CMAKE_MODULE_PATH}
)
macro(add_PGASUS_option NAME DOC INITVALUE)
option(PGASUS_${NAME} ${DOC} ${INITVALUE})
if (PGASUS_${NAME})
set(${NAME} 1)
else()
set(${NAME} 0)
endif()
endmacro()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(LINUX 1)
endif()
set(PGASUS_PLATFORM_X86_64 0)
set(PGASUS_PLATFORM_PPC64LE 0)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(PGASUS_PLATFORM_X86_64 1)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le")
set(PGASUS_PLATFORM_PPC64LE 1)
else()
message(WARNING "Unsupported platform: \"${CMAKE_SYSTEM_PROCESSOR}\"")
endif()
set(MEM_SOURCE_USE_PTHREAD_SPINLOCK_doc
"Use pthread spinlocks instead of own implementation")
set(MEM_SOURCE_USE_PTHREAD_SPINLOCK_default OFF)
if (PGASUS_PLATFORM_PPC64LE)
set(MEM_SOURCE_USE_PTHREAD_SPINLOCK_default ON)
endif()
option(PGASUS_PROFILING_GPROF "Compile for profiling with gprof" OFF)
add_PGASUS_option(ENABLE_DEBUG_LOG "Enable debug log for PGASUS/NUMA operations" OFF)
if (PGASUS_PLATFORM_PPC64LE AND PGASUS_ENABLE_DEBUG_LOG)
message(WARNING "PGASUS_ENABLE_DEBUG_LOG is set, but most performance logs "
"are not implemented for POWER platforms.")
endif()
add_PGASUS_option(MEM_SOURCE_USE_PTHREAD_SPINLOCK
${MEM_SOURCE_USE_PTHREAD_SPINLOCK_doc} ${MEM_SOURCE_USE_PTHREAD_SPINLOCK_default})
if (PGASUS_PLATFORM_PPC64LE AND NOT PGASUS_MEM_SOURCE_USE_PTHREAD_SPINLOCK)
message("Spinlocks are not implemented on your platform. "
"Using pthread spinlocks instead (see PGASUS_MEM_SOURCE_USE_PTHREAD_SPINLOCK).")
set(PGASUS_MEM_SOURCE_USE_PTHREAD_SPINLOCK ON CACHE BOOL
${MEM_SOURCE_USE_PTHREAD_SPINLOCK_doc} FORCE)
endif()
# "small allocation" threshold: On 64 bit systems, glibc's ptmalloc variant uses
# 32MB. ptmalloc3 and dlmalloc default to 256KB.
set(PGASUS_MMAP_THRESHOLD 33554432 CACHE STRING
"Minimum allocation size in bytes for using mmap to allocate memory \
directly from the operating system.")
if (NOT PGASUS_MMAP_THRESHOLD GREATER -1)
message(FATAL_ERROR "PGASUS_MMAP_THRESHOLD must be a positive integer. \
Current value: ${PGASUS_MMAP_THRESHOLD}")
endif()
set(PGASUS_REPLACE_MALLOC ON CACHE BOOL
"Determines whether PGASUS replaces the process-wide malloc function.")
add_PGASUS_option(WITH_TASKING
"Include tasking support, currently requiring boost version >= 1.58 and <= 1.60." ON)
add_PGASUS_option(BUILD_TESTS "Build the tests and benchmarks (requires further 3rd party libs)." ON)
add_PGASUS_option(TEST_WITH_FAKE_TOPOLOGY
"Simulate POWER-like virtualized topology by overriding some hwloc functions." OFF)
mark_as_advanced(PGASUS_TEST_WITH_FAKE_TOPOLOGY)
add_PGASUS_option(BUILD_DOCUMENTATION "Build the source documentation (requires doxygen)." ON)
option(PGASUS_ADD_CPPCHECK_TARGETS "Add a cppcheck target per C++-target." ON)
if (NOT DEFAULT_COMPILE_DEFINITIONS)
set(DEFAULT_COMPILE_DEFINITIONS)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(
-Wpedantic
-Wall
-Wno-missing-braces
)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
set(PGASUS_CLANG_DEBUGGER gdb CACHE STRING
"Debugger for that clang optimizes the DWARF debugging information")
set_property(CACHE PGASUS_CLANG_DEBUGGER PROPERTY STRINGS gdb lldb)
add_compile_options($<$<CONFIG:Debug>:-g${PGASUS_CLANG_DEBUGGER}>)
endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.0")
add_compile_options(
$<$<CONFIG:Debug>:-fno-limit-debug-info>
)
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
-Wpedantic
-Wall
$<$<CONFIG:Debug>:-ggdb3>
)
if (NOT PGASUS_PLATFORM_PPC64LE)
add_compile_options(
-march=native
)
endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0")
list(APPEND DEFAULT_COMPILE_DEFINITIONS
PUBLIC _GLIBCXX_USE_CXX11_ABI=1)
endif()
if (PGASUS_PROFILING_GPROF)
add_compile_options(-g -pg)
link_libraries(-g -pg)
endif()
option(PGASUS_USE_GLIBCXX_DEBUG
"Enable libstdc++ debug mode in Debug builds (Define _GLIBCXX_DEBUG - container bounds checks)." OFF)
if (PGASUS_USE_GLIBCXX_DEBUG)
list(APPEND DEFAULT_COMPILE_DEFINITIONS $<$<CONFIG:Debug>:PUBLIC _GLIBCXX_DEBUG>)
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
add_compile_options(-Wall $<$<CONFIG:Release>:-Ofast -no-prec-div -xHOST>)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "XL") # IBM XLC
add_compile_options(
# CMake does not know to configure XLC for C++11
$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>
$<$<COMPILE_LANGUAGE:C>:-std=c11>
)
endif()
option(PGASUS_BUILD_STATIC_LIBRARIES "Also build static libraries" ON)
option(PGASUS_RDTSC_PROFILING "Also rdtsc()-based profiling for msources and spinlocks" OFF)
if (PGASUS_RDTSC_PROFILING)
set(NUMA_PROFILE_SPINLOCK 1)
set(NUMA_PROFILE_MSOURCE 1)
else()
set(NUMA_PROFILE_SPINLOCK 0)
set(NUMA_PROFILE_MSOURCE 0)
endif()
option(PGASUS_DEBUG_MALLOC "Annotate freshly allocated and freed memory regions with special values (0xAA, 0xBB, 0xCC)" OFF)
if (PGASUS_DEBUG_MALLOC)
set(MEM_SOURCE_FILL_MEMORY_DEBUG 1)
else()
set(MEM_SOURCE_FILL_MEMORY_DEBUG 0)
endif()
# Set output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if (PGASUS_WITH_TASKING)
set(BOOST_MIN_REQUIRED_VERSION 1.56)
set(BOOST_MAX_REQUIRED_VERSION 1.60)
set(BOOST_REQUIRED_COMPONENTS context chrono thread system)
find_package(Boost ${BOOST_MIN_REQUIRED_VERSION} COMPONENTS ${BOOST_REQUIRED_COMPONENTS} REQUIRED)
set(BOOST_FOUND_VERSION ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION})
if (BOOST_FOUND_VERSION VERSION_GREATER BOOST_MAX_REQUIRED_VERSION)
message(FATAL_ERROR "Boost version newer than ${BOOST_MAX_REQUIRED_VERSION} is currently not supported. \
Disable tasking support to omit the Boost dependency (See PGASUS_WITH_TASKING).")
endif()
endif()
find_package(NUMA REQUIRED)
find_package(HWLOC REQUIRED)
find_package(Sanitizers QUIET)
if (NOT Sanitizers_FOUND)
function(add_sanitizers target)
endfunction()
endif()
set(package_name "PGASUS")
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR CMake)
else()
set(DEF_INSTALL_CMAKE_DIR lib/CMake/${package_name})
endif()
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
"Installation directory for CMake files")
# Make relative paths absolute (needed later on)
foreach(p LIB BIN INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
endforeach()
# populate ;-separated list with targets to be exported
set(export_targets_bin "" CACHE INTERNAL "")
set(export_targets_shlib "" CACHE INTERNAL "")
set(export_targets_staticlib "" CACHE INTERNAL "")
function(addExportTarget TARGET_NAME)
get_target_property(type ${TARGET_NAME} TYPE)
set(targetVar)
if (type STREQUAL EXECUTABLE)
set(targetVar export_targets_bin)
elseif(type STREQUAL SHARED_LIBRARY)
set(targetVar export_targets_shlib)
elseif(type STREQUAL STATIC_LIBRARY)
set(targetVar export_targets_staticlib)
else()
message(FATAL_ERROR "Unexpected target type: ${type} (target: \"${TARGET_NAME}\")")
endif()
set(separator)
if (${targetVar})
set(separator ";")
endif()
set(${targetVar} "${${targetVar}}${separator}${TARGET_NAME}"
CACHE INTERNAL "")
endfunction()
set(PGASUS_CONFIG_FILE ${PROJECT_BINARY_DIR}/src/PGASUS/PGASUS-config.h)
configure_file(${PROJECT_SOURCE_DIR}/cmake/PGASUS-config.h.in ${PGASUS_CONFIG_FILE})
# Install the whole include/PGASUS/... tree, which are the public headers of the libraries
# NOTE: Installation of only a subset of the libraries is not possible that way!
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/PGASUS"
DESTINATION ${INSTALL_INCLUDE_DIR} COMPONENT dev)
install(FILES ${PGASUS_CONFIG_FILE}
DESTINATION ${INSTALL_INCLUDE_DIR}/PGASUS COMPONENT dev)
# Set postfix for debug versions of libraries. This does not apply to executables!
set(CMAKE_DEBUG_POSTFIX "_d")
generate_cppcheck_suppressions()
# add sub-projects
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(docs)
create_cppcheck_ALL_target()
# Export to be usable in external projects
set(export_targets ${export_targets_bin} ${export_targets_shlib} ${export_targets_staticlib})
export(TARGETS ${export_targets}
NAMESPACE ${package_name}::
FILE "${PROJECT_BINARY_DIR}/${package_name}Targets.cmake")
export(PACKAGE ${package_name})
# Create the ${package_name}Config.cmake and ${package_name}ConfigVersion files
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
"${INSTALL_INCLUDE_DIR}")
# ... for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
configure_file("cmake/${package_name}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${package_name}Config.cmake" @ONLY)
# ... for the install tree
set(CONF_INCLUDE_DIRS "\${${package_name}_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file("cmake/${package_name}Config.cmake.in"
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${package_name}Config.cmake" @ONLY)
# ... for both
configure_file("cmake/${package_name}ConfigVersion.cmake.in"
"${PROJECT_BINARY_DIR}/${package_name}ConfigVersion.cmake" @ONLY)
# Install the ${package_name}Config.cmake and ${package_name}ConfigVersion.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${package_name}Config.cmake"
"${PROJECT_BINARY_DIR}/${package_name}ConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
# Install the export set for use with the install-tree
install(EXPORT ${package_name}Targets
NAMESPACE ${package_name}::
DESTINATION "${INSTALL_CMAKE_DIR}"
COMPONENT dev)