summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-03-03 16:11:52 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-03-03 16:11:58 (GMT)
commit957a117c705766d5d4d2d6c807217fe9d154cdff (patch)
tree5bffa910e35b950f868202f8da2a96427f3c0b3e
parenta88efbc9cfad2d69e1f1e8875383c4e9c1f39849 (diff)
parent005e2cdfb05d92e1b24df2d35ea10ac557b3d831 (diff)
downloadCMake-957a117c705766d5d4d2d6c807217fe9d154cdff.zip
CMake-957a117c705766d5d4d2d6c807217fe9d154cdff.tar.gz
CMake-957a117c705766d5d4d2d6c807217fe9d154cdff.tar.bz2
Merge topic 'android-r22'
005e2cdfb0 Android: Do not use gold for ndk >= r22 ed7a87f270 Tests: Update RunCMake.Android for NDK r22 4950d35733 Help: Document CMAKE_ANDROID_NDK_VERSION variable 746906242d Android: Detect NDK version number Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5862
-rw-r--r--Help/manual/cmake-toolchains.7.rst4
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/release/3.20.rst3
-rw-r--r--Help/variable/CMAKE_ANDROID_NDK_VERSION.rst8
-rw-r--r--Modules/Compiler/Clang.cmake2
-rw-r--r--Modules/Platform/Android-Determine.cmake39
-rw-r--r--Tests/RunCMake/Android/common.cmake15
7 files changed, 69 insertions, 3 deletions
diff --git a/Help/manual/cmake-toolchains.7.rst b/Help/manual/cmake-toolchains.7.rst
index 0267ca3..1ededee 100644
--- a/Help/manual/cmake-toolchains.7.rst
+++ b/Help/manual/cmake-toolchains.7.rst
@@ -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
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index b6764ac..4317dd4 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -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
diff --git a/Help/release/3.20.rst b/Help/release/3.20.rst
index b36d1c2..eede362 100644
--- a/Help/release/3.20.rst
+++ b/Help/release/3.20.rst
@@ -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
--------------
diff --git a/Help/variable/CMAKE_ANDROID_NDK_VERSION.rst b/Help/variable/CMAKE_ANDROID_NDK_VERSION.rst
new file mode 100644
index 0000000..5428d52
--- /dev/null
+++ b/Help/variable/CMAKE_ANDROID_NDK_VERSION.rst
@@ -0,0 +1,8 @@
+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.
diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake
index 5862521..9f93d41 100644
--- a/Modules/Compiler/Clang.cmake
+++ b/Modules/Compiler/Clang.cmake
@@ -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()
diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake
index c279086..2d2cd5c 100644
--- a/Modules/Platform/Android-Determine.cmake
+++ b/Modules/Platform/Android-Determine.cmake
@@ -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"
diff --git a/Tests/RunCMake/Android/common.cmake b/Tests/RunCMake/Android/common.cmake
index 32412aa..7c80a04 100644
--- a/Tests/RunCMake/Android/common.cmake
+++ b/Tests/RunCMake/Android/common.cmake
@@ -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()