From a5d161a6fad1d70cf933ee69392033d323bf4cd5 Mon Sep 17 00:00:00 2001 From: Pyry Haulos Date: Wed, 1 Oct 2014 16:18:37 -0700 Subject: [PATCH] Add preliminary support for NDK r10c This change adds toolchain file for NDK r10c and necessary build system changes for arm64-v8a ABI. The toolchain file assumes that the released toolchain uses android-21 instead of android-L as the ABI version. Only GCC toolchain file is provided. Change-Id: I52053569c5564b0b41b0c66f334a081de4ed584f --- android/scripts/common.py | 10 +- external/libpng/CMakeLists.txt | 10 ++ framework/delibs/cmake/Defs.cmake | 1 + .../delibs/cmake/toolchain-android-r10c.cmake | 145 +++++++++++++++++++++ targets/android/android.cmake | 4 +- 5 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 framework/delibs/cmake/toolchain-android-r10c.cmake diff --git a/android/scripts/common.py b/android/scripts/common.py index 1f5627a..9cd12b5 100644 --- a/android/scripts/common.py +++ b/android/scripts/common.py @@ -71,11 +71,11 @@ ANDROID_DIR = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(_ # Build configuration NATIVE_LIBS = [ - # library name API ABI -# NativeLib("testercore_legacy", 5, "armeabi-v7a"), # Pre-gingerbread -# NativeLib("testercore_legacy", 5, "armeabi"), # ARM v5 ABI / pre-gingerbread - NativeLib("testercore", 9, "armeabi-v7a"), # ARM v7a ABI -# NativeLib("testercore", 9, "x86"), # x86 + # library name API ABI +# NativeLib("testercore", 13, "armeabi"), # ARM v5 ABI + NativeLib("testercore", 13, "armeabi-v7a"), # ARM v7a ABI + NativeLib("testercore", 13, "x86"), # x86 +# NativeLib("testercore", 21, "arm64-v8a"), # ARM64 v8a ABI ] ANDROID_JAVA_API = "android-13" diff --git a/external/libpng/CMakeLists.txt b/external/libpng/CMakeLists.txt index 923cf4f..f3d6c65 100644 --- a/external/libpng/CMakeLists.txt +++ b/external/libpng/CMakeLists.txt @@ -26,6 +26,16 @@ set(PNG_SRCS ${PNG_SRC_PATH}/pngpread.c ) +if (DE_CPU_IS_ARM_64) + # armv8-a has always neon + set(PNG_SRCS + ${PNG_SRCS} + ${PNG_SRC_PATH}/arm/arm_init.c + ${PNG_SRC_PATH}/arm/filter_neon_intrinsics.c + ${PNG_SRC_PATH}/arm/filter_neon.S + ) +endif () + if (DE_DEBUG EQUAL 1) add_definitions(-DPNG_DEBUG) endif () diff --git a/framework/delibs/cmake/Defs.cmake b/framework/delibs/cmake/Defs.cmake index 0932909..8326645 100644 --- a/framework/delibs/cmake/Defs.cmake +++ b/framework/delibs/cmake/Defs.cmake @@ -114,6 +114,7 @@ endif () DE_MAKE_ENV_BOOL("DE_CPU" "VANILLA") DE_MAKE_ENV_BOOL("DE_CPU" "X86") DE_MAKE_ENV_BOOL("DE_CPU" "ARM") +DE_MAKE_ENV_BOOL("DE_CPU" "ARM_64") # \note [petri] Re-wrote in this ugly manner, because CMake 2.6 seems to # barf about the parenthesis in the previous way. Ugh. diff --git a/framework/delibs/cmake/toolchain-android-r10c.cmake b/framework/delibs/cmake/toolchain-android-r10c.cmake new file mode 100644 index 0000000..fe48832 --- /dev/null +++ b/framework/delibs/cmake/toolchain-android-r10c.cmake @@ -0,0 +1,145 @@ +# Platform defines. +set(CMAKE_SYSTEM_NAME Linux) + +set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) + +set(CMAKE_CROSSCOMPILING 1) + +# NDK installation path +if (NOT DEFINED ANDROID_NDK_PATH) + message(FATAL_ERROR "Please provide ANDROID_NDK_PATH") +endif () + +# Host os (for toolchain binaries) +if (NOT DEFINED ANDROID_NDK_HOST_OS) + message(STATUS "Warning: ANDROID_NDK_HOST_OS is not set") + if (WIN32) + set(ANDROID_NDK_HOST_OS "windows") + elseif (UNIX) + set(ANDROID_NDK_HOST_OS "linux-86") + endif () +endif () + +# Compile target +set(ANDROID_ABI "armeabi-v7a" CACHE STRING "Android ABI") +set(ANDROID_NDK_TARGET "android-${DE_ANDROID_API}") + +# dE defines +set(DE_OS "DE_OS_ANDROID") +set(DE_COMPILER "DE_COMPILER_GCC") +if (NOT DEFINED DE_ANDROID_API) + set(DE_ANDROID_API 9) +endif () + +set(COMMON_C_FLAGS "-fpic -DANDROID -D__ANDROID__ -D__STDC_INT64__") +set(COMMON_LINKER_FLAGS "") +set(ARM_C_FLAGS "-D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ") + +# ABI-dependent bits +if (ANDROID_ABI STREQUAL "x86") + set(DE_CPU "DE_CPU_X86") + set(CMAKE_SYSTEM_PROCESSOR i686-android-linux) + + set(ANDROID_CC_PATH "${ANDROID_NDK_PATH}/toolchains/x86-4.9/prebuilt/${ANDROID_NDK_HOST_OS}/") + set(CROSS_COMPILE "${ANDROID_CC_PATH}bin/i686-linux-android-") + set(ANDROID_SYSROOT "${ANDROID_NDK_PATH}/platforms/${ANDROID_NDK_TARGET}/arch-x86") + set(LIBGCC "${ANDROID_CC_PATH}lib/gcc/i686-linux-android/4.9/libgcc.a") + + set(CMAKE_FIND_ROOT_PATH + "${ANDROID_NDK_PATH}/sources/cxx-stl/gnu-libstdc++/4.9/libs/${ANDROID_ABI}" + "${ANDROID_CC_PATH}i686-linux-android" + "${ANDROID_CC_PATH}lib/gcc/i686-linux-android/4.9" + ${ANDROID_SYSROOT} + ) + + set(TARGET_C_FLAGS "-march=i686 -msse3 -mstackrealign -mfpmath=sse") + set(TARGET_LINKER_FLAGS "") + +elseif (ANDROID_ABI STREQUAL "armeabi" OR + ANDROID_ABI STREQUAL "armeabi-v7a") + set(DE_CPU "DE_CPU_ARM") + set(CMAKE_SYSTEM_PROCESSOR arm-linux-androideabi) + + set(ANDROID_CC_PATH "${ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-4.9/prebuilt/${ANDROID_NDK_HOST_OS}/") + set(CROSS_COMPILE "${ANDROID_CC_PATH}bin/arm-linux-androideabi-") + set(ANDROID_SYSROOT "${ANDROID_NDK_PATH}/platforms/${ANDROID_NDK_TARGET}/arch-arm") + + if (ANDROID_ABI STREQUAL "armeabi-v7a") + set(TARGET_C_FLAGS "${ARM_C_FLAGS} -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp") + set(TARGET_LINKER_FLAGS "-Wl,--fix-cortex-a8 -march=armv7-a") + set(LIBGCC "${ANDROID_CC_PATH}lib/gcc/arm-linux-androideabi/4.9/armv7-a/libgcc.a") + + else () # armeabi + set(TARGET_C_FLAGS "${ARM_C_FLAGS} -march=armv5te -mfloat-abi=softfp") + set(TARGET_LINKER_FLAGS "-Wl,--fix-cortex-a8 -march=armv5te") + set(LIBGCC "${ANDROID_CC_PATH}lib/gcc/arm-linux-androideabi/4.9/libgcc.a") + endif () + + set(CMAKE_FIND_ROOT_PATH + "${ANDROID_NDK_PATH}/sources/cxx-stl/gnu-libstdc++/4.9/libs/${ANDROID_ABI}" + "${ANDROID_CC_PATH}arm-linux-androideabi" + ${ANDROID_SYSROOT} + ) + +elseif (ANDROID_ABI STREQUAL "arm64-v8a") + set(DE_CPU "DE_CPU_ARM_64") + set(CMAKE_SYSTEM_PROCESSOR aarch64-linux-android) + set(CMAKE_SIZEOF_VOID_P 8) + + set(ANDROID_CC_PATH "${ANDROID_NDK_PATH}/toolchains/aarch64-linux-android-4.9/prebuilt/${ANDROID_NDK_HOST_OS}/") + set(CROSS_COMPILE "${ANDROID_CC_PATH}bin/aarch64-linux-android-") + set(ANDROID_SYSROOT "${ANDROID_NDK_PATH}/platforms/${ANDROID_NDK_TARGET}/arch-arm64") + set(LIBGCC "${ANDROID_CC_PATH}lib/gcc/aarch64-linux-android/4.9/libgcc.a") + + set(CMAKE_FIND_ROOT_PATH + "${ANDROID_NDK_PATH}/sources/cxx-stl/gnu-libstdc++/4.9/libs/${ANDROID_ABI}" + "${ANDROID_CC_PATH}arm-linux-androideabi" + ${ANDROID_SYSROOT} + ) + + set(TARGET_C_FLAGS "-march=armv8-a -mabi=lp64") + set(TARGET_LINKER_FLAGS "-march=armv8-a") + +else () + message(FATAL_ERROR "Unknown ABI \"${ANDROID_ABI}\"") +endif () + +# crtbegin_so.o & crtend_so.o \todo [pyry] Is there some special CMake variable for these? +if (DE_ANDROID_API GREATER 8) + set(CRTBEGIN_SO "${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o") + set(CRTEND_SO "${ANDROID_SYSROOT}/usr/lib/crtend_so.o") +endif () + +# C++ library +set(LIBCPP "${ANDROID_NDK_PATH}/sources/cxx-stl/gnu-libstdc++/4.9/libs/${ANDROID_ABI}/libgnustl_static.a") + +include(CMakeForceCompiler) + +if (ANDROID_NDK_HOST_OS STREQUAL "linux-x86" OR + ANDROID_NDK_HOST_OS STREQUAL "linux-x86_64" OR + ANDROID_NDK_HOST_OS STREQUAL "darwin-x86") + cmake_force_c_compiler("${CROSS_COMPILE}gcc" GNU) + cmake_force_cxx_compiler("${CROSS_COMPILE}g++" GNU) +elseif (ANDROID_NDK_HOST_OS STREQUAL "windows") + cmake_force_c_compiler("${CROSS_COMPILE}gcc.exe" GNU) + cmake_force_cxx_compiler("${CROSS_COMPILE}g++.exe" GNU) +else () + message(FATAL_ERROR "Unknown ANDROID_NDK_HOST_OS") +endif () + +set(CMAKE_SHARED_LIBRARY_C_FLAGS "") +set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") + +set(CMAKE_C_CREATE_SHARED_LIBRARY " -o ") +set(CMAKE_CXX_CREATE_SHARED_LIBRARY " -o ${CRTBEGIN_SO} ${LIBCPP} ${LIBGCC} ${CRTEND_SO}") +set(CMAKE_CXX_LINK_EXECUTABLE " -o ${LIBCPP} ${LIBGCC}") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# \note Without CACHE STRING FORCE cmake ignores these. +set(CMAKE_C_FLAGS "--sysroot=${ANDROID_SYSROOT} ${COMMON_C_FLAGS} ${TARGET_C_FLAGS}" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT} ${COMMON_C_FLAGS} ${TARGET_C_FLAGS} -I${ANDROID_NDK_PATH}/sources/cxx-stl/gnu-libstdc++/4.9/include -I${ANDROID_NDK_PATH}/sources/cxx-stl/gnu-libstdc++/4.9/libs/${ANDROID_ABI}/include" CACHE STRING "" FORCE) +set(CMAKE_SHARED_LINKER_FLAGS "-nostdlib -Wl,-shared,-Bsymbolic -Wl,--no-undefined ${COMMON_LINKER_FLAGS} ${TARGET_LINKER_FLAGS}" CACHE STRING "" FORCE) +set(CMAKE_EXE_LINKER_FLAGS "${COMMON_LINKER_FLAGS} ${TARGET_LINKER_FLAGS}" CACHE STRING "" FORCE) diff --git a/targets/android/android.cmake b/targets/android/android.cmake index 10e52be..4b8d81b 100644 --- a/targets/android/android.cmake +++ b/targets/android/android.cmake @@ -1,5 +1,5 @@ -# Android native ES2 -message("*** Using Android ES2") +# Android +message("*** Using Android") set(DEQP_TARGET_NAME "Android") set(DEQP_SUPPORT_GLES1 ON) set(DEQP_SUPPORT_GLES2 ON) -- 2.7.4