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