diff --git a/.github/workflows/poppler.yml b/.github/workflows/poppler.yml new file mode 100644 index 0000000..58dcc7d --- /dev/null +++ b/.github/workflows/poppler.yml @@ -0,0 +1,38 @@ +name: poppler +on: + workflow_dispatch: + push: + paths: + - 'buildSrc/**' + - '.github/workflows/build.yml' + - 'poppler/**' + - '.github/workflows/poppler.yml' + +jobs: + build-poppler-23_10_0: + name: poppler 23.10.0 + uses: ./.github/workflows/build.yml + with: + package: poppler + version: '23.10.0' + + build-poppler-21_02_0: + name: poppler 21.02.0 + uses: ./.github/workflows/build.yml + with: + package: poppler + version: '21.02.0' + + build-poppler-0_89_0: + name: poppler 0.89.0 + uses: ./.github/workflows/build.yml + with: + package: poppler + version: '0.89.0' + + build-poppler-0_81_0: + name: poppler 0.81.0 + uses: ./.github/workflows/build.yml + with: + package: poppler + version: '0.81.0' diff --git a/README.md b/README.md index 72c5552..97807d0 100644 --- a/README.md +++ b/README.md @@ -240,3 +240,18 @@ Pango-1.51.0 requires API level 21 [![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/fontforge-ndk25-shared.svg?label=Maven%20Central%20fontforge-ndk25-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:fontforge-ndk25-shared) [![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/fontforge-ndk26-static.svg?label=Maven%20Central%20fontforge-ndk26-static)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:fontforge-ndk26-static) [![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/fontforge-ndk26-shared.svg?label=Maven%20Central%20fontforge-ndk26-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:fontforge-ndk26-shared) + +#### [Poppler](https://poppler.freedesktop.org) + +Available versions: + +- 23.10.0 +- 21.02.0 +- 0.89.0 +- 0.81.0 + +[![poppler](https://github.com/ViliusSutkus89/ndkports/actions/workflows/poppler.yml/badge.svg)](https://github.com/ViliusSutkus89/ndkports/actions/workflows/poppler.yml) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/poppler-ndk25-static.svg?label=Maven%20Central%20poppler-ndk25-static)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:poppler-ndk25-static) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/poppler-ndk25-shared.svg?label=Maven%20Central%20poppler-ndk25-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:poppler-ndk25-shared) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/poppler-ndk26-static.svg?label=Maven%20Central%20poppler-ndk26-static)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:poppler-ndk26-static) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/poppler-ndk26-shared.svg?label=Maven%20Central%20poppler-ndk26-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:poppler-ndk26-shared) diff --git a/poppler/build.gradle.kts b/poppler/build.gradle.kts new file mode 100644 index 0000000..25e0b3b --- /dev/null +++ b/poppler/build.gradle.kts @@ -0,0 +1,276 @@ +import com.android.ndkports.CMakeCompatibleVersion +import com.android.ndkports.CMakePortTask +import com.android.ndkports.PrefabSysrootPlugin +import org.gradle.jvm.tasks.Jar + +group = rootProject.group + +// Hardcode a list of available versions +val portVersion = when(project.findProperty("packageVersion")) { + "0.81.0" -> { + version = "0.81.0-beta-1" + "0.81.0" + } + "0.89.0" -> { + version = "0.89.0-beta-1" + "0.89.0" + } + "21.02.0" -> { + version = "21.02.0-beta-1" + "21.02.0" + } + "23.10.0" -> { + version = "23.10.0-beta-1" + "0.81.0" + } + // @TODO: + else -> { + version = "0.81.0-beta-1" + "0.81.0" + } +} + +plugins { + id("maven-publish") + id("signing") + id("com.android.ndkports.NdkPorts") +} + +dependencies { + val ndkVersionSuffix = rootProject.extra.get("ndkVersionSuffix") + implementation("com.viliussutkus89.ndk.thirdparty:freetype${ndkVersionSuffix}-static:2.13.2-beta-3") + implementation("com.viliussutkus89.ndk.thirdparty:libiconv${ndkVersionSuffix}-static:1.17-beta-1") + implementation("com.viliussutkus89.ndk.thirdparty:libpng${ndkVersionSuffix}-static:1.6.40-beta-4") + implementation("com.viliussutkus89.ndk.thirdparty:libjpeg-turbo${ndkVersionSuffix}-static:3.0.1-beta-1") + implementation("com.viliussutkus89.ndk.thirdparty:libtiff${ndkVersionSuffix}-static:4.6.0-beta-2") + implementation("com.viliussutkus89.ndk.thirdparty:openjpeg${ndkVersionSuffix}-static:2.5.0-beta-2") + implementation("com.viliussutkus89.ndk.thirdparty:glib2${ndkVersionSuffix}-static:2.78.1-beta-2") + implementation("com.viliussutkus89.ndk.thirdparty:cairo${ndkVersionSuffix}-static:1.18.0-beta-1") + implementation("com.viliussutkus89.ndk.thirdparty:lcms2${ndkVersionSuffix}-static:2.15-beta-2") + + when (portVersion) { + // 23.10.0 supports Android's native alternative of fontconfig + "0.81.0", "0.89.0", "21.02.0" -> { + implementation("com.viliussutkus89.ndk.thirdparty:fontconfig${ndkVersionSuffix}-static:2.14.2-beta-1") + } + } +} + +ndkPorts { + ndkPath.set(File(project.findProperty("ndkPath") as String)) + minSdkVersion.set(rootProject.extra.get("minSdkSupportedByNdk").toString().toInt()) + source.set(project.file("${name}-${portVersion}.tar.xz")) +} + +tasks.findByName("extractSrc")?.dependsOn( + tasks.register("extractAssets", com.android.ndkports.SourceExtractTask::class.java) { + source.set(project.file("poppler-data-0.4.12.tar.gz")) + outDir.set(buildDir.resolve("assets/poppler")) + } +) + +fun File.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): File { + writeText(readText().replace(oldValue, newValue, ignoreCase)) + return this +} + +fun File.patch(patch: String) { + patch(projectDir.resolve("patches/$portVersion").resolve(patch)) +} + +fun File.patch(patch: File) { + val pb = ProcessBuilder( + if (isFile) listOf("patch", "-p0", absolutePath) + else listOf("patch", "-p0") + ) + + if (isDirectory) + pb.directory(absoluteFile) + + val process = pb.start() + process.outputStream.writer().use { + it.write(patch.readText()) + } + process.errorStream.bufferedReader().use { + println(it.readText()) + } + process.inputStream.bufferedReader().use { + println(it.readText()) + } + if (process.waitFor() != 0) { + throw RuntimeException("Patch failed!\n") + } +} + +tasks.extractSrc { + doLast { + val srcDir = outDir.get().asFile + when (portVersion) { + "0.81.0", "0.89.0", "21.02.0" -> { + srcDir.resolve("CMakeLists.txt").patch("fontconfig.patch") + srcDir.resolve("CMakeLists.txt").patch("FindCairo.patch") + srcDir.resolve("ConfigureChecks.cmake").patch("have_unistd_h.patch") + } + "0.89.0", "21.02.0" -> { + TODO() + } + "23.10.0" -> { + // https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md + projectDir.resolve("CheckFileOffsetBits.cmake").copyTo( + target = outDir.get().asFile.resolve("cmake/modules/CheckFileOffsetBits.cmake"), + overwrite = true + ) + } + } + } +} + +tasks.prefab { + generator.set(PrefabSysrootPlugin::class.java) +} + +tasks.register("buildPort") { + when (portVersion) { + "0.81.0", "0.89.0", "21.02.0" -> { + cmake { + args( + "-DENABLE_UNSTABLE_API_ABI_HEADERS=ON", + + // poppler-gLib requires older GLib version. + "-DENABLE_GLIB=OFF", + ) + } + doLast { + com.android.ndkports.Abi.values().forEach { abi -> + installDirectoryFor(abi) + .resolve("include/android.${abi.abiName}/lib/pkgconfig/poppler.pc").appendText( + "Requires: freetype2 libpng16 libturbojpeg libtiff-4 libopenjp2 glib-2.0 cairo lcms2 fontconfig" + ) + } + } + } + "23.10.0" -> { + cmake { + args( + "-DENABLE_NSS3=OFF", + "-DENABLE_GPGME=OFF", + "-DENABLE_QT5=OFF", + "-DENABLE_QT6=OFF", + "-DENABLE_BOOST=OFF", + "-DENABLE_LIBCURL=OFF", + + "-DENABLE_GLIB=OFF", + ) + } + } + } +} + + +tasks.prefabPackage { + version.set(CMakeCompatibleVersion.parse(portVersion)) + + licensePath.set("COPYING") + + modules { + create("poppler") { + static.set(project.findProperty("libraryType") == "static") + dependencies.set(listOf( + "//freetype:freetype", + "//libpng:png16", + "//libjpeg-turbo:turbojpeg", + "//libtiff:tiff", + "//openjpeg:openjp2", + "//glib2:glib-2.0", + "//cairo:cairo", + "//lcms2:lcms2", + "//fontconfig:fontconfig", + )) + } + create("poppler-cpp") { + static.set(project.findProperty("libraryType") == "static") + dependencies.set(listOf(":poppler")) + } + } +} + +val packageSources = tasks.register("packageSources") { + archiveClassifier.set("sources") + from(projectDir.resolve("build.gradle.kts")) + from(projectDir.resolve("patches/$portVersion")) + from(ndkPorts.source) +} + +publishing { + publications { + create("release") { + from(components["prefab"]) + artifactId += rootProject.extra.get("ndkVersionSuffix") + artifactId += rootProject.extra.get("libraryTypeSuffix") + artifact(packageSources) + pom { + name.set("Poppler") + description.set("Poppler is a free software utility library for rendering Portable Document Format (PDF) documents. Poppler-data bundled.") + url.set("https://poppler.freedesktop.org") + licenses { + // Poppler licenses + license { + name.set("GPLv2") + url.set("https://cgit.freedesktop.org/poppler/poppler/plain/COPYING?h=poppler-21.02.0") + distribution.set("repo") + } + license { + name.set("GPLv3") + url.set("https://cgit.freedesktop.org/poppler/poppler/plain/COPYING3?h=poppler-21.02.0") + distribution.set("repo") + } + + // Poppler-data licenses + license { + name.set("MIT") + url.set("https://cgit.freedesktop.org/poppler/poppler-data/tree/COPYING?h=POPPLER_DATA_0_4_12") + distribution.set("repo") + } + license { + name.set("COPYING.adobe") + url.set("https://cgit.freedesktop.org/poppler/poppler-data/tree/COPYING.adobe?h=POPPLER_DATA_0_4_12") + distribution.set("repo") + } + license { + name.set("GPLv2") + url.set("https://cgit.freedesktop.org/poppler/poppler-data/tree/COPYING.gpl2?h=POPPLER_DATA_0_4_12") + distribution.set("repo") + } + + } + developers { + // Developer list obtained from: + // https://gitlab.freedesktop.org/poppler/poppler/-/blob/poppler-21.02.0/AUTHORS + // https://gitlab.freedesktop.org/poppler/poppler-data/-/blob/POPPLER_DATA_0_4_12/README + developer { + name.set("Derek Noonburg") + email.set("derekn@foolabs.com") + } + developer { + name.set("Albert Astals Cid") + email.set("aacid@kde.org") + } + } + scm { + url.set("https://github.com/ViliusSutkus89/ndkports") + connection.set("scm:git:https://github.com/ViliusSutkus89/ndkports.git") + } + } + } + } +} + +afterEvaluate { + System.getenv("SIGNING_KEY")?.let { signingKey -> + signing { + isRequired = true + useInMemoryPgpKeys(signingKey, System.getenv("SIGNING_PASS")) + sign(publishing.publications.findByName("release")) + } + } +} diff --git a/poppler/patches/0.81.0/FindCairo.patch b/poppler/patches/0.81.0/FindCairo.patch new file mode 100644 index 0000000..02c279e --- /dev/null +++ b/poppler/patches/0.81.0/FindCairo.patch @@ -0,0 +1,13 @@ +--- CMakeLists.txt 2023-11-03 12:33:39.721000000 +0200 ++++ CMakeLists.txt 2023-11-03 12:34:02.079000000 +0200 +@@ -156,8 +156,9 @@ + endif() + endif() + +-macro_optional_find_package(Cairo ${CAIRO_VERSION}) ++pkg_search_module(CAIRO REQUIRED IMPORTED_TARGET cairo) + if(CAIRO_FOUND) ++ set(CAIRO_LIBRARIES PkgConfig::CAIRO) + set(HAVE_CAIRO ${CAIRO_FOUND}) + set(CAIRO_FEATURE "#define POPPLER_HAS_CAIRO 1") + set(CAIRO_REQ "cairo") diff --git a/poppler/patches/0.81.0/fontconfig.patch b/poppler/patches/0.81.0/fontconfig.patch new file mode 100644 index 0000000..bb2dd85 --- /dev/null +++ b/poppler/patches/0.81.0/fontconfig.patch @@ -0,0 +1,41 @@ +--- CMakeLists.txt 2019-09-22 18:56:22.000000000 +0300 ++++ CMakeLists.txt 2023-11-03 10:53:17.851000000 +0200 +@@ -93,9 +93,6 @@ + + if(WIN32) + set(_default_fontconfiguration "win32") +-elseif(ANDROID) +- # on android we don't have fontconfig and we don't want windows-specific code +- set(_default_fontconfiguration "generic") + else() + set(_default_fontconfiguration "fontconfig") + endif() +@@ -124,7 +121,7 @@ + macro_bool_to_01(ENABLE_SPLASH HAVE_SPLASH) + find_package(Freetype REQUIRED) + if(WITH_FONTCONFIGURATION_FONTCONFIG) +- find_package(Fontconfig REQUIRED) ++ pkg_search_module(FONTCONFIG REQUIRED IMPORTED_TARGET fontconfig) + endif() + macro_optional_find_package(JPEG) + macro_optional_find_package(PNG) +@@ -237,10 +234,6 @@ + # Use mingw's ansi stdio extensions + add_definitions(-D__USE_MINGW_ANSI_STDIO=1) + endif() +-if(FONTCONFIG_FOUND) +- add_definitions(${FONTCONFIG_DEFINITIONS}) +- include_directories(SYSTEM ${FONTCONFIG_INCLUDE_DIR}) +-endif() + if(WITH_FONTCONFIGURATION_WIN32) + if(MINGW) + # Set the minimum required Internet Explorer version to 5.0 +@@ -428,7 +421,7 @@ + ) + endif() + if(FONTCONFIG_FOUND) +- set(poppler_LIBS ${poppler_LIBS} ${FONTCONFIG_LIBRARIES}) ++ set(poppler_LIBS ${poppler_LIBS} PkgConfig::FONTCONFIG) + endif() + + if(JPEG_FOUND) diff --git a/poppler/patches/0.81.0/have_unistd_h.patch b/poppler/patches/0.81.0/have_unistd_h.patch new file mode 100644 index 0000000..c509185 --- /dev/null +++ b/poppler/patches/0.81.0/have_unistd_h.patch @@ -0,0 +1,11 @@ +--- ConfigureChecks.cmake 2019-09-22 18:56:22.000000000 +0300 ++++ ConfigureChecks.cmake 2023-11-03 10:50:16.125000000 +0200 +@@ -24,7 +24,7 @@ + check_include_files(stdlib.h HAVE_STDLIB_H) + check_include_files(sys/mman.h HAVE_SYS_MMAN_H) + check_include_files(sys/stat.h HAVE_SYS_STAT_H) +-check_include_files(unistd.h HAVE_UNISTD_H) ++SET(HAVE_UNISTD_H 1) + check_include_file_cxx(codecvt HAVE_CODECVT) + + check_function_exists(fseek64 HAVE_FSEEK64) diff --git a/poppler/poppler-0.81.0.tar.xz b/poppler/poppler-0.81.0.tar.xz new file mode 100644 index 0000000..07b8802 Binary files /dev/null and b/poppler/poppler-0.81.0.tar.xz differ diff --git a/poppler/poppler-0.89.0.tar.xz b/poppler/poppler-0.89.0.tar.xz new file mode 100644 index 0000000..302b62a Binary files /dev/null and b/poppler/poppler-0.89.0.tar.xz differ diff --git a/poppler/poppler-21.02.0.tar.xz b/poppler/poppler-21.02.0.tar.xz new file mode 100644 index 0000000..7493af1 Binary files /dev/null and b/poppler/poppler-21.02.0.tar.xz differ diff --git a/poppler/poppler-23.10.0.tar.xz b/poppler/poppler-23.10.0.tar.xz new file mode 100644 index 0000000..6a190b3 Binary files /dev/null and b/poppler/poppler-23.10.0.tar.xz differ diff --git a/poppler/poppler-data-0.4.12.tar.gz b/poppler/poppler-data-0.4.12.tar.gz new file mode 100644 index 0000000..c012136 Binary files /dev/null and b/poppler/poppler-data-0.4.12.tar.gz differ diff --git a/settings.gradle.kts b/settings.gradle.kts index 88be615..e6280e9 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -35,6 +35,7 @@ include(":fontconfig") include(":cairo") include(":lcms2") include(":openjpeg") +include(":poppler") include(":libxml2") include(":fribidi") include(":graphite2")