1PROJECT(Couchstore)
2CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
3
4IF (${CMAKE_MAJOR_VERSION} GREATER 2)
5    CMAKE_POLICY(SET CMP0042 NEW)
6ENDIF (${CMAKE_MAJOR_VERSION} GREATER 2)
7
8INCLUDE(CheckFunctionExists)
9INCLUDE(CheckIncludeFile)
10INCLUDE(CheckIncludeFiles)
11INCLUDE(CheckLibraryExists)
12INCLUDE(CheckSymbolExists)
13INCLUDE(CheckTypeSize)
14INCLUDE(CTest)
15INCLUDE(GenerateExportHeader)
16
17INCLUDE_DIRECTORIES(BEFORE ${CMAKE_INSTALL_PREFIX}/include
18                           ${CMAKE_CURRENT_SOURCE_DIR}/include
19                           ${CMAKE_CURRENT_SOURCE_DIR}/src
20                           ${CMAKE_CURRENT_BINARY_DIR}
21                           ${CMAKE_CURRENT_SOURCE_DIR}
22                           ${BOOST_INCLUDE_DIR}
23                           ${Platform_SOURCE_DIR}/include
24                           ${phosphor_SOURCE_DIR}/include)
25
26INCLUDE_DIRECTORIES(AFTER ${gsl_lite_SOURCE_DIR}/include)
27
28IF (LUA_FOUND)
29   INCLUDE_DIRECTORIES(AFTER {LUA_INCLUDE_DIR})
30ENDIF (LUA_FOUND)
31
32INCLUDE_DIRECTORIES(AFTER
33                    ${KVEngineAPI_SOURCE_DIR}
34                    ${KVEngineAPI_BINARY_DIR})
35
36INCLUDE_DIRECTORIES(AFTER ${ICU_INCLUDE_DIR}
37                          ${V8_INCLUDE_DIR})
38
39CHECK_INCLUDE_FILES("netinet/in.h" HAVE_NETINET_IN_H)
40CHECK_INCLUDE_FILES("inttypes.h" HAVE_INTTYPES_H)
41CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)
42CHECK_SYMBOL_EXISTS(fdatasync "unistd.h" HAVE_FDATASYNC)
43CHECK_SYMBOL_EXISTS(qsort_r "stdlib.h" HAVE_QSORT_R)
44
45IF (WIN32)
46  SET(COUCHSTORE_FILE_OPS "src/os_win.cc")
47ELSE(WIN32)
48  SET(COUCHSTORE_FILE_OPS "src/os.cc")
49ENDIF(WIN32)
50
51SET(COUCHSTORE_SOURCES src/arena.cc
52                       src/bitfield.cc
53                       src/btree_modify.cc
54                       src/btree_read.cc
55                       src/couch_db.cc
56                       src/couch_file_read.cc
57                       src/couch_file_write.cc
58                       src/couch_latency.cc
59                       src/couch_save.cc
60                       src/crc32.cc
61                       src/db_compact.cc
62                       src/file_merger.cc
63                       src/file_name_utils.c
64                       src/file_sorter.cc
65                       src/iobuffer.cc
66                       src/llmsort.cc
67                       src/mergesort.cc
68                       src/node_types.cc
69                       src/reduces.cc
70                       src/strerror.cc
71                       src/tree_writer.cc
72                       src/util.cc
73                       src/views/bitmap.c
74                       src/views/collate_json.cc
75                       src/views/file_merger.cc
76                       src/views/file_sorter.cc
77                       src/views/index_header.cc
78                       src/views/keys.cc
79                       src/views/mapreduce/mapreduce.cc
80                       src/views/mapreduce/mapreduce_c.cc
81                       src/views/reducers.cc
82                       src/views/reductions.cc
83                       src/views/sorted_list.c
84                       src/views/spatial.cc
85                       src/views/spatial_modify.cc
86                       src/views/util.cc
87                       src/views/values.cc
88                       src/views/view_group.cc
89                       src/views/purgers.cc
90                       src/views/compaction.cc
91                       src/quicksort.c
92                       ${COUCHSTORE_FILE_OPS})
93SET(COUCHSTORE_LIBRARIES ${V8_LIBRARIES} ${ICU_LIBRARIES} cbcompress platform phosphor)
94
95SET(COUCHSTORE_GTEST_LIBRARIES gtest gtest_main gmock phosphor)
96SET(COUCHSTORE_GTEST_INCLUDES ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)
97
98ADD_LIBRARY(couchstore SHARED ${COUCHSTORE_SOURCES})
99SET_TARGET_PROPERTIES(couchstore PROPERTIES COMPILE_FLAGS "-DLIBCOUCHSTORE_INTERNAL=1 -DLIBMAPREDUCE_INTERNAL=1")
100TARGET_LINK_LIBRARIES(couchstore ${COUCHSTORE_LIBRARIES})
101GENERATE_EXPORT_HEADER(couchstore
102                       EXPORT_MACRO_NAME LIBCOUCHSTORE_API
103                       EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/include/libcouchstore/visibility.h
104                       NO_EXPORT_MACRO_NAME STATIC
105                       STATIC_DEFINE LIBCOUCHSTORE_NO_VISIBILITY)
106TARGET_INCLUDE_DIRECTORIES(couchstore PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include)
107
108ADD_EXECUTABLE(couch_dbdump
109               src/dbdump.cc
110               src/tracking_file_ops.cc
111               ${COUCHSTORE_SOURCES}
112               ${KVEngineAPI_BINARY_DIR}/xattr/visibility.h)
113
114ADD_DEPENDENCIES(couch_dbdump xattr)
115SET_TARGET_PROPERTIES(couch_dbdump PROPERTIES COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1")
116TARGET_INCLUDE_DIRECTORIES(couch_dbdump
117        PRIVATE
118        ${CMAKE_CURRENT_BINARY_DIR}/include)
119TARGET_LINK_LIBRARIES(couch_dbdump ${COUCHSTORE_LIBRARIES} xattr)
120
121ADD_EXECUTABLE(couch_dbck src/dbck.cc)
122TARGET_LINK_LIBRARIES(couch_dbck couchstore platform)
123
124ADD_EXECUTABLE(couch_dbinfo src/dbinfo.cc)
125TARGET_LINK_LIBRARIES(couch_dbinfo couchstore platform)
126
127ADD_EXECUTABLE(couch_compact src/compactor.cc)
128TARGET_LINK_LIBRARIES(couch_compact couchstore)
129
130ADD_EXECUTABLE(couch_view_file_merger src/views/bin/couch_view_file_merger.cc src/views/bin/util.cc)
131TARGET_LINK_LIBRARIES(couch_view_file_merger couchstore)
132
133ADD_EXECUTABLE(couch_view_index_builder src/views/bin/couch_view_index_builder.cc src/views/bin/util.cc)
134TARGET_LINK_LIBRARIES(couch_view_index_builder couchstore)
135
136ADD_EXECUTABLE(couch_view_group_cleanup src/views/bin/couch_view_group_cleanup.cc src/views/bin/util.cc)
137TARGET_LINK_LIBRARIES(couch_view_group_cleanup couchstore)
138
139ADD_EXECUTABLE(couch_view_index_updater src/views/bin/couch_view_index_updater.cc src/views/bin/util.cc)
140TARGET_LINK_LIBRARIES(couch_view_index_updater couchstore)
141
142ADD_EXECUTABLE(couch_view_group_compactor src/views/bin/couch_view_group_compactor.cc src/views/bin/util.cc)
143TARGET_LINK_LIBRARIES(couch_view_group_compactor couchstore)
144
145ADD_EXECUTABLE(couch_create src/couch_create.cc src/crc32.cc)
146TARGET_LINK_LIBRARIES(couch_create couchstore platform)
147
148
149IF (INSTALL_HEADER_FILES)
150   INSTALL(FILES
151           include/libcouchstore/couch_db.h
152           include/libcouchstore/couch_index.h
153           include/libcouchstore/couch_common.h
154           include/libcouchstore/error.h
155           include/libcouchstore/file_ops.h
156           include/libcouchstore/visibility.h
157           DESTINATION include/libcouchstore)
158ENDIF(INSTALL_HEADER_FILES)
159
160INSTALL(TARGETS couchstore
161        RUNTIME DESTINATION bin
162        LIBRARY DESTINATION lib
163        ARCHIVE DESTINATION lib)
164
165IF (APPLE)
166    SET_TARGET_PROPERTIES(couchstore
167                          PROPERTIES
168                          INSTALL_RPATH "@loader_path")
169ENDIF (APPLE)
170
171INSTALL(TARGETS couch_dbdump
172                couch_dbinfo
173                couch_dbck
174                couch_compact
175                couch_view_file_merger
176                couch_view_index_builder
177                couch_view_group_cleanup
178                couch_view_index_updater
179                couch_view_group_compactor
180        RUNTIME DESTINATION bin)
181
182INSTALL(FILES
183        python/couchstore.py
184        DESTINATION lib/python)
185
186CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in
187               ${CMAKE_CURRENT_BINARY_DIR}/config.h)
188
189# Tests:
190
191IF (LUA_FOUND)
192   ADD_EXECUTABLE(couchscript src/couchscript.cc)
193   SET_TARGET_PROPERTIES(couchscript PROPERTIES COMPILE_FLAGS
194                         -I${LUA_INCLUDE_DIR})
195   TARGET_LINK_LIBRARIES(couchscript couchstore ${LUA_LIBRARIES})
196
197   ADD_TEST(couchstore-localdoc
198            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/localdoc.lua)
199   ADD_TEST(couchstore-corrupt
200            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/corrupt.lua)
201   ADD_TEST(couchstore-bulk
202            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/bulk.lua)
203   ADD_TEST(couchstore-changes-since-filter
204           couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/changessincefilter.lua)
205   ADD_TEST(couchstore-compact
206            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/compact.lua)
207   ADD_TEST(couchstore-dropdel
208            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/dropdel.lua)
209   ADD_TEST(couchstore-largefile
210            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/largefile.lua)
211   ADD_TEST(couchstore-large
212            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/large.lua)
213ENDIF(LUA_FOUND)
214
215MACRO (M_ADD_PYTHON_TEST name pyfile)
216  ADD_TEST(${name} python ${pyfile})
217  SET_PROPERTY(TEST ${name} PROPERTY ENVIRONMENT
218    "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python"
219    "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}")
220ENDMACRO()
221
222M_ADD_PYTHON_TEST(couchstore-purge ${CMAKE_CURRENT_SOURCE_DIR}/tests/purge.py)
223M_ADD_PYTHON_TEST(couchstore-rewind ${CMAKE_CURRENT_SOURCE_DIR}/tests/rewind.py)
224M_ADD_PYTHON_TEST(couchstore-changecount ${CMAKE_CURRENT_SOURCE_DIR}/tests/changecount.py)
225
226MACRO (M_MAKE_LEGACY_TEST name)
227    ADD_EXECUTABLE(${name} ${ARGN})
228    SET_TARGET_PROPERTIES(${name} PROPERTIES
229            COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
230    TARGET_LINK_LIBRARIES(${name} couchstore)
231ENDMACRO()
232
233M_MAKE_LEGACY_TEST(couchstore_file-deduper-test
234        src/file_merger.cc
235        tests/file_deduper_tests.c)
236
237M_MAKE_LEGACY_TEST(couchstore_file-merger-test
238        src/file_merger.cc
239        tests/file_merger_tests.c)
240
241M_MAKE_LEGACY_TEST(couchstore_file-sorter-test
242        src/file_merger.cc
243        src/file_name_utils.c
244        src/file_sorter.cc
245        src/quicksort.c
246        tests/file_sorter_tests.c)
247
248SET(MAP_REDUCE_SOURCES
249        src/views/mapreduce/mapreduce.cc
250        src/views/mapreduce/mapreduce_c.cc)
251
252M_MAKE_LEGACY_TEST(couchstore_mapreduce-builtin-test
253        ${MAP_REDUCE_SOURCES}
254        tests/mapreduce/builtin.c)
255
256M_MAKE_LEGACY_TEST(couchstore_mapreduce-map-test
257        ${MAP_REDUCE_SOURCES}
258        tests/mapreduce/map.c)
259
260M_MAKE_LEGACY_TEST(couchstore_mapreduce-reduce-test
261        ${MAP_REDUCE_SOURCES}
262        tests/mapreduce/reduce.c)
263
264ADD_EXECUTABLE(couchstore_testapp
265               tests/testapp.c
266               tests/views/tests.cc
267               tests/views/collate_json_test.cc
268               tests/views/index_headers.cc
269               tests/views/bitmaps.cc
270               tests/views/sorted_lists.cc
271               tests/views/reductions.cc
272               tests/views/keys.cc
273               tests/views/values.cc
274               tests/views/reducers.cc
275               tests/views/cleanup.cc
276               tests/views/spatial.cc
277               tests/btree_purge/purge_tests.h
278               tests/btree_purge/tests.cc
279               tests/btree_purge/purge.cc
280               ${COUCHSTORE_SOURCES})
281SET_TARGET_PROPERTIES(couchstore_testapp PROPERTIES
282        COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
283TARGET_INCLUDE_DIRECTORIES(couchstore_testapp
284        PRIVATE
285        ${CMAKE_CURRENT_BINARY_DIR}/include)
286TARGET_LINK_LIBRARIES(couchstore_testapp ${COUCHSTORE_LIBRARIES})
287
288ADD_EXECUTABLE(couchstore_gtest
289               tests/couchstoretest.cc
290               tests/documents.cc
291               tests/gtest_tests.cc
292               tests/test_fileops.cc
293               src/node_types.cc
294               src/crc32.cc
295               ${COUCHSTORE_FILE_OPS})
296SET_TARGET_PROPERTIES(couchstore_gtest PROPERTIES
297                      COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
298TARGET_INCLUDE_DIRECTORIES(couchstore_gtest PRIVATE ${COUCHSTORE_GTEST_INCLUDES})
299TARGET_LINK_LIBRARIES(couchstore_gtest couchstore ${COUCHSTORE_GTEST_LIBRARIES})
300
301ADD_EXECUTABLE(couchstore_internal_gtest
302        tests/couchstoretest.cc
303        tests/documents.cc
304        tests/gtest_internal_tests.cc
305        tests/test_fileops.cc
306        ${COUCHSTORE_SOURCES}
307        )
308SET_TARGET_PROPERTIES(couchstore_internal_gtest PROPERTIES
309        COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
310TARGET_INCLUDE_DIRECTORIES(couchstore_internal_gtest
311        PRIVATE
312        ${CMAKE_CURRENT_BINARY_DIR}/include)
313TARGET_LINK_LIBRARIES(couchstore_internal_gtest
314        ${COUCHSTORE_GTEST_LIBRARIES}
315        ${COUCHSTORE_LIBRARIES})
316
317# This is an object library and can be used for verifying
318# FileOpsInterface implementations that wrap other FileOps
319# propogate errors correctly.
320#
321# Example usage can be found in tests/wrapped_fileops_test.cc
322ADD_LIBRARY(couchstore_wrapped_fileops_test_framework OBJECT
323        tests/test_fileops.cc
324        ${COUCHSTORE_FILE_OPS})
325SET_TARGET_PROPERTIES(couchstore_wrapped_fileops_test_framework PROPERTIES
326        COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
327TARGET_INCLUDE_DIRECTORIES(couchstore_wrapped_fileops_test_framework
328        PRIVATE
329        ${COUCHSTORE_GTEST_INCLUDES}
330        ${CMAKE_CURRENT_BINARY_DIR}/include)
331
332ADD_EXECUTABLE(couchstore_wrapped_fileops_test
333               src/crc32.cc
334               src/iobuffer.cc
335               tests/wrapped_fileops_test.cc
336               $<TARGET_OBJECTS:couchstore_wrapped_fileops_test_framework>
337               )
338SET_TARGET_PROPERTIES(couchstore_wrapped_fileops_test PROPERTIES
339        COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
340TARGET_INCLUDE_DIRECTORIES(couchstore_wrapped_fileops_test
341        PRIVATE
342        ${CMAKE_CURRENT_BINARY_DIR}/include)
343TARGET_LINK_LIBRARIES(couchstore_wrapped_fileops_test ${COUCHSTORE_GTEST_LIBRARIES} platform)
344
345ADD_LIBRARY(couchstore_test_fileops OBJECT
346        tests/test_fileops.cc)
347TARGET_INCLUDE_DIRECTORIES(couchstore_test_fileops
348        PRIVATE
349        ${COUCHSTORE_GTEST_INCLUDES}
350        ${CMAKE_CURRENT_BINARY_DIR}/include)
351
352ADD_TEST(couchstore-file-deduper-test couchstore_file-deduper-test)
353ADD_TEST(couchstore-file-merge-test couchstore_file-merger-test)
354ADD_TEST(couchstore-file-sorter-test couchstore_file-sorter-test)
355ADD_TEST(couchstore-gtest couchstore_gtest)
356ADD_TEST(couchstore-internal-gtest couchstore_internal_gtest)
357ADD_TEST(couchstore-mapreduce-builtin-test couchstore_mapreduce-builtin-test)
358ADD_TEST(couchstore-mapreduce-map-test couchstore_mapreduce-map-test)
359ADD_TEST(couchstore-mapreduce-reduce-test couchstore_mapreduce-reduce-test)
360ADD_TEST(couchstore-testapp couchstore_testapp)
361ADD_TEST(couchstore-wrapped_fileops-test couchstore_wrapped_fileops_test)
362
363
364
365ADD_SUBDIRECTORY(programs)
366
367ENABLE_CODE_COVERAGE_REPORT()
368