xref: /3.0.2-MP2/memcached/CMakeLists.txt (revision 9de7f95d)
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   ENDIF (DTRACE_NEED_INSTUMENT)
160ENDIF (ENABLE_DTRACE)
161
162ADD_EXECUTABLE(memcached_config_test tests/config_test.c
163               daemon/config_util.c daemon/config_util.h)
164TARGET_LINK_LIBRARIES(memcached_config_test cJSON)
165ADD_EXECUTABLE(ssltest tests/ssltest.c
166                       programs/utilities.c
167                       programs/utilities.h)
168
169ADD_EXECUTABLE(memcached_testapp tests/testapp.c daemon/cache.c)
170
171SET(CBSASL_SOURCES include/cbsasl/cbsasl.h include/cbsasl/visibility.h
172                   cbsasl/client.c cbsasl/common.c cbsasl/cram-md5/cram-md5.c
173                   cbsasl/cram-md5/cram-md5.h cbsasl/cram-md5/hmac.c
174                   cbsasl/cram-md5/hmac.h cbsasl/cram-md5/md5.c
175                   cbsasl/cram-md5/md5.h cbsasl/hash.c cbsasl/hash.h
176                   cbsasl/plain/plain.c cbsasl/plain/plain.h cbsasl/pwfile.c
177                   cbsasl/pwfile.h cbsasl/server.c cbsasl/strcmp.c
178                   cbsasl/util.h)
179
180ADD_LIBRARY(cbsasl SHARED ${CBSASL_SOURCES})
181SET_TARGET_PROPERTIES(cbsasl PROPERTIES SOVERSION 1.1.1)
182SET_TARGET_PROPERTIES(cbsasl PROPERTIES COMPILE_FLAGS -DBUILDING_CBSASL=1)
183SET_TARGET_PROPERTIES(cbsasl PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
184
185ADD_EXECUTABLE(cbsasl_hmac_test tests/cbsasl/hmac_test.c
186                                cbsasl/cram-md5/hmac.c
187                                cbsasl/cram-md5/hmac.h
188                                cbsasl/cram-md5/md5.c
189                                cbsasl/cram-md5/md5.h)
190
191ADD_EXECUTABLE(cbsasl_pwfile_test tests/cbsasl/pwfile_test.c
192                                  cbsasl/pwfile.c
193                                  cbsasl/pwfile.h
194                                  cbsasl/hash.c
195                                  cbsasl/hash.h)
196
197# We're using an "internal api" of the library in the test so we can't
198# use the library we just built
199ADD_EXECUTABLE(sasl_test tests/cbsasl/sasl_server_test.c ${CBSASL_SOURCES})
200SET_TARGET_PROPERTIES(sasl_test PROPERTIES COMPILE_FLAGS -DBUILDING_CBSASL=1)
201
202ADD_EXECUTABLE(cbsasl_test tests/cbsasl/cbsasl_test.c
203                           include/cbsasl/cbsasl.h
204                           include/cbsasl/visibility.h)
205TARGET_LINK_LIBRARIES(cbsasl_test cbsasl)
206
207TARGET_LINK_LIBRARIES(cbsasl platform)
208TARGET_LINK_LIBRARIES(cbsasl_pwfile_test platform)
209TARGET_LINK_LIBRARIES(sasl_test platform)
210
211ADD_EXECUTABLE(cbsasl_strcmp_test tests/cbsasl/strcmp_test.c
212                                  include/cbsasl/cbsasl.h
213                                  include/cbsasl/visibility.h
214                                  cbsasl/strcmp.c)
215#
216# Add linker flags to all of the binaries
217#
218TARGET_LINK_LIBRARIES(bucket_engine mcd_util platform ${COUCHBASE_NETWORK_LIBS} ${COUCHBASE_MATH_LIBS})
219TARGET_LINK_LIBRARIES(default_engine mcd_util platform ${COUCHBASE_NETWORK_LIBS})
220TARGET_LINK_LIBRARIES(basic_engine_testsuite mcd_util platform ${COUCHBASE_NETWORK_LIBS})
221TARGET_LINK_LIBRARIES(stdin_term_handler platform)
222TARGET_LINK_LIBRARIES(fragment_rw_ops mcd_util platform ${COUCHBASE_NETWORK_LIBS})
223TARGET_LINK_LIBRARIES(engine_testapp mcd_util platform ${COUCHBASE_NETWORK_LIBS})
224TARGET_LINK_LIBRARIES(bucket_engine_testapp mcd_util platform ${COUCHBASE_NETWORK_LIBS} ${COUCHBASE_MATH_LIBS})
225TARGET_LINK_LIBRARIES(cbsasladm platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
226TARGET_LINK_LIBRARIES(mcstat platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
227TARGET_LINK_LIBRARIES(mctimings cJSON platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
228TARGET_LINK_LIBRARIES(mcctl platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
229TARGET_LINK_LIBRARIES(mchello platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
230TARGET_LINK_LIBRARIES(ssltest platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
231TARGET_LINK_LIBRARIES(tap_mock_engine platform ${COUCHBASE_NETWORK_LIBS})
232TARGET_LINK_LIBRARIES(testapp_extension mcd_util platform ${COUCHBASE_NETWORK_LIBS})
233
234TARGET_LINK_LIBRARIES(mcd_util platform)
235TARGET_LINK_LIBRARIES(memcached mcd_util cbsasl platform cJSON JSON_checker ${SNAPPY_LIBRARIES} ${MALLOC_LIBRARIES} ${LIBEVENT_LIBRARIES} ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
236TARGET_LINK_LIBRARIES(memcached_testapp mcd_util cJSON platform ${SNAPPY_LIBRARIES} ${LIBEVENT_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
237
238TARGET_LINK_LIBRARIES(file_logger platform)
239
240IF (INSTALL_HEADER_FILES)
241   INSTALL (FILES include/memcached/allocator_hooks.h
242                  include/memcached/callback.h
243                  include/memcached/config_parser.h
244                  include/memcached/engine.h
245                  include/memcached/engine_common.h
246                  include/memcached/engine_testapp.h
247                  include/memcached/extension.h
248                  include/memcached/extension_loggers.h
249                  include/memcached/protocol_binary.h
250                  include/memcached/protocol_plugin.h
251                  include/memcached/server_api.h
252                  include/memcached/types.h
253                  include/memcached/dcp.h
254                  include/memcached/util.h
255                  include/memcached/vbucket.h
256                  include/memcached/visibility.h
257            DESTINATION include/memcached)
258
259   INSTALL(FILES
260           include/cbsasl/cbsasl.h
261           include/cbsasl/visibility.h
262           DESTINATION include/cbsasl)
263ENDIF(INSTALL_HEADER_FILES)
264
265SET_TARGET_PROPERTIES(mcd_util PROPERTIES SOVERSION 1.0.0)
266INSTALL(TARGETS mcd_util
267        RUNTIME DESTINATION bin
268        LIBRARY DESTINATION lib/memcached
269        ARCHIVE DESTINATION lib/memcached)
270
271INSTALL(TARGETS default_engine bucket_engine blackhole_logger
272                fragment_rw_ops stdin_term_handler file_logger
273        RUNTIME DESTINATION lib/memcached
274        LIBRARY DESTINATION lib/memcached
275        ARCHIVE DESTINATION lib/memcached)
276
277SET_TARGET_PROPERTIES(mcd_util PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
278SET_TARGET_PROPERTIES(default_engine PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
279SET_TARGET_PROPERTIES(bucket_engine PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
280SET_TARGET_PROPERTIES(blackhole_logger PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
281SET_TARGET_PROPERTIES(fragment_rw_ops PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
282SET_TARGET_PROPERTIES(stdin_term_handler PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
283SET_TARGET_PROPERTIES(file_logger PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
284
285INSTALL(TARGETS engine_testapp cbsasladm mcctl mcstat mctimings memcached
286        RUNTIME DESTINATION bin)
287
288INSTALL(TARGETS cbsasl
289        RUNTIME DESTINATION bin
290        LIBRARY DESTINATION lib
291        ARCHIVE DESTINATION lib)
292
293ADD_TEST(memcached-config memcached_config_test)
294ADD_TEST(memcached-sizes memcached_sizes)
295ADD_TEST(memcached-basic-unit-tests memcached_testapp)
296ADD_TEST(memcached-bucket_engine-unit-tests bucket_engine_testapp)
297ADD_TEST(memcached-basic-engine-tests engine_testapp -E default_engine.so -T basic_engine_testsuite.so)
298
299IF(${COUCHBASE_PYTHON})
300ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated_breakdancer_testsuite.c
301                  COMMAND
302                        ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testsuite/breakdancer/engine_test.py > ${CMAKE_CURRENT_BINARY_DIR}/generated_breakdancer_testsuite.c
303                  DEPENDS
304                        testsuite/breakdancer/breakdancer.py
305                        testsuite/breakdancer/engine_test.py
306                  COMMENT "Generating the test suite")
307
308ADD_LIBRARY(breakdancer_testsuite SHARED
309            testsuite/breakdancer/suite_stubs.c
310            ${CMAKE_CURRENT_BINARY_DIR}/generated_breakdancer_testsuite.c)
311SET_TARGET_PROPERTIES(breakdancer_testsuite PROPERTIES PREFIX "")
312ADD_TEST(memcached-breakdancer-engine-tests engine_testapp -E default_engine.so -T breakdancer_testsuite.so)
313ENDIF(${COUCHBASE_PYTHON})
314
315IF ("${MEMORY_ALLOCATOR}" STREQUAL "tcmalloc")
316   ADD_EXECUTABLE(memcached_tcmalloc_test daemon/alloc_hooks.c
317                                          daemon/alloc_hooks.h
318                                          tests/tcmalloc_test.cc)
319   TARGET_LINK_LIBRARIES(memcached_tcmalloc_test platform ${TCMALLOC_LIBRARIES})
320   ADD_TEST(memcached-tcmalloc-hooks memcached_tcmalloc_test)
321ENDIF ("${MEMORY_ALLOCATOR}" STREQUAL "tcmalloc")
322
323
324ADD_TEST(cbsasl-hmac cbsasl_hmac_test)
325ADD_TEST(cbsasl-pwfile cbsasl_pwfile_test)
326ADD_TEST(cbsasl-sasl sasl_test)
327ADD_TEST(cbsasl-client-server cbsasl_test)
328ADD_TEST(cbsasl-strcmp cbsasl_strcmp_test)
329
330ADD_CUSTOM_TARGET(memcached-manpage
331                  COMMAND a2x -L --doctype manpage --format manpage
332                          ${CMAKE_CURRENT_SOURCE_DIR}/man/man4/memcached.json.4.txt
333                  COMMAND a2x -L --doctype manpage --format pdf
334                          ${CMAKE_CURRENT_SOURCE_DIR}/man/man4/memcached.json.4.txt
335                  VERBATIM)
336
337IF (NOT WIN32)
338   INSTALL(FILES man/man4/memcached.json.4
339           DESTINATION man/man4)
340ENDIF(NOT WIN32)
341
342INSTALL(FILES man/man4/memcached.json.4.pdf
343        DESTINATION doc)
344
345ADD_EXECUTABLE(memcached_logger_test tests/logger_test.cc)
346TARGET_LINK_LIBRARIES(memcached_logger_test mcd_util file_logger dirutils)
347ADD_TEST(memcached-logger-test memcached_logger_test)
348