From 1b671c932ae9c9ce1734ab5db5e1a9d5dea1aac6 Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 8 Aug 2022 11:32:01 +0800 Subject: [PATCH] Build libsquish and astc-encoder for android --- android/Android.mk | 23 ++++++++++++-- android/make_deps.sh | 58 +++++++++++++++++++++++++++++++++++ cmake/Toolchain-android.cmake | 2 +- 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/android/Android.mk b/android/Android.mk index 1afea8017..9c61353c1 100644 --- a/android/Android.mk +++ b/android/Android.mk @@ -93,6 +93,20 @@ include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) +# libsquish +LOCAL_MODULE := libsquish +LOCAL_SRC_FILES := deps-$(TARGET_ARCH_ABI)/libsquish/libsquish.a +include $(PREBUILT_STATIC_LIBRARY) +include $(CLEAR_VARS) + + +# astc-encoder +LOCAL_MODULE := libastcenc +LOCAL_SRC_FILES := deps-$(TARGET_ARCH_ABI)/astc-encoder/Source/libastcenc.a +include $(PREBUILT_STATIC_LIBRARY) +include $(CLEAR_VARS) + + # ifaddrs LOCAL_MODULE := ifaddrs LOCAL_PATH := . @@ -168,15 +182,18 @@ LOCAL_PATH := . LOCAL_CPP_FEATURES += rtti exceptions LOCAL_SRC_FILES := $(wildcard ../lib/graphics_engine/src/*.c) \ $(wildcard ../lib/graphics_engine/src/*.cpp) -LOCAL_CFLAGS := -I../lib/graphics_engine/include \ +LOCAL_CFLAGS := -DENABLE_LIBASTCENC \ + -I../lib/graphics_engine/include \ -I../lib/graphics_utils \ -I../lib/sdl2/include/ \ -I../lib/bullet/src/ \ - -I../lib/irrlicht/include/ + -I../lib/irrlicht/include/ \ + -I../lib/libsquish \ + -Ideps-$(TARGET_ARCH_ABI)/astc-encoder/Source ifeq ($(TARGET_ARCH_ABI), armeabi-v7a) LOCAL_ARM_NEON := false endif -LOCAL_STATIC_LIBRARIES := shaderc +LOCAL_STATIC_LIBRARIES := shaderc libsquish libastcenc include $(BUILD_STATIC_LIBRARY) $(call import-module, third_party/shaderc) include $(CLEAR_VARS) diff --git a/android/make_deps.sh b/android/make_deps.sh index c3aedc15d..1ef95ea6d 100755 --- a/android/make_deps.sh +++ b/android/make_deps.sh @@ -283,6 +283,64 @@ build_deps() check_error touch "$DIRNAME/deps-$ARCH_OPTION/libvorbis.stamp" fi + + # Libsquish + if [ ! -f "$DIRNAME/deps-$ARCH_OPTION/libsquish.stamp" ]; then + echo "Compiling $ARCH_OPTION libsquish" + mkdir -p "$DIRNAME/deps-$ARCH_OPTION/libsquish" + cp -a -f "$DIRNAME/../lib/libsquish/"* "$DIRNAME/deps-$ARCH_OPTION/libsquish" + + cd "$DIRNAME/deps-$ARCH_OPTION/libsquish" + if [[ "$ARCH_OPTION" = "x86" || "$ARCH_OPTION" = "x86_64" ]]; then + cmake . -DCMAKE_TOOLCHAIN_FILE=../../../cmake/Toolchain-android.cmake \ + -DHOST=$HOST -DARCH=$ARCH \ + -DCMAKE_C_FLAGS="-fpic -O3 -g -DSQUISH_USE_SSE=2 -msse2" \ + -DCMAKE_CXX_FLAGS="-fpic -O3 -g -DSQUISH_USE_SSE=2 -msse2" + else + cmake . -DCMAKE_TOOLCHAIN_FILE=../../../cmake/Toolchain-android.cmake \ + -DHOST=$HOST -DARCH=$ARCH -DCMAKE_C_FLAGS="-fpic -O3 -g" \ + -DCMAKE_CXX_FLAGS="-fpic -O3 -g" + fi + make -j $(($(nproc) + 1)) VERBOSE=1 + check_error + touch "$DIRNAME/deps-$ARCH_OPTION/libsquish.stamp" + fi + + # ASTC-encoder + if [ ! -f "$DIRNAME/deps-$ARCH_OPTION/astc-encoder.stamp" ]; then + echo "Compiling $ARCH_OPTION astc-encoder" + mkdir -p "$DIRNAME/deps-$ARCH_OPTION/astc-encoder" + cp -a -f "$DIRNAME/../lib/astc-encoder/"* "$DIRNAME/deps-$ARCH_OPTION/astc-encoder" + + cd "$DIRNAME/deps-$ARCH_OPTION/astc-encoder" + sed -i '/-Werror/d' Source/cmake_core.cmake + sed -i 's|${ASTC_TARGET}-static|astcenc|g' Source/cmake_core.cmake + if [ "$ARCH_OPTION" = "armeabi-v7a" ]; then + cmake . -DCMAKE_TOOLCHAIN_FILE=../../../cmake/Toolchain-android.cmake \ + -DHOST=$HOST -DARCH=$ARCH -DSTK_ARM_NEON=ON \ + -DCMAKE_C_FLAGS="-fpic -O3 -g -mfpu=neon" \ + -DCMAKE_CXX_FLAGS="-fpic -O3 -g -mfpu=neon" \ + -DNO_INVARIANCE=ON -DCLI=OFF + elif [ "$ARCH_OPTION" = "arm64-v8a" ]; then + cmake . -DCMAKE_TOOLCHAIN_FILE=../../../cmake/Toolchain-android.cmake \ + -DHOST=$HOST -DARCH=$ARCH -DCMAKE_C_FLAGS="-fpic -O3 -g" \ + -DCMAKE_CXX_FLAGS="-fpic -O3 -g" \ + -DISA_NEON=ON -DNO_INVARIANCE=ON -DCLI=OFF + elif [ "$ARCH_OPTION" = "x86" ]; then + cmake . -DCMAKE_TOOLCHAIN_FILE=../../../cmake/Toolchain-android.cmake \ + -DHOST=$HOST -DARCH=$ARCH -DCMAKE_C_FLAGS="-fpic -O3 -g" \ + -DCMAKE_CXX_FLAGS="-fpic -O3 -g" \ + -DISA_SSE2=ON -DNO_INVARIANCE=ON -DCLI=OFF + else + cmake . -DCMAKE_TOOLCHAIN_FILE=../../../cmake/Toolchain-android.cmake \ + -DHOST=$HOST -DARCH=$ARCH -DCMAKE_C_FLAGS="-fpic -O3 -g" \ + -DCMAKE_CXX_FLAGS="-fpic -O3 -g" \ + -DISA_SSE41=ON -DNO_INVARIANCE=ON -DCLI=OFF + fi + make -j $(($(nproc) + 1)) + check_error + touch "$DIRNAME/deps-$ARCH_OPTION/astc-encoder.stamp" + fi } if [ -z "$COMPILE_ARCH" ] || [ "$COMPILE_ARCH" = "all" ]; then diff --git a/cmake/Toolchain-android.cmake b/cmake/Toolchain-android.cmake index 5fd81c372..fdab82cf4 100644 --- a/cmake/Toolchain-android.cmake +++ b/cmake/Toolchain-android.cmake @@ -16,7 +16,7 @@ set(CMAKE_SYSTEM_PROCESSOR ${ARCH}) # Starting NDK21 it enables NEON by default on 32-bit ARM target # Disable it to support more devices -if("${ARCH}" STREQUAL "arm") +if("${ARCH}" STREQUAL "arm" AND NOT STK_ARM_NEON) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfpv3-d16") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfpv3-d16") endif()