forked from couchbase/couchbase-lite-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
351 lines (311 loc) · 11.8 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#[[
LiteCore CMake Project
This is the CMake project for building the Couchbase LiteCore project. This is the core of the Couchbase Lite library.
It makes use of a lot of source and sublibraries and some cannot be used on their own. Here are a description of the
targets that result from this project:
BLIPStatic - The BLIP communication library for crafting messages that can be sent over a provided connection
C4Tests - A test runner that runs tests based on the shared library
CppTests - A test runner that runs test based on the static library
FleeceStatic - The Fleece serialization library for saving data to a binary format
LiteCoreStatic - The static LiteCore library
LiteCore - The shared LiteCore library
LiteCoreWebSocket - WebSocket implementation with C4Socket API to plug into LiteCore
LiteCoreREST - A simple library used for enabling testing of the shared library (not used in production)
mbedcrypto - The cryptography suite from mbedTLS (https://tls.mbed.org/)
SQLite3_UnicodeSN - The snowball tokenizer library for SQLite
This project is built for the following platforms at Couchbase:
- Windows 10
- UWP
- macOS 10.13
- CentOS 7 (gcc 7.x+)
- Android API 22+
Platform logic is largely separated into the cmake/platform_*.cmake files. Platforms are conglomerated together as follows
- platform_base
- platform_unix
- platform_apple
- platform_linux
- platform_linux_desktop
- platform_android
- platform_win
- platform_win_desktop
- platform_win_store
]]#
cmake_minimum_required (VERSION 3.9)
cmake_policy(VERSION 3.9)
# Mac/apple setup -- must appear before the first "project()" line"
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12")
if(NOT DEFINED CMAKE_OSX_SYSROOT)
# Tells Mac builds to use the current SDK's headers & libs, not what's in the OS.
set(CMAKE_OSX_SYSROOT macosx)
endif()
project (LiteCore)
include(CMakeDependentOption)
### BUILD SETTINGS:
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
$<$<CONFIG:Debug>:DEBUG>
)
option(CODE_COVERAGE_ENABLED "Set whether or not code coverage information should be generated" OFF)
option(BUILD_ENTERPRISE "Set whether or not to build enterprise edition" OFF)
option(LITECORE_DISABLE_ICU "Disables ICU linking" OFF)
option(DISABLE_LTO_BUILD "Disable build with Link-time optimization" OFF)
option(LITECORE_BUILD_TESTS "Builds C4Tests and CppTests" ON)
option(LITECORE_MAINTAINER_MODE "Build the library with official options, disable this to reveal additional options" ON)
# The following will only show up if LITECORE_MAINTAINER_MODE is disabled, in other words if LITECORE_MAINTAINER_MODE is on
# the following options will be ON, but if LITECORE_MAINTAINER_MODE is off, the the following options can be
# selected on or off. Standard warning about dragons!
cmake_dependent_option(
USE_COUCHBASE_SQLITE
"If enabled, the Couchbase provided SQLite will be built"
OFF "NOT LITECORE_MAINTAINER_MODE" ON
)
if(CODE_COVERAGE_ENABLED)
message("Code coverage enabled, forcing sanitizers off")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
elseif(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(WARN " Code coverage not supported for non-debug builds")
else()
message(WARN " Code coverage only supported on Clang")
endif()
endif()
add_definitions(
-DCMAKE # Let the source know this is a CMAKE build
-D__STDC_FORMAT_MACROS # Enables printf format macros for variable sized types (e.g. size_t)
)
if(BUILD_ENTERPRISE)
add_definitions(
-DCOUCHBASE_ENTERPRISE # Tells LiteCore it's an EE build
)
endif()
if(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0A00)
if(WINDOWS_STORE)
include("${PROJECT_SOURCE_DIR}/cmake/platform_win_store.cmake")
else()
include("${PROJECT_SOURCE_DIR}/cmake/platform_win_desktop.cmake")
endif()
elseif(APPLE)
include("${PROJECT_SOURCE_DIR}/cmake/platform_apple.cmake")
elseif(ANDROID)
include("${PROJECT_SOURCE_DIR}/cmake/platform_android.cmake")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
include("${PROJECT_SOURCE_DIR}/cmake/platform_linux_desktop.cmake")
else()
message(FATAL_ERROR "Unable to determine a supported platform from ${CMAKE_SYSTEM_NAME}")
endif(MSVC)
if(CMAKE_COMPILER_IS_GNUCC)
# Suppress an annoying note about GCC 7 ABI changes, and linker errors about the Fleece C API
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi -Wno-odr")
endif()
check_threading()
setup_globals()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LITECORE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LITECORE_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LITECORE_SHARED_LINKER_FLAGS}")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${LITECORE_STATIC_LINKER_FLAGS}")
set(SQLITE3_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/vendor/SQLiteCpp/sqlite3) # For SQLite3_UnicodeSN
add_subdirectory(vendor/fleece EXCLUDE_FROM_ALL)
add_subdirectory(vendor/sqlite3-unicodesn EXCLUDE_FROM_ALL)
add_subdirectory(vendor/mbedtls EXCLUDE_FROM_ALL)
# Generate file repo_version.h containing Git repo information, and add it to #include path:
set(GENERATED_HEADERS_DIR "${CMAKE_BINARY_DIR}/generated_headers")
file(MAKE_DIRECTORY "${GENERATED_HEADERS_DIR}")
configure_file(cmake/config_thread.h.in ${GENERATED_HEADERS_DIR}/config_thread.h)
if (UNIX)
execute_process(COMMAND /bin/bash "${PROJECT_SOURCE_DIR}/build_cmake/scripts/get_repo_version.sh"
"${GENERATED_HEADERS_DIR}/repo_version.h"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
else()
execute_process(COMMAND powershell "${PROJECT_SOURCE_DIR}/build_cmake/scripts/get_repo_version.ps1"
"${GENERATED_HEADERS_DIR}/repo_version.h"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
endif()
include_directories(${GENERATED_HEADERS_DIR})
add_subdirectory(Networking/BLIP EXCLUDE_FROM_ALL)
add_subdirectory(REST EXCLUDE_FROM_ALL)
### sqlite3 LIBRARY:
# Separate library to make possible replace or not use
# during static linking
add_library(CouchbaseSqlite3 STATIC LiteCore/Storage/SQLiteChooser.c)
target_include_directories(CouchbaseSqlite3 PUBLIC vendor/SQLiteCpp/sqlite3)
target_compile_definitions(
CouchbaseSqlite3
PUBLIC
-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 # Default to NORMAL sync mode on SQLite (safe with WAL mode)
-DSQLITE_LIKE_DOESNT_MATCH_BLOBS # Optimize SQLite "like" queries
-DSQLITE_OMIT_SHARED_CACHE # Allows SQLite to discard shared cache, eliminating some branches
-DSQLITE_OMIT_DECLTYPE # Disable returning the declared column type from query (reduces memory usage)
-DSQLITE_OMIT_DATETIME_FUNCS # Don't compile SQLite date functions
-DSQLITE_ENABLE_EXPLAIN_COMMENTS # Add comment text to the result of sqlite3_explain
-DSQLITE_DISABLE_FTS3_UNICODE # Disable FTS3 unicode61 tokenizer (not used in LiteCore)
-DSQLITE_ENABLE_MEMORY_MANAGEMENT # Enable sqlite3_release_memory to release unused memory faster
-DSQLITE_ENABLE_STAT4 # Enable enhanced query planning
-DSQLITE_HAVE_ISNAN # Use system provided isnan()
-DHAVE_LOCALTIME_R # Use localtime_r instead of localtime
-DHAVE_USLEEP # Allow millisecond precision sleep
-DHAVE_UTIME # Use utime() instead of utimes()
-DSQLITE_OMIT_LOAD_EXTENSION # Disable extensions (not needed for LiteCore)
-DSQLITE_ENABLE_FTS4 # Build FTS versions 3 and 4
-DSQLITE_ENABLE_FTS3_PARENTHESIS # Allow AND and NOT support in FTS parser
-DSQLITE_ENABLE_FTS3_TOKENIZER # Allow LiteCore to define a tokenizer
-DSQLITE_DQS=0 # Disallow double-quoted strings (only identifiers)
)
### WebSocket LIBRARY:
set(
LC_WEBSOCKET_SRC
Networking/HTTP/HTTPTypes.cc
Networking/HTTP/HTTPLogic.cc
Networking/NetworkInterfaces.cc
Networking/Poller.cc
Networking/TCPSocket.cc
Networking/TLSContext.cc
Networking/WebSockets/BuiltInWebSocket.cc
REST/netUtils.cc
vendor/sockpp/src/acceptor.cpp
vendor/sockpp/src/connector.cpp
vendor/sockpp/src/datagram_socket.cpp
vendor/sockpp/src/exception.cpp
vendor/sockpp/src/inet_address.cpp
vendor/sockpp/src/inet6_address.cpp
vendor/sockpp/src/mbedtls_context.cpp
vendor/sockpp/src/socket.cpp
vendor/sockpp/src/stream_socket.cpp
)
add_library(LiteCoreWebSocket STATIC ${LC_WEBSOCKET_SRC})
target_include_directories(
LiteCoreWebSocket PRIVATE
C
C/include
Crypto
LiteCore/Support
Networking
Networking/BLIP/
Networking/HTTP
Networking/WebSockets
Replicator
REST
vendor/fleece/Fleece/Support
vendor/fleece/API
vendor/sockpp/include
vendor/mbedtls/include
vendor/mbedtls/crypto/include
)
target_link_libraries(
LiteCoreWebSocket PUBLIC
LiteCoreStatic
)
### LITECORE LIBRARY:
set_litecore_source(RESULT ALL_SRC_FILES)
add_library(LiteCoreStatic STATIC ${ALL_SRC_FILES})
target_compile_definitions(
LiteCoreStatic PRIVATE
LITECORE_IMPL
HAS_UNCAUGHT_EXCEPTIONS # date.h use std::uncaught_exceptions instead of std::uncaught_exception
)
target_compile_definitions(
LiteCoreStatic PUBLIC
-DLITECORE_EXPORTS
)
if(BUILD_ENTERPRISE)
target_compile_definitions(CouchbaseSqlite3
PRIVATE
-DSQLITE_HAS_CODEC # Enables SQLite encryption extension (SEE)
)
endif()
target_include_directories(
LiteCoreStatic PRIVATE
vendor/fleece/API
vendor/fleece/Fleece/Core
vendor/fleece/Fleece/Mutable
vendor/fleece/Fleece/Support
vendor/fleece/vendor/date/include
LiteCore/BlobStore
LiteCore/Database
LiteCore/Query
LiteCore/Query/N1QL_Parser
LiteCore/RevTrees
LiteCore/Storage
LiteCore/Support
C
C/include
Crypto
Networking
Networking/BLIP/
Networking/HTTP
Networking/WebSockets
Replicator
REST
vendor/SQLiteCpp/include
vendor/sqlite3-unicodesn
vendor/mbedtls/include
vendor/mbedtls/crypto/include
vendor/sockpp/include
)
if(WIN32)
add_library(LiteCore SHARED MSVC/SQLiteTempDirectory.cc) #No-op for non-UWP
target_include_directories(
LiteCore PRIVATE
vendor/SQLiteCpp/sqlite3
)
else()
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
file(WRITE empty.cpp)
endif()
add_library(LiteCore SHARED empty.cpp)
endif()
# Library flags defined in platform_linux
if(BUILD_ENTERPRISE)
set(
LITECORE_LIBRARIES_PRIVATE
${WHOLE_LIBRARY_FLAG}
LiteCoreStatic
LiteCoreREST_Static
FleeceStatic
${NO_WHOLE_LIBRARY_FLAG}
LiteCoreWebSocket
)
else()
set(
LITECORE_LIBRARIES_PRIVATE
${WHOLE_LIBRARY_FLAG}
LiteCoreStatic
FleeceStatic
${NO_WHOLE_LIBRARY_FLAG}
)
endif()
target_include_directories(
LiteCore INTERFACE
C/include
)
target_link_libraries(LiteCore PRIVATE ${LITECORE_LIBRARIES_PRIVATE})
target_link_libraries(
LiteCoreStatic INTERFACE
FleeceStatic
SQLite3_UnicodeSN
BLIPStatic
mbedcrypto
mbedtls
mbedx509
)
if(USE_COUCHBASE_SQLITE)
target_link_libraries(
LiteCoreStatic PUBLIC
CouchbaseSqlite3
)
endif()
setup_litecore_build()
install (
TARGETS LiteCore
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
OPTIONAL
)
### TESTS:
add_subdirectory(LiteCore/tests)
add_subdirectory(C/tests)