Spaces:
Running
android : update CMakeLists.txt to use FetchContent for ggml (#3268)
Browse files* 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 +3 -3
- examples/whisper.android.java/app/src/main/AndroidManifest.xml +2 -2
- examples/whisper.android.java/app/src/main/java/com/whispercpp/java/whisper/WhisperLib.java +1 -1
- examples/whisper.android.java/app/src/main/jni/whisper/CMakeLists.txt +6 -17
- examples/whisper.android.java/build.gradle +3 -3
- examples/whisper.android.java/gradle/wrapper/gradle-wrapper.properties +1 -1
- examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt +6 -32
|
@@ -3,13 +3,13 @@ plugins {
|
|
| 3 |
}
|
| 4 |
|
| 5 |
android {
|
| 6 |
-
compileSdkVersion
|
| 7 |
buildToolsVersion '30.0.3'
|
| 8 |
|
| 9 |
defaultConfig {
|
| 10 |
applicationId "com.litongjava.whisper.android.java"
|
| 11 |
minSdkVersion 21
|
| 12 |
-
targetSdkVersion
|
| 13 |
versionCode 1
|
| 14 |
versionName "1.0"
|
| 15 |
|
|
@@ -55,4 +55,4 @@ dependencies {
|
|
| 55 |
implementation 'com.litongjava:android-view-inject:1.0'
|
| 56 |
implementation 'com.litongjava:jfinal-aop:1.0.1'
|
| 57 |
implementation 'com.litongjava:litongjava-android-utils:1.0.0'
|
| 58 |
-
}
|
|
|
|
| 3 |
}
|
| 4 |
|
| 5 |
android {
|
| 6 |
+
compileSdkVersion 31
|
| 7 |
buildToolsVersion '30.0.3'
|
| 8 |
|
| 9 |
defaultConfig {
|
| 10 |
applicationId "com.litongjava.whisper.android.java"
|
| 11 |
minSdkVersion 21
|
| 12 |
+
targetSdkVersion 31
|
| 13 |
versionCode 1
|
| 14 |
versionName "1.0"
|
| 15 |
|
|
|
|
| 55 |
implementation 'com.litongjava:android-view-inject:1.0'
|
| 56 |
implementation 'com.litongjava:jfinal-aop:1.0.1'
|
| 57 |
implementation 'com.litongjava:litongjava-android-utils:1.0.0'
|
| 58 |
+
}
|
|
@@ -10,7 +10,7 @@
|
|
| 10 |
android:roundIcon="@mipmap/ic_launcher_round"
|
| 11 |
android:supportsRtl="true"
|
| 12 |
android:theme="@style/Theme.Whisperandroidjava">
|
| 13 |
-
<activity android:name=".MainActivity">
|
| 14 |
<intent-filter>
|
| 15 |
<action android:name="android.intent.action.MAIN" />
|
| 16 |
|
|
@@ -19,4 +19,4 @@
|
|
| 19 |
</activity>
|
| 20 |
</application>
|
| 21 |
|
| 22 |
-
</manifest>
|
|
|
|
| 10 |
android:roundIcon="@mipmap/ic_launcher_round"
|
| 11 |
android:supportsRtl="true"
|
| 12 |
android:theme="@style/Theme.Whisperandroidjava">
|
| 13 |
+
<activity android:name=".MainActivity" android:exported="true">
|
| 14 |
<intent-filter>
|
| 15 |
<action android:name="android.intent.action.MAIN" />
|
| 16 |
|
|
|
|
| 19 |
</activity>
|
| 20 |
</application>
|
| 21 |
|
| 22 |
+
</manifest>
|
|
@@ -72,4 +72,4 @@ public class WhisperLib {
|
|
| 72 |
public static native String benchMemcpy(int nthread);
|
| 73 |
|
| 74 |
public static native String benchGgmlMulMat(int nthread);
|
| 75 |
-
}
|
|
|
|
| 72 |
public static native String benchMemcpy(int nthread);
|
| 73 |
|
| 74 |
public static native String benchGgmlMulMat(int nthread);
|
| 75 |
+
}
|
|
@@ -6,28 +6,14 @@ set(CMAKE_CXX_STANDARD 17)
|
|
| 6 |
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../../)
|
| 7 |
|
| 8 |
set(SOURCE_FILES
|
| 9 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml.c
|
| 10 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ggml-cpu.c
|
| 11 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/traits.cpp
|
| 12 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/arch/arm/quants.c
|
| 13 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/arch/arm/repack.cpp
|
| 14 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/quants.c
|
| 15 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ggml-cpu.cpp
|
| 16 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/unary-ops.cpp
|
| 17 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/binary-ops.cpp
|
| 18 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/vec.cpp
|
| 19 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ops.cpp
|
| 20 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-alloc.c
|
| 21 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-backend.cpp
|
| 22 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-backend-reg.cpp
|
| 23 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-quants.c
|
| 24 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-threading.cpp
|
| 25 |
${WHISPER_LIB_DIR}/src/whisper.cpp
|
| 26 |
${CMAKE_SOURCE_DIR}/jni.c
|
| 27 |
)
|
| 28 |
|
| 29 |
find_library(LOG_LIB log)
|
| 30 |
|
|
|
|
|
|
|
| 31 |
function(build_library target_name)
|
| 32 |
add_library(
|
| 33 |
${target_name}
|
|
@@ -35,7 +21,10 @@ function(build_library target_name)
|
|
| 35 |
${SOURCE_FILES}
|
| 36 |
)
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
|
| 40 |
|
| 41 |
if (${target_name} STREQUAL "whisper_v8fp16_va")
|
|
|
|
| 6 |
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../../)
|
| 7 |
|
| 8 |
set(SOURCE_FILES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
${WHISPER_LIB_DIR}/src/whisper.cpp
|
| 10 |
${CMAKE_SOURCE_DIR}/jni.c
|
| 11 |
)
|
| 12 |
|
| 13 |
find_library(LOG_LIB log)
|
| 14 |
|
| 15 |
+
include(FetchContent)
|
| 16 |
+
|
| 17 |
function(build_library target_name)
|
| 18 |
add_library(
|
| 19 |
${target_name}
|
|
|
|
| 21 |
${SOURCE_FILES}
|
| 22 |
)
|
| 23 |
|
| 24 |
+
FetchContent_Declare(ggml SOURCE_DIR ${WHISPER_LIB_DIR}/ggml)
|
| 25 |
+
FetchContent_MakeAvailable(ggml)
|
| 26 |
+
|
| 27 |
+
target_link_libraries(${target_name} ${LOG_LIB} android ggml)
|
| 28 |
target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
|
| 29 |
|
| 30 |
if (${target_name} STREQUAL "whisper_v8fp16_va")
|
|
@@ -2,10 +2,10 @@
|
|
| 2 |
buildscript {
|
| 3 |
repositories {
|
| 4 |
google()
|
| 5 |
-
|
| 6 |
}
|
| 7 |
dependencies {
|
| 8 |
-
classpath "com.android.tools.build:gradle:4.
|
| 9 |
|
| 10 |
// NOTE: Do not place your application dependencies here; they belong
|
| 11 |
// in the individual module build.gradle files
|
|
@@ -15,7 +15,7 @@ buildscript {
|
|
| 15 |
allprojects {
|
| 16 |
repositories {
|
| 17 |
google()
|
| 18 |
-
|
| 19 |
maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
|
| 20 |
}
|
| 21 |
}
|
|
|
|
| 2 |
buildscript {
|
| 3 |
repositories {
|
| 4 |
google()
|
| 5 |
+
mavenCentral()
|
| 6 |
}
|
| 7 |
dependencies {
|
| 8 |
+
classpath "com.android.tools.build:gradle:7.4.0"
|
| 9 |
|
| 10 |
// NOTE: Do not place your application dependencies here; they belong
|
| 11 |
// in the individual module build.gradle files
|
|
|
|
| 15 |
allprojects {
|
| 16 |
repositories {
|
| 17 |
google()
|
| 18 |
+
mavenCentral()
|
| 19 |
maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
|
| 20 |
}
|
| 21 |
}
|
|
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|
| 3 |
distributionPath=wrapper/dists
|
| 4 |
zipStoreBase=GRADLE_USER_HOME
|
| 5 |
zipStorePath=wrapper/dists
|
| 6 |
-
distributionUrl=https\://services.gradle.org/distributions/gradle-
|
|
|
|
| 3 |
distributionPath=wrapper/dists
|
| 4 |
zipStoreBase=GRADLE_USER_HOME
|
| 5 |
zipStorePath=wrapper/dists
|
| 6 |
+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
|
|
@@ -14,34 +14,10 @@ set(
|
|
| 14 |
${CMAKE_SOURCE_DIR}/jni.c
|
| 15 |
)
|
| 16 |
|
| 17 |
-
# TODO: this needs to be updated to work with the new ggml CMakeLists
|
| 18 |
-
|
| 19 |
-
if (NOT GGML_HOME)
|
| 20 |
-
set(
|
| 21 |
-
SOURCE_FILES
|
| 22 |
-
${SOURCE_FILES}
|
| 23 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml.c
|
| 24 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-alloc.c
|
| 25 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-backend.cpp
|
| 26 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-backend-reg.cpp
|
| 27 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-quants.c
|
| 28 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-threading.cpp
|
| 29 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ggml-cpu.c
|
| 30 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ggml-cpu.cpp
|
| 31 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/hbm.cpp
|
| 32 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/traits.cpp
|
| 33 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/unary-ops.cpp
|
| 34 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/binary-ops.cpp
|
| 35 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/vec.cpp
|
| 36 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/ops.cpp
|
| 37 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/arch/arm/quants.c
|
| 38 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/arch/arm/repack.cpp
|
| 39 |
-
${WHISPER_LIB_DIR}/ggml/src/ggml-cpu/quants.c
|
| 40 |
-
)
|
| 41 |
-
endif()
|
| 42 |
-
|
| 43 |
find_library(LOG_LIB log)
|
| 44 |
|
|
|
|
|
|
|
| 45 |
function(build_library target_name)
|
| 46 |
add_library(
|
| 47 |
${target_name}
|
|
@@ -70,15 +46,13 @@ function(build_library target_name)
|
|
| 70 |
endif ()
|
| 71 |
|
| 72 |
if (GGML_HOME)
|
| 73 |
-
include(FetchContent)
|
| 74 |
FetchContent_Declare(ggml SOURCE_DIR ${GGML_HOME})
|
| 75 |
-
FetchContent_MakeAvailable(ggml)
|
| 76 |
-
|
| 77 |
-
target_compile_options(ggml PRIVATE ${GGML_COMPILE_OPTIONS})
|
| 78 |
-
target_link_libraries(${target_name} ${LOG_LIB} android ggml)
|
| 79 |
else()
|
| 80 |
-
|
| 81 |
endif()
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
endfunction()
|
|
|
|
| 14 |
${CMAKE_SOURCE_DIR}/jni.c
|
| 15 |
)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
find_library(LOG_LIB log)
|
| 18 |
|
| 19 |
+
include(FetchContent)
|
| 20 |
+
|
| 21 |
function(build_library target_name)
|
| 22 |
add_library(
|
| 23 |
${target_name}
|
|
|
|
| 46 |
endif ()
|
| 47 |
|
| 48 |
if (GGML_HOME)
|
|
|
|
| 49 |
FetchContent_Declare(ggml SOURCE_DIR ${GGML_HOME})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
else()
|
| 51 |
+
FetchContent_Declare(ggml SOURCE_DIR ${WHISPER_LIB_DIR}/ggml)
|
| 52 |
endif()
|
| 53 |
+
FetchContent_MakeAvailable(ggml)
|
| 54 |
+
target_compile_options(ggml PRIVATE ${GGML_COMPILE_OPTIONS})
|
| 55 |
+
target_link_libraries(${target_name} ${LOG_LIB} android ggml)
|
| 56 |
|
| 57 |
|
| 58 |
endfunction()
|