junkfood commited on
Commit
df7ed53
·
unverified ·
1 Parent(s): 26a54a0

whisper.android : migrate from ndk-build to CMake (#1204)

Browse files
examples/whisper.android/app/build.gradle CHANGED
@@ -18,6 +18,9 @@ android {
18
  vectorDrawables {
19
  useSupportLibrary true
20
  }
 
 
 
21
  }
22
 
23
  buildTypes {
@@ -42,8 +45,8 @@ android {
42
  }
43
  ndkVersion "25.1.8937393"
44
  externalNativeBuild {
45
- ndkBuild {
46
- path 'src/main/jni/whisper/Android.mk'
47
  }
48
  }
49
  packagingOptions {
 
18
  vectorDrawables {
19
  useSupportLibrary true
20
  }
21
+ ndk {
22
+ abiFilters 'arm64-v8a', 'armeabi-v7a'
23
+ }
24
  }
25
 
26
  buildTypes {
 
45
  }
46
  ndkVersion "25.1.8937393"
47
  externalNativeBuild {
48
+ cmake {
49
+ path = file("src/main/jni/whisper/CMakeLists.txt")
50
  }
51
  }
52
  packagingOptions {
examples/whisper.android/app/src/main/jni/whisper/Android.mk DELETED
@@ -1,26 +0,0 @@
1
- LOCAL_PATH := $(call my-dir)
2
- include $(CLEAR_VARS)
3
- LOCAL_MODULE := libwhisper
4
- include $(LOCAL_PATH)/Whisper.mk
5
- include $(BUILD_SHARED_LIBRARY)
6
-
7
- ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
8
- include $(CLEAR_VARS)
9
- LOCAL_MODULE := libwhisper_vfpv4
10
- include $(LOCAL_PATH)/Whisper.mk
11
- # Allow building NEON FMA code.
12
- # https://android.googlesource.com/platform/ndk/+/master/sources/android/cpufeatures/cpu-features.h
13
- LOCAL_CFLAGS += -mfpu=neon-vfpv4
14
- include $(BUILD_SHARED_LIBRARY)
15
- endif
16
-
17
- ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
18
- include $(CLEAR_VARS)
19
- LOCAL_MODULE := libwhisper_v8fp16_va
20
- include $(LOCAL_PATH)/Whisper.mk
21
- # Allow building NEON FMA code.
22
- # https://android.googlesource.com/platform/ndk/+/master/sources/android/cpufeatures/cpu-features.h
23
- LOCAL_CFLAGS += -march=armv8.2-a+fp16
24
- include $(BUILD_SHARED_LIBRARY)
25
- endif
26
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
examples/whisper.android/app/src/main/jni/whisper/Application.mk DELETED
@@ -1 +0,0 @@
1
- APP_STL := c++_static
 
 
examples/whisper.android/app/src/main/jni/whisper/CMakeLists.txt ADDED
@@ -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 DELETED
@@ -1,18 +0,0 @@
1
- WHISPER_LIB_DIR := $(LOCAL_PATH)/../../../../../../../
2
- LOCAL_LDLIBS := -landroid -llog
3
-
4
- # Make the final output library smaller by only keeping the symbols referenced from the app.
5
- ifneq ($(APP_OPTIM),debug)
6
- LOCAL_CFLAGS += -O3
7
- LOCAL_CFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
8
- LOCAL_CFLAGS += -ffunction-sections -fdata-sections
9
- LOCAL_LDFLAGS += -Wl,--gc-sections
10
- LOCAL_LDFLAGS += -Wl,--exclude-libs,ALL
11
- LOCAL_LDFLAGS += -flto
12
- endif
13
-
14
- LOCAL_CFLAGS += -DSTDC_HEADERS -std=c11 -I $(WHISPER_LIB_DIR)
15
- LOCAL_CPPFLAGS += -std=c++11
16
- LOCAL_SRC_FILES := $(WHISPER_LIB_DIR)/ggml.c \
17
- $(WHISPER_LIB_DIR)/whisper.cpp \
18
- $(LOCAL_PATH)/jni.c