forked from TGX-Android/Telegram-X
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
286 lines (240 loc) · 6.67 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
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
project(tgx VERSION 1.0.0 LANGUAGES C CXX)
# == Include ==
include("${CMAKE_HOME_DIRECTORY}/cmake/ReadVariables.cmake")
include("${CMAKE_HOME_DIRECTORY}/cmake/Prefix.cmake")
include("${CMAKE_HOME_DIRECTORY}/cmake/Join.cmake")
# == Dirs ==
set(THIRDPARTY_DIR "${CMAKE_HOME_DIRECTORY}/third_party")
set(STUB_DIR "${CMAKE_HOME_DIRECTORY}/stub")
set(TGX_ROOT_DIR "${CMAKE_HOME_DIRECTORY}/../..")
set(TDLIB_DIR "${TGX_ROOT_DIR}/tdlib")
set(UTILS_DIR "${THIRDPARTY_DIR}/jni-utils")
set(ENABLE_TG_CALLS yes)
# Using webp only if building for 32-bit platform
if (${ANDROID_ABI} STREQUAL "armeabi-v7a" OR ${ANDROID_ABI} STREQUAL "x86")
set(USE_WEBP yes)
else()
set(USE_WEBP no)
endif()
if (${ANDROID_ABI} STREQUAL "x86_64" OR ${ANDROID_ABI} STREQUAL "arm64-v8a")
set(FFMPEG_ABI ${ANDROID_ABI})
elseif(${ANDROID_ABI} STREQUAL "x86")
set(FFMPEG_ABI "i686")
elseif(${ANDROID_ABI} STREQUAL "armeabi-v7a")
set(FFMPEG_ABI "armv7-a")
else()
message(FATAL_ERROR "Unknown abi: ${ANDROID_ABI}")
endif()
set(FFMPEG_DIR "${THIRDPARTY_DIR}/ffmpeg/build/${FFMPEG_ABI}")
set(FFMPEG_LIBS
swresample
avformat
swscale
avcodec
avfilter
avutil
)
set(VPX_DIR "${THIRDPARTY_DIR}/libvpx/build/${FFMPEG_ABI}")
set(VPX_LIB_PATH "${VPX_DIR}/lib/libvpx.a")
# == Constants ==
# $IS_ARM_FAMILY – armeabi-v7a or arm64-v8a
if (${ANDROID_ABI} STREQUAL "armeabi-v7a" OR ${ANDROID_ABI} STREQUAL "arm64-v8a")
set(IS_ARM_FAMILY yes)
else()
set(IS_ARM_FAMILY no)
endif()
message(STATUS "Building native library... \
CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE} \
IS_ARM_FAMILY: ${IS_ARM_FAMILY}")
# == CMake global settings ==
set(CMAKE_SKIP_RPATH ON)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
if (${IS_ARM_FAMILY})
enable_language(ASM)
else()
enable_language(ASM_NASM)
endif()
set(ORIGINAL_CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS}")
set(EXCLUDE_LIBS
libjni-utils.a
libflac.a
libyuv.a
"${VPX_LIB_PATH}"
libopus.a
libogg.a
libopusfile.a
librlottie.a
liblz4.a
)
if (${USE_WEBP})
list(APPEND EXCLUDE_LIBS
libwebpdecoder_static.a
)
endif()
foreach(ffmpeg_lib ${FFMPEG_LIBS})
list(APPEND EXCLUDE_LIBS
"${FFMPEG_DIR}/lib/lib${ffmpeg_lib}.a"
)
endforeach()
Join(EXCLUDE_LIBS "${EXCLUDE_LIBS}" ",")
list(APPEND ADD_LINKER_FLAGS
-Wl,--exclude-libs,${EXCLUDE_LIBS}
)
Join(ADD_LINKER_FLAGS "${ADD_LINKER_FLAGS}" " ")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ADD_LINKER_FLAGS}")
# == Libraries ==
# tdjni
add_library(crypto SHARED IMPORTED)
set_target_properties(crypto PROPERTIES IMPORTED_LOCATION
${TDLIB_DIR}/openssl/${ANDROID_ABI}/lib/libcryptox.so
)
add_library(ssl SHARED IMPORTED)
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION
${TDLIB_DIR}/openssl/${ANDROID_ABI}/lib/libsslx.so
)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.11.0")
target_include_directories(crypto INTERFACE
${TDLIB_DIR}/openssl/${ANDROID_ABI}/include
)
target_include_directories(ssl INTERFACE
${TDLIB_DIR}/openssl/${ANDROID_ABI}/include
)
endif()
add_library(tdjni SHARED IMPORTED)
set_target_properties(tdjni PROPERTIES IMPORTED_LOCATION
${TDLIB_DIR}/src/main/libs/${ANDROID_ABI}/libtdjni.so
)
target_link_libraries(tdjni INTERFACE ssl crypto)
# flac
include("${CMAKE_HOME_DIRECTORY}/BuildFlac.cmake")
# jni-utils
add_subdirectory(
"${UTILS_DIR}"
)
# yuv
include("${CMAKE_HOME_DIRECTORY}/BuildYuv.cmake")
# vpx
add_library(vpx STATIC IMPORTED)
set_target_properties(vpx PROPERTIES IMPORTED_LOCATION "${VPX_LIB_PATH}")
target_include_directories(vpx INTERFACE "${VPX_DIR}/include")
# opus
include("${CMAKE_HOME_DIRECTORY}/BuildOpus.cmake")
# ogg
include("${CMAKE_HOME_DIRECTORY}/BuildOgg.cmake")
# opusfile
include("${CMAKE_HOME_DIRECTORY}/BuildOpusfile.cmake")
# rlottie
include("${CMAKE_HOME_DIRECTORY}/BuildRlottie.cmake")
# lz4
include("${CMAKE_HOME_DIRECTORY}/BuildLz4.cmake")
if (${ENABLE_TG_CALLS})
# usrsctp
include("${CMAKE_HOME_DIRECTORY}/BuildUsrSCTP.cmake")
# srtp
include("${CMAKE_HOME_DIRECTORY}/BuildLibSRTP.cmake")
# openh264
include("${CMAKE_HOME_DIRECTORY}/BuildOpenH264.cmake")
# absl
include("${CMAKE_HOME_DIRECTORY}/BuildAbsl.cmake")
# json11
include("${CMAKE_HOME_DIRECTORY}/BuildJson11.cmake")
# rnnoise
include("${CMAKE_HOME_DIRECTORY}/BuildRNNoise.cmake")
# webrtc
include("${CMAKE_HOME_DIRECTORY}/BuildWebRTC.cmake")
# libtgvoip
include("${CMAKE_HOME_DIRECTORY}/BuildTelegramVoIP.cmake")
# tgcalls
include("${CMAKE_HOME_DIRECTORY}/BuildTgCalls.cmake")
endif()
# webp
if (${USE_WEBP})
include("${CMAKE_HOME_DIRECTORY}/BuildWebp.cmake")
endif()
# ffmpeg
foreach(FFMPEG_LIB IN LISTS FFMPEG_LIBS)
add_library(${FFMPEG_LIB} STATIC IMPORTED)
set_target_properties(${FFMPEG_LIB} PROPERTIES IMPORTED_LOCATION "${FFMPEG_DIR}/lib/lib${FFMPEG_LIB}.a")
target_include_directories(${FFMPEG_LIB} INTERFACE "${FFMPEG_DIR}/include")
endforeach()
# == Target ==
set(NATIVE_LIB "tgxjni")
add_library(${NATIVE_LIB} SHARED
log.cpp
"${THIRDPARTY_DIR}/telegram_intro/IntroRenderer.c"
"${THIRDPARTY_DIR}/emoji_suggestions/emoji_suggestions_data.cpp"
"${THIRDPARTY_DIR}/emoji_suggestions/emoji_suggestions.cpp"
jni.c
voice.c
emoji.cpp
utils.cpp
image.c
gif.cpp
views.c
"${THIRDPARTY_DIR}/exoplayer/opus_jni.cc"
"${THIRDPARTY_DIR}/exoplayer/flac_jni.cc"
"${THIRDPARTY_DIR}/exoplayer/flac_parser.cc"
"${THIRDPARTY_DIR}/exoplayer/ffmpeg_jni.cc"
"${THIRDPARTY_DIR}/exoplayer/vpx_jni.cc"
bridge.cpp
)
target_include_directories(${NATIVE_LIB} PRIVATE
"${THIRDPARTY_DIR}/telegram_intro"
"${THIRDPARTY_DIR}/exoplayer"
"${THIRDPARTY_DIR}"
.
)
target_compile_definitions(${NATIVE_LIB} PUBLIC
SOCKLEN_T=socklen_t
LOCALE_NOT_USED
DISABLE_IMPORTGL
BSD=1
AVOID_TABLES
ANDROID_TILE_BASED_DECODE
ANDROID_ARMV6_IDCT
__STDC_CONSTANT_MACROS
TDLIB_TDAPI_CLASS_PATH="org/drinkless/tdlib/TdApi"
)
target_compile_options(${NATIVE_LIB} PUBLIC
-Wall -Werror -Wno-deprecated-declarations
-Wno-macro-redefined -Wno-unused-variable
-fno-math-errno -fno-strict-aliasing -funroll-loops
-ffast-math
-fno-rtti
)
# TODO: remove -Wno-macro-redefined -Wno-unused-variable
# only "${THIRDPARTY_DIR}/exoplayer/ffmpeg_jni.cc" needs them.
# == Linking dependencies ==
target_link_libraries(${NATIVE_LIB}
crypto
ssl
tdjni
jni-utils
flac
yuv
vpx
ogg
opusfile
opus
rlottie
lz4
)
if (${USE_WEBP})
target_link_libraries(${NATIVE_LIB} webpdecoder_static)
else()
target_compile_definitions(${NATIVE_LIB} PRIVATE NO_WEBP)
endif()
foreach(ffmpeg_lib ${FFMPEG_LIBS})
target_link_libraries(${NATIVE_LIB} "${ffmpeg_lib}")
endforeach()
target_link_libraries(${NATIVE_LIB}
jnigraphics
log
GLESv2
EGL
android
cpufeatures
)
include(AndroidNdkModules)
android_ndk_import_module_cpufeatures()