|
12 | 12 | ${CMAKE_SOURCE_DIR}/jni.c
|
13 | 13 | )
|
14 | 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 () |
| 15 | +find_library(LOG_LIB log) |
20 | 16 |
|
21 |
| -add_library( |
22 |
| - ${WHISPER_LIBRARY_NAME} |
| 17 | +function(build_library target_name) |
| 18 | + add_library( |
| 19 | + ${target_name} |
23 | 20 | SHARED
|
24 | 21 | ${SOURCE_FILES}
|
25 |
| -) |
| 22 | + ) |
| 23 | + |
| 24 | + target_link_libraries(${target_name} ${LOG_LIB} android) |
| 25 | + |
| 26 | + if (${target_name} STREQUAL "whisper_v8fp16_va") |
| 27 | + target_compile_options(${target_name} PRIVATE -march=armv8.2-a+fp16) |
| 28 | + elseif (${target_name} STREQUAL "whisper_vfpv4") |
| 29 | + target_compile_options(${target_name} PRIVATE -mfpu=neon-vfpv4) |
| 30 | + endif () |
| 31 | + |
| 32 | + if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug") |
| 33 | + |
| 34 | + target_compile_options(${target_name} PRIVATE -O3) |
| 35 | + target_compile_options(${target_name} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden) |
| 36 | + target_compile_options(${target_name} PRIVATE -ffunction-sections -fdata-sections) |
| 37 | + |
| 38 | + target_link_options(${target_name} PRIVATE -Wl,--gc-sections) |
| 39 | + target_link_options(${target_name} PRIVATE -Wl,--exclude-libs,ALL) |
| 40 | + target_link_options(${target_name} PRIVATE -flto) |
| 41 | + |
| 42 | + endif () |
| 43 | +endfunction() |
| 44 | + |
| 45 | +build_library("whisper") # Default target |
26 | 46 |
|
27 | 47 | if (${ANDROID_ABI} STREQUAL "arm64-v8a")
|
28 |
| - target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -march=armv8.2-a+fp16) |
| 48 | + build_library("whisper_v8fp16_va") |
29 | 49 | elseif (${ANDROID_ABI} STREQUAL "armeabi-v7a")
|
30 |
| - target_compile_options(${WHISPER_LIBRARY_NAME} PRIVATE -mfpu=neon-vfpv4) |
| 50 | + build_library("whisper_vfpv4") |
31 | 51 | endif ()
|
32 | 52 |
|
33 |
| - |
34 |
| -target_link_libraries(${WHISPER_LIBRARY_NAME} log android) |
35 | 53 | 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 () |
|
0 commit comments