Skip to content
Snippets Groups Projects
Commit ef3d1ebd authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'android-r22' into release-3.20


005e2cdf Android: Do not use gold for ndk >= r22
ed7a87f2 Tests: Update RunCMake.Android for NDK r22
4950d357 Help: Document CMAKE_ANDROID_NDK_VERSION variable
74690624 Android: Detect NDK version number

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !5862
parents 97944e01 005e2cdf
No related branches found
No related tags found
No related merge requests found
......@@ -359,6 +359,10 @@ CMake uses the following steps to select one of the environments:
* Else, an error diagnostic will be issued that neither the NDK or
Standalone Toolchain can be found.
.. versionadded:: 3.20
If an Android NDK is selected, its version number is reported
in the :variable:`CMAKE_ANDROID_NDK_VERSION` variable.
.. _`Cross Compiling for Android with the NDK`:
Cross Compiling for Android with the NDK
......
......@@ -278,6 +278,7 @@ Variables that Describe the System
/variable/ANDROID
/variable/APPLE
/variable/BORLAND
/variable/CMAKE_ANDROID_NDK_VERSION
/variable/CMAKE_CL_64
/variable/CMAKE_COMPILER_2005
/variable/CMAKE_HOST_APPLE
......
......@@ -73,6 +73,9 @@ Platforms
- The default :variable:`CMAKE_BUILD_TYPE` for Android is
now ``RelWithDebInfo``.
- The :variable:`CMAKE_ANDROID_NDK_VERSION` variable was added to
report the version of the NDK.
File-Based API
--------------
......
CMAKE_ANDROID_NDK_VERSION
-------------------------
.. versionadded:: 3.20
When :ref:`Cross Compiling for Android with the NDK` and using an
Android NDK version 11 or higher, this variable is provided by
CMake to report the NDK version number.
......@@ -77,7 +77,7 @@ else()
set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-flto")
endif()
if(ANDROID)
if(ANDROID AND NOT CMAKE_ANDROID_NDK_VERSION VERSION_GREATER_EQUAL "22")
# https://github.com/android-ndk/ndk/issues/242
set(CMAKE_${lang}_LINK_OPTIONS_IPO "-fuse-ld=gold")
endif()
......
......@@ -226,6 +226,44 @@ if(CMAKE_ANDROID_NDK)
include("${CMAKE_ANDROID_NDK}/build/cmake/abis.cmake" OPTIONAL RESULT_VARIABLE _INCLUDED_ABIS)
endif()
if(CMAKE_ANDROID_NDK AND EXISTS "${CMAKE_ANDROID_NDK}/source.properties")
# Android NDK revision
# Possible formats:
# * r16, build 1234: 16.0.1234
# * r16b, build 1234: 16.1.1234
# * r16 beta 1, build 1234: 16.0.1234-beta1
#
# Canary builds are not specially marked.
file(READ "${CMAKE_ANDROID_NDK}/source.properties" _ANDROID_NDK_SOURCE_PROPERTIES)
set(_ANDROID_NDK_REVISION_REGEX
"^Pkg\\.Desc = Android NDK\nPkg\\.Revision = ([0-9]+)\\.([0-9]+)\\.([0-9]+)(-beta([0-9]+))?")
if(NOT _ANDROID_NDK_SOURCE_PROPERTIES MATCHES "${_ANDROID_NDK_REVISION_REGEX}")
string(REPLACE "\n" "\n " _ANDROID_NDK_SOURCE_PROPERTIES "${_ANDROID_NDK_SOURCE_PROPERTIES}")
message(FATAL_ERROR
"Android: Failed to parse NDK revision from:\n"
" ${CMAKE_ANDROID_NDK}/source.properties\n"
"with content:\n"
" ${_ANDROID_NDK_SOURCE_PROPERTIES}")
endif()
set(_ANDROID_NDK_MAJOR "${CMAKE_MATCH_1}")
set(_ANDROID_NDK_MINOR "${CMAKE_MATCH_2}")
set(_ANDROID_NDK_BUILD "${CMAKE_MATCH_3}")
set(_ANDROID_NDK_BETA "${CMAKE_MATCH_5}")
if(_ANDROID_NDK_BETA STREQUAL "")
set(_ANDROID_NDK_BETA "0")
endif()
set(CMAKE_ANDROID_NDK_VERSION "${_ANDROID_NDK_MAJOR}.${_ANDROID_NDK_MINOR}")
unset(_ANDROID_NDK_SOURCE_PROPERTIES)
unset(_ANDROID_NDK_REVISION_REGEX)
unset(_ANDROID_NDK_MAJOR)
unset(_ANDROID_NDK_MINOR)
unset(_ANDROID_NDK_BUILD)
unset(_ANDROID_NDK_BETA)
endif()
if(CMAKE_ANDROID_NDK)
# Identify the host platform.
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
......@@ -523,6 +561,7 @@ if(CMAKE_ANDROID_NDK)
string(APPEND CMAKE_SYSTEM_CUSTOM_CODE
"set(CMAKE_ANDROID_ARCH_TRIPLE \"${CMAKE_ANDROID_ARCH_TRIPLE}\")\n"
"set(CMAKE_ANDROID_ARCH_LLVM_TRIPLE \"${CMAKE_ANDROID_ARCH_LLVM_TRIPLE}\")\n"
"set(CMAKE_ANDROID_NDK_VERSION \"${CMAKE_ANDROID_NDK_VERSION}\")\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"
......
......@@ -5,10 +5,21 @@ if(NOT ANDROID)
message(SEND_ERROR "CMake variable 'ANDROID' is not set to a true value.")
endif()
foreach(f
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}ar${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
set(files
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}ar${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
)
if(NOT CMAKE_ANDROID_NDK_VERSION VERSION_GREATER_EQUAL 22)
list(APPEND files
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}ld${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
)
endif()
if(NOT CMAKE_ANDROID_NDK_VERSION VERSION_GREATER_EQUAL 19)
list(APPEND files
"${CMAKE_C_ANDROID_TOOLCHAIN_PREFIX}gcc${CMAKE_C_ANDROID_TOOLCHAIN_SUFFIX}"
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}g++${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
)
endif()
foreach(f IN LISTS files)
if(NOT EXISTS "${f}")
message(SEND_ERROR "Expected file does not exist:\n \"${f}\"")
endif()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment