This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
249 lines (195 loc) · 7.44 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
#
# SPDX-License-Identifier: MIT
#
# Copyright (C) 2015-2020 Micron Technology, Inc. All rights reserved.
#
cmake_minimum_required( VERSION 3.6 )
cmake_policy( SET CMP0046 OLD )
cmake_policy( SET CMP0053 NEW )
project( mpool C )
set( PROJECT_VERSION "${BUILD_PKG_VERSION}" )
set( PROJECT_HOMEPAGE_URL "https://github.com/hse-project/mpool" )
set( CMAKE_PROJECT_VERSION "${PROJECT_VERSION}" )
set( CMAKE_PROJECT_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}" )
message( STATUS "Configuring project ${PROJECT_NAME} ${PROJECT_VERSION} ${BUILD_PKG_TAG} common..." )
set( CMAKE_C_STANDARD 99 )
set( CMAKE_INSTALL_PREFIX /usr )
include(GNUInstallDirs)
##################
# The next three variables determine where the build outputs land:
#
# MPOOL_EXT_INSTALL_PREFIX
# - used by external code in ./sub directory.
#
# MPOOL_STAGE_INSTALL_PREFIX
# - used by mpool code.
#
# MPOOL_SCRIPTS_DIR
# - Scripts related to the mpool source tree (building it, working
# with git, etc.)
#
# Build outputs for mpool and external code are kept separate primarily so
# developers can rebuild just the mpool code which is much quicker than
# building everything.
##################
set( MPOOL_EXT_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/ext_install)
set( MPOOL_STAGE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/stage)
set( MPOOL_SCRIPTS_DIR ${PROJECT_SOURCE_DIR}/scripts )
set( MPOOL_SUB_REPOS ${PROJECT_SOURCE_DIR}/sub)
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MPOOL_STAGE_INSTALL_PREFIX}/bin)
set( MPOOL_UTIL_DIR
${PROJECT_SOURCE_DIR}/src/util)
set( MPOOL_3RDPARTY_DIR
${PROJECT_SOURCE_DIR}/3rdparty)
set( MPOOL_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src/mpool/include )
include_directories( ${MPOOL_EXT_INSTALL_PREFIX}/include )
include_directories( ${MPOOL_STAGE_INSTALL_PREFIX}/include )
# Translate "-DFOO -DBAR" to "-DFOO;-DBAR" for add_definitions()
#
separate_arguments( BUILD_CDEFS_SEPARATED UNIX_COMMAND ${BUILD_CDEFS} )
add_definitions( ${BUILD_CDEFS_SEPARATED} )
add_compile_options(
${BUILD_CFLAGS} -g3 -std=gnu99 -Wall -Werror
-Wlogical-op -Wno-missing-field-initializers -Wuninitialized -Wmaybe-uninitialized
-Wextra -Wno-conversion -Wno-sign-conversion -Wno-sign-compare -Wno-unused-parameter
)
if ( ${UBSAN} )
message(STATUS "Enabling ubsan support")
add_compile_options( -fno-omit-frame-pointer )
add_compile_options( -fsanitize=undefined -fno-sanitize=alignment )
link_libraries( -fsanitize=undefined -fno-sanitize=alignment )
endif()
if ( ${ASAN} )
message(STATUS "Enabling asan/lsan support")
add_compile_options( -fno-omit-frame-pointer )
add_compile_options( -fsanitize=address )
link_libraries( -fsanitize=address )
endif()
# Until we resolve these problems...
#
if ( ${CMAKE_C_COMPILER_VERSION} GREATER 7 )
add_compile_options( -Wimplicit-fallthrough=0 )
endif()
# Define valgrind wrapper functions if valgrind-devel package
# is installed (sudo dnf install valgrind-devel).
#
find_path(ValgrindIncludes valgrind.h PATHS /usr/include/valgrind)
if(ValgrindIncludes)
message(STATUS "Enabling valgrind support")
else()
message(STATUS "Disabling valgrind support")
add_definitions( -DNVALGRIND )
endif()
#
# Python
#
# Fedora system packages use Python 3; RHEL7 packages use Python 2
if( EXISTS /etc/fedora-release )
set( MPOOL_PYTHON /usr/bin/python3 )
else()
set( MPOOL_PYTHON /usr/bin/python )
endif()
execute_process( COMMAND ${MPOOL_PYTHON} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE MPOOL_PYTHON_PKG_DIR )
get_filename_component( MPOOL_PYTHON_BASE_DIR ${MPOOL_PYTHON_PKG_DIR}/.. ABSOLUTE )
set ( MPOOL_PYTHON_SOS_DIR ${MPOOL_PYTHON_PKG_DIR}/sos )
set ( MPOOL_PYTHON_SOS_PLUGINS_DIR ${MPOOL_PYTHON_PKG_DIR}/sos/plugins )
include(CMakeLists.macros)
# Flags to enable the use of gprof
#
set( PROFILING false )
if( ${PROFILING} )
add_compile_options( -pg )
link_directories( /usr/local/lib )
link_libraries( profiler )
endif( ${PROFILING} )
# Needed for the JNI bridge.
#
set( YCSB TRUE CACHE BOOL "Build JNI bridge artifacts" )
if( ${YCSB} )
add_compile_options( -fPIC )
endif()
################################################################
#
# Establish prerequisites for all compiled targets
#
################################################################
#
# All compiled binaries should depend upon mpool_version.
#
macro(add_library _target)
_add_library(${_target} ${ARGN})
add_dependencies(${_target} mpool_version)
endmacro()
macro(add_executable _target)
_add_executable(${_target} ${ARGN})
add_dependencies(${_target} mpool_version)
endmacro()
# Common package options...
#
set( CPACK_PACKAGE_LICENSE "MIT" )
set( CPACK_PACKAGE_VENDOR "${BUILD_PKG_VENDOR}" )
set( CPACK_PACKAGE_VERSION "${PROJECT_VERSION}${BUILD_PKG_VQUAL}" )
set( CPACK_PACKAGE_DESCRIPTION_SUMMARY
"media pool ${BUILD_PKG_TAG}-${BUILD_STYPE}${BUILD_NUMBER}" )
set( CPACK_PACKAGE_DESCRIPTION "Object Storage Media Pool (mpool)" )
set( CPACK_COMPONENT_RUNTIME_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION} runtime" )
set( CPACK_COMPONENT_DEVEL_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION} SDK" )
set( CPACK_COMPONENT_TEST_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION} test tools" )
set( CPACK_COMPONENT_TEST_DEPENDS "runtime" )
if( "${BUILD_NUMBER}" )
set( BUILD_RTYPE "${BUILD_STYPE}${BUILD_NUMBER}" )
else()
set( BUILD_RTYPE "" )
endif()
set( CPACK_PACKAGE_RELEASE "${BUILD_PKG_REL}${BUILD_RTYPE}${BUILD_PKG_DIST}" )
# Create the version header file template:
#
file( WRITE ${CMAKE_BINARY_DIR}/mpool_version.h.in
"static const char mpool_version[] = \"@CPACK_PACKAGE_VERSION@-@CPACK_PACKAGE_RELEASE@\";\n"
"static const char mpool_tag[] = \"@BUILD_PKG_TAG@\";\n"
"static const char mpool_sha[] = \"@BUILD_PKG_SHA@\";\n"
)
configure_file(
${CMAKE_BINARY_DIR}/mpool_version.h.in
${MPOOL_STAGE_INSTALL_PREFIX}/include/mpool_version.h
@ONLY
)
################################################################
#
# Subdirectories
#
################################################################
enable_testing()
add_subdirectory( sub )
add_subdirectory( src )
add_subdirectory( test )
add_subdirectory( samples )
add_subdirectory( include )
add_subdirectory( scripts/tmpfiles.d )
add_subdirectory( scripts/systemd )
add_subdirectory( scripts/udev/rules.d )
add_subdirectory( scripts/sysctl.d )
add_subdirectory( scripts/modules-load.d )
# Configure cpack now that we've seen all components...
#
include( ${MPOOL_SCRIPTS_DIR}/${BUILD_PKG_TYPE}/CMakeLists.txt )
include( CPack )
# CTest pretest script
#
configure_file( "${MPOOL_SCRIPTS_DIR}/cmake/CTestCustom.cmake.in"
${CMAKE_BINARY_DIR}/CTestCustom.cmake )
get_directory_property( DirIncs INCLUDE_DIRECTORIES )
get_directory_property( DirCDefs COMPILE_DEFINITIONS )
get_directory_property( DirCOpts COMPILE_OPTIONS )
get_directory_property( DirLDirs LINK_DIRECTORIES )
get_directory_property( DirLLibs LINK_LIBRARIES )
get_directory_property( DirLOpts LINK_OPTIONS )
message( STATUS "Compiler flags:" )
message( STATUS " INCLUDE_DIRECTORIES ${DirIncs}" )
message( STATUS " COMPILE_DEFINITIONS ${DirCDefs}" )
message( STATUS " COMPILE_OPTIONS ${DirCOpts}" )
message( STATUS " LINK_DIRECTORIES ${DirLDirs}" )
message( STATUS " LINK_LIBRARIES ${DirLLibs}" )
message( STATUS " LINK_OPTIONS ${DirLOpts}" )