forked from couchbase/couchbase-lite-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
399 lines (347 loc) · 15 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
cmake_minimum_required (VERSION 3.1)
cmake_policy(VERSION 3.1)
project (LiteCore)
### BUILD SETTINGS:
set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -Werror")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
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)
add_definitions(-DSQLITE_OMIT_LOAD_EXTENSION # This one's for SQLiteCpp
-DUSE_WEBSOCKET # Enables CivetWeb WebSocket support
-DNO_FILES # No file system support in CivetWeb (unneeded)
-DNO_CGI # No CGI support in CivetWeb (unneeded)
-DNO_CACHING # No file caching support in CivetWeb (unneeded)
-DUSE_IPV6 # Enable IPv6 support in CivetWeb
-DCMAKE # Let the source know this is a CMAKE build
-D__STDC_LIMIT_MACROS # Ensure the presence of UINT64_MAX, etc
-DNOMINMAX # Get rid of pesky Windows macros for min and max
-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1
-DSQLITE_LIKE_DOESNT_MATCH_BLOBS
-DSQLITE_OMIT_SHARED_CACHE
-DSQLITE_OMIT_DECLTYPE
-DSQLITE_OMIT_DATETIME_FUNCS
-DSQLITE_ENABLE_EXPLAIN_COMMENTS
-DSQLITE_DISABLE_FTS3_UNICODE
-DSQLITE_ENABLE_MEMORY_MANAGEMENT
-DSQLITE_ENABLE_STAT4
-DSQLITE_HAVE_ISNAN
-DHAVE_LOCALTIME_R
-DHAVE_USLEEP
-DHAVE_UTIME
-DSQLITE_OMIT_LOAD_EXTENSION
-DSQLITE_ENABLE_FTS4
-DSQLITE_ENABLE_FTS3_PARENTHESIS
-DSQLITE_ENABLE_FTS3_TOKENIZER)
if(BUILD_ENTERPRISE)
add_definitions(-DCOUCHBASE_ENTERPRISE # Tells LiteCore it's an EE build
-DSQLITE_HAS_CODEC # Enables SQLite encryption extension (SEE)
-DCCCRYPT256 # Enables AES256 in SEE
-DSQLITE_TEMP_STORE=2) # Don't write temp files to disk (for security)
endif()
if(MSVC)
if(WINDOWS_STORE)
add_definitions(-DSQLITE_OS_WINRT
-DMBEDTLS_NO_PLATFORM_ENTROPY
-D_WIN32_WINNT=0x0602) # Support back to Windows 8 for Windows Store
else()
add_definitions(-D_WIN32_WINNT=0x0601 # Support back to Windows 7 for Windows desktop
-DINCL_EXTRA_HTON_FUNCTIONS)# Make sure htonll is defined for WebSocketProtocol.hh
endif()
elseif(ANDROID)
# See: https://github.com/android-ndk/ndk/issues/477
# The issue is also applicable for other areas like fseeko
add_definitions(-DLITECORE_USES_ICU=1 -D_FILE_OFFSET_BITS=32)
endif()
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
$<$<CONFIG:Debug>:DEBUG>
)
if(CODE_COVERAGE_ENABLED)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -O0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -O0")
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()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /EHsc /wd4068 /wd4244 /wd4018 /wd4819 /wd4800 -D_CRT_SECURE_NO_WARNINGS=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8 -D_CRT_SECURE_NO_WARNINGS=1")
endif()
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
add_definitions(-DLITECORE_USES_ICU=1)
# Enable relative RPATHs for installed bits
set (CMAKE_INSTALL_RPATH "\$ORIGIN")
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} is not supported for building!")
endif()
find_library(LIBCXX_LIB c++)
if (NOT LIBCXX_LIB)
message(FATAL_ERROR "libc++ not found")
endif()
message("Found libc++ at ${LIBCXX_LIB}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
find_library(LIBCXXABI_LIB c++abi)
if (NOT LIBCXXABI_LIB)
message(FATAL_ERROR "libc++abi not found")
endif()
message("Found libc++abi at ${LIBCXXABI_LIB}")
find_path(LIBCXX_INCLUDE c++/v1/string
HINTS "${CMAKE_BINARY_DIR}/tlm/deps/libcxx.exploded"
PATH_SUFFIXES include)
if (NOT LIBCXX_INCLUDE)
message(FATAL_ERROR "libc++ header files not found")
endif()
message("Using libc++ header files in ${LIBCXX_INCLUDE}")
include_directories("${LIBCXX_INCLUDE}/c++/v1")
if(NOT EXISTS "/usr/include/xlocale.h")
include_directories("${LIBCXX_INCLUDE}/c++/v1/support/xlocale") # this fixed path is here to avoid compilation on Ubuntu 17.10 where xlocale.h is searched by some header(s) in libc++ as <xinclude.h> but not found from search path without this modification. However, only do it if the original xlocale.h does not exist since this will get searched before /usr/include and override a valid file with an empty one.
endif()
include_directories("/usr/include/libcxxabi") # this fixed path is here to avoid Clang issue noted at http://lists.alioth.debian.org/pipermail/pkg-llvm-team/2015-September/005208.html
find_library(ICU4C_COMMON icuuc)
if (NOT ICU4C_COMMON)
message(FATAL_ERROR "libicuuc not found")
endif()
message("Found libicuuc at ${ICU4C_COMMON}")
find_library(ICU4C_I18N icui18n)
if (NOT ICU4C_I18N)
message(FATAL_ERROR "libicui18n not found")
endif()
message("Found libicui18n at ${ICU4C_I18N}")
find_path(LIBICU_INCLUDE unicode/ucol.h
HINTS "${CMAKE_BINARY_DIR}/tlm/deps/icu4c.exploded"
PATH_SUFFIXES include)
if (NOT LIBCXX_INCLUDE)
message(FATAL_ERROR "libicu header files not found")
endif()
message("Using libicu header files in ${LIBICU_INCLUDE}")
include_directories("${LIBICU_INCLUDE}")
endif()
if(WIN32 OR ANDROID)
if(ANDROID)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,libgcc.a")
endif()
endif()
### SUBMODULES:
include_directories("vendor/fleece/Fleece"
"vendor/fleece/vendor"
"vendor/SQLiteCpp/include"
"vendor/SQLiteCpp/sqlite3"
"vendor/sqlite3-unicodesn"
"vendor/BLIP-Cpp/include/blip_cpp"
"vendor/BLIP-Cpp/src/util"
"vendor/civetweb/include"
"vendor/mbedtls/include")
if(WIN32)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4099 /ignore:4221")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
include_directories("MSVC")
elseif(ANDROID)
include_directories("LiteCore/Unix")
include_directories("LiteCore/Android")
elseif(UNIX AND NOT APPLE)
include_directories("LiteCore/Unix")
endif()
add_subdirectory(REST)
add_subdirectory(vendor/fleece EXCLUDE_FROM_ALL)
add_subdirectory(vendor/sqlite3-unicodesn EXCLUDE_FROM_ALL)
add_subdirectory(vendor/BLIP-Cpp EXCLUDE_FROM_ALL)
add_subdirectory(vendor/mbedtls EXCLUDE_FROM_ALL)
### MORE BUILD SETTINGS:
# Mac/iOS stuff
if (APPLE)
# Specify that we want to use CommonCrypto:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRYPTO_CC")
elseif(UNIX AND NOT ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRYPTO_MBEDTLS")
endif()
# 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}")
if (UNIX)
execute_process(COMMAND /bin/bash "${PROJECT_SOURCE_DIR}/build_cmake/scripts/get_repo_version.sh"
"${GENERATED_HEADERS_DIR}/repo_version.h")
else()
execute_process(COMMAND powershell "${PROJECT_SOURCE_DIR}/build_cmake/scripts/get_repo_version.ps1"
"${GENERATED_HEADERS_DIR}/repo_version.h")
endif()
include_directories(${GENERATED_HEADERS_DIR})
### SOURCE FILES:
include_directories(LiteCore/BlobStore
LiteCore/Database
LiteCore/Indexes
LiteCore/Query
LiteCore/RevTrees
LiteCore/Storage
LiteCore/Support
LiteCore/VersionVectors
C/include C)
# TODO: CMake docs say it's better to list the source files explicitly than use aux_source_directory
aux_source_directory(C C_SRC)
aux_source_directory(LiteCore/BlobStore BLOBSTORE_SRC)
aux_source_directory(LiteCore/Database DATABASE_SRC)
aux_source_directory(LiteCore/Indexes INDEXES_SRC)
aux_source_directory(LiteCore/Query QUERY_SRC)
aux_source_directory(LiteCore/RevTrees REVTREES_SRC)
aux_source_directory(LiteCore/Storage STORAGE_SRC)
aux_source_directory(LiteCore/VersionVectors VERSIONVECTORS_SRC)
aux_source_directory(LiteCore/Support SUPPORT_SRC)
list(REMOVE_ITEM SUPPORT_SRC LiteCore/Support/Logging_Stub.cc)
aux_source_directory(vendor/SQLiteCpp/src SQLITECPP_SRC)
aux_source_directory(Replicator REPLICATOR_SRC)
set(CIVETWEB_SRC "vendor/civetweb/src/civetweb.c"
"REST/civetUtils.cc")
if(!MSVC)
set_source_files_properties(${C_SRC} PROPERTIES COMPILE_FLAGS -Wno-return-type-c-linkage)
endif()
### BUILDING THE LIBRARY:
set(ALL_SRC_FILES
${BLOBSTORE_SRC}
${DATABASE_SRC}
${INDEXES_SRC}
${QUERY_SRC}
${REVTREES_SRC}
${STORAGE_SRC}
${SUPPORT_SRC}
${VERSIONVECTORS_SRC}
${C_SRC}
${SQLITECPP_SRC}
${REPLICATOR_SRC})
if(MSVC)
include_directories("vendor/fleece/MSVC")
elseif(ANDROID)
set(ALL_SRC_FILES ${ALL_SRC_FILES}
LiteCore/Unix/strlcat.c
LiteCore/Unix/arc4random.cc
LiteCore/Android/unicode/ndk_icu.c)
elseif(UNIX AND NOT APPLE)
set(ALL_SRC_FILES ${ALL_SRC_FILES}
LiteCore/Unix/strlcat.c
LiteCore/Unix/arc4random.cc)
endif()
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
# libc++ is special - clang will introduce an implicit -lc++ when it is used.
# That means we need to tell the linker the path to the directory containing
# libc++.so rather than just linking the .so directly. This must be done
# *before* the target declaration as it affects all subsequent targets.
get_filename_component (LIBCXX_LIBDIR "${LIBCXX_LIB}" DIRECTORY)
link_directories (${LIBCXX_LIBDIR})
endif()
add_library(LiteCoreStatic STATIC ${ALL_SRC_FILES})
target_compile_definitions(LiteCoreStatic PRIVATE -DLITECORE_IMPL)
if(WIN32)
add_library(LiteCore SHARED MSVC/SQLiteTempDirectory.cc) #No-op for non-UWP
else()
file(WRITE empty.cpp)
add_library(LiteCore SHARED empty.cpp)
endif()
install (TARGETS LiteCore
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib)
if(UNIX AND NOT APPLE)
set(WHOLE_LIBRARY_FLAG "-Wl,--whole-archive")
set(NO_WHOLE_LIBRARY_FLAG "-Wl,--no-whole-archive")
endif()
set(LITECORE_LIBRARIES_PRIVATE ${WHOLE_LIBRARY_FLAG}
LiteCoreStatic
FleeceStatic
${NO_WHOLE_LIBRARY_FLAG}
Support
SQLite3_UnicodeSN
BLIPStatic
CivetWeb
mbedcrypto)
target_link_libraries(LiteCore PRIVATE ${LITECORE_LIBRARIES_PRIVATE})
# Mac/iOS stuff
if (APPLE)
set_target_properties(LiteCore PROPERTIES LINK_FLAGS
"-exported_symbols_list ${PROJECT_SOURCE_DIR}/C/c4.exp")
target_link_libraries(LiteCore PUBLIC "-framework CoreFoundation"
"-framework Foundation"
"-framework CFNetwork"
"-framework Security"
z)
elseif(UNIX AND NOT ANDROID)
target_link_libraries(LiteCore PUBLIC z ${ICU4C_COMMON} ${ICU4C_I18N})
elseif(ANDROID)
target_compile_definitions(LiteCoreStatic PUBLIC -D_CRYPTO_MBEDTLS)
target_link_libraries(LiteCore PRIVATE "atomic" "log" zlibstatic)
else()
target_compile_definitions(LiteCoreStatic PUBLIC -DUNICODE -D_UNICODE -D_CRYPTO_MBEDTLS -D_USE_MATH_DEFINES -DLITECORE_EXPORTS -DWIN32)
if(WINDOWS_STORE)
target_compile_definitions(LiteCoreStatic PUBLIC -DMBEDTLS_NO_PLATFORM_ENTROPY)
set_target_properties(LiteCore PROPERTIES COMPILE_FLAGS /ZW)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /nodefaultlib:kernel32.lib /nodefaultlib:ole32.lib")
endif()
set_target_properties(LiteCore PROPERTIES LINK_FLAGS
"/def:${PROJECT_SOURCE_DIR}/C/c4.def")
target_link_libraries(LiteCore PRIVATE zlibstatic Ws2_32)
endif()
### JNI:
if (JNI)
add_subdirectory(Java)
endif()
### REST LISTENER LIBRARY:
add_library(LiteCoreREST SHARED LiteCore/Support/Error.cc
LiteCore/Support/Error_android.cc
LiteCore/Support/Error_windows.cc
LiteCore/Support/FilePath.cc
LiteCore/Support/Logging_Stub.cc
LiteCore/Support/StringUtil.cc
LiteCore/Support/RefCounted.cc
C/c4ExceptionUtils.cc)
target_link_libraries(LiteCoreREST PRIVATE ${WHOLE_LIBRARY_FLAG} LiteCoreREST_Static ${NO_WHOLE_LIBRARY_FLAG} LiteCore FleeceStatic)
if (APPLE)
set_target_properties(LiteCoreREST PROPERTIES LINK_FLAGS
"-exported_symbols_list ${PROJECT_SOURCE_DIR}/REST/c4REST.exp")
elseif(MSVC)
target_link_libraries(LiteCoreREST PUBLIC)
set_target_properties(LiteCoreREST PROPERTIES LINK_FLAGS
"/def:${PROJECT_SOURCE_DIR}/REST/c4REST.def")
elseif(ANDROID)
target_link_libraries(LiteCoreREST PRIVATE "atomic" "log")
endif()
### SUPPORT LIB:
if(MSVC)
set(PLATFORM_SRC
MSVC/asprintf.c
vendor/fleece/MSVC/memmem.cc
MSVC/mkstemp.cc
MSVC/mkdtemp.cc
MSVC/strlcat.c
MSVC/vasprintf-msvc.c
MSVC/arc4random.cc
MSVC/strptime.cc
LiteCore/Support/PlatformIO.cc)
elseif(ANDROID)
set(PLATFORM_SRC
LiteCore/Unix/strlcat.c
LiteCore/Unix/arc4random.cc)
elseif(UNIX AND NOT APPLE)
set(PLATFORM_SRC
LiteCore/Unix/strlcat.c
LiteCore/Unix/arc4random.cc)
endif()
add_library(Support STATIC
C/c4ExceptionUtils.cc
LiteCore/Support/LibC++Debug.cc
LiteCore/Support/Error.cc
LiteCore/Support/Error_windows.cc
LiteCore/Support/Error_android.cc
LiteCore/Support/FilePath.cc
LiteCore/Support/Logging_Stub.cc
LiteCore/Support/RefCounted.cc
LiteCore/Support/StringUtil.cc
Replicator/Address.cc
${PLATFORM_SRC}
)
### TOOLS:
add_subdirectory(tools)
### TESTS:
add_subdirectory(LiteCore/tests)
add_subdirectory(C/tests)