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