Skip to content

Commit

Permalink
Merge pull request #23 from kiwix/adapt_wrapper
Browse files Browse the repository at this point in the history
Adapt wrapper to new API of libzim/libkiwix
  • Loading branch information
kelson42 authored Feb 9, 2023
2 parents 98388aa + 929ae6d commit 4b5cc44
Show file tree
Hide file tree
Showing 59 changed files with 2,568 additions and 1,493 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle
local.properties
build
lib/.cxx
34 changes: 32 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ android {
}
externalNativeBuild {
cmake {
path file('src/cpp/CMakeLists.txt')
path file('src/main/cpp/CMakeLists.txt')
version '3.18.1'
}
}
Expand Down Expand Up @@ -285,5 +285,35 @@ task checkCurrentJavaVersion() {

task generateHeaderFilesFromJavaWrapper(type: Exec) {
workingDir "${projectDir}/src/main/java/org/kiwix/"
commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${buildDir}/kiwixlib/ kiwixlib/Book.java kiwixlib/DirectAccessInfo.java kiwixlib/Filter.java kiwixlib/JNIICU.java kiwixlib/JNIKiwixBool.java kiwixlib/JNIKiwixException.java kiwixlib/JNIKiwixInt.java kiwixlib/JNIKiwixReader.java kiwixlib/JNIKiwixSearcher.java kiwixlib/JNIKiwixServer.java kiwixlib/JNIKiwixString.java kiwixlib/Library.java kiwixlib/Manager.java"
commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${buildDir}/libzim/ ${getLibzimFiles()} ${getLibkiwixFiles()}"
}

String getLibkiwixFiles() {
return "${projectDir}/src/main/java/org/kiwix/libkiwix/Book.java " +
"${projectDir}/src/main/java/org/kiwix/libkiwix/Bookmark.java " +
"${projectDir}/src/main/java/org/kiwix/libkiwix/Filter.java " +
"${projectDir}/src/main/java/org/kiwix/libkiwix/JNIICU.java " +
"${projectDir}/src/main/java/org/kiwix/libkiwix/Illustration.java " +
"${projectDir}/src/main/java/org/kiwix/libkiwix/JNIKiwixException.java " +
"${projectDir}/src/main/java/org/kiwix/libkiwix/Library.java " +
"${projectDir}/src/main/java/org/kiwix/libkiwix/Manager.java " +
"${projectDir}/src/main/java/org/kiwix/libkiwix/Server.java"
}

String getLibzimFiles() {
return "${projectDir}/src/main/java/org/kiwix/libzim/Archive.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/Blob.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/DirectAccessInfo.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/EntryIterator.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/Entry.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/Item.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/Query.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/Searcher.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/SearchIterator.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/Search.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/SuggestionItem.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/SuggestionIterator.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/SuggestionSearcher.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/SuggestionSearch.java " +
"${projectDir}/src/main/java/org/kiwix/libzim/ZimFileFormatException.java"
}
97 changes: 97 additions & 0 deletions lib/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
cmake_minimum_required(VERSION 3.18.1)

set(CMAKE_ANDROID_STL_TYPE llvm-libc++_static)

project("libkiwix_wrapper")

add_library(
zim_wrapper

SHARED
libzim/archive.cpp
libzim/entry.cpp
libzim/entry_iterator.cpp
libzim/item.cpp
libzim/blob.cpp
libzim/searcher.cpp
libzim/query.cpp
libzim/search.cpp
libzim/search_iterator.cpp
libzim/suggestion_searcher.cpp
libzim/suggestion_search.cpp
libzim/suggestion_iterator.cpp
libzim/suggestion_item.cpp
)

find_library(libzim
zim
PATHS
${BUILD_DIR}/jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libzim)
if (NOT libzim)
message(FATAL_ERROR "libzim not found!")
endif()
add_library(libzim SHARED IMPORTED)

set_property(TARGET
libzim
PROPERTY
IMPORTED_LOCATION
${BUILD_DIR}/jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libzim/libzim.so)


add_library(
kiwix_wrapper

SHARED
libkiwix/book.cpp
libkiwix/filter.cpp
libkiwix/kiwixicu.cpp
libkiwix/kiwixserver.cpp
libkiwix/library.cpp
libkiwix/bookmark.cpp
libkiwix/manager.cpp
libkiwix/illustration.cpp
)

find_library(libkiwix
kiwix
PATHS
${BUILD_DIR}/jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libkiwix)
if (NOT libkiwix)
message(FATAL_ERROR "libkiwix not found!")
endif()
add_library(libkiwix SHARED IMPORTED)

set_property(TARGET
libkiwix
PROPERTY
IMPORTED_LOCATION
${BUILD_DIR}/jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libkiwix/libkiwix.so)

include_directories(
${CMAKE_SOURCE_DIR}
${BUILD_DIR}/include/libkiwix
${BUILD_DIR}/include/libzim
${BUILD_DIR}/include/javah_generated
#${CMAKE_SOURCE_DIR}/include/utils
)

find_library(
log-lib
log)

target_link_libraries(
zim_wrapper
libzim
${log-lib}
)

target_link_libraries(
kiwix_wrapper
libkiwix
libzim
${log-lib}
)

Loading

0 comments on commit 4b5cc44

Please sign in to comment.