]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
whisper.android : migrate from ndk-build to CMake (#1204)
authorjunkfood <redacted>
Sun, 27 Aug 2023 16:35:16 +0000 (00:35 +0800)
committerGitHub <redacted>
Sun, 27 Aug 2023 16:35:16 +0000 (19:35 +0300)
examples/whisper.android/app/build.gradle
examples/whisper.android/app/src/main/jni/whisper/Android.mk [deleted file]
examples/whisper.android/app/src/main/jni/whisper/Application.mk [deleted file]
examples/whisper.android/app/src/main/jni/whisper/CMakeLists.txt [new file with mode: 0644]
examples/whisper.android/app/src/main/jni/whisper/Whisper.mk [deleted file]

index 66add99161052dad9930ff4d6b4eadc0aba6c07a..ab4956913bd28b2ff1fde6f71c272c6ac55224a0 100644 (file)
@@ -18,6 +18,9 @@ android {
         vectorDrawables {
             useSupportLibrary true
         }
+        ndk {
+            abiFilters 'arm64-v8a', 'armeabi-v7a'
+        }
     }
 
     buildTypes {
@@ -42,8 +45,8 @@ android {
     }
     ndkVersion "25.1.8937393"
     externalNativeBuild {
-        ndkBuild {
-            path 'src/main/jni/whisper/Android.mk'
+        cmake {
+            path = file("src/main/jni/whisper/CMakeLists.txt")
         }
     }
     packagingOptions {
diff --git a/examples/whisper.android/app/src/main/jni/whisper/Android.mk b/examples/whisper.android/app/src/main/jni/whisper/Android.mk
deleted file mode 100644 (file)
index 22fc77f..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-LOCAL_MODULE    := libwhisper
-include $(LOCAL_PATH)/Whisper.mk
-include $(BUILD_SHARED_LIBRARY)
-
-ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
-       include $(CLEAR_VARS)
-       LOCAL_MODULE    := libwhisper_vfpv4
-       include $(LOCAL_PATH)/Whisper.mk
-       # Allow building NEON FMA code.
-       # https://android.googlesource.com/platform/ndk/+/master/sources/android/cpufeatures/cpu-features.h
-       LOCAL_CFLAGS += -mfpu=neon-vfpv4
-       include $(BUILD_SHARED_LIBRARY)
-endif
-
-ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
-       include $(CLEAR_VARS)
-       LOCAL_MODULE    := libwhisper_v8fp16_va
-       include $(LOCAL_PATH)/Whisper.mk
-       # Allow building NEON FMA code.
-       # https://android.googlesource.com/platform/ndk/+/master/sources/android/cpufeatures/cpu-features.h
-       LOCAL_CFLAGS += -march=armv8.2-a+fp16
-       include $(BUILD_SHARED_LIBRARY)
-endif
-
diff --git a/examples/whisper.android/app/src/main/jni/whisper/Application.mk b/examples/whisper.android/app/src/main/jni/whisper/Application.mk
deleted file mode 100644 (file)
index 067c76f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-APP_STL := c++_static
\ No newline at end of file
diff --git a/examples/whisper.android/app/src/main/jni/whisper/CMakeLists.txt b/examples/whisper.android/app/src/main/jni/whisper/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0d33db2
--- /dev/null
@@ -0,0 +1,44 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(whisper.cpp)
+
+set(CMAKE_CXX_STANDARD 11)
+set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../../)
+
+set(
+        SOURCE_FILES
+        ${WHISPER_LIB_DIR}/ggml.c
+        ${WHISPER_LIB_DIR}/whisper.cpp
+        ${CMAKE_SOURCE_DIR}/jni.c
+)
+
+if (${ANDROID_ABI} STREQUAL "arm64-v8a")
+    set(WHISPER_LIBRARY_NAME whisper_v8fp16_va)
+elseif (${ANDROID_ABI} STREQUAL "armeabi-v7a")
+    set(WHISPER_LIBRARY_NAME whisper_vfpv4)
+endif ()
+
+add_library(
+        ${WHISPER_LIBRARY_NAME}
+        SHARED
+        ${SOURCE_FILES}
+)
+
+if (${ANDROID_ABI} STREQUAL "arm64-v8a")
+    target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -march=armv8.2-a+fp16)
+elseif (${ANDROID_ABI} STREQUAL "armeabi-v7a")
+    target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -mfpu=neon-vfpv4)
+endif ()
+
+
+target_link_libraries(${WHISPER_LIBRARY_NAME} log android)
+include_directories(${WHISPER_LIB_DIR})
+
+if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
+    target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -O3)
+    target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)
+    target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -ffunction-sections -fdata-sections)
+    target_link_options(${WHISPER_LIBRARY_NAME} PRIVATE -Wl,--gc-sections)
+    target_link_options(${WHISPER_LIBRARY_NAME} PRIVATE -Wl,--exclude-libs,ALL)
+    target_link_options(${WHISPER_LIBRARY_NAME} PRIVATE -flto)
+endif ()
diff --git a/examples/whisper.android/app/src/main/jni/whisper/Whisper.mk b/examples/whisper.android/app/src/main/jni/whisper/Whisper.mk
deleted file mode 100644 (file)
index 6d9113b..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-WHISPER_LIB_DIR := $(LOCAL_PATH)/../../../../../../../
-LOCAL_LDLIBS    := -landroid -llog
-
-# Make the final output library smaller by only keeping the symbols referenced from the app.
-ifneq ($(APP_OPTIM),debug)
-    LOCAL_CFLAGS += -O3
-    LOCAL_CFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
-    LOCAL_CFLAGS += -ffunction-sections -fdata-sections
-    LOCAL_LDFLAGS += -Wl,--gc-sections
-    LOCAL_LDFLAGS += -Wl,--exclude-libs,ALL
-    LOCAL_LDFLAGS += -flto
-endif
-
-LOCAL_CFLAGS    += -DSTDC_HEADERS -std=c11 -I $(WHISPER_LIB_DIR)
-LOCAL_CPPFLAGS  += -std=c++11
-LOCAL_SRC_FILES := $(WHISPER_LIB_DIR)/ggml.c \
-                   $(WHISPER_LIB_DIR)/whisper.cpp \
-                   $(LOCAL_PATH)/jni.c
\ No newline at end of file