-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
334 lines (279 loc) · 11.6 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
cmake_minimum_required(VERSION 3.0)
project(pelikan C)
# Uncomment the following to output dependency graph debugging messages
# set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1)
###################
# detect platform #
###################
# TODO(yao):
# 1. make this a .cmake macro and put it under cmake/
# 2. avoid calling this twice when included by another project, e.g. Pelikan
include(CheckSymbolExists)
# detect platform
macro(set_platform system_name)
if(${system_name} MATCHES "Darwin")
set(OS_PLATFORM "OS_DARWIN")
add_definitions(-DOS_DARWIN)
elseif(${system_name} MATCHES "Linux")
set(OS_PLATFORM "OS_LINUX")
check_symbol_exists(EFD_NONBLOCK "sys/eventfd.h" USE_EVENT_FD)
add_definitions(-DOS_LINUX)
if(USE_EVENT_FD)
add_definitions(-DUSE_EVENT_FD)
endif()
else()
set(OS_PLATFORM "OS_UNSUPPORTED")
endif()
endmacro(set_platform)
set_platform(${CMAKE_SYSTEM_NAME})
if(OS_PLATFORM STREQUAL "OS_UNSUPPORTED")
message(FATAL_ERROR "unsupported operating system")
endif()
####################
# define variables #
####################
# the following sections work with config.h(.in): version, compile variables
# config.h.in has to include entries set/tested here for them to have effect
# version info
set(${PROJECT_NAME}_VERSION_MAJOR 0)
set(${PROJECT_NAME}_VERSION_MINOR 1)
set(${PROJECT_NAME}_VERSION_PATCH 1)
set(${PROJECT_NAME}_VERSION
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}
)
set(${PROJECT_NAME}_RELEASE_VERSION
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}
)
# flags => compile-time variables: use modules/macros
option(HAVE_ASSERT_LOG "assert_log enabled by default" OFF)
option(HAVE_ASSERT_PANIC "assert_panic disabled by default" OFF)
option(HAVE_LOGGING "logging enabled by default" OFF)
option(HAVE_STATS "stats enabled by default" OFF)
option(HAVE_TEST "test built by default" OFF)
option(HAVE_DEBUG_MM "debugging oriented memory management disabled by default" OFF)
option(HAVE_COVERAGE "code coverage" OFF)
option(HAVE_RUST "rust bindings not built by default" OFF)
option(HAVE_ITT_INSTRUMENTATION "instrument code with ITT API" OFF)
option(FORCE_CHECK_BUILD "Force building check with ci/install-check.sh" OFF)
if(HAVE_RUST)
option(RUST_VERBOSE_BUILD "pass -vv to cargo compilation" OFF)
endif()
option(TARGET_PINGSERVER "build pingserver binary" ON)
option(TARGET_RDS "build rich data server binary" ON)
option(TARGET_SLIMRDS "build slim rich data server binary" ON)
option(TARGET_SLIMCACHE "build slimcache binary" ON)
option(TARGET_TWEMCACHE "build twemcache binary" ON)
option(TARGET_SEGCACHE "build TTL-driven segment-structured cache binary" ON)
option(TARGET_CDB "build cdb binary (implies HAVE_RUST)" OFF)
option(TARGET_RESPCLI "build resp-cli binary" ON)
option(TARGET_HTTP "build experimental twemcache-http server (implies HAVE_RUST)" OFF)
option(USE_PMEM "build persistent memory features" OFF)
include(CheckFunctionExists)
check_function_exists(backtrace HAVE_BACKTRACE)
# how to use config.h.in to generate config.h
# this has to be set _after_ the above checks
configure_file(
"${PROJECT_SOURCE_DIR}/cmake/config.h.in"
"${PROJECT_BINARY_DIR}/config.h")
# Note: duplicate custom targets only works with Makefile generators, will break XCode & VS
# reference: http://public.kitware.com/Bug/view.php?id=6348
set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
set(CMAKE_MACOSX_RPATH 1)
# Required for properly linking with rust code
set(CMAKE_POSITION_INDEPENDENT_CODE true)
# set compiler flags
# string concat is easier in 3.0, but older versions don't have the concat subcommand
# so we are using list as input until we move to new version
add_definitions(-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64)
# Set a default build type (Release) if none was specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
endif()
add_definitions()
set(CFLAGS_LIST
"-std=c11 "
"-ggdb3 "
"-Wall -Wshadow -Winline "
"-Wstrict-prototypes -Wmissing-prototypes "
"-Wmissing-declarations -Wredundant-decls "
"-Wunused-function -Wunused-value -Wunused-variable "
"-fno-strict-aliasing ")
if(BUILD_AND_INSTALL_CHECK)
# (simms) What follows is a crime against build systems as we run the build/install
# for the check library up front, during the planning phase.
set(LIBCHECK_PREFIX "${CMAKE_BINARY_DIR}/check")
# check for a local install of check
if(NOT EXISTS "${LIBCHECK_PREFIX}")
# (simms) This is terrible and I did it this way to ensure this gets built
# before the rest of the 'check' tests run. This should be rewritten so that
# the other dependencies know that there's a target that can build check
execute_process(
COMMAND "bash" "${PROJECT_SOURCE_DIR}/ci/install-check.sh" "${LIBCHECK_PREFIX}"
TIMEOUT 300 # if this doesn't build in 5 minutes something is hosed
)
endif()
set(CHECK_ROOT_DIR "${LIBCHECK_PREFIX}")
set(CMAKE_REQUIRED_INCLUDES "${CHECK_ROOT_DIR}/include") # these make check link correctly in ccommon and pelikan
endif()
if(${OS_PLATFORM} MATCHES "OS_LINUX")
set(CFLAGS_LIST "${CFLAGS_LIST} -lrt")
endif()
string(REPLACE "" "" LOCAL_CFLAGS ${CFLAGS_LIST})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LOCAL_CFLAGS}")
if (COVERAGE)
if(NOT ${CMAKE_BUILD_TYPE} MATCHES Debug)
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading" )
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif(COVERAGE)
# build dependencies
# dependency: libccommon
set(CCOMMON_SOURCE_DIR "${PROJECT_SOURCE_DIR}/deps/ccommon" CACHE PATH "Path to the ccommon")
add_subdirectory(${CCOMMON_SOURCE_DIR} ${PROJECT_BINARY_DIR}/ccommon)
# other dependencies
include(FindPackageHandleStandardArgs)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
# test dependencies
if (HAVE_TEST)
enable_testing()
# first we try default ways of finding gmodules
find_package(CHECK)
if(CHECK_FOUND)
check_symbol_exists(ck_assert_int_eq check.h CHECK_WORKING)
endif(CHECK_FOUND)
# if we don't have a working version of check, build it
if(NOT CHECK_LIBRARIES OR FORCE_CHECK_BUILD)
set(LIBCHECK_PREFIX "${CMAKE_BINARY_DIR}/check")
execute_process(
COMMAND "bash" "${PROJECT_SOURCE_DIR}/ci/install-check.sh" "${LIBCHECK_PREFIX}"
TIMEOUT 300 # if this doesn't build in 5 minutes something is hosed
RESULT_VARIABLE LIBCHECK_RETCODE
)
if(LIBCHECK_RETCODE) # non-zero means error
message(STATUS "build libcheck failed, return code: " ${LIBCHECK_RETCODE})
else(LIBCHECK_RETCODE)
# use locally built libcheck
set(CHECK_ROOT_DIR "${LIBCHECK_PREFIX}")
find_package(CHECK)
endif(LIBCHECK_RETCODE)
endif(NOT CHECK_LIBRARIES OR FORCE_CHECK_BUILD)
# use fluxcapacitor to mock time
if(OS_PLATFORM STREQUAL "OS_LINUX")
set(FLUXCAP_PREFIX "${CMAKE_BINARY_DIR}/fluxcapacitor")
execute_process(
COMMAND "bash" "${PROJECT_SOURCE_DIR}/ci/install-fluxcapacitor.sh" "${FLUXCAP_PREFIX}"
TIMEOUT 60 # if this doesn't build in 60 seconds something is hosed
RESULT_VARIABLE FLUXCAP_RETCODE
)
if(FLUXCAP_RETCODE) # non-zero means error
message(STATUS "build fluxcapacitor failed, return code: " ${FLUXCAP_RETCODE})
else(FLUXCAP_RETCODE)
set(FLUXCAP_BINARY "${FLUXCAP_PREFIX}/fluxcapacitor")
message(STATUS "fluxcapacitor available at: " ${FLUXCAP_BINARY})
endif(FLUXCAP_RETCODE)
endif(OS_PLATFORM STREQUAL "OS_LINUX")
endif(HAVE_TEST)
find_package(PkgConfig QUIET)
if (USE_PMEM)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBPMEM REQUIRED libpmem>=1.0)
else()
find_package(LIBPMEM REQUIRED 1.0)
endif()
link_directories(${LIBPMEM_LIBRARY_DIRS})
endif(USE_PMEM)
if (HAVE_ITT_INSTRUMENTATION)
if(PKG_CONFIG_FOUND)
pkg_check_modules(ITTNOTIFY REQUIRED ittnotify>=1.0)
else()
find_package(ITTNOTIFY REQUIRED 1.0)
endif()
include_directories(${ITTNOTIFY_INCLUDE_DIRS})
link_directories(${ITTNOTIFY_LIBRARY_DIRS})
link_libraries(${ITTNOTIFY_LIBRARIES})
endif(HAVE_ITT_INSTRUMENTATION)
find_package(Threads)
if(TARGET_CDB)
set(HAVE_RUST on)
endif(TARGET_CDB)
if(TARGET_HTTP)
set(HAVE_RUST on)
endif()
if(HAVE_RUST)
include(cmake/CMakeCargo.cmake)
endif(HAVE_RUST)
#set(CMAKE_INCLUDE_CURRENT_DIR)
include_directories(${include_directories}
"${PROJECT_BINARY_DIR}"
"${CCOMMON_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/benchmarks")
# server & (cli) client
add_subdirectory(src)
if(HAVE_TEST)
include_directories(${include_directories} ${CHECK_INCLUDES})
add_subdirectory(test)
endif(HAVE_TEST)
#if(${OS_PLATFORM} MATCHES "OS_LINUX")
add_subdirectory(benchmarks)
#endif()
###################
# print a summary #
###################
message(STATUS "<<++=====------------------\\/------------------=====++>>")
message(STATUS "<<++ pelikan summary ++>>")
message(STATUS "<<++=====------------------/\\------------------=====++>>")
message(STATUS "=============CMake related=============")
message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
message(STATUS "PLATFORM: " ${OS_PLATFORM})
message(STATUS "CPPFLAGS: " ${CMAKE_CPP_FLAGS})
message(STATUS "CFLAGS: " ${CMAKE_C_FLAGS})
message(STATUS "=======================================")
message(STATUS "=======Status of system features=======")
message(STATUS "HAVE_BACKTRACE: " ${HAVE_BACKTRACE})
message(STATUS "USE_EVENT_FD: " ${USE_EVENT_FD})
message(STATUS "=======================================")
message(STATUS "======Status of optional features======")
message(STATUS "HAVE_RUST: " ${HAVE_RUST})
message(STATUS "HAVE_ASSERT_LOG: " ${HAVE_ASSERT_LOG})
message(STATUS "HAVE_ASSERT_PANIC: " ${HAVE_ASSERT_PANIC})
message(STATUS "HAVE_LOGGING: " ${HAVE_LOGGING})
message(STATUS "HAVE_STATS: " ${HAVE_STATS})
message(STATUS "HAVE_ITT_INSTRUMENTATION: " ${HAVE_ITT_INSTRUMENTATION})
message(STATUS "HAVE_DEBUG_MM: " ${HAVE_DEBUG_MM})
message(STATUS "HAVE_TEST: " ${HAVE_TEST})
message(STATUS "HAVE_COVERAGE: " ${HAVE_COVERAGE})
message(STATUS "USE_PMEM: " ${USE_PMEM})
message(STATUS "=======================================")
if(DUMP_ALL)
message(STATUS "<<++=====------------------\\/------------------=====++>>")
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
message(STATUS "<<++=====------------------/\\------------------=====++>>")
endif()
# Note: to uninstall targets, run:
# xargs rm < install_manifest.txt
# vim:ts=4:sw=4:et
if(HAVE_RUST)
# Create a .cargo file which sets the target directory
make_directory(.cargo)
file(WRITE .cargo/config "[build]\ntarget-dir=\"${CMAKE_BINARY_DIR}/target\"\n")
set_directory_properties(
PROPERTIES
ADDITIONAL_CLEAN_FILES "${CMAKE_BINARY_DIR}/target"
)
# Add a rust-docs target
add_custom_target(
rust-doc
COMMAND ${CMAKE_COMMAND} -E env "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}" "CARGO_TARGET_DIR=${CMAKE_BINARY_DIR}/target" cargo doc
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()