xref: /3.0.2-MP2/memcached/CMakeLists.txt (revision 410effde)
1PROJECT(Memcached)
2CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
3
4IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
5   EXECUTE_PROCESS(COMMAND git log -1 --pretty=format:%H
6                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
7                   OUTPUT_VARIABLE MEMCACHED_VERSION
8                   ERROR_QUIET
9                   OUTPUT_STRIP_TRAILING_WHITESPACE)
10ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
11   SET(MEMCACHED_VERSION "unknown")
12ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
13
14CHECK_INCLUDE_FILE_CXX("atomic" HAVE_ATOMIC)
15
16CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
17               ${CMAKE_CURRENT_BINARY_DIR}/config.h)
18
19IF (ENABLE_DTRACE)
20   ADD_DEFINITIONS(-DENABLE_DTRACE=1)
21ENDIF (ENABLE_DTRACE)
22
23ADD_CUSTOM_COMMAND(OUTPUT ${Memcached_BINARY_DIR}/memcached_dtrace.h
24                   COMMAND
25                     ${DTRACE} -h
26                               -s ${Memcached_SOURCE_DIR}/memcached_dtrace.d
27                               -o ${Memcached_BINARY_DIR}/memcached_dtrace.h
28                   DEPENDS
29                         memcached_dtrace.d
30                   COMMENT "Generating DTrace probe header file"
31                   VERBATIM)
32
33INCLUDE_DIRECTORIES(BEFORE
34                    ${LIBEVENT_INCLUDE_DIR}
35                    ${SNAPPY_INCLUDE_DIR}
36                    ${OPENSSL_INCLUDE_DIR}
37                    ${CMAKE_INSTALL_PREFIX}/include
38                    ${CMAKE_CURRENT_SOURCE_DIR}/include
39                    ${CMAKE_CURRENT_BINARY_DIR}
40                    ${CMAKE_CURRENT_SOURCE_DIR}
41                    ${Platform_SOURCE_DIR}/include)
42
43IF (MEMORY_ALLOCATOR)
44   INCLUDE_DIRECTORIES(AFTER ${MALLOC_INCLUDE_DIR})
45ELSE (MEMORY_ALLOCATOR)
46   SET(MALLOC_LIBRARIES "")
47ENDIF (MEMORY_ALLOCATOR)
48
49IF (WIN32)
50   INCLUDE_DIRECTORIES(AFTER ${Platform_SOURCE_DIR}/include/win32)
51ELSE (WIN32)
52   ADD_EXECUTABLE(mcbasher programs/mcbasher.cc)
53   TARGET_LINK_LIBRARIES(mcbasher platform ${COUCHBASE_NETWORK_LIBS})
54   ADD_EXECUTABLE(timedrun programs/timedrun.c)
55ENDIF (WIN32)
56
57ADD_SUBDIRECTORY(support-files)
58
59#
60# Add all of the libraries
61#
62ADD_LIBRARY(mcd_util SHARED
63            utilities/config_parser.c
64            utilities/engine_loader.c
65            utilities/extension_loggers.c
66            utilities/util.c)
67ADD_LIBRARY(default_engine SHARED
68            engines/default_engine/assoc.c
69            engines/default_engine/default_engine.c
70            engines/default_engine/items.c
71            engines/default_engine/slabs.c)
72ADD_LIBRARY(bucket_engine SHARED
73            engines/bucket_engine/bucket_engine.c
74            engines/bucket_engine/topkeys.c
75            engines/bucket_engine/genhash.c)
76ADD_LIBRARY(basic_engine_testsuite SHARED testsuite/basic_engine_testsuite.c)
77ADD_LIBRARY(blackhole_logger SHARED extensions/loggers/blackhole_logger.c)
78ADD_LIBRARY(fragment_rw_ops SHARED extensions/protocol/fragment_rw.c)
79ADD_LIBRARY(stdin_term_handler SHARED extensions/daemon/stdin_check.c)
80ADD_LIBRARY(tap_mock_engine SHARED engines/tap_mock_engine/tap_mock_engine.cc)
81ADD_LIBRARY(bucket_engine_mock_engine SHARED
82            engines/bucket_engine/mock_engine.c
83            engines/bucket_engine/genhash.c)
84ADD_LIBRARY(file_logger SHARED extensions/loggers/file_logger.c)
85ADD_LIBRARY(testapp_extension SHARED extensions/protocol/testapp_extension.c)
86
87SET_TARGET_PROPERTIES(default_engine PROPERTIES PREFIX "")
88SET_TARGET_PROPERTIES(bucket_engine PROPERTIES PREFIX "")
89SET_TARGET_PROPERTIES(basic_engine_testsuite PROPERTIES PREFIX "")
90SET_TARGET_PROPERTIES(blackhole_logger PROPERTIES PREFIX "")
91SET_TARGET_PROPERTIES(fragment_rw_ops PROPERTIES PREFIX "")
92SET_TARGET_PROPERTIES(stdin_term_handler PROPERTIES PREFIX "")
93SET_TARGET_PROPERTIES(tap_mock_engine PROPERTIES PREFIX "")
94SET_TARGET_PROPERTIES(bucket_engine_mock_engine PROPERTIES PREFIX "")
95SET_TARGET_PROPERTIES(file_logger PROPERTIES PREFIX "")
96SET_TARGET_PROPERTIES(testapp_extension PROPERTIES PREFIX "")
97
98#
99# All of the binaries we're building
100#
101ADD_EXECUTABLE(bucket_engine_testapp
102               engines/bucket_engine/testapp.c
103               engines/bucket_engine/genhash.c)
104ADD_EXECUTABLE(engine_testapp programs/engine_testapp/engine_testapp.c
105                              programs/engine_testapp/mock_server.c
106                              programs/engine_testapp/mock_server.h)
107ADD_EXECUTABLE(cbsasladm programs/cbsasladm.c
108                         programs/utilities.c
109                         programs/utilities.h)
110ADD_EXECUTABLE(mcstat programs/mcstat.c
111                      programs/utilities.c
112                      programs/utilities.h)
113ADD_EXECUTABLE(mctimings programs/mctimings.c
114                         programs/utilities.c
115                         programs/utilities.h
116                         utilities/protocol2text.c)
117ADD_EXECUTABLE(mcctl programs/mcctl.c
118                     programs/utilities.c
119                     programs/utilities.h
120                     utilities/util.c)
121
122ADD_EXECUTABLE(mchello programs/mchello.c
123                       programs/utilities.c
124                       programs/utilities.h)
125ADD_EXECUTABLE(memcached_sizes tests/sizes.c)
126ADD_EXECUTABLE(memcached
127               daemon/alloc_hooks.c
128               daemon/cache.c
129               daemon/cmdline.c
130               daemon/cmdline.h
131               daemon/config_util.c
132               daemon/config_util.h
133               daemon/config_parse.c
134               daemon/daemon.c
135               daemon/hash.c
136               daemon/memcached.c
137               daemon/privileges.c
138               daemon/stats.c
139               daemon/thread.c
140               daemon/timings.cc
141               daemon/mc_time.c)
142
143IF (ENABLE_DTRACE)
144   ADD_CUSTOM_TARGET(generate_memcached_dtrace_h
145                     DEPENDS ${Memcached_BINARY_DIR}/memcached_dtrace.h)
146   ADD_DEPENDENCIES(memcached generate_memcached_dtrace_h)
147   ADD_DEPENDENCIES(default_engine generate_memcached_dtrace_h)
148
149   IF (DTRACE_NEED_INSTUMENT)
150      ADD_CUSTOM_COMMAND(TARGET memcached PRE_LINK
151                         COMMAND
152                         ${DTRACE} -o memcached_dtrace.o
153                                   -G
154                                   -s ${Memcached_SOURCE_DIR}/memcached_dtrace.d
155                                   *.o
156                         WORKING_DIRECTORY ${Memcached_BINARY_DIR}/CMakeFiles/memcached.dir/daemon)
157      SET_TARGET_PROPERTIES(memcached PROPERTIES LINK_FLAGS
158                            "${Memcached_BINARY_DIR}/CMakeFiles/memcached.dir/daemon/memcached_dtrace.o")
159
160      ADD_CUSTOM_COMMAND(TARGET default_engine PRE_LINK
161                         COMMAND
162                         ${DTRACE} -o de_dtrace.o
163                                   -G
164                                   -s ${Memcached_SOURCE_DIR}/memcached_dtrace.d
165                                   *.o
166                         WORKING_DIRECTORY ${Memcached_BINARY_DIR}/CMakeFiles/default_engine.dir/engines/default_engine)
167      SET_TARGET_PROPERTIES(default_engine PROPERTIES LINK_FLAGS
168                            "${Memcached_BINARY_DIR}/CMakeFiles/default_engine.dir/engines/default_engine/de_dtrace.o")
169
170   ENDIF (DTRACE_NEED_INSTUMENT)
171ENDIF (ENABLE_DTRACE)
172
173ADD_EXECUTABLE(memcached_config_test tests/config_test.c
174               daemon/config_util.c daemon/config_util.h)
175TARGET_LINK_LIBRARIES(memcached_config_test cJSON)
176ADD_EXECUTABLE(ssltest tests/ssltest.c
177                       programs/utilities.c
178                       programs/utilities.h)
179
180ADD_EXECUTABLE(memcached_testapp tests/testapp.c daemon/cache.c programs/utilities.c)
181
182SET(CBSASL_SOURCES include/cbsasl/cbsasl.h include/cbsasl/visibility.h
183                   cbsasl/client.c cbsasl/common.c cbsasl/cram-md5/cram-md5.c
184                   cbsasl/cram-md5/cram-md5.h cbsasl/cram-md5/hmac.c
185                   cbsasl/cram-md5/hmac.h cbsasl/cram-md5/md5.c
186                   cbsasl/cram-md5/md5.h cbsasl/hash.c cbsasl/hash.h
187                   cbsasl/plain/plain.c cbsasl/plain/plain.h cbsasl/pwfile.c
188                   cbsasl/pwfile.h cbsasl/server.c cbsasl/strcmp.c
189                   cbsasl/util.h)
190
191ADD_LIBRARY(cbsasl SHARED ${CBSASL_SOURCES})
192SET_TARGET_PROPERTIES(cbsasl PROPERTIES SOVERSION 1.1.1)
193SET_TARGET_PROPERTIES(cbsasl PROPERTIES COMPILE_FLAGS -DBUILDING_CBSASL=1)
194SET_TARGET_PROPERTIES(cbsasl PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
195
196ADD_EXECUTABLE(cbsasl_hmac_test tests/cbsasl/hmac_test.c
197                                cbsasl/cram-md5/hmac.c
198                                cbsasl/cram-md5/hmac.h
199                                cbsasl/cram-md5/md5.c
200                                cbsasl/cram-md5/md5.h)
201
202ADD_EXECUTABLE(cbsasl_pwfile_test tests/cbsasl/pwfile_test.c
203                                  cbsasl/pwfile.c
204                                  cbsasl/pwfile.h
205                                  cbsasl/hash.c
206                                  cbsasl/hash.h)
207
208# We're using an "internal api" of the library in the test so we can't
209# use the library we just built
210ADD_EXECUTABLE(sasl_test tests/cbsasl/sasl_server_test.c ${CBSASL_SOURCES})
211SET_TARGET_PROPERTIES(sasl_test PROPERTIES COMPILE_FLAGS -DBUILDING_CBSASL=1)
212
213ADD_EXECUTABLE(cbsasl_test tests/cbsasl/cbsasl_test.c
214                           include/cbsasl/cbsasl.h
215                           include/cbsasl/visibility.h)
216TARGET_LINK_LIBRARIES(cbsasl_test cbsasl)
217
218TARGET_LINK_LIBRARIES(cbsasl platform)
219TARGET_LINK_LIBRARIES(cbsasl_pwfile_test platform)
220TARGET_LINK_LIBRARIES(sasl_test platform)
221
222ADD_EXECUTABLE(cbsasl_strcmp_test tests/cbsasl/strcmp_test.c
223                                  include/cbsasl/cbsasl.h
224                                  include/cbsasl/visibility.h
225                                  cbsasl/strcmp.c)
226#
227# Add linker flags to all of the binaries
228#
229TARGET_LINK_LIBRARIES(bucket_engine mcd_util platform ${COUCHBASE_NETWORK_LIBS} ${COUCHBASE_MATH_LIBS})
230TARGET_LINK_LIBRARIES(default_engine mcd_util platform ${COUCHBASE_NETWORK_LIBS})
231TARGET_LINK_LIBRARIES(basic_engine_testsuite mcd_util platform ${COUCHBASE_NETWORK_LIBS})
232TARGET_LINK_LIBRARIES(stdin_term_handler platform)
233TARGET_LINK_LIBRARIES(fragment_rw_ops mcd_util platform ${COUCHBASE_NETWORK_LIBS})
234TARGET_LINK_LIBRARIES(engine_testapp mcd_util platform ${COUCHBASE_NETWORK_LIBS})
235TARGET_LINK_LIBRARIES(bucket_engine_testapp mcd_util platform ${COUCHBASE_NETWORK_LIBS} ${COUCHBASE_MATH_LIBS})
236TARGET_LINK_LIBRARIES(cbsasladm platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
237TARGET_LINK_LIBRARIES(mcstat platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
238TARGET_LINK_LIBRARIES(mctimings cJSON platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
239TARGET_LINK_LIBRARIES(mcctl platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
240TARGET_LINK_LIBRARIES(mchello platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
241TARGET_LINK_LIBRARIES(ssltest platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
242TARGET_LINK_LIBRARIES(tap_mock_engine platform ${COUCHBASE_NETWORK_LIBS})
243TARGET_LINK_LIBRARIES(testapp_extension mcd_util platform ${COUCHBASE_NETWORK_LIBS})
244
245TARGET_LINK_LIBRARIES(mcd_util platform)
246TARGET_LINK_LIBRARIES(memcached mcd_util cbsasl platform cJSON JSON_checker ${SNAPPY_LIBRARIES} ${MALLOC_LIBRARIES} ${LIBEVENT_LIBRARIES} ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
247TARGET_LINK_LIBRARIES(memcached_testapp mcd_util cJSON platform ${SNAPPY_LIBRARIES} ${LIBEVENT_LIBRARIES} ${COUCHBASE_NETWORK_LIBS} ${OPENSSL_LIBRARIES})
248
249TARGET_LINK_LIBRARIES(file_logger platform)
250
251IF (INSTALL_HEADER_FILES)
252   INSTALL (FILES include/memcached/allocator_hooks.h
253                  include/memcached/callback.h
254                  include/memcached/config_parser.h
255                  include/memcached/engine.h
256                  include/memcached/engine_common.h
257                  include/memcached/engine_testapp.h
258                  include/memcached/extension.h
259                  include/memcached/extension_loggers.h
260                  include/memcached/protocol_binary.h
261                  include/memcached/protocol_plugin.h
262                  include/memcached/server_api.h
263                  include/memcached/types.h
264                  include/memcached/dcp.h
265                  include/memcached/util.h
266                  include/memcached/vbucket.h
267                  include/memcached/visibility.h
268            DESTINATION include/memcached)
269
270   INSTALL(FILES
271           include/cbsasl/cbsasl.h
272           include/cbsasl/visibility.h
273           DESTINATION include/cbsasl)
274ENDIF(INSTALL_HEADER_FILES)
275
276SET_TARGET_PROPERTIES(mcd_util PROPERTIES SOVERSION 1.0.0)
277INSTALL(TARGETS mcd_util
278        RUNTIME DESTINATION bin
279        LIBRARY DESTINATION lib/memcached
280        ARCHIVE DESTINATION lib/memcached)
281
282INSTALL(TARGETS default_engine bucket_engine blackhole_logger
283                fragment_rw_ops stdin_term_handler file_logger
284        RUNTIME DESTINATION lib/memcached
285        LIBRARY DESTINATION lib/memcached
286        ARCHIVE DESTINATION lib/memcached)
287
288SET_TARGET_PROPERTIES(mcd_util PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
289SET_TARGET_PROPERTIES(default_engine PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
290SET_TARGET_PROPERTIES(bucket_engine PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
291SET_TARGET_PROPERTIES(blackhole_logger PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
292SET_TARGET_PROPERTIES(fragment_rw_ops PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
293SET_TARGET_PROPERTIES(stdin_term_handler PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
294SET_TARGET_PROPERTIES(file_logger PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
295
296INSTALL(TARGETS engine_testapp cbsasladm mcctl mcstat mctimings memcached
297        RUNTIME DESTINATION bin)
298
299INSTALL(TARGETS cbsasl
300        RUNTIME DESTINATION bin
301        LIBRARY DESTINATION lib
302        ARCHIVE DESTINATION lib)
303
304ADD_TEST(memcached-config memcached_config_test)
305ADD_TEST(memcached-sizes memcached_sizes)
306ADD_TEST(memcached-basic-unit-tests memcached_testapp)
307ADD_TEST(memcached-bucket_engine-unit-tests bucket_engine_testapp)
308ADD_TEST(memcached-basic-engine-tests engine_testapp -E default_engine.so -T basic_engine_testsuite.so)
309
310IF(${COUCHBASE_PYTHON})
311    ADD_CUSTOM_COMMAND(OUTPUT
312                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_0.c
313                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_1.c
314                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_2.c
315                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_3.c
316                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_4.c
317                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_5.c
318                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_6.c
319                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_7.c
320                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_8.c
321                           ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_9.c
322                       COMMAND
323                           ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testsuite/breakdancer/engine_test.py
324                       DEPENDS
325                           testsuite/breakdancer/engine_test.py
326                           testsuite/breakdancer/breakdancer.py
327                       COMMENT "Generating testsuite")
328
329    ADD_LIBRARY(memcached_generated_testsuite SHARED
330                testsuite/breakdancer/suite_stubs.c
331                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_0.c
332                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_1.c
333                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_2.c
334                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_3.c
335                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_4.c
336                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_5.c
337                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_6.c
338                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_7.c
339                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_8.c
340                ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_9.c)
341
342    SET_TARGET_PROPERTIES(memcached_generated_testsuite PROPERTIES PREFIX "")
343    ADD_TEST(memcached-breakdancer-engine-tests engine_testapp -E default_engine.so -T memcached_generated_testsuite.so)
344ENDIF(${COUCHBASE_PYTHON})
345
346IF ("${MEMORY_ALLOCATOR}" STREQUAL "tcmalloc")
347   ADD_EXECUTABLE(memcached_tcmalloc_test daemon/alloc_hooks.c
348                                          daemon/alloc_hooks.h
349                                          tests/tcmalloc_test.cc)
350   TARGET_LINK_LIBRARIES(memcached_tcmalloc_test platform ${TCMALLOC_LIBRARIES})
351   ADD_TEST(memcached-tcmalloc-hooks memcached_tcmalloc_test)
352ENDIF ("${MEMORY_ALLOCATOR}" STREQUAL "tcmalloc")
353
354CONFIGURE_FILE(tests/cert/testapp.pem tests/cert/testapp.pem COPYONLY)
355CONFIGURE_FILE(tests/cert/testapp.cert tests/cert/testapp.cert COPYONLY)
356
357ADD_TEST(cbsasl-hmac cbsasl_hmac_test)
358ADD_TEST(cbsasl-pwfile cbsasl_pwfile_test)
359ADD_TEST(cbsasl-sasl sasl_test)
360ADD_TEST(cbsasl-client-server cbsasl_test)
361ADD_TEST(cbsasl-strcmp cbsasl_strcmp_test)
362
363ADD_CUSTOM_TARGET(memcached-manpage
364                  COMMAND a2x -L --doctype manpage --format manpage
365                          ${CMAKE_CURRENT_SOURCE_DIR}/man/man4/memcached.json.4.txt
366                  COMMAND a2x -L --doctype manpage --format pdf
367                          ${CMAKE_CURRENT_SOURCE_DIR}/man/man4/memcached.json.4.txt
368                  VERBATIM)
369
370IF (NOT WIN32)
371   INSTALL(FILES man/man4/memcached.json.4
372           DESTINATION man/man4)
373ENDIF(NOT WIN32)
374
375INSTALL(FILES man/man4/memcached.json.4.pdf
376        DESTINATION doc)
377
378ADD_EXECUTABLE(memcached_logger_test tests/logger_test.cc)
379TARGET_LINK_LIBRARIES(memcached_logger_test mcd_util file_logger dirutils)
380ADD_TEST(memcached-logger-test memcached_logger_test)
381