Skip to content

Commit 20a8097

Browse files
authored
whisper.android : migrate from ndk-build to CMake (ggml-org#1204)
1 parent 7ef3f38 commit 20a8097

File tree

5 files changed

+49
-47
lines changed

5 files changed

+49
-47
lines changed

examples/whisper.android/app/build.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ android {
1818
vectorDrawables {
1919
useSupportLibrary true
2020
}
21+
ndk {
22+
abiFilters 'arm64-v8a', 'armeabi-v7a'
23+
}
2124
}
2225

2326
buildTypes {
@@ -42,8 +45,8 @@ android {
4245
}
4346
ndkVersion "25.1.8937393"
4447
externalNativeBuild {
45-
ndkBuild {
46-
path 'src/main/jni/whisper/Android.mk'
48+
cmake {
49+
path = file("src/main/jni/whisper/CMakeLists.txt")
4750
}
4851
}
4952
packagingOptions {

examples/whisper.android/app/src/main/jni/whisper/Android.mk

-26
This file was deleted.

examples/whisper.android/app/src/main/jni/whisper/Application.mk

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project(whisper.cpp)
4+
5+
set(CMAKE_CXX_STANDARD 11)
6+
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../../)
7+
8+
set(
9+
SOURCE_FILES
10+
${WHISPER_LIB_DIR}/ggml.c
11+
${WHISPER_LIB_DIR}/whisper.cpp
12+
${CMAKE_SOURCE_DIR}/jni.c
13+
)
14+
15+
if (${ANDROID_ABI} STREQUAL "arm64-v8a")
16+
set(WHISPER_LIBRARY_NAME whisper_v8fp16_va)
17+
elseif (${ANDROID_ABI} STREQUAL "armeabi-v7a")
18+
set(WHISPER_LIBRARY_NAME whisper_vfpv4)
19+
endif ()
20+
21+
add_library(
22+
${WHISPER_LIBRARY_NAME}
23+
SHARED
24+
${SOURCE_FILES}
25+
)
26+
27+
if (${ANDROID_ABI} STREQUAL "arm64-v8a")
28+
target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -march=armv8.2-a+fp16)
29+
elseif (${ANDROID_ABI} STREQUAL "armeabi-v7a")
30+
target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -mfpu=neon-vfpv4)
31+
endif ()
32+
33+
34+
target_link_libraries(${WHISPER_LIBRARY_NAME} log android)
35+
include_directories(${WHISPER_LIB_DIR})
36+
37+
if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
38+
target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -O3)
39+
target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)
40+
target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -ffunction-sections -fdata-sections)
41+
target_link_options(${WHISPER_LIBRARY_NAME} PRIVATE -Wl,--gc-sections)
42+
target_link_options(${WHISPER_LIBRARY_NAME} PRIVATE -Wl,--exclude-libs,ALL)
43+
target_link_options(${WHISPER_LIBRARY_NAME} PRIVATE -flto)
44+
endif ()

examples/whisper.android/app/src/main/jni/whisper/Whisper.mk

-18
This file was deleted.

0 commit comments

Comments
 (0)