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                           ${Platform_SOURCE_DIR}/include)
22
23IF (LUA_FOUND)
24   INCLUDE_DIRECTORIES(AFTER {LUA_INCLUDE_DIR})
25ENDIF (LUA_FOUND)
26
27INCLUDE_DIRECTORIES(AFTER ${ICU_INCLUDE_DIR}
28                          ${V8_INCLUDE_DIR}
29                          ${SNAPPY_INCLUDE_DIR})
30
31CHECK_INCLUDE_FILES("netinet/in.h" HAVE_NETINET_IN_H)
32CHECK_INCLUDE_FILES("inttypes.h" HAVE_INTTYPES_H)
33CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)
34CHECK_SYMBOL_EXISTS(fdatasync "unistd.h" HAVE_FDATASYNC)
35CHECK_SYMBOL_EXISTS(qsort_r "stdlib.h" HAVE_QSORT_R)
36
37IF (WIN32)
38  SET(COUCHSTORE_FILE_OPS "src/os_win.c")
39ELSE(WIN32)
40  SET(COUCHSTORE_FILE_OPS "src/os.c")
41ENDIF(WIN32)
42
43SET(COUCHSTORE_SOURCES src/arena.cc src/bitfield.c src/btree_modify.cc
44            src/btree_read.cc src/couch_db.cc src/couch_file_read.cc
45            src/couch_file_write.cc src/couch_save.cc src/crc32.cc
46            src/db_compact.cc src/file_merger.cc src/file_name_utils.c
47            src/file_sorter.cc src/iobuffer.cc src/llmsort.cc
48            src/mergesort.cc src/node_types.cc src/reduces.cc
49            src/rfc1321/md5c.c src/strerror.cc src/tree_writer.cc
50            src/util.cc src/views/bitmap.c src/views/collate_json.c
51            src/views/file_merger.c src/views/file_sorter.c
52            src/views/index_header.c src/views/keys.c
53            src/views/mapreduce/mapreduce.cc
54            src/views/mapreduce/mapreduce_c.cc src/views/reducers.c
55            src/views/reductions.c src/views/sorted_list.c
56            src/views/spatial.c src/views/spatial_modify.c
57            src/views/util.c src/views/values.c
58            src/views/view_group.c src/views/purgers.c
59            src/views/compaction.c src/quicksort.c ${COUCHSTORE_FILE_OPS})
60SET(COUCHSTORE_LIBRARIES ${V8_LIBRARIES} ${ICU_LIBRARIES} ${SNAPPY_LIBRARIES} platform)
61
62ADD_LIBRARY(couchstore SHARED ${COUCHSTORE_SOURCES})
63SET_TARGET_PROPERTIES(couchstore PROPERTIES COMPILE_FLAGS "-DLIBCOUCHSTORE_INTERNAL=1 -DLIBMAPREDUCE_INTERNAL=1")
64TARGET_LINK_LIBRARIES(couchstore ${COUCHSTORE_LIBRARIES})
65
66ADD_EXECUTABLE(couch_dbdump src/dbdump.c ${COUCHSTORE_SOURCES})
67SET_TARGET_PROPERTIES(couch_dbdump PROPERTIES COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1")
68TARGET_LINK_LIBRARIES(couch_dbdump ${COUCHSTORE_LIBRARIES})
69
70ADD_EXECUTABLE(couch_dbinfo src/dbinfo.c)
71TARGET_LINK_LIBRARIES(couch_dbinfo couchstore platform)
72
73ADD_EXECUTABLE(couch_compact src/compactor.c)
74TARGET_LINK_LIBRARIES(couch_compact couchstore)
75
76ADD_EXECUTABLE(couch_view_file_merger src/views/bin/couch_view_file_merger.c src/views/bin/util.c)
77TARGET_LINK_LIBRARIES(couch_view_file_merger couchstore)
78
79ADD_EXECUTABLE(couch_view_index_builder src/views/bin/couch_view_index_builder.c src/views/bin/util.c)
80TARGET_LINK_LIBRARIES(couch_view_index_builder couchstore)
81
82ADD_EXECUTABLE(couch_view_group_cleanup src/views/bin/couch_view_group_cleanup.c src/views/bin/util.c)
83TARGET_LINK_LIBRARIES(couch_view_group_cleanup couchstore)
84
85ADD_EXECUTABLE(couch_view_index_updater src/views/bin/couch_view_index_updater.c src/views/bin/util.c)
86TARGET_LINK_LIBRARIES(couch_view_index_updater couchstore)
87
88ADD_EXECUTABLE(couch_view_group_compactor src/views/bin/couch_view_group_compactor.c src/views/bin/util.c)
89TARGET_LINK_LIBRARIES(couch_view_group_compactor couchstore)
90
91IF (INSTALL_HEADER_FILES)
92   INSTALL(FILES
93           include/libcouchstore/couch_db.h
94           include/libcouchstore/couch_index.h
95           include/libcouchstore/couch_common.h
96           include/libcouchstore/error.h
97           include/libcouchstore/file_ops.h
98           include/libcouchstore/visibility.h
99           DESTINATION include/libcouchstore)
100ENDIF(INSTALL_HEADER_FILES)
101
102INSTALL(TARGETS couchstore
103        RUNTIME DESTINATION bin
104        LIBRARY DESTINATION lib
105        ARCHIVE DESTINATION lib)
106
107IF (APPLE)
108    SET_TARGET_PROPERTIES(couchstore
109                          PROPERTIES
110                          INSTALL_RPATH "@loader_path")
111ENDIF (APPLE)
112
113INSTALL(TARGETS couch_dbdump
114                couch_dbinfo
115                couch_compact
116                couch_view_file_merger
117                couch_view_index_builder
118                couch_view_group_cleanup
119                couch_view_index_updater
120                couch_view_group_compactor
121        RUNTIME DESTINATION bin)
122
123INSTALL(FILES
124        python/couchstore.py
125        DESTINATION lib/python)
126
127CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in
128               ${CMAKE_CURRENT_BINARY_DIR}/config.h)
129
130# Tests:
131
132IF (LUA_FOUND)
133   ADD_EXECUTABLE(couchscript src/couchscript.cc)
134   SET_TARGET_PROPERTIES(couchscript PROPERTIES COMPILE_FLAGS
135                         -I${LUA_INCLUDE_DIR})
136   TARGET_LINK_LIBRARIES(couchscript couchstore ${LUA_LIBRARIES})
137
138   ADD_TEST(couchstore-localdoc
139            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/localdoc.lua)
140   ADD_TEST(couchstore-corrupt
141            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/corrupt.lua)
142   ADD_TEST(couchstore-bulk
143            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/bulk.lua)
144   ADD_TEST(couchstore-changes-since-filter
145           couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/changessincefilter.lua)
146   ADD_TEST(couchstore-compact
147            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/compact.lua)
148   ADD_TEST(couchstore-dropdel
149            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/dropdel.lua)
150   ADD_TEST(couchstore-largefile
151            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/largefile.lua)
152   ADD_TEST(couchstore-large
153            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/large.lua)
154ENDIF(LUA_FOUND)
155
156MACRO (M_ADD_PYTHON_TEST name pyfile)
157  ADD_TEST(${name} python ${pyfile})
158  SET_PROPERTY(TEST ${name} PROPERTY ENVIRONMENT
159    "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python"
160    "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}")
161ENDMACRO()
162
163# Skip python tests on OS X. To fix MB-16454 we implemented a workaround to
164# deal with linking issues in OS X 10.11 where we had to hardcode the path
165# to libcouchbase from the python library.
166IF (NOT APPLE)
167    M_ADD_PYTHON_TEST(couchstore-purge ${CMAKE_CURRENT_SOURCE_DIR}/tests/purge.py)
168    M_ADD_PYTHON_TEST(couchstore-rewind ${CMAKE_CURRENT_SOURCE_DIR}/tests/rewind.py)
169    M_ADD_PYTHON_TEST(couchstore-changecount ${CMAKE_CURRENT_SOURCE_DIR}/tests/changecount.py)
170ENDIF (NOT APPLE)
171
172ADD_EXECUTABLE(couchstore_testapp
173               tests/testapp.c
174               tests/file_merger_tests.c
175               tests/file_sorter_tests.c
176               tests/file_deduper_tests.c
177               tests/mapreduce/tests.c
178               tests/mapreduce/map.c
179               tests/mapreduce/reduce.c
180               tests/mapreduce/builtin.c
181               tests/views/tests.c
182               tests/views/collate_json_test.c
183               tests/views/index_headers.c
184               tests/views/bitmaps.c
185               tests/views/sorted_lists.c
186               tests/views/reductions.c
187               tests/views/keys.c
188               tests/views/values.c
189               tests/views/reducers.c
190               tests/views/cleanup.c
191               tests/views/spatial.c
192               tests/btree_purge/purge_tests.h
193               tests/btree_purge/tests.c
194               tests/btree_purge/purge.c
195               ${COUCHSTORE_SOURCES})
196TARGET_LINK_LIBRARIES(couchstore_testapp ${COUCHSTORE_LIBRARIES})
197SET_TARGET_PROPERTIES(couchstore_testapp PROPERTIES
198                      COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
199ADD_TEST(couchstore-testapp couchstore_testapp)
200
201ADD_EXECUTABLE(couchstore_gtest
202               tests/couchstoretest.cc
203               tests/documents.cc
204               tests/gtest_tests.cc
205               src/node_types.cc)
206
207SET_TARGET_PROPERTIES(couchstore_gtest PROPERTIES
208                      COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
209TARGET_INCLUDE_DIRECTORIES(couchstore_gtest PUBLIC ${gtest_SOURCE_DIR}/include)
210
211TARGET_LINK_LIBRARIES(couchstore_gtest
212  gtest
213  gtest_main
214  couchstore
215  ${COUCHSTORE_LIBRARIES})
216
217ADD_TEST(couchstore-gtest couchstore_gtest)
218
219ADD_EXECUTABLE(couchstore_internal_gtest
220        tests/couchstoretest.cc
221        tests/documents.cc
222        tests/gtest_internal_tests.cc
223        ${COUCHSTORE_SOURCES}
224        )
225
226SET_TARGET_PROPERTIES(couchstore_internal_gtest PROPERTIES
227        COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
228TARGET_INCLUDE_DIRECTORIES(couchstore_internal_gtest PUBLIC ${gtest_SOURCE_DIR}/include src)
229
230TARGET_LINK_LIBRARIES(couchstore_internal_gtest
231        gtest
232        gtest_main
233        ${COUCHSTORE_LIBRARIES})
234
235ADD_TEST(couchstore-internal-gtest couchstore_internal_gtest)
236ADD_SUBDIRECTORY(programs)
237
238ENABLE_CODE_COVERAGE_REPORT()
239