Skip to content

Commit 3e65f51

Browse files
authored
android : update CMakeLists.txt to use FetchContent for ggml (#3268)
* 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: #3265 (comment) * 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.
1 parent 17bece1 commit 3e65f51

File tree

7 files changed

+22
-59
lines changed

7 files changed

+22
-59
lines changed

examples/whisper.android.java/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ plugins {
33
}
44

55
android {
6-
compileSdkVersion 30
6+
compileSdkVersion 31
77
buildToolsVersion '30.0.3'
88

99
defaultConfig {
1010
applicationId "com.litongjava.whisper.android.java"
1111
minSdkVersion 21
12-
targetSdkVersion 30
12+
targetSdkVersion 31
1313
versionCode 1
1414
versionName "1.0"
1515

@@ -55,4 +55,4 @@ dependencies {
5555
implementation 'com.litongjava:android-view-inject:1.0'
5656
implementation 'com.litongjava:jfinal-aop:1.0.1'
5757
implementation 'com.litongjava:litongjava-android-utils:1.0.0'
58-
}
58+
}

examples/whisper.android.java/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
android:roundIcon="@mipmap/ic_launcher_round"
1111
android:supportsRtl="true"
1212
android:theme="@style/Theme.Whisperandroidjava">
13-
<activity android:name=".MainActivity">
13+
<activity android:name=".MainActivity" android:exported="true">
1414
<intent-filter>
1515
<action android:name="android.intent.action.MAIN" />
1616

@@ -19,4 +19,4 @@
1919
</activity>
2020
</application>
2121

22-
</manifest>
22+
</manifest>

examples/whisper.android.java/app/src/main/java/com/whispercpp/java/whisper/WhisperLib.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ public class WhisperLib {
7272
public static native String benchMemcpy(int nthread);
7373

7474
public static native String benchGgmlMulMat(int nthread);
75-
}
75+
}

examples/whisper.android.java/app/src/main/jni/whisper/CMakeLists.txt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,25 @@ set(CMAKE_CXX_STANDARD 17)
66
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../../)
77

88
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
259
${WHISPER_LIB_DIR}/src/whisper.cpp
2610
${CMAKE_SOURCE_DIR}/jni.c
2711
)
2812

2913
find_library(LOG_LIB log)
3014

15+
include(FetchContent)
16+
3117
function(build_library target_name)
3218
add_library(
3319
${target_name}
3420
SHARED
3521
${SOURCE_FILES}
3622
)
3723

38-
target_link_libraries(${target_name} ${LOG_LIB} android)
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)
3928
target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
4029

4130
if (${target_name} STREQUAL "whisper_v8fp16_va")

examples/whisper.android.java/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
buildscript {
33
repositories {
44
google()
5-
jcenter()
5+
mavenCentral()
66
}
77
dependencies {
8-
classpath "com.android.tools.build:gradle:4.1.3"
8+
classpath "com.android.tools.build:gradle:7.4.0"
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
@@ -15,7 +15,7 @@ buildscript {
1515
allprojects {
1616
repositories {
1717
google()
18-
jcenter()
18+
mavenCentral()
1919
maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
2020
}
2121
}

examples/whisper.android.java/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,10 @@ set(
1414
${CMAKE_SOURCE_DIR}/jni.c
1515
)
1616

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-
4317
find_library(LOG_LIB log)
4418

19+
include(FetchContent)
20+
4521
function(build_library target_name)
4622
add_library(
4723
${target_name}
@@ -70,15 +46,13 @@ function(build_library target_name)
7046
endif ()
7147

7248
if (GGML_HOME)
73-
include(FetchContent)
7449
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)
7950
else()
80-
target_link_libraries(${target_name} ${LOG_LIB} android)
51+
FetchContent_Declare(ggml SOURCE_DIR ${WHISPER_LIB_DIR}/ggml)
8152
endif()
53+
FetchContent_MakeAvailable(ggml)
54+
target_compile_options(ggml PRIVATE ${GGML_COMPILE_OPTIONS})
55+
target_link_libraries(${target_name} ${LOG_LIB} android ggml)
8256

8357

8458
endfunction()

0 commit comments

Comments
 (0)