| 7 |
| set(CMAKE_CXX_FLAGS "-DANDROID") |
| 8 | set(CMAKE_C_FLAGS "-w -std=c11 -DANDROID -D_LARGEFILE_SOURCE=1 -Wno-error=implicit-function-declaration") |
| 9 | set(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp") |
| 10 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -fvisibility=hidden -flto=full") |
| 11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -flto=full") |
| 12 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto=full -Wl,--gc-sections -Wl,--icf=safe -Wl,-Bsymbolic") |
| 13 |
| 14 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 15 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g") |
| 16 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g") |
| 17 | else() |
| 18 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Os -DNDEBUG") |
| 19 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Os -DNDEBUG") |
| 20 | set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,-exclude-libs,ALL -Wl,--gc-sections -Wl,--strip-all") |
| 21 | endif() |
| 22 |
| 23 | if (${ANDROID_ABI} STREQUAL "armeabi-v7a" OR ${ANDROID_ABI} STREQUAL "arm64-v8a") |
| 24 | enable_language(ASM) |
| 25 | else() |
| 26 | enable_language(ASM_NASM) |
| 27 | endif() |
| 28 |
| 29 | set(CAN_COMPILE_SME FALSE CACHE INTERNAL "Disable libyuv SME" FORCE) |
| 30 | add_subdirectory( |
| 31 | third_party/libyuv |
| 32 | ${CMAKE_CURRENT_BINARY_DIR}/libyuv |
| 33 | EXCLUDE_FROM_ALL) |
| 34 |
| 35 | # Abseil |
| 36 | set(ABSL_PROPAGATE_CXX_STD ON) |
| 37 | set(ABSL_BUILD_TESTING OFF) |
| 38 | set(ABSL_ENABLE_INSTALL OFF) |
| 39 | add_subdirectory( |
| 40 | third_party/absl |
| 41 | ${CMAKE_CURRENT_BINARY_DIR}/absl |
| 42 | EXCLUDE_FROM_ALL) |
| 43 |
| 44 | add_library(webrtc_absl INTERFACE) |
| 45 | target_link_libraries(webrtc_absl INTERFACE |
| 46 | absl::base |
| 47 | absl::strings |
| 48 | absl::str_format |
| 49 | absl::cord |
| 50 | absl::synchronization |
| 51 | absl::time |
| 52 | absl::status |
| 53 | absl::statusor |
| 54 | absl::hash |
| 55 | absl::flat_hash_map |
| 56 | absl::flat_hash_set |
| 57 | absl::flags |
| 58 | absl::flags_parse |
| 59 | absl::random_random |
| 60 | absl::random_distributions |
| 61 | absl::crc32c |
| 62 | absl::log |
| 63 | absl::check |
| 64 | ) |
| 65 |
| 66 | add_library(avutil STATIC IMPORTED) |
| 67 | set_target_properties(avutil PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libavutil.a) |
| 68 |
| 69 | add_library(avformat STATIC IMPORTED) |
| 70 | set_target_properties(avformat PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libavformat.a) |
| 71 |
| 72 | add_library(avcodec STATIC IMPORTED) |
| 73 | set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libavcodec.a) |
| 74 |
| 75 | add_library(swresample STATIC IMPORTED) |
| 76 | set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libswresample.a) |
| 77 |
| 78 | add_library(swscale STATIC IMPORTED) |
| 79 | set_target_properties(swscale PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libswscale.a) |
| 80 |
| 81 | add_library(crypto STATIC IMPORTED) |
| 82 | set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libcrypto.a) |
| 83 |
| 84 | add_library(ssl STATIC IMPORTED) |
| 85 | set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libssl.a) |
| 86 |
| 87 |
| 88 | #aesige |
| 89 | #add_library(aesige STATIC openssl/aes_ige.c) |
| 90 | #target_compile_options(aesige PUBLIC -Wall -frtti -finline-functions -ffast-math -Oz) |
| 91 | #target_include_directories(aesige PUBLIC third_party/boringssl/include openssl/include) |
| 92 | #target_link_libraries(aesige crypto) |
| 93 |
| 94 |
| 95 | add_library(libvpx STATIC IMPORTED) |
| 96 | set_target_properties(libvpx PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libvpx.a) |
| 97 |
| 98 | add_library(libdav1d STATIC IMPORTED) |
| 99 | set_target_properties(libdav1d PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libdav1d.a) |
| 100 |
| 101 | add_library(libopus STATIC IMPORTED) |
| 102 | set_target_properties(libopus PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libopus.a) |
| 103 |
| 104 | add_library(tde2e STATIC IMPORTED) |
| 105 | set_target_properties(tde2e PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libtde2e.a) |
| 106 |
| 107 | add_library(tdutils STATIC IMPORTED) |
| 108 | set_target_properties(tdutils PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libtdutils.a) |
| 109 |
| 110 | add_subdirectory( |
| 111 | prisma |
| 112 | ${CMAKE_CURRENT_BINARY_DIR}/prisma |
| 113 | EXCLUDE_FROM_ALL) |
| 114 |
| 115 | #tgnet |
| 116 | add_library(tgnet STATIC |
| 117 | openssl/aes_ige.c |
| 118 | tgnet/ApiScheme.cpp |
| 119 | tgnet/BuffersStorage.cpp |
| 120 | tgnet/ByteArray.cpp |
| 121 | tgnet/ByteStream.cpp |
| 122 | tgnet/Connection.cpp |
| 123 | tgnet/ConnectionSession.cpp |
| 124 | tgnet/ConnectionsManager.cpp |
| 125 | tgnet/TLSHello.cpp |
| 126 | tgnet/ConnectionSocket.cpp |
| 127 | tgnet/Datacenter.cpp |
| 128 | tgnet/EventObject.cpp |
| 129 | tgnet/FileLog.cpp |
| 130 | tgnet/MTProtoScheme.cpp |
| 131 | tgnet/NativeByteBuffer.cpp |
| 132 | tgnet/Request.cpp |
| 133 | tgnet/Timer.cpp |
| 134 | tgnet/TLObject.cpp |
| 135 | tgnet/ProxyCheckInfo.cpp |
| 136 | tgnet/Handshake.cpp |
| 137 | tgnet/Config.cpp) |
| 138 | target_compile_options(tgnet PUBLIC |
| 139 | -Wall -frtti -finline-functions -ffast-math -Oz) |
| 140 | set_target_properties(tgnet PROPERTIES |
| 141 | ANDROID_ARM_MODE arm) |
| 142 | target_compile_definitions(tgnet PUBLIC |
| 143 | HAVE_PTHREAD) |
| 144 | target_include_directories(tgnet PUBLIC |
| 145 | third_party/boringssl/include |
| 146 | openssl/include) |
| 147 | target_link_libraries(tgnet |
| 148 | crypto) |
| 149 |
| 150 | # tlottie (prebuilt Rust static library) |
| 151 | add_library(tlottie STATIC IMPORTED) |
| 152 | set_target_properties(tlottie PROPERTIES |
| 153 | IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/prebuild/lib/${ANDROID_ABI}/libtlottie.a) |
| 154 |
| 155 | # Wallet Engine: matching Rust archive and generated UniFFI C++20 wrapper. |
| 156 | set(WALLET_ENGINE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/prebuild/include/wallet-engine) |
| 157 | add_library(wallet_engine STATIC IMPORTED) |
| 158 | set_target_properties(wallet_engine PROPERTIES |
| 159 | IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/prebuild/lib/${ANDROID_ABI}/libwallet_engine.a) |
| 160 |
| 161 | add_library(wallet_engine_cpp STATIC |
| 162 | ${WALLET_ENGINE_INCLUDE_DIR}/wallet_engine.cpp |
| 163 | ${WALLET_ENGINE_INCLUDE_DIR}/gram_wallet.cpp) |
| 164 | # Keep C++20 local: existing JNI sources include Breakpad's C++17-only headers. |
| 165 | # Any new source that includes wallet_engine.hpp must also opt into C++20. |
| 166 | target_compile_features(wallet_engine_cpp PRIVATE cxx_std_20) |
| 167 | # Keep unused bindings discardable even when voip resets CMAKE_CXX_FLAGS below. |
| 168 | target_compile_options(wallet_engine_cpp PRIVATE -ffunction-sections -fdata-sections) |
| 169 | target_include_directories(wallet_engine_cpp PUBLIC ${WALLET_ENGINE_INCLUDE_DIR}) |
| 170 | target_link_libraries(wallet_engine_cpp PUBLIC wallet_engine dl m) |
| 171 |
| 172 | # Compile the JNI bridge as C++20 without changing the legacy JNI sources. |
| 173 | # An object library keeps its JNI entry points in the existing tmessages .so. |
| 174 | add_library(wallet_engine_jni OBJECT wallet/WalletEngineBridge.cpp wallet/GramWalletAdapter.cpp) |
| 175 | target_compile_features(wallet_engine_jni PRIVATE cxx_std_20) |
| 176 | set_target_properties(wallet_engine_jni PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 177 | target_link_libraries(wallet_engine_jni PRIVATE wallet_engine_cpp) |
| 178 |
| 179 | #sqlite |
| 180 | add_library(sqlite STATIC |
| 181 | sqlite/sqlite3.c) |
| 182 | target_compile_options(sqlite PUBLIC |
| 183 | -fno-strict-aliasing -Oz) |
| 184 | set_target_properties(sqlite PROPERTIES |
| 185 | ANDROID_ARM_MODE arm) |
| 186 | target_compile_definitions(sqlite PUBLIC |
| 187 | NULL=0 SOCKLEN_T=socklen_t LOCALE_NOT_USED ANDROID_NDK DISABLE_IMPORTGL AVOID_TABLES ANDROID_TILE_BASED_DECODE HAVE_STRCHRNUL=0 ANDROID_ARMV6_IDCT) |
| 188 |
| 189 | #breakpad |
| 190 | add_library(breakpad STATIC |
| 191 | third_party/breakpad/src/client/linux/crash_generation/crash_generation_client.cc |
| 192 | third_party/breakpad/src/client/linux/handler/exception_handler.cc |
| 193 | third_party/breakpad/src/client/linux/handler/minidump_descriptor.cc |
| 194 | third_party/breakpad/src/client/linux/log/log.cc |
| 195 | third_party/breakpad/src/client/linux/dump_writer_common/thread_info.cc |
| 196 | third_party/breakpad/src/client/linux/dump_writer_common/seccomp_unwinder.cc |
| 197 | third_party/breakpad/src/client/linux/dump_writer_common/ucontext_reader.cc |
| 198 | third_party/breakpad/src/client/linux/microdump_writer/microdump_writer.cc |
| 199 | third_party/breakpad/src/client/linux/minidump_writer/linux_dumper.cc |
| 200 | third_party/breakpad/src/client/linux/minidump_writer/linux_ptrace_dumper.cc |
| 201 | third_party/breakpad/src/client/linux/minidump_writer/minidump_writer.cc |
| 202 | third_party/breakpad/src/client/minidump_file_writer.cc |
| 203 | third_party/breakpad/src/common/android/breakpad_getcontext.S |
| 204 | third_party/breakpad/src/common/convert_UTF.c |
| 205 | third_party/breakpad/src/common/md5.cc |
| 206 | third_party/breakpad/src/common/string_conversion.cc |
| 207 | third_party/breakpad/src/common/linux/elfutils.cc |
| 208 | third_party/breakpad/src/common/linux/file_id.cc |
| 209 | third_party/breakpad/src/common/linux/guid_creator.cc |
| 210 | third_party/breakpad/src/common/linux/linux_libc_support.cc |
| 211 | third_party/breakpad/src/common/linux/memory_mapped_file.cc |
| 212 | third_party/breakpad/src/common/linux/safe_readlink.cc) |
| 213 | set_target_properties(breakpad PROPERTIES ANDROID_ARM_MODE arm) |
| 214 | set_property(SOURCE third_party/breakpad/src/common/android/breakpad_getcontext.S PROPERTY LANGUAGE C) |
| 215 | target_include_directories(breakpad PUBLIC |
| 216 | third_party/breakpad/src/common/android/include |
| 217 | third_party/breakpad/src) |
| 218 |
| 219 |
| 220 | #voip |
| 221 | include(${CMAKE_HOME_DIRECTORY}/voip/CMakeLists.txt) |
| 222 |
| 223 | # verify |
| 224 | include(${CMAKE_HOME_DIRECTORY}/integrity/CMakeLists.txt) |
| 225 |
| 226 | set(NATIVE_LIB "tmessages.49") |
| 227 |
| 228 | #tmessages |
| 229 | add_library(${NATIVE_LIB} SHARED |
| 230 | jni.c |
| 231 | audio.c |
| 232 | webm_encoder.c |
| 233 | webm_to_gif.cpp |
| 234 | image.cpp |
| 235 | intro/IntroRenderer.c |
| 236 | SqliteWrapper.cpp |
| 237 | utilities.cpp |
| 238 | gifvideo.cpp |
| 239 | lottie.cpp |
| 240 | TgNetWrapper.cpp |
| 241 | ffmpeg_jni.cc |
| 242 | fast-edge.cpp |
| 243 | genann.c |
| 244 | secureid_ocr.cpp |
| 245 | tde2e/bridge.cpp |
| 246 | tests.cpp |
| 247 | ) |
| 248 |
| 249 | # HTML widgets are libtwidget.so, apart from the client library: the isolated engine process loads only it |
| 250 | # (WidgetEngineService), the client never does. What the client needs of the same code (the gesture policy, the CPU |
| 251 | # filter pass; no widget code reaches either) is compiled into the client library (twidget_client_sources). |
| 252 | include(twidget/twidget.cmake) |
| 253 | add_library(twidget SHARED twidget/twidget-onload.cpp twidget/twidget-seccomp.cpp) |
| 254 | twidget_target_sources(twidget) |
| 255 | twidget_client_sources(${NATIVE_LIB}) |
| 256 | target_link_options(twidget PRIVATE "-Wl,-z,max-page-size=16384") |
| 257 | target_link_options(twidget PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/twidget/exports.map") |
| 258 |
| 259 | # Compile JNI directly into the shared library so archive extraction cannot drop its exports. |
| 260 | set(PRISMA_BRIDGE_SOURCES |
| 261 | "${CMAKE_CURRENT_SOURCE_DIR}/prisma/bridge/PrismaEngine.cpp" |
| 262 | "${CMAKE_CURRENT_SOURCE_DIR}/prisma/bridge/PrismaJni.cpp") |
| 263 | target_sources(${NATIVE_LIB} PRIVATE ${PRISMA_BRIDGE_SOURCES}) |
| 264 | target_include_directories(${NATIVE_LIB} PRIVATE |
| 265 | "${CMAKE_CURRENT_SOURCE_DIR}/prisma/bridge") |
| 266 | set_property(SOURCE ${PRISMA_BRIDGE_SOURCES} APPEND PROPERTY |
| 267 | COMPILE_OPTIONS -fexceptions -frtti) |
| 268 | set_property(SOURCE ${PRISMA_BRIDGE_SOURCES} APPEND PROPERTY |
| 269 | COMPILE_DEFINITIONS BOOST_REGEX_STANDALONE) |
| 270 |
| 271 | target_compile_options(${NATIVE_LIB} PUBLIC |
| 272 | -ffast-math -Oz -funroll-loops -ffast-math -fno-strict-aliasing -fno-math-errno) |
| 273 |
| 274 | target_compile_definitions(${NATIVE_LIB} PUBLIC |
| 275 | BSD=1 NULL=0 SOCKLEN_T=socklen_t ANDROID_NDK DISABLE_IMPORTGL AVOID_TABLES ANDROID_TILE_BASED_DECODE __STDC_CONSTANT_MACROS ANDROID_ARMV6_IDCT OPUS_BUILD FIXED_POINT USE_ALLOCA restrict= __EMX__ LOCALE_NOT_USED HAVE_LRINT HAVE_LRINTF) |
| 276 |
| 277 | target_sources(${NATIVE_LIB} PRIVATE |
| 278 |
| 279 | third_party/xiph/opusfile/src/info.c |
| 280 | third_party/xiph/opusfile/src/internal.c |
| 281 | third_party/xiph/opusfile/src/opusfile.c |
| 282 | third_party/xiph/opusfile/src/stream.c |
| 283 | third_party/xiph/ogg/src/bitwise.c |
| 284 | third_party/xiph/ogg/src/framing.c) |
| 285 |
| 286 | target_include_directories(${NATIVE_LIB} PUBLIC |
| 287 | third_party/xiph/opus/include |
| 288 | third_party/xiph/opus/silk |
| 289 | third_party/xiph/opus/silk/fixed |
| 290 | third_party/xiph/opus/celt |
| 291 | third_party/xiph/opus |
| 292 | third_party/xiph/opusfile/include |
| 293 | third_party/xiph/ogg/include |
| 294 | third_party/libyuv/include |
| 295 | third_party/absl |
| 296 | third_party/boringssl/include |
| 297 | openssl/include |
| 298 | prebuild/include/${ANDROID_ABI} |
| 299 | third_party/ffmpeg |
| 300 | third_party/libvpx |
| 301 | third_party/dav1d/include |
| 302 | emoji |
| 303 | exoplayer/include |
| 304 | intro |
| 305 | tlottie/include |
| 306 | tgcalls/ |
| 307 | webrtc/ |
| 308 | td/tde2e |
| 309 | td/tde2e/td/e2e |
| 310 | ) |
| 311 |
| 312 | target_link_options(${NATIVE_LIB} PRIVATE "-Wl,-z,max-page-size=16384") |
| 313 | target_link_options(${NATIVE_LIB} PRIVATE "-Wl,-z,common-page-size=16384") |
| 314 | target_link_options(${NATIVE_LIB} PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports.map") |
| 315 | target_link_libraries(${NATIVE_LIB} |
| 316 | -Wl,--whole-archive rnnoise openh264 voipandroid -Wl,--no-whole-archive |
| 317 | webrtc_absl |
| 318 | tgcalls |
| 319 | wasm |
| 320 | tgcalls_tp |
| 321 | tgnet |
| 322 | prisma |
| 323 | tlottie |
| 324 | wallet_engine_jni |
| 325 | wallet_engine_cpp |
| 326 | sqlite |
| 327 | swscale |
| 328 | avformat |
| 329 | avcodec |
| 330 | swresample |
| 331 | libvpx |
| 332 | libdav1d |
| 333 | libopus |
| 334 | tde2e |
| 335 | tdutils |
| 336 | yuv |
| 337 | avutil |
| 338 | ssl |
| 339 | crypto |
| 340 | jnigraphics |
| 341 | log |
| 342 | z |
| 343 | GLESv2 |
| 344 | EGL |
| 345 | android |
| 346 | OpenSLES |
| 347 | cpufeatures |
| 348 | integrity |
| 349 | breakpad) |
| 350 |
| 351 |
| 352 | include(AndroidNdkModules) |
| 353 | android_ndk_import_module_cpufeatures() |
| 354 |