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