1#
2# This is the toplevel CMakeLists.txt that is used to build Couchbase
3#
4CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
5
6IF (NOT(${CMAKE_MAJOR_VERSION} LESS 3))
7  CMAKE_POLICY(SET CMP0026 OLD)
8ENDIF (NOT(${CMAKE_MAJOR_VERSION} LESS 3))
9
10STRING(REGEX REPLACE "[ ]" "a" modified_source_dir "${CMAKE_SOURCE_DIR}")
11IF (NOT modified_source_dir STREQUAL CMAKE_SOURCE_DIR)
12  MESSAGE(FATAL_ERROR "Couchbase cannot be built in a source directory containing a space character")
13ENDIF (NOT modified_source_dir STREQUAL CMAKE_SOURCE_DIR)
14
15STRING(REGEX REPLACE "[ ]" "a" modified_binary_dir "${CMAKE_BINARY_DIR}")
16IF (NOT modified_binary_dir STREQUAL CMAKE_BINARY_DIR)
17  MESSAGE(FATAL_ERROR "Couchbase cannot be built in a build directory containing a space character")
18ENDIF (NOT modified_binary_dir STREQUAL CMAKE_BINARY_DIR)
19
20
21# The PROJECT() macro sets it's own default build type, so need to specify
22# ours first.
23IF (NOT DEFINED CMAKE_BUILD_TYPE)
24   SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
25       "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
26       FORCE)
27ENDIF ()
28
29PROJECT("Couchbase")
30
31IF (DEFINED JETBRAINS_CLION_IDE)
32   # CLion tries to autodetect all of the different configuration
33   # types and generate projects for them. That cause a race condition
34   # with the population pf the precompiled binaries we've got
35   # making an incomplete configuration. To work around that,
36   # let's just remove all of the other configurations and just
37   # build a debug build
38   SET(CMAKE_CONFIGURATION_TYPES Debug CACHE STRING "" FORCE)
39   ADD_DEFINITIONS(-DJETBRAINS_CLION_IDE)
40ENDIF (DEFINED JETBRAINS_CLION_IDE)
41
42# RPATH is more or less "broken" on MacOSX in cmake < 3.x
43IF (APPLE)
44   IF (${CMAKE_MAJOR_VERSION} LESS 3)
45      MESSAGE(STATUS "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
46      MESSAGE(STATUS "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
47      MESSAGE(STATUS "@@@ The version of cmake you're using  @@@")
48      MESSAGE(STATUS "@@@ does not properly handle $RPATH    @@@")
49      MESSAGE(STATUS "@@@ RPATH for macosx was introduced in @@@")
50      MESSAGE(STATUS "@@@ cmake 3.0.0                        @@@")
51      MESSAGE(STATUS "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
52      MESSAGE(STATUS "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
53      MESSAGE(FATAL_ERROR "Please upgrade cmake")
54   ENDIF (${CMAKE_MAJOR_VERSION} LESS 3)
55ENDIF(APPLE)
56
57IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
58  SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE STRING
59      "The install location" FORCE)
60  LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}")
61ENDIF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
62
63SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tlm/cmake/Modules/")
64SET(COUCHBASE_SERVER_BUILD True CACHE BOOL "Indicating this is a server build")
65
66# Try to download the prebuilt 3rd-party dependencies by default
67IF (NOT DEFINED CB_DOWNLOAD_DEPS)
68   SET(CB_DOWNLOAD_DEPS True
69       CACHE BOOL "Download prebuilt dependencies by default")
70ENDIF (NOT DEFINED CB_DOWNLOAD_DEPS)
71
72# Have to add deps first, before any other part of the build tries to
73# FIND anything
74ADD_SUBDIRECTORY(tlm/deps)
75
76INCLUDE(CouchbaseDefaultValues)
77
78IF ("" STREQUAL "${BUILD_ENTERPRISE}")
79   SET(CB_BUILD_TYPE "Community Edition")
80ELSE ("" STREQUAL "${BUILD_ENTERPRISE}")
81   SET(CB_BUILD_TYPE "Enterprise Edition")
82ENDIF ("" STREQUAL "${BUILD_ENTERPRISE}")
83
84MESSAGE(STATUS "Using cmake version: ${CMAKE_VERSION}")
85MESSAGE(STATUS "Installing to ${CMAKE_INSTALL_PREFIX}")
86MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE} (${CB_BUILD_TYPE})")
87
88INCLUDE(CouchbaseAddressSanitizer)
89INCLUDE(CouchbaseThreadSanitizer)
90INCLUDE(CouchbaseMemoryAllocator)
91
92INCLUDE(FindCouchbaseOpenSSL)
93INCLUDE(FindCouchbaseLibevent)
94INCLUDE(FindCouchbaseCurl)
95INCLUDE(FindCouchbaseIcu)
96INCLUDE(FindCouchbaseSnappy)
97INCLUDE(FindCouchbaseLua)
98INCLUDE(FindCouchbasePythonInterp)
99INCLUDE(FindCouchbaseErlang)
100INCLUDE(FindCouchbaseDtrace)
101INCLUDE(FindCouchbaseGo)
102INCLUDE(FindCouchbaseBreakpad)
103INCLUDE(FindCouchbaseFlatbuffers)
104INCLUDE(FindCouchbaseValgrind)
105INCLUDE(CouchbaseCompilerOptions)
106INCLUDE(FindCouchbaseV8)
107
108IF (WIN32)
109   SET(COUCHBASE_NETWORK_LIBS "Ws2_32")
110ELSEIF ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
111   SET(COUCHBASE_NETWORK_LIBS socket nsl)
112ENDIF (WIN32)
113MESSAGE(STATUS "Linking with network libraries: ${COUCHBASE_NETWORK_LIBS}")
114
115IF (NOT WIN32)
116   SET(COUCHBASE_MATH_LIBS m)
117ENDIF(NOT WIN32)
118
119INCLUDE(CouchbaseCodeCoverage)
120
121INCLUDE(TestBigEndian)
122TEST_BIG_ENDIAN(WORDS_BIG_ENDIAN)
123IF (WORDS_BIG_ENDIAN)
124  MESSAGE(STATUS "Builing on big endian system")
125  ADD_DEFINITIONS(-DWORDS_BIGENDIAN=1)
126ENDIF(WORDS_BIG_ENDIAN)
127
128ENABLE_TESTING()
129
130INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/platform/include)
131
132# Add a quick (and safe) way to nuke everything
133ADD_CUSTOM_TARGET(reset
134                  COMMAND repo forall -c "git clean -dfx"
135                  VERBATIM)
136
137SET (gtest_force_shared_crt ON CACHE BOOL
138     "Use shared (DLL) run-time lib even when Google Test is built as static lib.")
139ADD_SUBDIRECTORY(googletest EXCLUDE_FROM_ALL)
140
141ADD_SUBDIRECTORY(platform)
142ADD_SUBDIRECTORY(subjson)
143ADD_SUBDIRECTORY(memcached)
144ADD_SUBDIRECTORY(couchstore)
145ADD_SUBDIRECTORY(forestdb)
146ADD_SUBDIRECTORY(ep-engine)
147
148IF (NOT DEFINED COUCHBASE_KV_COMMIT_VALIDATION)
149   ADD_SUBDIRECTORY(couchbase-cli)
150   ADD_SUBDIRECTORY(couchbase-examples)
151ENDIF (NOT DEFINED COUCHBASE_KV_COMMIT_VALIDATION)
152
153ADD_SUBDIRECTORY(sigar)
154ADD_SUBDIRECTORY(moxi)
155
156IF (NOT DEFINED COUCHBASE_KV_COMMIT_VALIDATION)
157    ADD_SUBDIRECTORY(couchdb)
158    ADD_SUBDIRECTORY(geocouch)
159    ADD_SUBDIRECTORY(query-ui)
160ENDIF (NOT DEFINED COUCHBASE_KV_COMMIT_VALIDATION)
161
162SET (GODEPSDIR "${CMAKE_CURRENT_SOURCE_DIR}/godeps")
163
164IF (NOT DEFINED JETBRAINS_CLION_IDE AND NOT DEFINED COUCHBASE_KV_COMMIT_VALIDATION)
165
166  # The CLion IDE from JetBrains don't support building "in source",
167  # so let's just skip ns_server in that configuration (we don't use
168  # CLion for Erlang development anyway...
169  ADD_SUBDIRECTORY(ns_server ${CMAKE_CURRENT_SOURCE_DIR}/ns_server/build)
170ENDIF (NOT DEFINED JETBRAINS_CLION_IDE AND NOT DEFINED COUCHBASE_KV_COMMIT_VALIDATION)
171
172IF (NOT DEFINED COUCHBASE_KV_COMMIT_VALIDATION)
173    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/query)
174    SET (FORESTDB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/forestdb/include")
175    GET_PROPERTY (_dir TARGET forestdb PROPERTY LOCATION)
176    GET_FILENAME_COMPONENT (FORESTDB_LIBRARY_DIR "${_dir}" PATH)
177    SET (FORESTDB_TARGET forestdb)
178    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/indexing)
179    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/goxdcr)
180    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/gometa)
181    ADD_SUBDIRECTORY(godeps/src/github.com/couchbase/cbauth)
182
183    ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/cbft)
184
185    IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/goproj/src/github.com/couchbase/backup")
186      ADD_SUBDIRECTORY(goproj/src/github.com/couchbase/backup)
187    ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/goproj/src/github.com/couchbase/backup")
188ENDIF (NOT DEFINED COUCHBASE_KV_COMMIT_VALIDATION)
189
190IF (NOT WIN32)
191   CONFIGURE_FILE(tlm/memcached-wrapper.in ${CMAKE_BINARY_DIR}/tlm/memcached-wrapper)
192   CONFIGURE_FILE(tlm/moxi-wrapper.in ${CMAKE_BINARY_DIR}/tlm/moxi-wrapper)
193ENDIF (NOT WIN32)
194