1ca6022cdSTrond NorbyePROJECT(Couchstore)
2ca6022cdSTrond NorbyeCMAKE_MINIMUM_REQUIRED(VERSION 2.8)
3ca6022cdSTrond Norbye
446f1ef48STrond NorbyeIF (${CMAKE_MAJOR_VERSION} GREATER 2)
546f1ef48STrond Norbye    CMAKE_POLICY(SET CMP0042 NEW)
646f1ef48STrond NorbyeENDIF (${CMAKE_MAJOR_VERSION} GREATER 2)
746f1ef48STrond Norbye
80c640a13STrond NorbyeINCLUDE(CheckFunctionExists)
90c640a13STrond NorbyeINCLUDE(CheckIncludeFile)
100c640a13STrond NorbyeINCLUDE(CheckIncludeFiles)
110c640a13STrond NorbyeINCLUDE(CheckLibraryExists)
120c640a13STrond NorbyeINCLUDE(CheckSymbolExists)
130c640a13STrond NorbyeINCLUDE(CheckTypeSize)
14346633adSDave RigbyINCLUDE(CTest)
150c640a13STrond Norbye
16c80a2f8aSDave RigbyINCLUDE_DIRECTORIES(BEFORE ${CMAKE_INSTALL_PREFIX}/include
17c80a2f8aSDave Rigby                           ${CMAKE_CURRENT_SOURCE_DIR}/include
180c640a13STrond Norbye                           ${CMAKE_CURRENT_SOURCE_DIR}/src
190c640a13STrond Norbye                           ${CMAKE_CURRENT_BINARY_DIR}
20290dcd61STrond Norbye                           ${CMAKE_CURRENT_SOURCE_DIR}
21c80a2f8aSDave Rigby                           ${Platform_SOURCE_DIR}/include)
22c80a2f8aSDave Rigby
23d897c709STrond NorbyeIF (LUA_FOUND)
24d897c709STrond Norbye   INCLUDE_DIRECTORIES(AFTER {LUA_INCLUDE_DIR})
25d897c709STrond NorbyeENDIF (LUA_FOUND)
26d897c709STrond Norbye
270c640a13STrond NorbyeINCLUDE_DIRECTORIES(AFTER ${ICU_INCLUDE_DIR}
280c640a13STrond Norbye                          ${V8_INCLUDE_DIR}
290c640a13STrond Norbye                          ${SNAPPY_INCLUDE_DIR})
300c640a13STrond Norbye
310c640a13STrond NorbyeCHECK_INCLUDE_FILES("netinet/in.h" HAVE_NETINET_IN_H)
320c640a13STrond NorbyeCHECK_INCLUDE_FILES("inttypes.h" HAVE_INTTYPES_H)
33462b7a82STrond NorbyeCHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)
340c640a13STrond NorbyeCHECK_SYMBOL_EXISTS(fdatasync "unistd.h" HAVE_FDATASYNC)
3523b42d51SSarath LakshmanCHECK_SYMBOL_EXISTS(qsort_r "stdlib.h" HAVE_QSORT_R)
360c640a13STrond Norbye
370c640a13STrond NorbyeIF (WIN32)
380c640a13STrond Norbye  SET(COUCHSTORE_FILE_OPS "src/os_win.c")
390c640a13STrond NorbyeELSE(WIN32)
400c640a13STrond Norbye  SET(COUCHSTORE_FILE_OPS "src/os.c")
410c640a13STrond NorbyeENDIF(WIN32)
420c640a13STrond Norbye
43a01cb1aaSTrond NorbyeSET(COUCHSTORE_SOURCES src/arena.cc src/bitfield.c src/btree_modify.cc
44a01cb1aaSTrond Norbye            src/btree_read.cc src/couch_db.cc src/couch_file_read.cc
457a1ecb61SJim Walker            src/couch_file_write.cc src/couch_save.cc src/crc32.cc
460c640a13STrond Norbye            src/db_compact.cc src/file_merger.cc src/file_name_utils.c
470c640a13STrond Norbye            src/file_sorter.cc src/iobuffer.cc src/llmsort.cc
480c640a13STrond Norbye            src/mergesort.cc src/node_types.cc src/reduces.cc
490c640a13STrond Norbye            src/rfc1321/md5c.c src/strerror.cc src/tree_writer.cc
500c640a13STrond Norbye            src/util.cc src/views/bitmap.c src/views/collate_json.c
510c640a13STrond Norbye            src/views/file_merger.c src/views/file_sorter.c
520c640a13STrond Norbye            src/views/index_header.c src/views/keys.c
530c640a13STrond Norbye            src/views/mapreduce/mapreduce.cc
540c640a13STrond Norbye            src/views/mapreduce/mapreduce_c.cc src/views/reducers.c
550c640a13STrond Norbye            src/views/reductions.c src/views/sorted_list.c
56744ff400SVolker Mische            src/views/spatial.c src/views/spatial_modify.c
57744ff400SVolker Mische            src/views/util.c src/views/values.c
5896f21772SSarath Lakshman            src/views/view_group.c src/views/purgers.c
5923b42d51SSarath Lakshman            src/views/compaction.c src/quicksort.c ${COUCHSTORE_FILE_OPS})
60572cdfadSTrond NorbyeSET(COUCHSTORE_LIBRARIES ${V8_LIBRARIES} ${ICU_LIBRARIES} ${SNAPPY_LIBRARIES} platform)
610c640a13STrond Norbye
620c640a13STrond NorbyeADD_LIBRARY(couchstore SHARED ${COUCHSTORE_SOURCES})
6352f90763STrond NorbyeSET_TARGET_PROPERTIES(couchstore PROPERTIES COMPILE_FLAGS "-DLIBCOUCHSTORE_INTERNAL=1 -DLIBMAPREDUCE_INTERNAL=1")
640c640a13STrond NorbyeTARGET_LINK_LIBRARIES(couchstore ${COUCHSTORE_LIBRARIES})
650c640a13STrond Norbye
66657208f1SAaron MillerADD_EXECUTABLE(couch_dbdump src/dbdump.c ${COUCHSTORE_SOURCES})
6782fff8edSTrond NorbyeSET_TARGET_PROPERTIES(couch_dbdump PROPERTIES COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1")
68657208f1SAaron MillerTARGET_LINK_LIBRARIES(couch_dbdump ${COUCHSTORE_LIBRARIES})
690c640a13STrond Norbye
700c640a13STrond NorbyeADD_EXECUTABLE(couch_dbinfo src/dbinfo.c)
7133c63ffeSTrond NorbyeTARGET_LINK_LIBRARIES(couch_dbinfo couchstore platform)
720c640a13STrond Norbye
730c640a13STrond NorbyeADD_EXECUTABLE(couch_compact src/compactor.c)
740c640a13STrond NorbyeTARGET_LINK_LIBRARIES(couch_compact couchstore)
750c640a13STrond Norbye
762ad44a11SSarath LakshmanADD_EXECUTABLE(couch_view_file_merger src/views/bin/couch_view_file_merger.c src/views/bin/util.c)
770c640a13STrond NorbyeTARGET_LINK_LIBRARIES(couch_view_file_merger couchstore)
780c640a13STrond Norbye
792fd0ccfcSSarath LakshmanADD_EXECUTABLE(couch_view_index_builder src/views/bin/couch_view_index_builder.c src/views/bin/util.c)
800c640a13STrond NorbyeTARGET_LINK_LIBRARIES(couch_view_index_builder couchstore)
810c640a13STrond Norbye
822fd0ccfcSSarath LakshmanADD_EXECUTABLE(couch_view_group_cleanup src/views/bin/couch_view_group_cleanup.c src/views/bin/util.c)
83f2d99791SSarath LakshmanTARGET_LINK_LIBRARIES(couch_view_group_cleanup couchstore)
84f2d99791SSarath Lakshman
852fd0ccfcSSarath LakshmanADD_EXECUTABLE(couch_view_index_updater src/views/bin/couch_view_index_updater.c src/views/bin/util.c)
86ee29f96bSSarath LakshmanTARGET_LINK_LIBRARIES(couch_view_index_updater couchstore)
87ee29f96bSSarath Lakshman
882fd0ccfcSSarath LakshmanADD_EXECUTABLE(couch_view_group_compactor src/views/bin/couch_view_group_compactor.c src/views/bin/util.c)
89cc98f867SSarath LakshmanTARGET_LINK_LIBRARIES(couch_view_group_compactor couchstore)
90cc98f867SSarath Lakshman
91ae717639STrond NorbyeIF (INSTALL_HEADER_FILES)
926212a318STrond Norbye   INSTALL(FILES
936212a318STrond Norbye           include/libcouchstore/couch_db.h
946212a318STrond Norbye           include/libcouchstore/couch_index.h
956212a318STrond Norbye           include/libcouchstore/couch_common.h
966212a318STrond Norbye           include/libcouchstore/error.h
976212a318STrond Norbye           include/libcouchstore/file_ops.h
986212a318STrond Norbye           include/libcouchstore/visibility.h
996212a318STrond Norbye           DESTINATION include/libcouchstore)
100ae717639STrond NorbyeENDIF(INSTALL_HEADER_FILES)
1010c640a13STrond Norbye
1020c640a13STrond NorbyeINSTALL(TARGETS couchstore
1030c640a13STrond Norbye        RUNTIME DESTINATION bin
1040c640a13STrond Norbye        LIBRARY DESTINATION lib
1050c640a13STrond Norbye        ARCHIVE DESTINATION lib)
1060c640a13STrond Norbye
1077d6bc22aSMike WiederholdIF (APPLE)
1087d6bc22aSMike Wiederhold    SET_TARGET_PROPERTIES(couchstore
1097d6bc22aSMike Wiederhold                          PROPERTIES
1107d6bc22aSMike Wiederhold                          INSTALL_RPATH "@loader_path")
1117d6bc22aSMike WiederholdENDIF (APPLE)
1127d6bc22aSMike Wiederhold
1130c640a13STrond NorbyeINSTALL(TARGETS couch_dbdump
1140c640a13STrond Norbye                couch_dbinfo
1150c640a13STrond Norbye                couch_compact
1160c640a13STrond Norbye                couch_view_file_merger
1170c640a13STrond Norbye                couch_view_index_builder
118f2d99791SSarath Lakshman                couch_view_group_cleanup
119ee29f96bSSarath Lakshman                couch_view_index_updater
120cc98f867SSarath Lakshman                couch_view_group_compactor
1210c640a13STrond Norbye        RUNTIME DESTINATION bin)
1220c640a13STrond Norbye
123d40a6180STrond NorbyeINSTALL(FILES
124d40a6180STrond Norbye        python/couchstore.py
125d40a6180STrond Norbye        DESTINATION lib/python)
126d40a6180STrond Norbye
1270c640a13STrond NorbyeCONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in
1280c640a13STrond Norbye               ${CMAKE_CURRENT_BINARY_DIR}/config.h)
1290c640a13STrond Norbye
1300c640a13STrond Norbye# Tests:
1311b613a6bSAaron Miller
1320c640a13STrond NorbyeIF (LUA_FOUND)
1336212a318STrond Norbye   ADD_EXECUTABLE(couchscript src/couchscript.cc)
1346212a318STrond Norbye   SET_TARGET_PROPERTIES(couchscript PROPERTIES COMPILE_FLAGS
1356212a318STrond Norbye                         -I${LUA_INCLUDE_DIR})
1366212a318STrond Norbye   TARGET_LINK_LIBRARIES(couchscript couchstore ${LUA_LIBRARIES})
1376212a318STrond Norbye
1386212a318STrond Norbye   ADD_TEST(couchstore-localdoc
1396212a318STrond Norbye            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/localdoc.lua)
1406212a318STrond Norbye   ADD_TEST(couchstore-corrupt
1416212a318STrond Norbye            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/corrupt.lua)
1426212a318STrond Norbye   ADD_TEST(couchstore-bulk
1436212a318STrond Norbye            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/bulk.lua)
1446212a318STrond Norbye   ADD_TEST(couchstore-changes-since-filter
1456212a318STrond Norbye           couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/changessincefilter.lua)
1466212a318STrond Norbye   ADD_TEST(couchstore-compact
1476212a318STrond Norbye            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/compact.lua)
1486212a318STrond Norbye   ADD_TEST(couchstore-dropdel
1496212a318STrond Norbye            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/dropdel.lua)
1506212a318STrond Norbye   ADD_TEST(couchstore-largefile
1516212a318STrond Norbye            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/largefile.lua)
1526212a318STrond Norbye   ADD_TEST(couchstore-large
1536212a318STrond Norbye            couchscript ${CMAKE_CURRENT_SOURCE_DIR}/tests/large.lua)
1540c640a13STrond NorbyeENDIF(LUA_FOUND)
1550c640a13STrond Norbye
1561b613a6bSAaron MillerMACRO (M_ADD_PYTHON_TEST name pyfile)
1571b613a6bSAaron Miller  ADD_TEST(${name} python ${pyfile})
1581b613a6bSAaron Miller  SET_PROPERTY(TEST ${name} PROPERTY ENVIRONMENT
1591b613a6bSAaron Miller    "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python"
1601b613a6bSAaron Miller    "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}")
1611b613a6bSAaron MillerENDMACRO()
1621b613a6bSAaron Miller
1637d6bc22aSMike Wiederhold# Skip python tests on OS X. To fix MB-16454 we implemented a workaround to
1647d6bc22aSMike Wiederhold# deal with linking issues in OS X 10.11 where we had to hardcode the path
1657d6bc22aSMike Wiederhold# to libcouchbase from the python library.
1667d6bc22aSMike WiederholdIF (NOT APPLE)
1677d6bc22aSMike Wiederhold    M_ADD_PYTHON_TEST(couchstore-purge ${CMAKE_CURRENT_SOURCE_DIR}/tests/purge.py)
1687d6bc22aSMike Wiederhold    M_ADD_PYTHON_TEST(couchstore-rewind ${CMAKE_CURRENT_SOURCE_DIR}/tests/rewind.py)
1697d6bc22aSMike Wiederhold    M_ADD_PYTHON_TEST(couchstore-changecount ${CMAKE_CURRENT_SOURCE_DIR}/tests/changecount.py)
1707d6bc22aSMike WiederholdENDIF (NOT APPLE)
1711b613a6bSAaron Miller
1725815fc1cSJim WalkerADD_EXECUTABLE(couchstore_testapp
1735815fc1cSJim Walker               tests/testapp.c
1745815fc1cSJim Walker               tests/file_merger_tests.c
1755815fc1cSJim Walker               tests/file_sorter_tests.c
1765815fc1cSJim Walker               tests/file_deduper_tests.c
1775815fc1cSJim Walker               tests/mapreduce/tests.c
1785815fc1cSJim Walker               tests/mapreduce/map.c
1795815fc1cSJim Walker               tests/mapreduce/reduce.c
1805815fc1cSJim Walker               tests/mapreduce/builtin.c
1815815fc1cSJim Walker               tests/views/tests.c
1825815fc1cSJim Walker               tests/views/collate_json_test.c
1835815fc1cSJim Walker               tests/views/index_headers.c
1845815fc1cSJim Walker               tests/views/bitmaps.c
1855815fc1cSJim Walker               tests/views/sorted_lists.c
1865815fc1cSJim Walker               tests/views/reductions.c
1875815fc1cSJim Walker               tests/views/keys.c
1885815fc1cSJim Walker               tests/views/values.c
1895815fc1cSJim Walker               tests/views/reducers.c
1905815fc1cSJim Walker               tests/views/cleanup.c
1915815fc1cSJim Walker               tests/views/spatial.c
1925815fc1cSJim Walker               tests/btree_purge/purge_tests.h
1935815fc1cSJim Walker               tests/btree_purge/tests.c
1945815fc1cSJim Walker               tests/btree_purge/purge.c
1955815fc1cSJim Walker               ${COUCHSTORE_SOURCES})
1965815fc1cSJim WalkerTARGET_LINK_LIBRARIES(couchstore_testapp ${COUCHSTORE_LIBRARIES})
1978fe9bd3bSVolker MischeSET_TARGET_PROPERTIES(couchstore_testapp PROPERTIES
1988fe9bd3bSVolker Mische                      COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
199ab70e514SDave RigbyADD_TEST(couchstore-testapp couchstore_testapp)
2009b5a3b8dSJim Walker
2015815fc1cSJim WalkerADD_EXECUTABLE(couchstore_gtest
2025815fc1cSJim Walker               tests/couchstoretest.cc
2035815fc1cSJim Walker               tests/documents.cc
2045815fc1cSJim Walker               tests/gtest_tests.cc
2055815fc1cSJim Walker               src/node_types.cc)
2065815fc1cSJim Walker
2075815fc1cSJim WalkerSET_TARGET_PROPERTIES(couchstore_gtest PROPERTIES
2085815fc1cSJim Walker                      COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
2095815fc1cSJim WalkerTARGET_INCLUDE_DIRECTORIES(couchstore_gtest PUBLIC ${gtest_SOURCE_DIR}/include)
2105815fc1cSJim Walker
2115815fc1cSJim WalkerTARGET_LINK_LIBRARIES(couchstore_gtest
2125815fc1cSJim Walker  gtest
2135815fc1cSJim Walker  gtest_main
2145815fc1cSJim Walker  couchstore
2155815fc1cSJim Walker  ${COUCHSTORE_LIBRARIES})
2165815fc1cSJim Walker
2175815fc1cSJim WalkerADD_TEST(couchstore-gtest couchstore_gtest)
2185815fc1cSJim Walker
2191daef432SWill GardnerADD_EXECUTABLE(couchstore_internal_gtest
2201daef432SWill Gardner        tests/couchstoretest.cc
2211daef432SWill Gardner        tests/documents.cc
2221daef432SWill Gardner        tests/gtest_internal_tests.cc
2231daef432SWill Gardner        ${COUCHSTORE_SOURCES}
2241daef432SWill Gardner        )
2251daef432SWill Gardner
2261daef432SWill GardnerSET_TARGET_PROPERTIES(couchstore_internal_gtest PROPERTIES
2271daef432SWill Gardner        COMPILE_FLAGS "-DLIBCOUCHSTORE_NO_VISIBILITY=1 -DTESTAPP=1")
2281daef432SWill GardnerTARGET_INCLUDE_DIRECTORIES(couchstore_internal_gtest PUBLIC ${gtest_SOURCE_DIR}/include src)
2291daef432SWill Gardner
2301daef432SWill GardnerTARGET_LINK_LIBRARIES(couchstore_internal_gtest
2311daef432SWill Gardner        gtest
2321daef432SWill Gardner        gtest_main
2331daef432SWill Gardner        ${COUCHSTORE_LIBRARIES})
2341daef432SWill Gardner
2351daef432SWill GardnerADD_TEST(couchstore-internal-gtest couchstore_internal_gtest)
23638a4c08aSTrond NorbyeADD_SUBDIRECTORY(programs)
2370b948c55SWill Gardner
2380b948c55SWill GardnerENABLE_CODE_COVERAGE_REPORT()
239