1#
2# This is the toplevel CMakeLists.txt that is used to build Couchbase
3#
4CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
5CMAKE_POLICY(VERSION 2.8.12)
6
7STRING(REGEX REPLACE "[ ]" "a" modified_source_dir "${CMAKE_SOURCE_DIR}")
8IF (NOT modified_source_dir STREQUAL CMAKE_SOURCE_DIR)
9  MESSAGE(FATAL_ERROR "Couchbase cannot be built in a source directory containing a space character")
10ENDIF (NOT modified_source_dir STREQUAL CMAKE_SOURCE_DIR)
11
12STRING(REGEX REPLACE "[ ]" "a" modified_binary_dir "${CMAKE_BINARY_DIR}")
13IF (NOT modified_binary_dir STREQUAL CMAKE_BINARY_DIR)
14  MESSAGE(FATAL_ERROR "Couchbase cannot be built in a build directory containing a space character")
15ENDIF (NOT modified_binary_dir STREQUAL CMAKE_BINARY_DIR)
16
17
18# The PROJECT() macro sets it's own default build type, so need to specify
19# ours first.
20IF (NOT DEFINED CMAKE_BUILD_TYPE)
21   SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
22       "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
23       FORCE)
24ENDIF ()
25
26PROJECT("Couchbase")
27
28OPTION(COUCHBASE_KV_COMMIT_VALIDATION
29       "Only build modules used by KV commit validation"
30       OFF)
31
32# This option should be be enabled in the early phases of development
33# (e.g. when developing off master) and is used to guard additional
34# runtime checks which are desirable to report during testing; but
35# should not trigger in production.  As such this option should be set
36# to OFF before we move into the Beta/pre-release phase.
37#
38# Example usage - asserting that statistical counters are of an
39# expected range (don't underflow) - we would like to detect such
40# bugs; but they arn't serious enough to warrant crashing in a
41# customer environment.
42OPTION(CB_DEVELOPMENT_ASSERTS
43       "Enable additional asserts which abort execution if they fail."
44       OFF)
45IF (CB_DEVELOPMENT_ASSERTS)
46   MESSAGE(STATUS "Enabling CB_DEVELOPMENT_ASSERTS")
47   ADD_DEFINITIONS(-DCB_DEVELOPMENT_ASSERTS)
48ENDIF (CB_DEVELOPMENT_ASSERTS)
49
50IF ($ENV{JETBRAINS_IDE})
51   SET(JETBRAINS_CLION_IDE True CACHE BOOL "Build Couchbase under CLion")
52ENDIF ($ENV{JETBRAINS_IDE})
53
54IF (DEFINED JETBRAINS_CLION_IDE)
55   # CLion tries to autodetect all of the different configuration
56   # types and generate projects for them. That cause a race condition
57   # with the population pf the precompiled binaries we've got
58   # making an incomplete configuration. To work around that,
59   # let's just remove all of the other configurations and just
60   # build a debug build
61   SET(CMAKE_CONFIGURATION_TYPES Debug CACHE STRING "" FORCE)
62   ADD_DEFINITIONS(-DJETBRAINS_CLION_IDE)
63ENDIF (DEFINED JETBRAINS_CLION_IDE)
64
65IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
66  SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE STRING
67      "The install location" FORCE)
68  LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}")
69ENDIF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
70
71LIST (APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/tlm/cmake/Modules/")
72SET (COUCHBASE_SERVER_BUILD True CACHE BOOL "Indicating this is a server build")
73
74# Try to download the prebuilt 3rd-party dependencies by default
75IF (NOT DEFINED CB_DOWNLOAD_DEPS)
76   SET(CB_DOWNLOAD_DEPS True
77       CACHE BOOL "Download prebuilt dependencies by default")
78ENDIF (NOT DEFINED CB_DOWNLOAD_DEPS)
79
80# Have to add deps first, before any other part of the build tries to
81# FIND anything
82ADD_SUBDIRECTORY(tlm/deps)
83
84INCLUDE(CouchbaseDefaultValues)
85
86# If the user has synced any closed-source code, assume building EE
87IF (EXISTS "${PROJECT_SOURCE_DIR}/goproj/src/github.com/couchbase/backup")
88  SET (_ee_found ON)
89ELSE ()
90  SET (_ee_found OFF)
91ENDIF()
92OPTION (BUILD_ENTERPRISE "Building Enterprise Edition" ${_ee_found})
93
94# Build 'developer builds' by default
95OPTION (CB_DEVELOPER_BUILD "Produce Developer builds" ON)
96
97# 'Production builds' are those built by the official Couchbase build jobs
98OPTION (CB_PRODUCTION_BUILD "Official production build" OFF)
99
100# Temporary option to enable building eventing before it is fully phased into vulcan
101OPTION (CB_ENABLE_EVENTING "Enable eventing features" ON)
102
103MESSAGE(STATUS "Using cmake version: ${CMAKE_VERSION}")
104MESSAGE(STATUS "Installing to ${CMAKE_INSTALL_PREFIX}")
105MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
106
107INCLUDE(CouchbaseCompilerOptions)
108INCLUDE(CouchbaseSanitizers)
109INCLUDE(CouchbaseAsciiDocs)
110INCLUDE(CouchbaseMemoryAllocator)
111INCLUDE(CouchbaseCompression)
112
113INCLUDE(FindCouchbaseBoost)
114INCLUDE(FindCouchbaseOpenSSL)
115INCLUDE(FindCouchbaseLibevent)
116INCLUDE(FindCouchbaseCurl)
117INCLUDE(FindCouchbaseIcu)
118INCLUDE(FindCouchbaseLua)
119INCLUDE(FindCouchbasePythonInterp)
120INCLUDE(FindCouchbaseErlang)
121INCLUDE(FindCouchbaseDtrace)
122INCLUDE(FindCouchbaseGo)
123INCLUDE(FindCouchbaseBreakpad)
124INCLUDE(FindCouchbaseFlatbuffers)
125INCLUDE(FindCouchbaseValgrind)
126INCLUDE(FindCouchbaseV8)
127INCLUDE(FindCouchbaseNlohmannJson)
128INCLUDE(FindCouchbaseRocksDB)
129
130# Declare PRODUCT_VERSION in cache, but then override user-defined value
131# if it is an empty string
132SET (PRODUCT_VERSION "" CACHE STRING "Product version with build number")
133IF ("${PRODUCT_VERSION}" STREQUAL "")
134  IF (PYTHON_EXECUTABLE)
135    # Try to determine product version from manifest
136    EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} tlm/scripts/get_version.py
137      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
138      OUTPUT_VARIABLE _product_version
139      ERROR_QUIET
140      OUTPUT_STRIP_TRAILING_WHITESPACE)
141  ELSE (PYTHON_EXECUTABLE)
142    SET(_product_version "0.0.0-9999")
143  ENDIF (PYTHON_EXECUTABLE)
144  SET (PRODUCT_VERSION ${_product_version} CACHE STRING "Product version with build number" FORCE)
145ENDIF ("${PRODUCT_VERSION}" STREQUAL "")
146
147IF (BUILD_ENTERPRISE)
148  MESSAGE (STATUS "Building Couchbase Server ${PRODUCT_VERSION} Enterprise Edition")
149  ADD_DEFINITIONS(-DCOUCHBASE_ENTERPRISE_EDITION=1)
150ELSE ()
151  MESSAGE (STATUS "Building Couchbase Server ${PRODUCT_VERSION} Community Edition")
152ENDIF ()
153
154IF (WIN32)
155   SET(COUCHBASE_NETWORK_LIBS "Ws2_32")
156ELSEIF ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
157   SET(COUCHBASE_NETWORK_LIBS socket nsl)
158ENDIF (WIN32)
159MESSAGE(STATUS "Linking with network libraries: ${COUCHBASE_NETWORK_LIBS}")
160
161IF (NOT WIN32)
162   SET(COUCHBASE_MATH_LIBS m)
163ENDIF(NOT WIN32)
164
165INCLUDE(CouchbaseCodeCoverage)
166
167INCLUDE(TestBigEndian)
168TEST_BIG_ENDIAN(WORDS_BIG_ENDIAN)
169IF (WORDS_BIG_ENDIAN)
170  MESSAGE(STATUS "Builing on big endian system")
171  ADD_DEFINITIONS(-DWORDS_BIGENDIAN=1)
172ENDIF(WORDS_BIG_ENDIAN)
173
174ENABLE_TESTING()
175
176INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/platform/include)
177INCLUDE_DIRECTORIES(AFTER ${NLOHMANN_JSON_INCLUDE_DIR})
178
179# Add a quick (and safe) way to nuke everything
180ADD_CUSTOM_TARGET(reset
181                  COMMAND repo forall -c "git clean -dfx"
182                  VERBATIM)
183
184SET (gtest_force_shared_crt ON CACHE BOOL
185     "Use shared (DLL) run-time lib even when Google Test is built as static lib.")
186ADD_SUBDIRECTORY(googletest EXCLUDE_FROM_ALL)
187
188ADD_SUBDIRECTORY(benchmark EXCLUDE_FROM_ALL)
189
190ADD_SUBDIRECTORY(phosphor)
191OPTION(PHOSPHOR_DISABLE "Disable compilation of Phosphor trace points into components" OFF)
192
193IF (PHOSPHOR_DISABLE)
194    ADD_DEFINITIONS(-DPHOSPHOR_DISABLED=1)
195    SET(PHOSPHOR_LIB "")
196ENDIF (PHOSPHOR_DISABLE)
197
198ADD_SUBDIRECTORY(third_party EXCLUDE_FROM_ALL)
199
200ADD_SUBDIRECTORY(platform)
201ADD_SUBDIRECTORY(subjson)
202ADD_SUBDIRECTORY(kv_engine/include)
203ADD_SUBDIRECTORY(couchstore)
204IF (NOT COUCHBASE_KV_COMMIT_VALIDATION)
205    ADD_SUBDIRECTORY(forestdb)
206    SET (FORESTDB_INCLUDE_DIR "${ForestDB_SOURCE_DIR}/include")
207    SET(FORESTDB_LIBRARY_DIR "${ForestDB_BINARY_DIR}")
208    SET (FORESTDB_TARGET forestdb)
209ENDIF()
210ADD_SUBDIRECTORY(kv_engine)
211ADD_SUBDIRECTORY(sigar)
212ADD_SUBDIRECTORY(moxi)
213ADD_SUBDIRECTORY(product-texts/couchbase-server)
214
215IF (NOT COUCHBASE_KV_COMMIT_VALIDATION)
216    ADD_SUBDIRECTORY(couchbase-cli)
217    ADD_SUBDIRECTORY(couchdb)
218    ADD_SUBDIRECTORY(geocouch)
219    ADD_SUBDIRECTORY(query-ui)
220
221    SET (GODEPSDIR "${CMAKE_CURRENT_SOURCE_DIR}/godeps")
222
223    ADD_SUBDIRECTORY(ns_server ${CMAKE_CURRENT_SOURCE_DIR}/ns_server/build)
224
225    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/query)
226    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/indexing)
227    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/goxdcr)
228    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/gometa)
229    ADD_SUBDIRECTORY(godeps/src/github.com/couchbase/cbauth)
230
231    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/cbft)
232    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/docloader)
233
234    # Analytics CBGT connector
235    IF (BUILD_ENTERPRISE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/goproj/src/github.com/couchbaselabs/cbas")
236      ADD_SUBDIRECTORY(goproj/src/github.com/couchbaselabs/cbas)
237    ENDIF ()
238
239    # Analytics Maven project
240    IF (BUILD_ENTERPRISE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/analytics/CMakeLists.txt")
241      ADD_SUBDIRECTORY (analytics)
242    ENDIF ()
243
244    # Analytics UI
245    IF (BUILD_ENTERPRISE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cbas-ui")
246      ADD_SUBDIRECTORY (cbas-ui)
247    ENDIF ()
248
249    IF (BUILD_ENTERPRISE AND EXISTS "${PROJECT_SOURCE_DIR}/goproj/src/github.com/couchbase/backup")
250      ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/backup)
251    ENDIF()
252
253    IF (BUILD_ENTERPRISE AND EXISTS "${PROJECT_SOURCE_DIR}/goproj/src/github.com/couchbase/plasma")
254      ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/plasma)
255    ENDIF()
256
257    IF (BUILD_ENTERPRISE AND EXISTS "${PROJECT_SOURCE_DIR}/libcouchbase")
258      SET (LCB_NO_PLUGINS ON CACHE BOOL "Don't build plugins" FORCE)
259      SET (LCB_NO_TESTS ON CACHE BOOL "Don't run tests" FORCE)
260      SET (LCB_BUILD_DTRACE OFF CACHE BOOL "Turn off tracing" FORCE)
261      SET (LCB_INSTALL_HEADERS OFF CACHE BOOL "Don't install headers" FORCE)
262      SET (LCB_INSTALL_PKGCONFIG OFF CACHE BOOL "Don't install libcouchbase.pc" FORCE)
263      ADD_SUBDIRECTORY(libcouchbase)
264    ENDIF()
265
266    IF (BUILD_ENTERPRISE AND CB_ENABLE_EVENTING)
267      ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/eventing)
268    ENDIF()
269
270    IF (BUILD_ENTERPRISE AND EXISTS "${PROJECT_SOURCE_DIR}/goproj/src/github.com/couchbase/cbsummary")
271      ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/cbsummary)
272    ENDIF()
273
274ENDIF (NOT COUCHBASE_KV_COMMIT_VALIDATION)
275
276IF (NOT WIN32)
277   CONFIGURE_FILE(tlm/memcached-wrapper.in ${CMAKE_BINARY_DIR}/tlm/memcached-wrapper)
278   CONFIGURE_FILE(tlm/moxi-wrapper.in ${CMAKE_BINARY_DIR}/tlm/moxi-wrapper)
279ENDIF (NOT WIN32)
280