MB-19405: [BP] Address possible data races in PassiveStream context
[ep-engine.git] / CMakeLists.txt
1 PROJECT(EventuallyPersistentEngine)
2 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
3
4 INCLUDE(CheckFunctionExists)
5 INCLUDE(CheckIncludeFileCXX)
6 INCLUDE(CheckIncludeFiles)
7 INCLUDE(CheckLibraryExists)
8 INCLUDE(CheckSymbolExists)
9 INCLUDE(CheckTypeSize)
10
11 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_INSTALL_PREFIX}/include
12                            ${CMAKE_CURRENT_SOURCE_DIR}/include
13                            ${CMAKE_CURRENT_SOURCE_DIR}
14                            ${CMAKE_CURRENT_SOURCE_DIR}/src
15                            ${CMAKE_CURRENT_BINARY_DIR}/src
16                            ${SNAPPY_INCLUDE_DIR}
17                            ${Platform_SOURCE_DIR}/include
18                            ${Memcached_SOURCE_DIR}/include
19                            ${Couchstore_SOURCE_DIR}/include
20                            ${CMAKE_CURRENT_BINARY_DIR})
21
22 CHECK_INCLUDE_FILES("arpa/inet.h" HAVE_ARPA_INET_H)
23 CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)
24 CHECK_INCLUDE_FILES("netdb.h" HAVE_NETDB_H)
25 CHECK_INCLUDE_FILES("mach/mach_time.h" HAVE_MACH_MACH_TIME_H)
26 CHECK_INCLUDE_FILES("poll.h" HAVE_POLL_H)
27 CHECK_INCLUDE_FILES("atomic.h" HAVE_ATOMIC_H)
28 CHECK_INCLUDE_FILES("sysexits.h" HAVE_SYSEXITS_H)
29 CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)
30 CHECK_INCLUDE_FILES("sched.h" HAVE_SCHED_H)
31 CHECK_INCLUDE_FILES("sys/socket.h" HAVE_SYS_SOCKET_H)
32 CHECK_INCLUDE_FILES("sys/time.h" HAVE_SYS_TIME_H)
33 CHECK_INCLUDE_FILES("netinet/in.h" HAVE_NETINET_IN_H)
34 CHECK_INCLUDE_FILES("netinet/tcp.h" HAVE_NETINET_TCP_H)
35 CHECK_INCLUDE_FILE_CXX("tr1/memory" HAVE_TR1_MEMORY)
36 CHECK_INCLUDE_FILE_CXX("tr1/unordered_map" HAVE_TR1_UNORDERED_MAP)
37 CHECK_INCLUDE_FILE_CXX("unordered_map" HAVE_UNORDERED_MAP)
38 CHECK_INCLUDE_FILE_CXX("atomic" HAVE_ATOMIC)
39 CHECK_INCLUDE_FILE_CXX("thread" HAVE_THREAD)
40
41 CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
42 CHECK_FUNCTION_EXISTS(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
43 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
44 CHECK_FUNCTION_EXISTS(getopt_long HAVE_GETOPT_LONG)
45
46 # ---- uncomment the lines below ONLY for dev/debugging ---
47 #if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
48 #    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
49 #elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
50 #    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
51 #endif()
52
53 IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
54    EXECUTE_PROCESS(COMMAND git describe
55                    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
56                    OUTPUT_VARIABLE EP_ENGINE_VERSION
57                    ERROR_QUIET
58                    OUTPUT_STRIP_TRAILING_WHITESPACE)
59 ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
60    SET(EP_ENGINE_VERSION "unknown")
61 ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
62
63 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/src/config.cmake.h
64                 ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
65
66 # Generate the python wrappers
67 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
68                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbadm-tap-registration)
69 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
70                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbepctl)
71 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
72                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbstats)
73 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
74                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbcompact)
75 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
76                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvdiff)
77 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
78                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvbucketctl)
79
80 IF (WIN32)
81    INCLUDE_DIRECTORIES(AFTER ${CMAKE_SOURCE_DIR}/platform/include/win32)
82 ENDIF (WIN32)
83
84 ADD_EXECUTABLE(gencode tools/gencode.cc)
85 TARGET_LINK_LIBRARIES(gencode cJSON platform)
86
87 ADD_EXECUTABLE(genconfig tools/genconfig.cc)
88 TARGET_LINK_LIBRARIES(genconfig cJSON platform)
89
90 ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c
91                           ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.h
92                   COMMAND
93                      gencode -j ${CMAKE_CURRENT_SOURCE_DIR}/docs/stats.json -h ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.h -c ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c -f get_stats_info
94                   DEPENDS
95                         docs/stats.json
96                         gencode
97                   COMMENT "Generating code for stats info")
98
99 ADD_CUSTOM_COMMAND(OUTPUT
100                      ${CMAKE_CURRENT_BINARY_DIR}/src/generated_configuration.cc
101                      ${CMAKE_CURRENT_BINARY_DIR}/src/generated_configuration.h
102                   COMMAND
103                      genconfig ${CMAKE_CURRENT_SOURCE_DIR}/configuration.json
104                   DEPENDS
105                         configuration.json
106                         genconfig
107                   COMMENT "Generating code for configuration class")
108
109 SET(KVSTORE_SOURCE src/crc32.c src/kvstore.cc src/mutation_log.cc)
110 SET(COUCH_KVSTORE_SOURCE src/couch-kvstore/couch-kvstore.cc
111             src/couch-kvstore/couch-fs-stats.cc)
112 SET(OBJECTREGISTRY_SOURCE src/objectregistry.cc)
113 SET(CONFIG_SOURCE src/configuration.cc
114   ${CMAKE_CURRENT_BINARY_DIR}/src/generated_configuration.cc)
115
116 ADD_LIBRARY(ep SHARED
117             src/access_scanner.cc src/atomic.cc src/backfill.cc
118             src/bgfetcher.cc src/checkpoint.cc
119             src/checkpoint_remover.cc src/conflict_resolution.cc
120             src/ep.cc src/ep_engine.cc src/ep_time.c
121             src/executorpool.cc src/failover-table.cc
122             src/flusher.cc src/htresizer.cc
123             src/item.cc src/item_pager.cc src/kvshard.cc
124             src/memory_tracker.cc src/mutex.cc src/priority.cc
125             src/executorthread.cc
126             src/sizes.cc
127             ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c
128             src/stored-value.cc src/tapconnection.cc src/connmap.cc
129             src/tapthrottle.cc src/tasks.cc
130             src/taskqueue.cc
131             src/dcp-response.cc src/dcp-consumer.cc
132             src/dcp-producer.cc src/dcp-stream.cc src/vbucket.cc
133             src/vbucketmap.cc src/warmup.cc
134             ${KVSTORE_SOURCE} ${COUCH_KVSTORE_SOURCE}
135             ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
136
137 SET_TARGET_PROPERTIES(ep PROPERTIES PREFIX "")
138 TARGET_LINK_LIBRARIES(ep cJSON JSON_checker couchstore dirutils platform ${LIBEVENT_LIBRARIES})
139
140 ADD_EXECUTABLE(ep-engine_stream_test
141   tests/module_tests/stream_test.cc
142   src/access_scanner.cc
143   src/atomic.cc
144   src/backfill.cc
145   src/bgfetcher.cc
146   src/checkpoint.cc
147   src/checkpoint_remover.cc
148   src/conflict_resolution.cc
149   src/connmap.cc
150   src/dcp-consumer.cc
151   src/dcp-producer.cc
152   src/dcp-response.cc
153   src/dcp-stream.cc
154   src/ep.cc
155   src/ep_engine.cc
156   src/ep_time.c
157   src/executorpool.cc
158   src/executorthread.cc
159   src/failover-table.cc
160   src/flusher.cc
161   src/htresizer.cc
162   src/item.cc
163   src/item_pager.cc
164   src/kvshard.cc
165   src/memory_tracker.cc
166   src/mutation_log.cc
167   src/mutex.cc
168   src/objectregistry.cc
169   src/priority.cc
170   src/tapconnection.cc
171   src/stored-value.cc
172   src/tapthrottle.cc
173   src/tasks.cc
174   src/taskqueue.cc
175   src/vbucket.cc
176   src/vbucketmap.cc
177   src/warmup.cc
178   ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c
179   ${CONFIG_SOURCE}
180   ${KVSTORE_SOURCE}
181   ${COUCH_KVSTORE_SOURCE}
182   ${Memcached_SOURCE_DIR}/programs/engine_testapp/mock_server.c)
183 TARGET_LINK_LIBRARIES(ep-engine_stream_test couchstore cJSON dirutils JSON_checker mcd_util platform)
184
185 ADD_EXECUTABLE(ep-engine_atomic_ptr_test
186   tests/module_tests/atomic_ptr_test.cc
187   src/atomic.cc
188   src/testlogger.cc
189   src/mutex.cc)
190 TARGET_LINK_LIBRARIES(ep-engine_atomic_ptr_test platform)
191
192 ADD_EXECUTABLE(ep-engine_atomic_test
193   tests/module_tests/atomic_test.cc
194   src/testlogger.cc
195   src/mutex.cc)
196 TARGET_LINK_LIBRARIES(ep-engine_atomic_test platform)
197
198 ADD_EXECUTABLE(ep-engine_checkpoint_test
199   tests/module_tests/checkpoint_test.cc
200   src/checkpoint.cc src/failover-table.cc
201   src/testlogger.cc src/stored-value.cc
202   src/atomic.cc src/mutex.cc
203   tests/module_tests/test_memory_tracker.cc
204   src/item.cc src/vbucket.cc
205   ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
206 TARGET_LINK_LIBRARIES(ep-engine_checkpoint_test ${SNAPPY_LIBRARIES} cJSON platform)
207
208 ADD_EXECUTABLE(ep-engine_chunk_creation_test
209   tests/module_tests/chunk_creation_test.cc)
210
211 ADD_EXECUTABLE(ep-engine_hash_table_test
212   tests/module_tests/hash_table_test.cc src/item.cc
213   src/stored-value.cc
214   src/testlogger.cc src/atomic.cc src/mutex.cc
215   tests/module_tests/test_memory_tracker.cc
216   ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
217 TARGET_LINK_LIBRARIES(ep-engine_hash_table_test ${SNAPPY_LIBRARIES} platform)
218
219 ADD_EXECUTABLE(ep-engine_histo_test tests/module_tests/histo_test.cc)
220 ADD_EXECUTABLE(ep-engine_hrtime_test tests/module_tests/hrtime_test.cc)
221 TARGET_LINK_LIBRARIES(ep-engine_hrtime_test platform)
222
223 ADD_EXECUTABLE(ep-engine_misc_test tests/module_tests/misc_test.cc)
224 ADD_EXECUTABLE(ep-engine_mutex_test
225   tests/module_tests/mutex_test.cc src/testlogger.cc src/mutex.cc)
226 TARGET_LINK_LIBRARIES(ep-engine_mutex_test platform)
227
228 ADD_EXECUTABLE(ep-engine_priority_test  tests/module_tests/priority_test.cc
229                         src/priority.cc)
230 ADD_EXECUTABLE(ep-engine_ringbuffer_test tests/module_tests/ringbuffer_test.cc)
231
232 ADD_EXECUTABLE(ep-engine_failover_table_test tests/module_tests/failover_table_test.cc
233                         src/failover-table.cc src/mutex.cc src/testlogger.cc
234                         tests/module_tests/test_memory_tracker.cc
235                         ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
236 TARGET_LINK_LIBRARIES(ep-engine_failover_table_test cJSON platform)
237
238 ADD_TEST(ep-engine_atomic_ptr_test ep-engine_atomic_ptr_test)
239 ADD_TEST(ep-engine_atomic_test ep-engine_atomic_test)
240 ADD_TEST(ep-engine_checkpoint_test ep-engine_checkpoint_test)
241 ADD_TEST(ep-engine_chunk_creation_test ep-engine_chunk_creation_test)
242 ADD_TEST(ep-engine_failover_table_test ep-engine_failover_table_test)
243 ADD_TEST(ep-engine_hash_table_test ep-engine_hash_table_test)
244 ADD_TEST(ep-engine_histo_test ep-engine_histo_test)
245 ADD_TEST(ep-engine_hrtime_test ep-engine_hrtime_test)
246 ADD_TEST(ep-engine_misc_test ep-engine_misc_test)
247 ADD_TEST(ep-engine_mutex_test ep-engine_mutex_test)
248 ADD_TEST(ep-engine_priority_test ep-engine_priority_test)
249 ADD_TEST(ep-engine_ringbuffer_test ep-engine_ringbuffer_test)
250 ADD_TEST(ep-engine_stream_test ep-engine_stream_test)
251
252 ADD_LIBRARY(timing_tests SHARED tests/module_tests/timing_tests.cc)
253 SET_TARGET_PROPERTIES(timing_tests PROPERTIES PREFIX "")
254 TARGET_LINK_LIBRARIES(timing_tests platform)
255
256 ADD_EXECUTABLE(ep-engine_sizes src/sizes.cc src/mutex.h src/mutex.cc src/testlogger.cc
257               ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
258 TARGET_LINK_LIBRARIES(ep-engine_sizes platform)
259
260 ADD_LIBRARY(ep_testsuite SHARED
261    tests/ep_testsuite.cc
262    src/atomic.cc src/mutex.cc
263    src/item.cc src/testlogger.cc
264    src/ep_time.c
265    tests/mock/mock_dcp.cc
266    tests/ep_test_apis.cc ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
267 SET_TARGET_PROPERTIES(ep_testsuite PROPERTIES PREFIX "")
268 TARGET_LINK_LIBRARIES(ep_testsuite JSON_checker dirutils platform ${LIBEVENT_LIBRARIES} ${SNAPPY_LIBRARIES})
269
270
271 #ADD_CUSTOM_COMMAND(OUTPUT
272 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_0.c
273 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_1.c
274 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_2.c
275 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_3.c
276 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_4.c
277 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_5.c
278 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_6.c
279 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_7.c
280 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_8.c
281 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_9.c
282 #                  COMMAND
283 #                     ${PYTHON_EXECUTABLE} tests/module_tests/gen_engine_test.py
284 #                  DEPENDS
285 #                        tests/module_tests/gen_engine_test.py
286 #                        tests/module_tests/breakdancer.py
287 #                  COMMENT "Generating testsuite")
288 #
289 #ADD_LIBRARY(generated_testsuite SHARED
290 #            tests/suite_stubs.c
291 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_0.c
292 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_1.c
293 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_2.c
294 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_3.c
295 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_4.c
296 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_5.c
297 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_6.c
298 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_7.c
299 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_8.c
300 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_9.c)
301
302 #SET_TARGET_PROPERTIES(generated_testsuite PROPERTIES PREFIX "")
303
304 INSTALL(PROGRAMS
305         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbadm-tap-registration
306         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbepctl
307         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbstats
308         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbcompact
309         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvdiff
310         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvbucketctl
311         management/cbanalyze-core
312         DESTINATION bin)
313
314 INSTALL(PROGRAMS
315         management/cbadm-tap-registration
316         management/cbepctl
317         management/cbstats
318         management/cbcompact
319         management/cbvdiff
320         management/cbvbucketctl
321         DESTINATION lib/python)
322
323 INSTALL(FILES
324         management/clitool.py
325         management/mc_bin_client.py
326         management/mc_bin_server.py
327         management/memcacheConstants.py
328         management/tap.py
329         management/tap_example.py
330         DESTINATION lib/python)
331
332 INSTALL(TARGETS ep
333         RUNTIME DESTINATION lib/memcached
334         LIBRARY DESTINATION lib/memcached
335         ARCHIVE DESTINATION lib/memcached)
336
337 ADD_CUSTOM_TARGET(engine-tests
338                   COMMAND ${CMAKE_BINARY_DIR}/memcached/engine_testapp -E ep.so -T ep_testsuite.so -e "flushall_enabled=true;ht_size=13;ht_locks=7"
339                   VERBATIM)
340
341 ADD_TEST(ep-engine-engine-tests ${CMAKE_BINARY_DIR}/memcached/engine_testapp -E ep.so -T ep_testsuite.so -e "flushall_enabled=true;ht_size=13;ht_locks=7" )
342 # ADD_TEST(ep-engine-breakdancer-engine-tests ${CMAKE_BINARY_DIR}/memcached/engine_testapp -E ep.so -T generated_testsuite.so -e 'flushall_enabled=true;ht_size=13;ht_locks=7;backend=couchdb')
343
344 ADD_CUSTOM_TARGET(test-valgrind
345                   COMMAND valgrind --log-file=valgrind.log
346                                    --tool=Memcheck
347                                    --num-callers=50
348                                    --error-limit=yes
349                                    --track-origins=yes
350                                    --malloc-fill=55
351                                    --free-fill=aa
352                                    --dsymutil=yes -q
353                                    ${CMAKE_BINARY_DIR}/memcached/engine_testapp
354                                          -E ep.so
355                                          -T ep_testsuite.so
356                                          -e "flushall_enabled=true;ht_size=13;ht_locks=7"
357                   DEPENDS
358                         ${CMAKE_BINARY_DIR}/memcached/engine_testapp
359                         ep
360                         ep_testsuite
361                   VERBATIM)