1PROJECT(EventuallyPersistentEngine)
2CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
3
4INCLUDE(CheckFunctionExists)
5INCLUDE(CheckIncludeFileCXX)
6INCLUDE(CheckIncludeFiles)
7INCLUDE(CheckLibraryExists)
8INCLUDE(CheckSymbolExists)
9INCLUDE(CheckTypeSize)
10
11INCLUDE_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
22CHECK_INCLUDE_FILES("arpa/inet.h" HAVE_ARPA_INET_H)
23CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)
24CHECK_INCLUDE_FILES("netdb.h" HAVE_NETDB_H)
25CHECK_INCLUDE_FILES("mach/mach_time.h" HAVE_MACH_MACH_TIME_H)
26CHECK_INCLUDE_FILES("poll.h" HAVE_POLL_H)
27CHECK_INCLUDE_FILES("atomic.h" HAVE_ATOMIC_H)
28CHECK_INCLUDE_FILES("sysexits.h" HAVE_SYSEXITS_H)
29CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)
30CHECK_INCLUDE_FILES("sched.h" HAVE_SCHED_H)
31CHECK_INCLUDE_FILES("sys/socket.h" HAVE_SYS_SOCKET_H)
32CHECK_INCLUDE_FILES("sys/time.h" HAVE_SYS_TIME_H)
33CHECK_INCLUDE_FILES("netinet/in.h" HAVE_NETINET_IN_H)
34CHECK_INCLUDE_FILES("netinet/tcp.h" HAVE_NETINET_TCP_H)
35CHECK_INCLUDE_FILE_CXX("tr1/memory" HAVE_TR1_MEMORY)
36CHECK_INCLUDE_FILE_CXX("tr1/unordered_map" HAVE_TR1_UNORDERED_MAP)
37CHECK_INCLUDE_FILE_CXX("unordered_map" HAVE_UNORDERED_MAP)
38CHECK_INCLUDE_FILE_CXX("atomic" HAVE_ATOMIC)
39CHECK_INCLUDE_FILE_CXX("thread" HAVE_THREAD)
40
41CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
42CHECK_FUNCTION_EXISTS(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
43CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
44CHECK_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
53IF (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)
59ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
60   SET(EP_ENGINE_VERSION "unknown")
61ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
62
63CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/src/config.cmake.h
64                ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
65
66# Generate the python wrappers
67CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
68                ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbadm-tap-registration)
69CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
70                ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbepctl)
71CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
72                ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbstats)
73CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
74                ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbcompact)
75CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
76                ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvdiff)
77CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
78                ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvbucketctl)
79
80IF (WIN32)
81   INCLUDE_DIRECTORIES(AFTER ${CMAKE_SOURCE_DIR}/platform/include/win32)
82ENDIF (WIN32)
83
84ADD_EXECUTABLE(gencode tools/gencode.cc)
85TARGET_LINK_LIBRARIES(gencode cJSON platform)
86
87ADD_EXECUTABLE(genconfig tools/genconfig.cc)
88TARGET_LINK_LIBRARIES(genconfig cJSON platform)
89
90ADD_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
99ADD_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
109SET(KVSTORE_SOURCE src/crc32.c src/kvstore.cc src/mutation_log.cc)
110SET(COUCH_KVSTORE_SOURCE src/couch-kvstore/couch-kvstore.cc
111            src/couch-kvstore/couch-fs-stats.cc)
112SET(OBJECTREGISTRY_SOURCE src/objectregistry.cc)
113SET(CONFIG_SOURCE src/configuration.cc
114  ${CMAKE_CURRENT_BINARY_DIR}/src/generated_configuration.cc)
115
116ADD_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
137SET_TARGET_PROPERTIES(ep PROPERTIES PREFIX "")
138TARGET_LINK_LIBRARIES(ep cJSON JSON_checker couchstore dirutils platform ${LIBEVENT_LIBRARIES})
139
140ADD_EXECUTABLE(ep-engine_atomic_ptr_test
141  tests/module_tests/atomic_ptr_test.cc
142  src/atomic.cc
143  src/testlogger.cc
144  src/mutex.cc)
145TARGET_LINK_LIBRARIES(ep-engine_atomic_ptr_test platform)
146
147ADD_EXECUTABLE(ep-engine_atomic_test
148  tests/module_tests/atomic_test.cc
149  src/testlogger.cc
150  src/mutex.cc)
151TARGET_LINK_LIBRARIES(ep-engine_atomic_test platform)
152
153ADD_EXECUTABLE(ep-engine_checkpoint_test
154  tests/module_tests/checkpoint_test.cc
155  src/checkpoint.cc src/failover-table.cc
156  src/testlogger.cc src/stored-value.cc
157  src/atomic.cc src/mutex.cc
158  tests/module_tests/test_memory_tracker.cc
159  src/item.cc src/vbucket.cc
160  ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
161TARGET_LINK_LIBRARIES(ep-engine_checkpoint_test ${SNAPPY_LIBRARIES} cJSON platform)
162
163ADD_EXECUTABLE(ep-engine_chunk_creation_test
164  tests/module_tests/chunk_creation_test.cc)
165
166ADD_EXECUTABLE(ep-engine_hash_table_test
167  tests/module_tests/hash_table_test.cc src/item.cc
168  src/stored-value.cc
169  src/testlogger.cc src/atomic.cc src/mutex.cc
170  tests/module_tests/test_memory_tracker.cc
171  ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
172TARGET_LINK_LIBRARIES(ep-engine_hash_table_test ${SNAPPY_LIBRARIES} platform)
173
174ADD_EXECUTABLE(ep-engine_histo_test tests/module_tests/histo_test.cc)
175ADD_EXECUTABLE(ep-engine_hrtime_test tests/module_tests/hrtime_test.cc)
176TARGET_LINK_LIBRARIES(ep-engine_hrtime_test platform)
177
178ADD_EXECUTABLE(ep-engine_misc_test tests/module_tests/misc_test.cc)
179ADD_EXECUTABLE(ep-engine_mutex_test
180  tests/module_tests/mutex_test.cc src/testlogger.cc src/mutex.cc)
181TARGET_LINK_LIBRARIES(ep-engine_mutex_test platform)
182
183ADD_EXECUTABLE(ep-engine_priority_test  tests/module_tests/priority_test.cc
184                        src/priority.cc)
185ADD_EXECUTABLE(ep-engine_ringbuffer_test tests/module_tests/ringbuffer_test.cc)
186
187ADD_EXECUTABLE(ep-engine_failover_table_test tests/module_tests/failover_table_test.cc
188                        src/failover-table.cc src/mutex.cc src/testlogger.cc
189                        tests/module_tests/test_memory_tracker.cc
190                        ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
191TARGET_LINK_LIBRARIES(ep-engine_failover_table_test cJSON platform)
192
193ADD_TEST(ep-engine_atomic_ptr_test ep-engine_atomic_ptr_test)
194ADD_TEST(ep-engine_atomic_test ep-engine_atomic_test)
195ADD_TEST(ep-engine_checkpoint_test ep-engine_checkpoint_test)
196ADD_TEST(ep-engine_chunk_creation_test ep-engine_chunk_creation_test)
197ADD_TEST(ep-engine_failover_table_test ep-engine_failover_table_test)
198ADD_TEST(ep-engine_hash_table_test ep-engine_hash_table_test)
199ADD_TEST(ep-engine_histo_test ep-engine_histo_test)
200ADD_TEST(ep-engine_hrtime_test ep-engine_hrtime_test)
201ADD_TEST(ep-engine_misc_test ep-engine_misc_test)
202ADD_TEST(ep-engine_mutex_test ep-engine_mutex_test)
203ADD_TEST(ep-engine_priority_test ep-engine_priority_test)
204ADD_TEST(ep-engine_ringbuffer_test ep-engine_ringbuffer_test)
205
206ADD_LIBRARY(timing_tests SHARED tests/module_tests/timing_tests.cc)
207SET_TARGET_PROPERTIES(timing_tests PROPERTIES PREFIX "")
208TARGET_LINK_LIBRARIES(timing_tests platform)
209
210ADD_EXECUTABLE(ep-engine_sizes src/sizes.cc src/mutex.h src/mutex.cc src/testlogger.cc
211              ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
212TARGET_LINK_LIBRARIES(ep-engine_sizes platform)
213
214ADD_LIBRARY(ep_testsuite SHARED
215   tests/ep_testsuite.cc
216   src/atomic.cc src/mutex.cc
217   src/item.cc src/testlogger.cc
218   src/ep_time.c
219   tests/mock/mock_dcp.cc
220   tests/ep_test_apis.cc ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
221SET_TARGET_PROPERTIES(ep_testsuite PROPERTIES PREFIX "")
222TARGET_LINK_LIBRARIES(ep_testsuite JSON_checker dirutils platform ${LIBEVENT_LIBRARIES} ${SNAPPY_LIBRARIES})
223
224
225#ADD_CUSTOM_COMMAND(OUTPUT
226#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_0.c
227#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_1.c
228#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_2.c
229#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_3.c
230#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_4.c
231#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_5.c
232#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_6.c
233#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_7.c
234#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_8.c
235#                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_9.c
236#                  COMMAND
237#                     ${PYTHON_EXECUTABLE} tests/module_tests/gen_engine_test.py
238#                  DEPENDS
239#                        tests/module_tests/gen_engine_test.py
240#                        tests/module_tests/breakdancer.py
241#                  COMMENT "Generating testsuite")
242#
243#ADD_LIBRARY(generated_testsuite SHARED
244#            tests/suite_stubs.c
245#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_0.c
246#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_1.c
247#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_2.c
248#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_3.c
249#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_4.c
250#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_5.c
251#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_6.c
252#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_7.c
253#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_8.c
254#            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_9.c)
255
256#SET_TARGET_PROPERTIES(generated_testsuite PROPERTIES PREFIX "")
257
258INSTALL(PROGRAMS
259        ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbadm-tap-registration
260        ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbepctl
261        ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbstats
262        ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbcompact
263        ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvdiff
264        ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvbucketctl
265        management/cbanalyze-core
266        DESTINATION bin)
267
268INSTALL(PROGRAMS
269        management/cbadm-tap-registration
270        management/cbepctl
271        management/cbstats
272        management/cbcompact
273        management/cbvdiff
274        management/cbvbucketctl
275        DESTINATION lib/python)
276
277INSTALL(FILES
278        management/clitool.py
279        management/mc_bin_client.py
280        management/mc_bin_server.py
281        management/memcacheConstants.py
282        management/tap.py
283        management/tap_example.py
284        DESTINATION lib/python)
285
286INSTALL(TARGETS ep
287        RUNTIME DESTINATION lib/memcached
288        LIBRARY DESTINATION lib/memcached
289        ARCHIVE DESTINATION lib/memcached)
290
291ADD_CUSTOM_TARGET(engine-tests
292                  COMMAND ${CMAKE_BINARY_DIR}/memcached/engine_testapp -E ep.so -T ep_testsuite.so -e "flushall_enabled=true;ht_size=13;ht_locks=7"
293                  VERBATIM)
294
295ADD_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" )
296# 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')
297
298ADD_CUSTOM_TARGET(test-valgrind
299                  COMMAND valgrind --log-file=valgrind.log
300                                   --tool=Memcheck
301                                   --num-callers=50
302                                   --error-limit=yes
303                                   --track-origins=yes
304                                   --malloc-fill=55
305                                   --free-fill=aa
306                                   --dsymutil=yes -q
307                                   ${CMAKE_BINARY_DIR}/memcached/engine_testapp
308                                         -E ep.so
309                                         -T ep_testsuite.so
310                                         -e "flushall_enabled=true;ht_size=13;ht_locks=7"
311                  DEPENDS
312                        ${CMAKE_BINARY_DIR}/memcached/engine_testapp
313                        ep
314                        ep_testsuite
315                  VERBATIM)
316