]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
android : update CMakeLists.txt to use FetchContent for ggml (#3268)
authorDaniel Bevenius <redacted>
Thu, 19 Jun 2025 14:06:42 +0000 (16:06 +0200)
committerGitHub <redacted>
Thu, 19 Jun 2025 14:06:42 +0000 (16:06 +0200)
* android : update CMakeLists.txt to use FetchContent for ggml

This commit updates the CMakeLists.txt file for the Android Whisper
example to use FetchContent for managing the ggml library.

The motivation for this change is avoid having to make manual changes to
the CMakeLists.txt file after syncing the ggml library.

I've built and run the example locally to verify that it works as
expected.

Refs: https://github.com/ggml-org/whisper.cpp/pull/3265#issuecomment-2986715717

* android.java : update cmake to use FetchContent for ggml

This commit updates the CMake configuration for the Android Java example
to use `FetchContent` for including the `ggml` library. Do be able to
use FetchContent we also update the `compileSdkVersion` and
`targetSdkVersion` to 31, and the `buildToolsVersion` to '30.0.3'.
This also required a an update to the Gradle plugin version to 7.4.0.

The motivation for this change is avoid having to make manual changes to
the CMakeLists.txt file after syncing the ggml library.

examples/whisper.android.java/app/build.gradle
examples/whisper.android.java/app/src/main/AndroidManifest.xml
examples/whisper.android.java/app/src/main/java/com/whispercpp/java/whisper/WhisperLib.java
examples/whisper.android.java/app/src/main/jni/whisper/CMakeLists.txt
examples/whisper.android.java/build.gradle
examples/whisper.android.java/gradle/wrapper/gradle-wrapper.properties
examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt

index 532d780a19511bd5c456decd4e1561c46ad07590..543701e1bb1131df12e73749531bf7962cbe5c4f 100644 (file)
@@ -3,13 +3,13 @@ plugins {
 }
 
 android {
-  compileSdkVersion 30
+  compileSdkVersion 31
   buildToolsVersion '30.0.3'
 
   defaultConfig {
     applicationId "com.litongjava.whisper.android.java"
     minSdkVersion 21
-    targetSdkVersion 30
+    targetSdkVersion 31
     versionCode 1
     versionName "1.0"
 
@@ -55,4 +55,4 @@ dependencies {
   implementation 'com.litongjava:android-view-inject:1.0'
   implementation 'com.litongjava:jfinal-aop:1.0.1'
   implementation 'com.litongjava:litongjava-android-utils:1.0.0'
-}
\ No newline at end of file
+}
index f4980ad08ec48c6e2b16460044b4c40da368dd8d..7011531b180a4506b1106f7dd78653342cd4d92d 100644 (file)
@@ -10,7 +10,7 @@
     android:roundIcon="@mipmap/ic_launcher_round"
     android:supportsRtl="true"
     android:theme="@style/Theme.Whisperandroidjava">
-    <activity android:name=".MainActivity">
+    <activity android:name=".MainActivity" android:exported="true">
       <intent-filter>
         <action android:name="android.intent.action.MAIN" />
 
@@ -19,4 +19,4 @@
     </activity>
   </application>
 
-</manifest>
\ No newline at end of file
+</manifest>
index 38dd47a38a235ac894f6359eae8c10dd7af01ee4..9d0275cd3d74682fb4f272272c3a465a54011de1 100644 (file)
@@ -72,4 +72,4 @@ public class WhisperLib {
   public static native String benchMemcpy(int nthread);
 
   public static native String benchGgmlMulMat(int nthread);
-}
\ No newline at end of file
+}
index 68415f7f784a11469ed2c1938263930a5936d644..3514fbe28c7ccebb4ee1e22be12682870d60c1b4 100644 (file)
@@ -6,28 +6,14 @@ set(CMAKE_CXX_STANDARD 17)
 set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../../)
 
 set(SOURCE_FILES
-    ${WHISPER_LIB_DIR}/ggml/src/ggml.c
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ggml-cpu.c
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/traits.cpp
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/arch/arm/quants.c
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/arch/arm/repack.cpp
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/quants.c
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ggml-cpu.cpp
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/unary-ops.cpp
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/binary-ops.cpp
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/vec.cpp
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ops.cpp
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-alloc.c
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-backend.cpp
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-backend-reg.cpp
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-quants.c
-    ${WHISPER_LIB_DIR}/ggml/src/ggml-threading.cpp
     ${WHISPER_LIB_DIR}/src/whisper.cpp
     ${CMAKE_SOURCE_DIR}/jni.c
     )
 
 find_library(LOG_LIB log)
 
+include(FetchContent)
+
 function(build_library target_name)
     add_library(
         ${target_name}
@@ -35,7 +21,10 @@ function(build_library target_name)
         ${SOURCE_FILES}
     )
 
-    target_link_libraries(${target_name} ${LOG_LIB} android)
+    FetchContent_Declare(ggml SOURCE_DIR ${WHISPER_LIB_DIR}/ggml)
+    FetchContent_MakeAvailable(ggml)
+
+    target_link_libraries(${target_name} ${LOG_LIB} android ggml)
     target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
 
     if (${target_name} STREQUAL "whisper_v8fp16_va")
index cc32112cf61cf4d31a6294ff614a530bf4345cce..ef09bb6ebfaa51e57aae07158ad7891555b72d5a 100644 (file)
@@ -2,10 +2,10 @@
 buildscript {
   repositories {
     google()
-    jcenter()
+    mavenCentral()
   }
   dependencies {
-    classpath "com.android.tools.build:gradle:4.1.3"
+    classpath "com.android.tools.build:gradle:7.4.0"
 
     // NOTE: Do not place your application dependencies here; they belong
     // in the individual module build.gradle files
@@ -15,7 +15,7 @@ buildscript {
 allprojects {
   repositories {
     google()
-    jcenter()
+    mavenCentral()
     maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
   }
 }
index 9f4db5dbdd6631b1be7f919331588f110e1e4dc8..aa7e2229984ee8e07ef812fcae1e1f3cb4ee658e 100644 (file)
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
index cb789c42f6a18e40b954aece522eea7f7b13c44b..c986b417d55d0de6e9cd419fb289fbfe88dfc791 100644 (file)
@@ -14,34 +14,10 @@ set(
     ${CMAKE_SOURCE_DIR}/jni.c
     )
 
-# TODO: this needs to be updated to work with the new ggml CMakeLists
-
-if (NOT GGML_HOME)
-    set(
-        SOURCE_FILES
-        ${SOURCE_FILES}
-        ${WHISPER_LIB_DIR}/ggml/src/ggml.c
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-alloc.c
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-backend.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-backend-reg.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-quants.c
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-threading.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ggml-cpu.c
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ggml-cpu.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/hbm.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/traits.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/unary-ops.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/binary-ops.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/vec.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ops.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/arch/arm/quants.c
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/arch/arm/repack.cpp
-        ${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/quants.c
-        )
-endif()
-
 find_library(LOG_LIB log)
 
+include(FetchContent)
+
 function(build_library target_name)
     add_library(
         ${target_name}
@@ -70,15 +46,13 @@ function(build_library target_name)
     endif ()
 
     if (GGML_HOME)
-        include(FetchContent)
         FetchContent_Declare(ggml SOURCE_DIR ${GGML_HOME})
-        FetchContent_MakeAvailable(ggml)
-
-        target_compile_options(ggml PRIVATE ${GGML_COMPILE_OPTIONS})
-        target_link_libraries(${target_name} ${LOG_LIB} android ggml)
     else()
-        target_link_libraries(${target_name} ${LOG_LIB} android)
+        FetchContent_Declare(ggml SOURCE_DIR ${WHISPER_LIB_DIR}/ggml)
     endif()
+    FetchContent_MakeAvailable(ggml)
+    target_compile_options(ggml PRIVATE ${GGML_COMPILE_OPTIONS})
+    target_link_libraries(${target_name} ${LOG_LIB} android ggml)
 
 
 endfunction()