-
Notifications
You must be signed in to change notification settings - Fork 29
/
CMakeLists.txt
246 lines (205 loc) · 7.83 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
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
project(comm CXX C)
set(CMAKE_CXX_STANDARD 17)
# C0103 is a naming convention, but the variable names which need to be set
# are determined by the upstream project
# cmake-lint: disable=C0103
# Disable line length as some paths are hard to reduce without becoming cryptic
# cmake-lint: disable=C0301
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.18)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
set(PACKAGE_NAME "comm_jni_module")
find_library(log-lib log)
find_package(fbjni REQUIRED CONFIG)
set(BUILD_TESTING OFF)
set(HAVE_SYMBOLIZE OFF)
set(WITH_GTEST OFF CACHE BOOL "Use googletest" FORCE)
set(WITH_GFLAGS OFF CACHE BOOL "Use gflags" FORCE)
# General
set(_third_party_dir ${CMAKE_CURRENT_SOURCE_DIR}/build/third-party-ndk)
set(_android_build_dir build/${CMAKE_ANDROID_ARCH_ABI})
include(FetchContent)
if(CMAKE_ANDROID_ARCH_ABI STREQUAL arm64-v8a)
set(Rust_CARGO_TARGET aarch64-linux-android)
elseif(CMAKE_ANDROID_ARCH_ABI STREQUAL x86_64)
set(Rust_CARGO_TARGET x86_64-linux-android)
elseif(CMAKE_ANDROID_ARCH_ABI STREQUAL armeabi-v7a)
set(Rust_CARGO_TARGET armv7-linux-androideabi)
endif()
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} CMAKE_HOST_SYSTEM_NAME_LOWER)
set(_toolchain_path
"$ENV{ANDROID_HOME}/ndk/${NDK_VERSION}/toolchains/llvm/prebuilt/${CMAKE_HOST_SYSTEM_NAME_LOWER}-x86_64/bin"
)
if(EXISTS "${_toolchain_path}/${Rust_CARGO_TARGET}-ar")
set(AR "${_toolchain_path}/${Rust_CARGO_TARGET}-ar")
else()
set(AR "${_toolchain_path}/llvm-ar")
endif()
FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.2.1
)
FetchContent_MakeAvailable(Corrosion)
include(../../../shared/cmake/corrosion-cxx.cmake)
add_library_rust(PATH ../../native_rust_library NAMESPACE comm)
# We're updating parameters below for Cmake's find_OpenSSL() function
set(OPENSSL_ROOT_DIR
"${_third_party_dir}/openssl/openssl-${OPENSSL_VERSION}/${_android_build_dir}"
)
list(APPEND CMAKE_FIND_ROOT_PATH "${OPENSSL_ROOT_DIR}")
# Override HAVE_EXECINFO_H in glog's CMakeLists.txt
if(
CMAKE_ANDROID_ARCH_ABI STREQUAL arm64-v8a OR
CMAKE_ANDROID_ARCH_ABI STREQUAL armeabi-v7a
)
set(HAVE_EXECINFO_H OFF CACHE BOOL "Whether platform has execinfo.h")
endif()
add_subdirectory(${_third_party_dir}/glog/glog-${GLOG_VERSION}/)
file(GLOB LIBRN_DIR "${REACT_NATIVE_SO_DIR}/${ANDROID_ABI}")
if (NOT LIBRN_DIR)
# If /${ANDROID_ABI} dir not found, then ${REACT_NATIVE_SO_DIR} is probably:
# ReactAndroid/build/react-ndk/exported
file(GLOB LIBRN_DIR "${REACT_NATIVE_SO_DIR}")
endif ()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/folly-target.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/openssl-target.cmake)
add_subdirectory(../../node_modules/olm ./build)
set(_node_modules_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../node_modules)
set(_react_native_dir ${_node_modules_dir}/react-native)
add_subdirectory(../../cpp/CommonCpp/
${CMAKE_CURRENT_BINARY_DIR}/build/CommonCpp
EXCLUDE_FROM_ALL
)
file(GLOB SQLCIPHER
"${_node_modules_dir}/@commapp/sqlcipher-amalgamation/src/*.c"
)
# Add files which aren't a part of comm-tools
list(APPEND ANDROID_NATIVE_CODE
"./src/cpp/CommSecureStore.cpp"
"./src/cpp/DatabaseInitializerJNIHelper.cpp"
"./src/cpp/GlobalDBSingleton.cpp"
"./src/cpp/Logger.cpp"
"./src/cpp/MessageOperationsUtilitiesJNIHelper.cpp"
"./src/cpp/PlatformSpecificTools.cpp"
"./src/cpp/TerminateApp.cpp"
"./src/cpp/ThreadOperationsJNIHelper.cpp"
"./src/cpp/jsiInstaller.cpp"
"./src/cpp/NotificationsCryptoModuleJNIHelper.cpp"
"./src/cpp/StaffUtilsJNIHelper.cpp"
"./src/cpp/AESCrypto.cpp"
"./src/cpp/CommServicesAuthMetadataEmitter.cpp"
"./src/cpp/CommMMKV.cpp"
)
list(APPEND GENERATED_NATIVE_CODE
"../../cpp/CommonCpp/_generated/commJSI-generated.cpp"
"../../cpp/CommonCpp/_generated/utilsJSI-generated.cpp"
"../../cpp/CommonCpp/_generated/rustJSI-generated.cpp"
)
list(APPEND RUST_NATIVE_CODE
"../../native_rust_library/RustCallback.cpp"
"../../native_rust_library/RustAESCrypto.cpp"
"../../native_rust_library/RustCSAMetadataEmitter.cpp"
"../../native_rust_library/RustSecureStore.cpp"
"../../native_rust_library/RustBackupExecutor.cpp"
)
file(GLOB CRYPTO_NATIVE_CODE "../../cpp/CommonCpp/CryptoTools/*.cpp")
file(GLOB DB_NATIVE_CODE "../../cpp/CommonCpp/DatabaseManagers/*.cpp")
file(GLOB DB_ENTITIES_NATIVE_CODE "../../cpp/CommonCpp/DatabaseManagers/entities/*.cpp")
file(GLOB_RECURSE MODULE_NATIVE_CODE "../../cpp/CommonCpp/NativeModules/**/*.cpp")
file(GLOB MODULE_ROOT_NATIVE_CODE "../../cpp/CommonCpp/NativeModules/*.cpp")
file(GLOB NOTIFICATIONS_NATIVE_CODE "../../cpp/CommonCpp/Notifications/**/*.cpp")
add_library(
# Sets the name of the library
${PACKAGE_NAME}
# Sets the library as a shared library
SHARED
# React dependencies
${_react_native_dir}/ReactCommon/jsi/jsi/jsi.cpp
${_react_native_dir}/ReactCommon/jsi/jsi/JSIDynamic.cpp
${_react_native_dir}/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon/CallInvokerHolder.cpp
${_react_native_dir}/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp
${_react_native_dir}/ReactCommon/react/bridging/LongLivedObject.cpp
${_react_native_dir}/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.cpp
# Third party dependencies
${SQLCIPHER}
# comm code
${ANDROID_NATIVE_CODE}
${GENERATED_NATIVE_CODE}
${CRYPTO_NATIVE_CODE}
${DB_NATIVE_CODE}
${DB_ENTITIES_NATIVE_CODE}
${MODULE_NATIVE_CODE}
${MODULE_ROOT_NATIVE_CODE}
${TOOLS_NATIVE_CODE}
${NOTIFICATIONS_NATIVE_CODE}
${RUST_NATIVE_CODE}
)
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
target_include_directories(
${PACKAGE_NAME}
PRIVATE
# React Native
${_react_native_dir}/React
${_react_native_dir}/React/Base
${_react_native_dir}/ReactCommon
${_react_native_dir}/ReactCommon/jsi
${_react_native_dir}/ReactCommon/callinvoker
${_react_native_dir}/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon
# SQLCipher amalgamation
${_node_modules_dir}/@commapp/sqlcipher-amalgamation/src
# symlinked React Native headers
../headers
# comm android specific code
./src/cpp
# comm native mutual code
../../cpp/CommonCpp/
../../cpp/CommonCpp/NativeModules
../../cpp/CommonCpp/NativeModules/InternalModules
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/ThreadOperationsUtilities
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs
../../cpp/CommonCpp/DatabaseManagers
../../cpp/CommonCpp/Notifications
../../cpp/CommonCpp/Notifications/BackgroundDataStorage
# native rust library
${native_rust_library_include_dir}
)
add_definitions(
# SQLCipher
-DSQLITE_THREADSAFE=0
-DSQLITE_HAS_CODEC
-DSQLITE_TEMP_STORE=2
-DSQLCIPHER_CRYPTO_OPENSSL
-DSQLITE_ENABLE_SESSION
-DSQLITE_ENABLE_PREUPDATE_HOOK
)
target_link_libraries(
${PACKAGE_NAME}
fbjni::fbjni
android
${log-lib}
Folly::folly
glog::glog
olm
openssl-crypto
openssl-ssl
comm::native_rust_library
comm-tools
)
# add a dummy library which is required by CallInvokerHolderImpl.java
add_library(
turbomodulejsijni
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
./src/cpp/dummy.cpp
)