xref: /3.0.2-MP2/memcached/CMakeLists.txt (revision 6ae7c28b)
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)
85
86SET_TARGET_PROPERTIES(default_engine PROPERTIES PREFIX "")
87SET_TARGET_PROPERTIES(bucket_engine PROPERTIES PREFIX "")
88SET_TARGET_PROPERTIES(basic_engine_testsuite PROPERTIES PREFIX "")
89SET_TARGET_PROPERTIES(blackhole_logger PROPERTIES PREFIX "")
90SET_TARGET_PROPERTIES(fragment_rw_ops PROPERTIES PREFIX "")
91SET_TARGET_PROPERTIES(stdin_term_handler PROPERTIES PREFIX "")
92SET_TARGET_PROPERTIES(tap_mock_engine PROPERTIES PREFIX "")
93SET_TARGET_PROPERTIES(bucket_engine_mock_engine PROPERTIES PREFIX "")
94SET_TARGET_PROPERTIES(file_logger PROPERTIES PREFIX "")
95
96#
97# All of the binaries we're building
98#
99ADD_EXECUTABLE(bucket_engine_testapp
100               engines/bucket_engine/testapp.c
101               engines/bucket_engine/genhash.c)
102ADD_EXECUTABLE(engine_testapp programs/engine_testapp/engine_testapp.c
103                              programs/engine_testapp/mock_server.c
104                              programs/engine_testapp/mock_server.h)
105ADD_EXECUTABLE(cbsasladm programs/cbsasladm.c
106                         programs/utilities.c
107                         programs/utilities.h)
108ADD_EXECUTABLE(mcstat programs/mcstat.c
109                      programs/utilities.c
110                      programs/utilities.h)
111ADD_EXECUTABLE(mctimings programs/mctimings.c
112                         programs/utilities.c
113                         programs/utilities.h
114                         utilities/protocol2text.c)
115ADD_EXECUTABLE(mcctl programs/mcctl.c
116                     programs/utilities.c
117                     programs/utilities.h
118                     utilities/util.c)
119
120ADD_EXECUTABLE(mchello programs/mchello.c
121                       programs/utilities.c
122                       programs/utilities.h)
123ADD_EXECUTABLE(memcached_sizes tests/sizes.c)
124ADD_EXECUTABLE(memcached
125               daemon/alloc_hooks.c
126               daemon/cache.c
127               daemon/cmdline.c
128               daemon/cmdline.h
129               daemon/config_util.c
130               daemon/config_util.h
131               daemon/config_parse.c
132               daemon/daemon.c
133               daemon/hash.c
134               daemon/memcached.c
135               daemon/privileges.c
136               daemon/stats.c
137               daemon/thread.c
138               daemon/timings.cc)
139
140IF (ENABLE_DTRACE)
141   ADD_CUSTOM_TARGET(generate_memcached_dtrace_h
142                     DEPENDS ${Memcached_BINARY_DIR}/memcached_dtrace.h)
143   ADD_DEPENDENCIES(memcached generate_memcached_dtrace_h)
144   ADD_DEPENDENCIES(default_engine generate_memcached_dtrace_h)
145
146   IF (DTRACE_NEED_INSTUMENT)
147      ADD_CUSTOM_COMMAND(TARGET memcached PRE_LINK
148                         COMMAND
149                         ${DTRACE} -o memcached_dtrace.o
150                                   -G
151                                   -s ${Memcached_SOURCE_DIR}/memcached_dtrace.d
152                                   *.o
153                         WORKING_DIRECTORY ${Memcached_BINARY_DIR}/CMakeFiles/memcached.dir/daemon)
154      SET_TARGET_PROPERTIES(memcached PROPERTIES LINK_FLAGS
155                            "${Memcached_BINARY_DIR}/CMakeFiles/memcached.dir/daemon/memcached_dtrace.o")
156   ENDIF (DTRACE_NEED_INSTUMENT)
157ENDIF (ENABLE_DTRACE)
158
159ADD_EXECUTABLE(memcached_config_test tests/config_test.c
160               daemon/config_util.c daemon/config_util.h)
161TARGET_LINK_LIBRARIES(memcached_config_test cJSON)
162ADD_EXECUTABLE(ssltest tests/ssltest.c
163                       programs/utilities.c
164                       programs/utilities.h)
165
166ADD_EXECUTABLE(memcached_testapp tests/testapp.c daemon/cache.c)
167
168SET(CBSASL_SOURCES include/cbsasl/cbsasl.h include/cbsasl/visibility.h
169                   cbsasl/client.c cbsasl/common.c cbsasl/cram-md5/cram-md5.c
170                   cbsasl/cram-md5/cram-md5.h cbsasl/cram-md5/hmac.c
171                   cbsasl/cram-md5/hmac.h cbsasl/cram-md5/md5.c
172                   cbsasl/cram-md5/md5.h cbsasl/hash.c cbsasl/hash.h
173                   cbsasl/plain/plain.c cbsasl/plain/plain.h cbsasl/pwfile.c
174                   cbsasl/pwfile.h cbsasl/server.c cbsasl/strcmp.c
175                   cbsasl/util.h)
176
177ADD_LIBRARY(cbsasl SHARED ${CBSASL_SOURCES})
178SET_TARGET_PROPERTIES(cbsasl PROPERTIES SOVERSION 1.1.1)
179SET_TARGET_PROPERTIES(cbsasl PROPERTIES COMPILE_FLAGS -DBUILDING_CBSASL=1)
180SET_TARGET_PROPERTIES(cbsasl PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
181
182ADD_EXECUTABLE(cbsasl_hmac_test tests/cbsasl/hmac_test.c
183                                cbsasl/cram-md5/hmac.c
184                                cbsasl/cram-md5/hmac.h
185                                cbsasl/cram-md5/md5.c
186                                cbsasl/cram-md5/md5.h)
187
188ADD_EXECUTABLE(cbsasl_pwfile_test tests/cbsasl/pwfile_test.c
189                                  cbsasl/pwfile.c
190                                  cbsasl/pwfile.h
191                                  cbsasl/hash.c
192                                  cbsasl/hash.h)
193
194# We're using an "internal api" of the library in the test so we can't
195# use the library we just built
196ADD_EXECUTABLE(sasl_test tests/cbsasl/sasl_server_test.c ${CBSASL_SOURCES})
197SET_TARGET_PROPERTIES(sasl_test PROPERTIES COMPILE_FLAGS -DBUILDING_CBSASL=1)
198
199ADD_EXECUTABLE(cbsasl_test tests/cbsasl/cbsasl_test.c
200                           include/cbsasl/cbsasl.h
201                           include/cbsasl/visibility.h)
202TARGET_LINK_LIBRARIES(cbsasl_test cbsasl)
203
204TARGET_LINK_LIBRARIES(cbsasl platform)
205TARGET_LINK_LIBRARIES(cbsasl_pwfile_test platform)
206TARGET_LINK_LIBRARIES(sasl_test platform)
207
208ADD_EXECUTABLE(cbsasl_strcmp_test tests/cbsasl/strcmp_test.c
209                                  include/cbsasl/cbsasl.h
210                                  include/cbsasl/visibility.h
211                                  cbsasl/strcmp.c)
212#
213# Add linker flags to all of the binaries
214#
215TARGET_LINK_LIBRARIES(bucket_engine mcd_util platform ${COUCHBASE_NETWORK_LIBS} ${COUCHBASE_MATH_LIBS})
216TARGET_LINK_LIBRARIES(default_engine mcd_util platform ${COUCHBASE_NETWORK_LIBS})
217TARGET_LINK_LIBRARIES(basic_engine_testsuite mcd_util platform ${COUCHBASE_NETWORK_LIBS})
218TARGET_LINK_LIBRARIES(stdin_term_handler platform)
219TARGET_LINK_LIBRARIES(fragment_rw_ops mcd_util platform ${COUCHBASE_NETWORK_LIBS})
220TARGET_LINK_LIBRARIES(engine_testapp mcd_util platform ${COUCHBASE_NETWORK_LIBS})
221TARGET_LINK_LIBRARIES(bucket_engine_testapp mcd_util platform ${COUCHBASE_NETWORK_LIBS} ${COUCHBASE_MATH_LIBS})
222TARGET_LINK_LIBRARIES(cbsasladm platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
223TARGET_LINK_LIBRARIES(mcstat platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
224TARGET_LINK_LIBRARIES(mctimings cJSON platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
225TARGET_LINK_LIBRARIES(mcctl platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
226TARGET_LINK_LIBRARIES(mchello platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
227TARGET_LINK_LIBRARIES(ssltest platform ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
228TARGET_LINK_LIBRARIES(tap_mock_engine platform ${COUCHBASE_NETWORK_LIBS})
229
230TARGET_LINK_LIBRARIES(mcd_util platform)
231TARGET_LINK_LIBRARIES(memcached mcd_util cbsasl platform cJSON JSON_checker ${SNAPPY_LIBRARIES} ${MALLOC_LIBRARIES} ${LIBEVENT_LIBRARIES} ${OPENSSL_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
232TARGET_LINK_LIBRARIES(memcached_testapp mcd_util cJSON platform ${SNAPPY_LIBRARIES} ${LIBEVENT_LIBRARIES} ${COUCHBASE_NETWORK_LIBS})
233
234TARGET_LINK_LIBRARIES(file_logger platform)
235
236IF (INSTALL_HEADER_FILES)
237   INSTALL (FILES include/memcached/allocator_hooks.h
238                  include/memcached/callback.h
239                  include/memcached/config_parser.h
240                  include/memcached/engine.h
241                  include/memcached/engine_common.h
242                  include/memcached/engine_testapp.h
243                  include/memcached/extension.h
244                  include/memcached/extension_loggers.h
245                  include/memcached/protocol_binary.h
246                  include/memcached/protocol_plugin.h
247                  include/memcached/server_api.h
248                  include/memcached/types.h
249                  include/memcached/dcp.h
250                  include/memcached/util.h
251                  include/memcached/vbucket.h
252                  include/memcached/visibility.h
253            DESTINATION include/memcached)
254
255   INSTALL(FILES
256           include/cbsasl/cbsasl.h
257           include/cbsasl/visibility.h
258           DESTINATION include/cbsasl)
259ENDIF(INSTALL_HEADER_FILES)
260
261SET_TARGET_PROPERTIES(mcd_util PROPERTIES SOVERSION 1.0.0)
262INSTALL(TARGETS mcd_util
263        RUNTIME DESTINATION bin
264        LIBRARY DESTINATION lib/memcached
265        ARCHIVE DESTINATION lib/memcached)
266
267INSTALL(TARGETS default_engine bucket_engine blackhole_logger
268                fragment_rw_ops stdin_term_handler file_logger
269        RUNTIME DESTINATION lib/memcached
270        LIBRARY DESTINATION lib/memcached
271        ARCHIVE DESTINATION lib/memcached)
272
273SET_TARGET_PROPERTIES(mcd_util PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
274SET_TARGET_PROPERTIES(default_engine PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
275SET_TARGET_PROPERTIES(bucket_engine PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
276SET_TARGET_PROPERTIES(blackhole_logger PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
277SET_TARGET_PROPERTIES(fragment_rw_ops PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
278SET_TARGET_PROPERTIES(stdin_term_handler PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
279SET_TARGET_PROPERTIES(file_logger PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib/memcached)
280
281INSTALL(TARGETS engine_testapp cbsasladm mcstat mctimings memcached
282        RUNTIME DESTINATION bin)
283
284INSTALL(TARGETS cbsasl
285        RUNTIME DESTINATION bin
286        LIBRARY DESTINATION lib
287        ARCHIVE DESTINATION lib)
288
289ADD_TEST(memcached-config memcached_config_test)
290ADD_TEST(memcached-sizes memcached_sizes)
291ADD_TEST(memcached-basic-unit-tests memcached_testapp)
292ADD_TEST(memcached-bucket_engine-unit-tests bucket_engine_testapp)
293ADD_TEST(memcached-basic-engine-tests engine_testapp -E default_engine.so -T basic_engine_testsuite.so)
294
295IF(${COUCHBASE_PYTHON})
296ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated_breakdancer_testsuite.c
297                  COMMAND
298                        ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testsuite/breakdancer/engine_test.py > ${CMAKE_CURRENT_BINARY_DIR}/generated_breakdancer_testsuite.c
299                  DEPENDS
300                        testsuite/breakdancer/breakdancer.py
301                        testsuite/breakdancer/engine_test.py
302                  COMMENT "Generating the test suite")
303
304ADD_LIBRARY(breakdancer_testsuite SHARED
305            testsuite/breakdancer/suite_stubs.c
306            ${CMAKE_CURRENT_BINARY_DIR}/generated_breakdancer_testsuite.c)
307SET_TARGET_PROPERTIES(breakdancer_testsuite PROPERTIES PREFIX "")
308ADD_TEST(memcached-breakdancer-engine-tests engine_testapp -E default_engine.so -T breakdancer_testsuite.so)
309ENDIF(${COUCHBASE_PYTHON})
310
311IF ("${MEMORY_ALLOCATOR}" STREQUAL "tcmalloc")
312   ADD_EXECUTABLE(memcached_tcmalloc_test daemon/alloc_hooks.c
313                                          daemon/alloc_hooks.h
314                                          tests/tcmalloc_test.cc)
315   TARGET_LINK_LIBRARIES(memcached_tcmalloc_test platform ${TCMALLOC_LIBRARIES})
316   ADD_TEST(memcached-tcmalloc-hooks memcached_tcmalloc_test)
317ENDIF ("${MEMORY_ALLOCATOR}" STREQUAL "tcmalloc")
318
319
320ADD_TEST(cbsasl-hmac cbsasl_hmac_test)
321ADD_TEST(cbsasl-pwfile cbsasl_pwfile_test)
322ADD_TEST(cbsasl-sasl sasl_test)
323ADD_TEST(cbsasl-client-server cbsasl_test)
324ADD_TEST(cbsasl-strcmp cbsasl_strcmp_test)
325
326ADD_CUSTOM_TARGET(memcached-manpage
327                  COMMAND a2x -L --doctype manpage --format manpage
328                          ${CMAKE_CURRENT_SOURCE_DIR}/man/man4/memcached.json.4.txt
329                  COMMAND a2x -L --doctype manpage --format pdf
330                          ${CMAKE_CURRENT_SOURCE_DIR}/man/man4/memcached.json.4.txt
331                  VERBATIM)
332
333IF (NOT WIN32)
334   INSTALL(FILES man/man4/memcached.json.4
335           DESTINATION man/man4)
336ENDIF(NOT WIN32)
337
338INSTALL(FILES man/man4/memcached.json.4.pdf
339        DESTINATION doc)
340
341ADD_EXECUTABLE(memcached_logger_test tests/logger_test.cc)
342TARGET_LINK_LIBRARIES(memcached_logger_test mcd_util file_logger dirutils)
343ADD_TEST(memcached-logger-test memcached_logger_test)
344