From: Jesse Hall Date: Fri, 4 Aug 2017 21:24:10 +0000 (-0700) Subject: Support Android NDK r15 X-Git-Tag: upstream/1.3.5~2565^2~180 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba94ca60f6a716bab14be4fc65cb77ee26d57335;p=platform%2Fupstream%2FVK-GL-CTS.git Support Android NDK r15 Most of the changes vs. r11 are for dealing with the the NDK's new Unified Headers: there is now just one set of headers for all ABIs and all API versions, but libraries are still per-ABI and per-API. Building with NDK r15 requires CMake 3.2; otherwise, CMake 2.8 is still supported. Components: Framework Change-Id: I4e64b4516c5ac9f59ac97adf331e01fa8be8eae0 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b46f8f..73a7296 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(DEQP_TARGET "default" CACHE STRING "dEQP Target (default, android...)") if (DEFINED DEQP_TARGET_TOOLCHAIN) # \note Toolchain must be included before project() command - include(targets/${DEQP_TARGET}/${DEQP_TARGET_TOOLCHAIN}.cmake) + include(targets/${DEQP_TARGET}/${DEQP_TARGET_TOOLCHAIN}.cmake NO_POLICY_SCOPE) endif () project(dEQP-Core-${DEQP_TARGET}) diff --git a/scripts/android/build_apk.py b/scripts/android/build_apk.py index 796dbee..11e50e8 100644 --- a/scripts/android/build_apk.py +++ b/scripts/android/build_apk.py @@ -190,9 +190,9 @@ class Configuration: if not NDKEnv.isHostOsSupported(self.env.ndk.hostOsName): raise Exception("NDK '%s' is not supported on this machine" % self.env.ndk.hostOsName) - supportedNDKVersion = 11 - if self.env.ndk.version[0] != supportedNDKVersion: - raise Exception("Android NDK version %d is not supported; build requires NDK version %d" % (self.env.ndk.version[0], supportedNDKVersion)) + supportedNDKVersion = [11, 15] + if self.env.ndk.version[0] not in supportedNDKVersion: + raise Exception("Android NDK version %d is not supported; build requires NDK version %s" % (self.env.ndk.version[0], supportedNDKVersion)) if self.env.sdk.buildToolsVersion == (0,0,0): raise Exception("No build tools directory found at %s" % os.path.join(self.env.sdk.path, "build-tools")) diff --git a/targets/android/ndk-r15.cmake b/targets/android/ndk-r15.cmake new file mode 100644 index 0000000..bcbbb8f --- /dev/null +++ b/targets/android/ndk-r15.cmake @@ -0,0 +1,199 @@ +#------------------------------------------------------------------------- +# drawElements CMake utilities +# ---------------------------- +# +# Copyright 2016 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#------------------------------------------------------------------------- + +# CMake 3.2 fixed a bug [1] that prevents using different --sysroot arguments +# for compile and link steps in the built-in try_compile() that cmake does. +# Since NDK r15 has separate header and library sysroots, that's necessary. +# We could use -isysroot for headers and --sysroot= for libs, except that +# clang's -isysroot appears to be broken (Google internal b/64158294). +# +# [1] https://cmake.org/cmake/help/v3.2/policy/CMP0056.html +cmake_minimum_required(VERSION 3.2) + +# 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(FATAL_ERROR "Please provide ANDROID_NDK_HOST_OS") +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") + +if (NOT DEFINED DE_COMPILER) + set(DE_COMPILER "DE_COMPILER_CLANG") +endif () + +if (NOT DEFINED DE_ANDROID_API) + set(DE_ANDROID_API 9) +endif () + +# ABI-dependent bits +if (ANDROID_ABI STREQUAL "x86") + set(DE_CPU "DE_CPU_X86") + set(CMAKE_SYSTEM_PROCESSOR i686-linux-android) + + 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_LIB_SYSROOT "${ANDROID_NDK_PATH}/platforms/${ANDROID_NDK_TARGET}/arch-x86") + + set(CMAKE_FIND_ROOT_PATH + "${ANDROID_CC_PATH}i686-linux-android" + "${ANDROID_CC_PATH}lib/gcc/i686-linux-android/4.9" + ) + + set(TARGET_C_FLAGS "-march=i686 -msse3 -mstackrealign -mfpmath=sse") + set(TARGET_LINKER_FLAGS "") + set(LLVM_TRIPLE "i686-none-linux-android") + +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_LIB_SYSROOT "${ANDROID_NDK_PATH}/platforms/${ANDROID_NDK_TARGET}/arch-arm") + set(ARM_C_FLAGS "-D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ") + + 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(LLVM_TRIPLE "armv7-none-linux-androideabi") + + 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(LLVM_TRIPLE "armv5te-none-linux-androideabi") + endif () + + set(CMAKE_FIND_ROOT_PATH + "${ANDROID_CC_PATH}arm-linux-androideabi" + ) + +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_LIB_SYSROOT "${ANDROID_NDK_PATH}/platforms/${ANDROID_NDK_TARGET}/arch-arm64") + + set(CMAKE_FIND_ROOT_PATH + "${ANDROID_CC_PATH}arm-linux-androideabi" + ) + + set(TARGET_C_FLAGS "-march=armv8-a") + set(TARGET_LINKER_FLAGS "-Wl,--fix-cortex-a53-835769 -Wl,--fix-cortex-a53-835769 -march=armv8-a") + set(LLVM_TRIPLE "aarch64-none-linux-android") + + if (DE_COMPILER STREQUAL "DE_COMPILER_GCC") + set(TARGET_C_FLAGS "${TARGET_C_FLAGS} -mabi=lp64") + endif () + +elseif (ANDROID_ABI STREQUAL "x86_64") + set(DE_CPU "DE_CPU_X86_64") + set(CMAKE_SYSTEM_PROCESSOR x86_64-linux-android) + set(CMAKE_SIZEOF_VOID_P 8) + + set(CMAKE_LIBRARY_PATH "/usr/lib64") + + set(ANDROID_CC_PATH "${ANDROID_NDK_PATH}/toolchains/x86_64-4.9/prebuilt/${ANDROID_NDK_HOST_OS}/") + set(CROSS_COMPILE "${ANDROID_CC_PATH}bin/x86_64-linux-android-") + set(ANDROID_LIB_SYSROOT "${ANDROID_NDK_PATH}/platforms/${ANDROID_NDK_TARGET}/arch-x86_64") + + set(CMAKE_FIND_ROOT_PATH + "${ANDROID_CC_PATH}x86_64-linux-android" + ) + + set(LLVM_TRIPLE "x86_64-none-linux-android") + +else () + message(FATAL_ERROR "Unknown ABI \"${ANDROID_ABI}\"") +endif () + +set(ANDROID_HEADER_SYSROOT "${ANDROID_NDK_PATH}/sysroot") + +set(COMMON_C_FLAGS "-D__STDC_INT64__ -D__ANDROID_API__=${DE_ANDROID_API} -isystem ${ANDROID_HEADER_SYSROOT}/usr/include/${CMAKE_SYSTEM_PROCESSOR} --sysroot=${ANDROID_HEADER_SYSROOT}") +set(COMMON_CXX_FLAGS "${COMMON_C_FLAGS} -frtti -fexceptions") +set(COMMON_LINKER_FLAGS "--sysroot=${ANDROID_LIB_SYSROOT}") + +# Use LLVM libc++ for full C++11 support +set(ANDROID_CXX_PATH "${ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++") +set(ANDROID_CXX_LIBRARY "-L${ANDROID_CXX_PATH}/libs/${ANDROID_ABI} ${ANDROID_CXX_PATH}/libs/${ANDROID_ABI}/libc++_static.a" "${ANDROID_CXX_PATH}/libs/${ANDROID_ABI}/libc++abi.a" "${ANDROID_CXX_PATH}/libs/${ANDROID_ABI}/libandroid_support.a") +set(CXX_INCLUDES "-I${ANDROID_CXX_PATH}/include") + +set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${ANDROID_HEADER_SYSROOT} ${ANDROID_LIB_SYSROOT}) + +include(CMakeForceCompiler) + +if (ANDROID_NDK_HOST_OS STREQUAL "windows" OR + ANDROID_NDK_HOST_OS STREQUAL "windows-x86_64") + set(BIN_EXT ".exe") +else () + set(BIN_EXT "") +endif () + +if (DE_COMPILER STREQUAL "DE_COMPILER_GCC") + set(CMAKE_C_COMPILER "${CROSS_COMPILE}gcc${BIN_EXT}" CACHE FILEPATH "C Compiler") + set(CMAKE_CXX_COMPILER "${CROSS_COMPILE}g++${BIN_EXT}" CACHE FILEPATH "C++ Compiler") + + set(TARGET_C_FLAGS "-mandroid ${TARGET_C_FLAGS}") + +elseif (DE_COMPILER STREQUAL "DE_COMPILER_CLANG") + set(LLVM_PATH "${ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${ANDROID_NDK_HOST_OS}/") + + set(CMAKE_C_COMPILER "${LLVM_PATH}bin/clang${BIN_EXT}" CACHE FILEPATH "C Compiler") + set(CMAKE_CXX_COMPILER "${LLVM_PATH}bin/clang++${BIN_EXT}" CACHE FILEPATH "C++ Compiler") + set(CMAKE_AR "${CROSS_COMPILE}ar${BIN_EXT}" CACHE FILEPATH "Archiver") + set(CMAKE_RANLIB "${CROSS_COMPILE}ranlib${BIN_EXT}" CACHE FILEPATH "Indexer") + + set(TARGET_C_FLAGS "-target ${LLVM_TRIPLE} -gcc-toolchain ${ANDROID_CC_PATH} ${TARGET_C_FLAGS}") + set(TARGET_LINKER_FLAGS "-target ${LLVM_TRIPLE} -gcc-toolchain ${ANDROID_CC_PATH} ${TARGET_LINKER_FLAGS}") + +endif () + +set(CMAKE_SHARED_LIBRARY_C_FLAGS "") +set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") + +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 "${CMAKE_C_FLAGS} ${COMMON_C_FLAGS} ${TARGET_C_FLAGS}" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CXX_FLAGS} ${TARGET_C_FLAGS} ${CXX_INCLUDES} -I${ANDROID_NDK_PATH}/sources/android/support/include" CACHE STRING "" FORCE) +set(CMAKE_SHARED_LINKER_FLAGS "-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)