summaryrefslogtreecommitdiff
path: root/Modules/Platform/Android-Determine.cmake
diff options
context:
space:
mode:
authorbiao716.wang <biao716.wang@samsung.com>2020-03-19 01:04:30 +0900
committerbiao716.wang <biao716.wang@samsung.com>2020-03-19 01:04:30 +0900
commit1d6613f4446f69f63beddf2d97c201154fb35e33 (patch)
treef32eae75900a0df14ab8fa1e2bd436af159ef91d /Modules/Platform/Android-Determine.cmake
parentaabcd8e66e3268a232efe2e416635d5b6bf84ad5 (diff)
downloadcmake-1d6613f4446f69f63beddf2d97c201154fb35e33.tar.gz
cmake-1d6613f4446f69f63beddf2d97c201154fb35e33.tar.bz2
cmake-1d6613f4446f69f63beddf2d97c201154fb35e33.zip
Imported Upstream version 3.16.4upstream/3.16.4
Change-Id: Ic5262ea6c0872b353ea2dc35fe1e944063ae8409 Signed-off-by: biao716.wang <biao716.wang@samsung.com>
Diffstat (limited to 'Modules/Platform/Android-Determine.cmake')
-rw-r--r--Modules/Platform/Android-Determine.cmake98
1 files changed, 86 insertions, 12 deletions
diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake
index add1dc1f7..e7c1b48a9 100644
--- a/Modules/Platform/Android-Determine.cmake
+++ b/Modules/Platform/Android-Determine.cmake
@@ -18,6 +18,9 @@ if(CMAKE_SYSTEM_VERSION EQUAL 1)
return()
endif()
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
# If the user provided CMAKE_SYSROOT for us, extract information from it.
set(_ANDROID_SYSROOT_NDK "")
set(_ANDROID_SYSROOT_API "")
@@ -195,32 +198,66 @@ if(NOT CMAKE_SYSTEM_VERSION MATCHES "^[0-9]+$")
message(FATAL_ERROR "Android: The API specified by CMAKE_SYSTEM_VERSION='${CMAKE_SYSTEM_VERSION}' is not an integer.")
endif()
+if(CMAKE_ANDROID_NDK)
+ # Identify the host platform.
+ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
+ if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "darwin-x86_64")
+ else()
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "darwin-x86")
+ endif()
+ elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
+ if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "linux-x86_64")
+ else()
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "linux-x86")
+ endif()
+ elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
+ if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "windows-x86_64")
+ else()
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "windows")
+ endif()
+ else()
+ message(FATAL_ERROR "Android: Builds hosted on '${CMAKE_HOST_SYSTEM_NAME}' not supported.")
+ endif()
+
+ # Look for a unified toolchain/sysroot provided with the NDK.
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED "${CMAKE_ANDROID_NDK}/toolchains/llvm/prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}")
+ if(NOT IS_DIRECTORY "${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/sysroot")
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED "")
+ endif()
+else()
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "")
+ set(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED "")
+endif()
+
# https://developer.android.com/ndk/guides/abis.html
set(_ANDROID_ABI_arm64-v8a_PROC "aarch64")
set(_ANDROID_ABI_arm64-v8a_ARCH "arm64")
-set(_ANDROID_ABI_arm64-v8a_HEADER "aarch64-linux-android")
+set(_ANDROID_ABI_arm64-v8a_TRIPLE "aarch64-linux-android")
set(_ANDROID_ABI_armeabi-v7a_PROC "armv7-a")
set(_ANDROID_ABI_armeabi-v7a_ARCH "arm")
-set(_ANDROID_ABI_armeabi-v7a_HEADER "arm-linux-androideabi")
+set(_ANDROID_ABI_armeabi-v7a_TRIPLE "arm-linux-androideabi")
set(_ANDROID_ABI_armeabi-v6_PROC "armv6")
set(_ANDROID_ABI_armeabi-v6_ARCH "arm")
-set(_ANDROID_ABI_armeabi-v6_HEADER "arm-linux-androideabi")
+set(_ANDROID_ABI_armeabi-v6_TRIPLE "arm-linux-androideabi")
set(_ANDROID_ABI_armeabi_PROC "armv5te")
set(_ANDROID_ABI_armeabi_ARCH "arm")
-set(_ANDROID_ABI_armeabi_HEADER "arm-linux-androideabi")
+set(_ANDROID_ABI_armeabi_TRIPLE "arm-linux-androideabi")
set(_ANDROID_ABI_mips_PROC "mips")
set(_ANDROID_ABI_mips_ARCH "mips")
-set(_ANDROID_ABI_mips_HEADER "mipsel-linux-android")
+set(_ANDROID_ABI_mips_TRIPLE "mipsel-linux-android")
set(_ANDROID_ABI_mips64_PROC "mips64")
set(_ANDROID_ABI_mips64_ARCH "mips64")
-set(_ANDROID_ABI_mips64_HEADER "mips64el-linux-android")
+set(_ANDROID_ABI_mips64_TRIPLE "mips64el-linux-android")
set(_ANDROID_ABI_x86_PROC "i686")
set(_ANDROID_ABI_x86_ARCH "x86")
-set(_ANDROID_ABI_x86_HEADER "i686-linux-android")
+set(_ANDROID_ABI_x86_TRIPLE "i686-linux-android")
set(_ANDROID_ABI_x86_64_PROC "x86_64")
set(_ANDROID_ABI_x86_64_ARCH "x86_64")
-set(_ANDROID_ABI_x86_64_HEADER "x86_64-linux-android")
+set(_ANDROID_ABI_x86_64_TRIPLE "x86_64-linux-android")
set(_ANDROID_PROC_aarch64_ARCH_ABI "arm64-v8a")
set(_ANDROID_PROC_armv7-a_ARCH_ABI "armeabi-v7a")
@@ -261,7 +298,40 @@ if(NOT CMAKE_ANDROID_ARCH_ABI)
else()
# https://developer.android.com/ndk/guides/application_mk.html
# Default is the oldest ARM ABI.
- set(CMAKE_ANDROID_ARCH_ABI "armeabi")
+
+ # Lookup the available ABIs among all toolchains.
+ set(_ANDROID_ABIS "")
+ file(GLOB _ANDROID_CONFIG_MKS
+ "${CMAKE_ANDROID_NDK}/build/core/toolchains/*/config.mk"
+ "${CMAKE_ANDROID_NDK}/toolchains/*/config.mk"
+ )
+ foreach(config_mk IN LISTS _ANDROID_CONFIG_MKS)
+ file(STRINGS "${config_mk}" _ANDROID_TOOL_ABIS REGEX "^TOOLCHAIN_ABIS :=")
+ string(REPLACE "TOOLCHAIN_ABIS :=" "" _ANDROID_TOOL_ABIS "${_ANDROID_TOOL_ABIS}")
+ separate_arguments(_ANDROID_TOOL_ABIS UNIX_COMMAND "${_ANDROID_TOOL_ABIS}")
+ list(APPEND _ANDROID_ABIS ${_ANDROID_TOOL_ABIS})
+ unset(_ANDROID_TOOL_ABIS)
+ endforeach()
+ unset(_ANDROID_CONFIG_MKS)
+
+ # Choose the oldest among the available arm ABIs.
+ if(_ANDROID_ABIS)
+ list(REMOVE_DUPLICATES _ANDROID_ABIS)
+ cmake_policy(PUSH)
+ cmake_policy(SET CMP0057 NEW)
+ foreach(abi armeabi armeabi-v7a arm64-v8a)
+ if("${abi}" IN_LIST _ANDROID_ABIS)
+ set(CMAKE_ANDROID_ARCH_ABI "${abi}")
+ break()
+ endif()
+ endforeach()
+ cmake_policy(POP)
+ endif()
+ unset(_ANDROID_ABIS)
+
+ if(NOT CMAKE_ANDROID_ARCH_ABI)
+ set(CMAKE_ANDROID_ARCH_ABI "armeabi")
+ endif()
endif()
endif()
set(CMAKE_ANDROID_ARCH "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_ARCH}")
@@ -272,7 +342,7 @@ if(_ANDROID_SYSROOT_ARCH AND NOT "x${_ANDROID_SYSROOT_ARCH}" STREQUAL "x${CMAKE_
"does not match architecture '${CMAKE_ANDROID_ARCH}' for the ABI '${CMAKE_ANDROID_ARCH_ABI}'."
)
endif()
-set(CMAKE_ANDROID_ARCH_HEADER_TRIPLE "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_HEADER}")
+set(CMAKE_ANDROID_ARCH_TRIPLE "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_TRIPLE}")
# Select a processor.
if(NOT CMAKE_SYSTEM_PROCESSOR)
@@ -285,7 +355,7 @@ if(NOT _ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC STREQUAL CMAKE_SYSTEM_PROCESS
endif()
if(CMAKE_ANDROID_NDK AND NOT DEFINED CMAKE_ANDROID_NDK_DEPRECATED_HEADERS)
- if(IS_DIRECTORY "${CMAKE_ANDROID_NDK}/sysroot/usr/include/${CMAKE_ANDROID_ARCH_HEADER_TRIPLE}")
+ if(IS_DIRECTORY "${CMAKE_ANDROID_NDK}/sysroot/usr/include/${CMAKE_ANDROID_ARCH_TRIPLE}")
# Unified headers exist so we use them by default.
set(CMAKE_ANDROID_NDK_DEPRECATED_HEADERS 0)
else()
@@ -304,8 +374,10 @@ set(CMAKE_ANDROID_ARCH_ABI \"${CMAKE_ANDROID_ARCH_ABI}\")
if(CMAKE_ANDROID_NDK)
string(APPEND CMAKE_SYSTEM_CUSTOM_CODE
- "set(CMAKE_ANDROID_ARCH_HEADER_TRIPLE \"${CMAKE_ANDROID_ARCH_HEADER_TRIPLE}\")\n"
+ "set(CMAKE_ANDROID_ARCH_TRIPLE \"${CMAKE_ANDROID_ARCH_TRIPLE}\")\n"
"set(CMAKE_ANDROID_NDK_DEPRECATED_HEADERS \"${CMAKE_ANDROID_NDK_DEPRECATED_HEADERS}\")\n"
+ "set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG \"${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}\")\n"
+ "set(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED \"${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}\")\n"
)
endif()
@@ -338,3 +410,5 @@ endif()
# Report the chosen architecture.
message(STATUS "Android: Targeting API '${CMAKE_SYSTEM_VERSION}' with architecture '${CMAKE_ANDROID_ARCH}', ABI '${CMAKE_ANDROID_ARCH_ABI}', and processor '${CMAKE_SYSTEM_PROCESSOR}'")
+
+cmake_policy(POP)