Recently Written · git

subrep-android

Subrep on Android: live captions of the sound of the phone, made on the phone by Whisper, shared by link.

git clone https://github.com/equwal/subrep-android

Log | Files | Refs


app/src/main/cpp/CMakeLists.txt (2811 bytes)

1 cmake_minimum_required(VERSION 3.22)
2 project(subrep_whisper C CXX)
3 
4 set(CMAKE_C_STANDARD 11)
5 set(CMAKE_CXX_STANDARD 17)
6 
7 # Speech recognition is matrix arithmetic. Unoptimised it is ten times slower, so optimise
8 # whatever Gradle thinks the build type is.
9 if (CMAKE_BUILD_TYPE STREQUAL "Debug")
10     add_compile_options(-O3)
11 endif ()
12 
13 set(WHISPER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/whisper.cpp)
14 
15 # Reproducible build: F-Droid builds this library again, on Linux and at another
16 # path, and compares it with the signed APK. The maps remove the paths of the
17 # build machine from the __FILE__ strings of ggml. -ffile-reproducible writes "/"
18 # in them on Windows too. -fno-ident keeps the version line of the compiler out of
19 # the .comment section: the clang of the Windows NDK writes another line than the
20 # clang of the Linux NDK. An empty GIT_EXE stops ggml from recording the git state
21 # of the checkout, which the F-Droid scanner changes.
22 get_filename_component(SUBREP_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." ABSOLUTE)
23 get_filename_component(SUBREP_TOOLCHAIN_BIN "${CMAKE_C_COMPILER}" DIRECTORY)
24 get_filename_component(SUBREP_TOOLCHAIN_ROOT "${SUBREP_TOOLCHAIN_BIN}" DIRECTORY)
25 add_compile_options(
26     -ffile-reproducible
27     -fno-ident
28     "-ffile-prefix-map=${SUBREP_ROOT}=."
29     "-ffile-prefix-map=${SUBREP_TOOLCHAIN_ROOT}=toolchain")
30 set(GIT_EXE "" CACHE FILEPATH "Not used: the build records no git state" FORCE)
31 
32 set(BUILD_SHARED_LIBS      OFF CACHE BOOL "" FORCE)
33 set(WHISPER_BUILD_TESTS    OFF CACHE BOOL "" FORCE)
34 set(WHISPER_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
35 set(WHISPER_BUILD_SERVER   OFF CACHE BOOL "" FORCE)
36 set(GGML_NATIVE            OFF CACHE BOOL "" FORCE)   # cross-compiling: never probe the build host
37 set(GGML_OPENMP            OFF CACHE BOOL "" FORCE)   # ggml's own thread pool; no libomp to ship
38 set(GGML_LLAMAFILE         OFF CACHE BOOL "" FORCE)
39 
40 # Half-precision and dot-product instructions are most of the speed on ARM. Each CPU since the
41 # Cortex-A55/A75 (2018) has them. Whisper.kt checks before it loads this library, so an older
42 # CPU gets a message, not a SIGILL.
43 if (ANDROID_ABI STREQUAL "arm64-v8a")
44     set(GGML_CPU_ARM_ARCH "armv8.2-a+fp16+dotprod" CACHE STRING "" FORCE)
45 endif ()
46 
47 add_subdirectory(${WHISPER_DIR} whisper EXCLUDE_FROM_ALL)
48 
49 add_library(subrep_whisper SHARED whisper_jni.c)
50 target_link_libraries(subrep_whisper PRIVATE whisper log)
51 target_link_options(subrep_whisper PRIVATE -Wl,--gc-sections -Wl,--exclude-libs,ALL)
52 # No GNU build ID. The linker makes it from the debug information, and that holds the
53 # build folder of Gradle (.cxx/<hash>), whose name is different on each machine.
54 # Without it, the stripped library is the same on the F-Droid build server.
55 target_link_options(subrep_whisper PRIVATE -Wl,--build-id=none)