summaryrefslogtreecommitdiffstats
path: root/Modules/Platform/Android-Common.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-07-26 16:48:35 (GMT)
committerBrad King <brad.king@kitware.com>2019-07-26 18:17:07 (GMT)
commit97bca2f9fab58fcf5bbcb29e1e7e86e37b5cc1e0 (patch)
tree048fee25cd8797b3527994c504c5b8ce50e2ede2 /Modules/Platform/Android-Common.cmake
parent19f36c5fb2497703e4f071b3a9424a8d121ccef9 (diff)
downloadCMake-97bca2f9fab58fcf5bbcb29e1e7e86e37b5cc1e0.zip
CMake-97bca2f9fab58fcf5bbcb29e1e7e86e37b5cc1e0.tar.gz
CMake-97bca2f9fab58fcf5bbcb29e1e7e86e37b5cc1e0.tar.bz2
Android: Use unified toolchain in NDK r19+
The NDK build system now uses only a single toolchain in <ndk>/toolchains/llvm/prebuilt/<host> Its compilers are always `bin/{clang,clang++}` and its binutils are always `bin/<triple>-*`. It is a standalone toolchain: * The Anrdoid API level is specified at the end of `--target=`. * The standard library may be specified via `-stdlib=`. * No need to pass system includes or libraries explicitly. * No need to pass `--sysroot` or `-gcc-toolchain`. Teach CMake to recognize NDK versions that have a unified toolchain with its own sysroot and use the above approach. Fixes: #18739
Diffstat (limited to 'Modules/Platform/Android-Common.cmake')
-rw-r--r--Modules/Platform/Android-Common.cmake42
1 files changed, 40 insertions, 2 deletions
diff --git a/Modules/Platform/Android-Common.cmake b/Modules/Platform/Android-Common.cmake
index fb9ebd0..1affcd0 100644
--- a/Modules/Platform/Android-Common.cmake
+++ b/Modules/Platform/Android-Common.cmake
@@ -47,7 +47,41 @@ if(CMAKE_ANDROID_NDK)
endif()
if(CMAKE_ANDROID_STL_TYPE)
- if(CMAKE_ANDROID_NDK)
+ if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
+ if(CMAKE_ANDROID_STL_TYPE STREQUAL "system")
+ set(_ANDROID_STL_EXCEPTIONS 0)
+ set(_ANDROID_STL_RTTI 0)
+ macro(__android_stl lang)
+ string(APPEND CMAKE_${lang}_FLAGS_INIT " -stdlib=libstdc++")
+ endmacro()
+ elseif(CMAKE_ANDROID_STL_TYPE STREQUAL "c++_static")
+ set(_ANDROID_STL_EXCEPTIONS 1)
+ set(_ANDROID_STL_RTTI 1)
+ macro(__android_stl lang)
+ string(APPEND CMAKE_${lang}_FLAGS_INIT " -stdlib=libc++")
+ string(APPEND CMAKE_${lang}_STANDARD_LIBRARIES " -static-libstdc++")
+ endmacro()
+ elseif(CMAKE_ANDROID_STL_TYPE STREQUAL "c++_shared")
+ set(_ANDROID_STL_EXCEPTIONS 1)
+ set(_ANDROID_STL_RTTI 1)
+ macro(__android_stl lang)
+ string(APPEND CMAKE_${lang}_FLAGS_INIT " -stdlib=libc++")
+ endmacro()
+ elseif(CMAKE_ANDROID_STL_TYPE STREQUAL "none")
+ set(_ANDROID_STL_RTTI 0)
+ set(_ANDROID_STL_EXCEPTIONS 0)
+ macro(__android_stl lang)
+ # FIXME: Add a way to add project-wide language-specific compile-only flags.
+ set(CMAKE_CXX_COMPILE_OBJECT
+ "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE> -nostdinc++")
+ string(APPEND CMAKE_${lang}_STANDARD_LIBRARIES " -nostdlib++")
+ endmacro()
+ else()
+ message(FATAL_ERROR
+ "Android: STL '${CMAKE_ANDROID_STL_TYPE}' not supported by this NDK."
+ )
+ endif()
+ elseif(CMAKE_ANDROID_NDK)
macro(__android_stl_inc lang dir req)
if(EXISTS "${dir}")
@@ -152,6 +186,10 @@ macro(__android_compiler_common lang)
__android_stl(CXX)
endif()
+ if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
+ string(APPEND CMAKE_${lang}_STANDARD_LIBRARIES " -latomic -lm")
+ endif()
+
# <ndk>/build/core/definitions.mk appends the sysroot's include directory
# explicitly at the end of the command-line include path so that it
# precedes the toolchain's builtin include directories. This is
@@ -161,7 +199,7 @@ macro(__android_compiler_common lang)
#
# Do not do this for a standalone toolchain because it is already
# tied to a specific API version.
- if(CMAKE_ANDROID_NDK)
+ if(CMAKE_ANDROID_NDK AND NOT CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
if(CMAKE_SYSROOT_COMPILE)
set(_cmake_sysroot_compile "${CMAKE_SYSROOT_COMPILE}")
else()