Commit 61daf8f14377a192598fe42b912cc5cdc1900918
1 parent
9e189725
Fix android build issues (fixes #950)
Showing
3 changed files
with
47 additions
and
6 deletions
.github/workflows/main.yml
build-scripts/build-android-ndk
0 → 100755
| 1 | +#!/bin/bash | |
| 2 | +set -xeo pipefail | |
| 3 | +cd $(dirname $0)/.. | |
| 4 | + | |
| 5 | +# Build a static libqpdf for android with an ABI version <= 24. This | |
| 6 | +# is just to exercise that configuring for that platform works. | |
| 7 | + | |
| 8 | +declare -a android_flags | |
| 9 | +android_flags=( \ | |
| 10 | + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ | |
| 11 | + -DANDROID_ABI=armeabi-v7a \ | |
| 12 | + -DANDROID_PLATFORM=android-21 \ | |
| 13 | +) | |
| 14 | + | |
| 15 | +rm -rf android-work build-android | |
| 16 | +mkdir android-work | |
| 17 | +pushd android-work | |
| 18 | +export WORK=$PWD | |
| 19 | +git clone https://github.com/libjpeg-turbo/libjpeg-turbo | |
| 20 | +cd libjpeg-turbo | |
| 21 | +cmake -S . -B build \ | |
| 22 | + "${android_flags[@]}" \ | |
| 23 | + -DCMAKE_INSTALL_PREFIX="$WORK" \ | |
| 24 | + -DENABLE_STATIC=ON \ | |
| 25 | + -DENABLE_SHARED=OFF \ | |
| 26 | + -DCMAKE_POSITION_INDEPENDENT_CODE=ON | |
| 27 | +make -C build -j$(nproc) | |
| 28 | +make -C build install | |
| 29 | +popd | |
| 30 | + | |
| 31 | +export CMAKE_PREFIX_PATH=$WORK LDFLAGS="-L$WORK/lib" | |
| 32 | +cmake -S . -B build-android \ | |
| 33 | + "${android_flags[@]}" \ | |
| 34 | + -DCMAKE_BUILD_TYPE=RelWithDebinfo \ | |
| 35 | + -DUSE_IMPLICIT_CRYPTO=OFF \ | |
| 36 | + -DBUILD_SHARED_LIBS=OFF \ | |
| 37 | + -DBUILD_STATIC_LIBS=ON \ | |
| 38 | + -DREQUIRE_CRYPTO_NATIVE=ON | |
| 39 | + | |
| 40 | +cmake --build build-android -t libqpdf --verbose -j$(nproc) -- -k | |
| 41 | +file build-android/libqpdf/CMakeFiles/libqpdf_object.dir/QUtil.cc.o | grep 'ARM, EABI5' | ... | ... |
libqpdf/CMakeLists.txt
| ... | ... | @@ -349,7 +349,11 @@ int main(int argc, char* argv[]) { |
| 349 | 349 | LFS_WITHOUT_MACROS) |
| 350 | 350 | |
| 351 | 351 | check_c_source_compiles( |
| 352 | -"#define _FILE_OFFSET_BITS 64 | |
| 352 | +"#if !(defined(__ANDROID__) && __ANDROID_API__ <= 24) | |
| 353 | +// Defining _FILE_OFFSET_BITS on Android <= 24 is known to | |
| 354 | +// produce incorrect results. | |
| 355 | +#define _FILE_OFFSET_BITS 64 | |
| 356 | +#endif | |
| 353 | 357 | #include <stdio.h> |
| 354 | 358 | #include <sys/types.h> |
| 355 | 359 | int main(int argc, char* argv[]) { |
| ... | ... | @@ -359,11 +363,6 @@ int main(int argc, char* argv[]) { |
| 359 | 363 | if(LFS_WITH_MACROS AND NOT LFS_WITHOUT_MACROS) |
| 360 | 364 | set(_FILE_OFFSET_BITS 64) |
| 361 | 365 | endif() |
| 362 | - | |
| 363 | -# fseeko may not exist with _FILE_OFFSET_BITS=64 but can exist with | |
| 364 | -# _FILE_OFFSET_BITS unset or 32 (e.g. Android ARMv7 with NDK 26b and | |
| 365 | -# API level < 24) so we need to test fseeko after testing for | |
| 366 | -# _FILE_OFFSET_BITS. See https://github.com/qpdf/qpdf/issues/950. | |
| 367 | 366 | check_symbol_exists(fseeko "stdio.h" HAVE_FSEEKO) |
| 368 | 367 | check_symbol_exists(fseeko64 "stdio.h" HAVE_FSEEKO64) |
| 369 | 368 | ... | ... |