From c471ab351f9d3f766528d8ec86baf40a1b2abaf2 Mon Sep 17 00:00:00 2001 From: Jesse Hall Date: Mon, 4 Dec 2017 13:49:31 -0800 Subject: [PATCH] Use NDK's CMake toolchain for NDK r15+ The ndk-r11.cmake file is pretty complex because neither CMake nor the NDK provided adequate support. Starting in NDK r15, the NDK provides an officially supported CMake toolchain file. So dEQP's ndk-modern.cmake, used for NDK r15 and later, can just delegate to that for everything that isn't specific to dEQP, instead of duplicating large parts of it. This will make future NDK versions easier to support. Components: Framework, AOSP VK-GL-CTS: 1533 VK-GL-CTS issue: 723 Google bug: 75980403 Change-Id: Icc6ec38601017d2fb6ca40defe2f8e73ba76ca96 (cherry picked from commit 627db59d4b6d74673eda4de10cbbcb934cb99c3f) --- external/vulkancts/README.md | 4 +- framework/delibs/debase/CMakeLists.txt | 3 +- framework/delibs/decpp/CMakeLists.txt | 3 +- framework/delibs/deutil/CMakeLists.txt | 5 +- scripts/android/build_apk.py | 17 +-- targets/android/ndk-modern.cmake | 61 ++++++++++ targets/android/ndk-r15.cmake | 199 --------------------------------- 7 files changed, 77 insertions(+), 215 deletions(-) create mode 100644 targets/android/ndk-modern.cmake delete mode 100644 targets/android/ndk-r15.cmake diff --git a/external/vulkancts/README.md b/external/vulkancts/README.md index 2c45a58..cbcdbb7 100644 --- a/external/vulkancts/README.md +++ b/external/vulkancts/README.md @@ -16,7 +16,7 @@ The following tools must be installed and present in the PATH variable: * Git (for checking out sources) * Python 2.7.x (all recent versions in 2.x should work, 3.x is not supported) - * CMake 2.8 (3.2 for Android NDK r15 builds) or newer + * CMake 2.8 (3.6 for Android NDK r15+ builds) or newer ### Win32 @@ -28,7 +28,7 @@ The following tools must be installed and present in the PATH variable: ### Android - * Android NDK r11c (NDK r15 support is experimental) + * Android NDK r15c or later. NDK r11c still works but will be deprecated soon. * Android SDK with: SDK Tools, SDK Platform-tools, SDK Build-tools, and API 22 * Java Development Kit (JDK) * Windows: either NMake or Ninja in PATH diff --git a/framework/delibs/debase/CMakeLists.txt b/framework/delibs/debase/CMakeLists.txt index 800507e..f06236c 100644 --- a/framework/delibs/debase/CMakeLists.txt +++ b/framework/delibs/debase/CMakeLists.txt @@ -35,7 +35,8 @@ if (DE_OS_IS_UNIX OR DE_OS_IS_QNX) add_definitions(-D_XOPEN_SOURCE=600) endif () -if (DE_OS_IS_ANDROID) +# This is no longer needed in modern NDKs +if (DE_OS_IS_ANDROID AND DEQP_TARGET_TOOLCHAIN STREQUAL "ndk-r11") find_library(C_LIBRARY NAMES c PATHS /usr/lib /lib) find_library(M_LIBRARY NAMES m PATHS /usr/lib /lib) find_library(LOG_LIBRARY NAMES log PATHS /usr/lib) diff --git a/framework/delibs/decpp/CMakeLists.txt b/framework/delibs/decpp/CMakeLists.txt index 1266335..5450d46 100644 --- a/framework/delibs/decpp/CMakeLists.txt +++ b/framework/delibs/decpp/CMakeLists.txt @@ -71,7 +71,8 @@ set(DECPP_LIBS ) # \note [pyry] Somewhat kludgy that toolchain file doesn't set it, but there is no easy way -if (DE_OS_IS_ANDROID) +# This is no longer needed in modern NDKs +if (DE_OS_IS_ANDROID AND DEQP_TARGET_TOOLCHAIN STREQUAL "ndk-r11") if (DEFINED ANDROID_CXX_LIBRARY) set(DECPP_LIBS ${DECPP_LIBS} ${ANDROID_CXX_LIBRARY}) else () diff --git a/framework/delibs/deutil/CMakeLists.txt b/framework/delibs/deutil/CMakeLists.txt index cee5409..545c42b 100644 --- a/framework/delibs/deutil/CMakeLists.txt +++ b/framework/delibs/deutil/CMakeLists.txt @@ -34,7 +34,10 @@ if (DE_OS_IS_ANDROID) # inline keyword in headers... set_source_files_properties(deSocket.c COMPILE_FLAGS -std=c99) - set(DEUTIL_LIBS ${DEUTIL_LIBS} dl) + # This is no longer needed on modern NDKs + if (DEQP_TARGET_TOOLCHAIN STREQUAL "ndk-r11") + set(DEUTIL_LIBS ${DEUTIL_LIBS} dl) + endif () endif () if (DE_OS_IS_WIN32) diff --git a/scripts/android/build_apk.py b/scripts/android/build_apk.py index bee6aa0..79805ba 100644 --- a/scripts/android/build_apk.py +++ b/scripts/android/build_apk.py @@ -190,16 +190,8 @@ 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, 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)) - - # https://gitlab.khronos.org/Tracker/vk-gl-cts/issues/723 - if self.env.ndk.version[0] == 15: - if "armeabi-v7a" in self.abis: - raise Exception("dEQP is incompatible with NDK r15 for armeabi-v7a") - else: - print >> sys.stderr, "WARNING: Support for NDK r15 is experimental; NDK r11c is recommended for official submissions" + if self.env.ndk.version[0] < 15 and self.env.ndk.version[0] != 11: + raise Exception("Android NDK version %d is not supported; build requires NDK version 11c or >= 15" % (self.env.ndk.version[0])) 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")) @@ -337,7 +329,10 @@ def buildNativeLibrary (config, abiName): return "r%d%s" % (version[0], minorVersionString) def getBuildArgs (config, abiName): - toolchain = 'ndk-%s' % makeNDKVersionString((config.env.ndk.version[0], 0)) + if config.env.ndk.version[0] == 11: + toolchain = 'ndk-%s' % makeNDKVersionString((config.env.ndk.version[0], 0)) + else: + toolchain = 'ndk-modern' return ['-DDEQP_TARGET=android', '-DDEQP_TARGET_TOOLCHAIN=%s' % toolchain, '-DCMAKE_C_FLAGS=-Werror', diff --git a/targets/android/ndk-modern.cmake b/targets/android/ndk-modern.cmake new file mode 100644 index 0000000..cad1b3d --- /dev/null +++ b/targets/android/ndk-modern.cmake @@ -0,0 +1,61 @@ +#------------------------------------------------------------------------- +# 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. +# +#------------------------------------------------------------------------- + +# Delegate most things to the NDK's cmake toolchain script + +if (NOT DEFINED ANDROID_NDK_PATH) + message(FATAL_ERROR "Please provide ANDROID_NDK_PATH") +endif () + +set(ANDROID_PLATFORM "android-${DE_ANDROID_API}") +set(ANDROID_STL c++_static) +set(ANDROID_CPP_FEATURES "rtti exceptions") + +include(${ANDROID_NDK_PATH}/build/cmake/android.toolchain.cmake) + +# The try_compile() used to verify the C/C++ compilers are sane tries to +# generate an executable, but doesn't seem to use the right compiler/linker +# options when cross-compiling, so it fails even when building an actual +# shared library or executable succeeds. +# +# I don't know why this doesn't affect simpler projects that use the NDK +# toolchain. +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +# Set variables used by other parts of dEQP's build scripts + +set(DE_OS "DE_OS_ANDROID") + +if (NOT DEFINED DE_COMPILER) + set(DE_COMPILER "DE_COMPILER_CLANG") +endif () + +if (ANDROID_ABI STREQUAL "x86") + set(DE_CPU "DE_CPU_X86") +elseif (ANDROID_ABI STREQUAL "armeabi" OR + ANDROID_ABI STREQUAL "armeabi-v7a") + set(DE_CPU "DE_CPU_ARM") +elseif (ANDROID_ABI STREQUAL "arm64-v8a") + set(DE_CPU "DE_CPU_ARM_64") +elseif (ANDROID_ABI STREQUAL "x86_64") + set(DE_CPU "DE_CPU_X86_64") +else () + message(FATAL_ERROR "Unknown ABI \"${ANDROID_ABI}\"") +endif () diff --git a/targets/android/ndk-r15.cmake b/targets/android/ndk-r15.cmake deleted file mode 100644 index bcbbb8f..0000000 --- a/targets/android/ndk-r15.cmake +++ /dev/null @@ -1,199 +0,0 @@ -#------------------------------------------------------------------------- -# 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) -- 2.7.4