diff options
author | Brad King <brad.king@kitware.com> | 2016-08-24 13:45:50 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2016-08-24 13:45:50 (GMT) |
commit | 96de37092a29cb2e7a92e9cb10b0ef47bca32732 (patch) | |
tree | ddaacef7de12a87abd0e5c446cde824290076828 /Modules | |
parent | ccddb454b8e7ae3ae075db5fd3233ce86c8c70cb (diff) | |
parent | 7b637ebdc97655462d08d8ff70bee5d4f32e4681 (diff) | |
download | CMake-96de37092a29cb2e7a92e9cb10b0ef47bca32732.zip CMake-96de37092a29cb2e7a92e9cb10b0ef47bca32732.tar.gz CMake-96de37092a29cb2e7a92e9cb10b0ef47bca32732.tar.bz2 |
Merge topic 'android-platform-modules'
7b637ebd Android: Add `ANDROID` variable to indicate the target
c2f561e5 Android: Add test cases covering use of the NDK and standalone toolchains
6b84df8d Help: Document cross compiling for Android
d7d40830 Android: Select the STL type for NDK builds
b22294bc Android: Populate compiler flags for current ABI
b6a3102a Android: Add a CMAKE_BUILD_TYPE default
d1e3cec2 Android: Add Clang -target option for current ABI
504db72d Android: Add placeholders for compiler/abi-specific settings
fa632578 Android: Avoid interfering with common pre-existing toolchain files
6299693f Android: Search for NDK and standalone toolchain in more places
29b51379 Android: Detect and save a standalone toolchain without the NDK
7d9b49fb Android: Detect settings from the CMAKE_SYSROOT if it is set
4389664a Android: Detect and save a toolchain from the NDK
328191f6 Android: Set CMAKE_SYSROOT automatically
9e032304 Android: Detect and save the architecture, ABI, and processor
fde59c4d Android: Detect and save the API level
...
Diffstat (limited to 'Modules')
53 files changed, 1311 insertions, 1 deletions
diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index f109a14..50b12f2 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -59,6 +59,7 @@ if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") endif() +@CMAKE_C_COMPILER_CUSTOM_CODE@ @CMAKE_C_SYSROOT_FLAG_CODE@ @CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG_CODE@ diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index 9e90aea..c295b74 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -60,6 +60,7 @@ if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX) set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}") endif() +@CMAKE_CXX_COMPILER_CUSTOM_CODE@ @CMAKE_CXX_SYSROOT_FLAG_CODE@ @CMAKE_CXX_OSX_DEPLOYMENT_TARGET_FLAG_CODE@ diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake index d9f7579..f7a32b7 100644 --- a/Modules/CMakeDetermineSystem.cmake +++ b/Modules/CMakeDetermineSystem.cmake @@ -131,6 +131,7 @@ else() set(PRESET_CMAKE_SYSTEM_NAME FALSE) endif() +include(Platform/${CMAKE_SYSTEM_NAME}-Determine OPTIONAL) macro(ADJUST_CMAKE_SYSTEM_VARIABLES _PREFIX) if(NOT ${_PREFIX}_NAME) diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index 2a4bea4..8e92f65 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -54,6 +54,8 @@ if(CMAKE_Fortran_LIBRARY_ARCHITECTURE) set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_Fortran_LIBRARY_ARCHITECTURE@") endif() +@CMAKE_Fortran_COMPILER_CUSTOM_CODE@ + set(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "@CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES@") set(CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES "@CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES@") set(CMAKE_Fortran_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_Fortran_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@") diff --git a/Modules/CMakeSystem.cmake.in b/Modules/CMakeSystem.cmake.in index 70c98d5..ef8aaa0 100644 --- a/Modules/CMakeSystem.cmake.in +++ b/Modules/CMakeSystem.cmake.in @@ -9,7 +9,7 @@ set(CMAKE_SYSTEM "@CMAKE_SYSTEM@") set(CMAKE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@") set(CMAKE_SYSTEM_VERSION "@CMAKE_SYSTEM_VERSION@") set(CMAKE_SYSTEM_PROCESSOR "@CMAKE_SYSTEM_PROCESSOR@") - +@CMAKE_SYSTEM_CUSTOM_CODE@ set(CMAKE_CROSSCOMPILING "@CMAKE_CROSSCOMPILING@") set(CMAKE_SYSTEM_LOADED 1) diff --git a/Modules/Platform/Android-Clang-C.cmake b/Modules/Platform/Android-Clang-C.cmake new file mode 100644 index 0000000..9e16911 --- /dev/null +++ b/Modules/Platform/Android-Clang-C.cmake @@ -0,0 +1,2 @@ +include(Platform/Android-Clang) +__android_compiler_clang(C) diff --git a/Modules/Platform/Android-Clang-CXX.cmake b/Modules/Platform/Android-Clang-CXX.cmake new file mode 100644 index 0000000..7111836 --- /dev/null +++ b/Modules/Platform/Android-Clang-CXX.cmake @@ -0,0 +1,2 @@ +include(Platform/Android-Clang) +__android_compiler_clang(CXX) diff --git a/Modules/Platform/Android-Clang.cmake b/Modules/Platform/Android-Clang.cmake new file mode 100644 index 0000000..7ed5046 --- /dev/null +++ b/Modules/Platform/Android-Clang.cmake @@ -0,0 +1,52 @@ +#============================================================================= +# Copyright 2015-2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# This module is shared by multiple languages; use include blocker. +if(__ANDROID_COMPILER_CLANG) + return() +endif() +set(__ANDROID_COMPILER_CLANG 1) + +# Support for NVIDIA Nsight Tegra Visual Studio Edition was previously +# implemented in the CMake VS IDE generators. Avoid interfering with +# that functionality for now. Later we may try to integrate this. +if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android") + macro(__android_compiler_clang lang) + endmacro() + return() +endif() + +# Commonly used Android toolchain files that pre-date CMake upstream support +# set CMAKE_SYSTEM_VERSION to 1. Avoid interfering with them. +if(CMAKE_SYSTEM_VERSION EQUAL 1) + macro(__android_compiler_clang lang) + endmacro() + return() +endif() + +include(Platform/Android-Common) + +# The NDK toolchain configuration files at: +# +# <ndk>/[build/core/]toolchains/*-clang*/setup.mk +# +# contain logic to set LLVM_TRIPLE for Clang-based toolchains for each target. +# We need to produce the same target here to produce compatible binaries. +include(Platform/Android/abi-${CMAKE_ANDROID_ARCH_ABI}-Clang) + +macro(__android_compiler_clang lang) + __android_compiler_common(${lang}) + if(NOT CMAKE_${lang}_COMPILER_TARGET) + set(CMAKE_${lang}_COMPILER_TARGET "${_ANDROID_ABI_CLANG_TARGET}") + endif() +endmacro() diff --git a/Modules/Platform/Android-Common.cmake b/Modules/Platform/Android-Common.cmake new file mode 100644 index 0000000..6e86c10 --- /dev/null +++ b/Modules/Platform/Android-Common.cmake @@ -0,0 +1,158 @@ +#============================================================================= +# Copyright 2015-2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# This module is shared by multiple languages; use include blocker. +if(__ANDROID_COMPILER_COMMON) + return() +endif() +set(__ANDROID_COMPILER_COMMON 1) + +if(CMAKE_ANDROID_NDK) + # <ndk>/build/core/definitions.mk + + set(_ANDROID_STL_TYPES + none + system + c++_static + c++_shared + gabi++_static + gabi++_shared + gnustl_static + gnustl_shared + stlport_static + stlport_shared + ) + + if(CMAKE_ANDROID_STL_TYPE) + list(FIND _ANDROID_STL_TYPES "${CMAKE_ANDROID_STL_TYPE}" _ANDROID_STL_TYPE_FOUND) + if(_ANDROID_STL_TYPE_FOUND EQUAL -1) + string(REPLACE ";" "\n " _msg ";${_ANDROID_STL_TYPES}") + message(FATAL_ERROR + "The CMAKE_ANDROID_STL_TYPE '${CMAKE_ANDROID_STL_TYPE}' is not one of the allowed values:${_msg}\n" + ) + endif() + unset(_ANDROID_STL_TYPE_FOUND) + else() + set(CMAKE_ANDROID_STL_TYPE "gnustl_static") + endif() + + unset(_ANDROID_STL_TYPES) + + # Forward Android-specific platform variables to try_compile projects. + list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES + CMAKE_ANDROID_STL_TYPE + ) +endif() + +if(CMAKE_ANDROID_STL_TYPE) + if(CMAKE_ANDROID_NDK) + + macro(__android_stl_inc lang dir req) + if(EXISTS "${dir}") + list(APPEND CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES "${dir}") + elseif(${req}) + message(FATAL_ERROR + "Android: STL '${CMAKE_ANDROID_STL_TYPE}' include directory not found:\n" + " ${dir}" + ) + endif() + endmacro() + + macro(__android_stl_lib lang lib req) + if(CMAKE_ANDROID_ARCH_ABI MATCHES "^armeabi" AND NOT CMAKE_ANDROID_ARM_MODE) + get_filename_component(_ANDROID_STL_LIBDIR "${lib}" DIRECTORY) + get_filename_component(_ANDROID_STL_LIBNAME "${lib}" NAME) + set(_ANDROID_STL_LIBTHUMB "${_ANDROID_STL_LIBDIR}/thumb/${_ANDROID_STL_LIBNAME}") + unset(_ANDROID_STL_LIBDIR) + unset(_ANDROID_STL_LIBNAME) + else() + set(_ANDROID_STL_LIBTHUMB "") + endif() + + if(_ANDROID_STL_LIBTHUMB AND EXISTS "${_ANDROID_STL_LIBTHUMB}") + string(APPEND CMAKE_${lang}_STANDARD_LIBRARIES " \"${_ANDROID_STL_LIBTHUMB}\"") + elseif(EXISTS "${lib}") + string(APPEND CMAKE_${lang}_STANDARD_LIBRARIES " \"${lib}\"") + elseif(${req}) + message(FATAL_ERROR + "Android: STL '${CMAKE_ANDROID_STL_TYPE}' library file not found:\n" + " ${lib}" + ) + endif() + + unset(_ANDROID_STL_LIBTHUMB) + endmacro() + + include(Platform/Android/ndk-stl-${CMAKE_ANDROID_STL_TYPE}) + else() + macro(__android_stl lang) + endmacro() + endif() +else() + macro(__android_stl lang) + endmacro() +endif() + +# The NDK toolchain configuration files at: +# +# <ndk>/[build/core/]toolchains/*/setup.mk +# +# contain logic to set TARGET_CFLAGS and TARGET_LDFLAGS (and debug/release +# variants) to tell their build system what flags to pass for each ABI. +# We need to produce the same flags here to produce compatible binaries. +# We initialize these variables here and set them in the compiler-specific +# modules that include this one. Then we use them in the macro below when +# it is called. +set(_ANDROID_ABI_INIT_CFLAGS "") +set(_ANDROID_ABI_INIT_CFLAGS_DEBUG "") +set(_ANDROID_ABI_INIT_CFLAGS_RELEASE "") +set(_ANDROID_ABI_INIT_LDFLAGS "") + +macro(__android_compiler_common lang) + if(_ANDROID_ABI_INIT_CFLAGS) + string(APPEND CMAKE_${lang}_FLAGS_INIT " ${_ANDROID_ABI_INIT_CFLAGS}") + endif() + if(_ANDROID_ABI_INIT_CFLAGS_DEBUG) + string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " ${_ANDROID_ABI_INIT_CFLAGS_DEBUG}") + endif() + if(_ANDROID_ABI_INIT_CFLAGS_RELEASE) + string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " ${_ANDROID_ABI_INIT_CFLAGS_RELEASE}") + string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " ${_ANDROID_ABI_INIT_CFLAGS_RELEASE}") + string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " ${_ANDROID_ABI_INIT_CFLAGS_RELEASE}") + endif() + if(_ANDROID_ABI_INIT_LDFLAGS) + foreach(t EXE SHARED MODULE) + string(APPEND CMAKE_${t}_LINKER_FLAGS_INIT " ${_ANDROID_ABI_INIT_LDFLAGS}") + endforeach() + endif() + + if(DEFINED _ANDROID_STL_EXCEPTIONS) + if(_ANDROID_STL_EXCEPTIONS) + string(APPEND CMAKE_${lang}_FLAGS_INIT " -fexceptions") + else() + string(APPEND CMAKE_${lang}_FLAGS_INIT " -fno-exceptions") + endif() + endif() + + if("x${lang}" STREQUAL "xCXX" AND DEFINED _ANDROID_STL_RTTI) + if(_ANDROID_STL_RTTI) + string(APPEND CMAKE_${lang}_FLAGS_INIT " -frtti") + else() + string(APPEND CMAKE_${lang}_FLAGS_INIT " -fno-rtti") + endif() + endif() + + if("x${lang}" STREQUAL "xCXX") + __android_stl(CXX) + endif() +endmacro() diff --git a/Modules/Platform/Android-Determine-C.cmake b/Modules/Platform/Android-Determine-C.cmake new file mode 100644 index 0000000..c7d1d15 --- /dev/null +++ b/Modules/Platform/Android-Determine-C.cmake @@ -0,0 +1,2 @@ +include(Platform/Android/Determine-Compiler) +__android_determine_compiler(C) diff --git a/Modules/Platform/Android-Determine-CXX.cmake b/Modules/Platform/Android-Determine-CXX.cmake new file mode 100644 index 0000000..3a3de88 --- /dev/null +++ b/Modules/Platform/Android-Determine-CXX.cmake @@ -0,0 +1,2 @@ +include(Platform/Android/Determine-Compiler) +__android_determine_compiler(CXX) diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake new file mode 100644 index 0000000..0a89c58 --- /dev/null +++ b/Modules/Platform/Android-Determine.cmake @@ -0,0 +1,301 @@ +#============================================================================= +# Copyright 2015-2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# When CMAKE_SYSTEM_NAME is "Android", CMakeDetermineSystem loads this module. +# This module detects platform-wide information about the Android target +# in order to store it in "CMakeSystem.cmake". + +# Support for NVIDIA Nsight Tegra Visual Studio Edition was previously +# implemented in the CMake VS IDE generators. Avoid interfering with +# that functionality for now. Later we may try to integrate this. +if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android") + return() +endif() + +# Commonly used Android toolchain files that pre-date CMake upstream support +# set CMAKE_SYSTEM_VERSION to 1. Avoid interfering with them. +if(CMAKE_SYSTEM_VERSION EQUAL 1) + return() +endif() + +# If the user provided CMAKE_SYSROOT for us, extract information from it. +set(_ANDROID_SYSROOT_NDK "") +set(_ANDROID_SYSROOT_API "") +set(_ANDROID_SYSROOT_ARCH "") +set(_ANDROID_SYSROOT_STANDALONE_TOOLCHAIN "") +if(CMAKE_SYSROOT) + if(NOT IS_DIRECTORY "${CMAKE_SYSROOT}") + message(FATAL_ERROR + "Android: The specified CMAKE_SYSROOT:\n" + " ${CMAKE_SYSROOT}\n" + "is not an existing directory." + ) + endif() + if(CMAKE_SYSROOT MATCHES "^([^\\\n]*)/platforms/android-([0-9]+)/arch-([a-z0-9_]+)$") + set(_ANDROID_SYSROOT_NDK "${CMAKE_MATCH_1}") + set(_ANDROID_SYSROOT_API "${CMAKE_MATCH_2}") + set(_ANDROID_SYSROOT_ARCH "${CMAKE_MATCH_3}") + elseif(CMAKE_SYSROOT MATCHES "^([^\\\n]*)/sysroot$") + set(_ANDROID_SYSROOT_STANDALONE_TOOLCHAIN "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR + "The value of CMAKE_SYSROOT:\n" + " ${CMAKE_SYSROOT}\n" + "does not match any of the forms:\n" + " <ndk>/platforms/android-<api>/arch-<arch>\n" + " <standalone-toolchain>/sysroot\n" + "where:\n" + " <ndk> = Android NDK directory (with forward slashes)\n" + " <api> = Android API version number (decimal digits)\n" + " <arch> = Android ARCH name (lower case)\n" + " <standalone-toolchain> = Path to standalone toolchain prefix\n" + ) + endif() +endif() + +# Find the Android NDK. +if(CMAKE_ANDROID_NDK) + if(NOT IS_DIRECTORY "${CMAKE_ANDROID_NDK}") + message(FATAL_ERROR + "Android: The NDK root directory specified by CMAKE_ANDROID_NDK:\n" + " ${CMAKE_ANDROID_NDK}\n" + "does not exist." + ) + endif() +elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN) + if(NOT IS_DIRECTORY "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}") + message(FATAL_ERROR + "Android: The standalone toolchain directory specified by CMAKE_ANDROID_STANDALONE_TOOLCHAIN:\n" + " ${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}\n" + "does not exist." + ) + endif() + if(NOT EXISTS "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h") + message(FATAL_ERROR + "Android: The standalone toolchain directory specified by CMAKE_ANDROID_STANDALONE_TOOLCHAIN:\n" + " ${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}\n" + "does not contain a sysroot with a known layout. The file:\n" + " ${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h\n" + "does not exist." + ) + endif() +else() + if(IS_DIRECTORY "${_ANDROID_SYSROOT_NDK}") + set(CMAKE_ANDROID_NDK "${_ANDROID_SYSROOT_NDK}") + elseif(IS_DIRECTORY "${_ANDROID_SYSROOT_STANDALONE_TOOLCHAIN}") + set(CMAKE_ANDROID_STANDALONE_TOOLCHAIN "${_ANDROID_SYSROOT_STANDALONE_TOOLCHAIN}") + elseif(IS_DIRECTORY "${ANDROID_NDK}") + file(TO_CMAKE_PATH "${ANDROID_NDK}" CMAKE_ANDROID_NDK) + elseif(IS_DIRECTORY "${ANDROID_STANDALONE_TOOLCHAIN}") + file(TO_CMAKE_PATH "${ANDROID_STANDALONE_TOOLCHAIN}" CMAKE_ANDROID_STANDALONE_TOOLCHAIN) + elseif(IS_DIRECTORY "$ENV{ANDROID_NDK_ROOT}") + file(TO_CMAKE_PATH "$ENV{ANDROID_NDK_ROOT}" CMAKE_ANDROID_NDK) + elseif(IS_DIRECTORY "$ENV{ANDROID_NDK}") + file(TO_CMAKE_PATH "$ENV{ANDROID_NDK}" CMAKE_ANDROID_NDK) + elseif(IS_DIRECTORY "$ENV{ANDROID_STANDALONE_TOOLCHAIN}") + file(TO_CMAKE_PATH "$ENV{ANDROID_STANDALONE_TOOLCHAIN}" CMAKE_ANDROID_STANDALONE_TOOLCHAIN) + endif() + # TODO: Search harder for the NDK or standalone toolchain. +endif() + +set(_ANDROID_STANDALONE_TOOLCHAIN_API "") +if(CMAKE_ANDROID_STANDALONE_TOOLCHAIN) + set(_ANDROID_API_LEVEL_H_REGEX "^[\t ]*#[\t ]*define[\t ]+__ANDROID_API__[\t ]+([0-9]+)") + file(STRINGS "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" + _ANDROID_API_LEVEL_H_CONTENT REGEX "${_ANDROID_API_LEVEL_H_REGEX}") + if(_ANDROID_API_LEVEL_H_CONTENT MATCHES "${_ANDROID_API_LEVEL_H_REGEX}") + set(_ANDROID_STANDALONE_TOOLCHAIN_API "${CMAKE_MATCH_1}") + endif() +endif() + +if(NOT CMAKE_ANDROID_NDK AND NOT CMAKE_ANDROID_STANDALONE_TOOLCHAIN) + message(FATAL_ERROR "Android: Neither the NDK or a standalone toolchain was found.") +endif() + +# Select an API. +if(CMAKE_SYSTEM_VERSION) + set(_ANDROID_API_VAR CMAKE_SYSTEM_VERSION) +elseif(CMAKE_ANDROID_API) + set(CMAKE_SYSTEM_VERSION "${CMAKE_ANDROID_API}") + set(_ANDROID_API_VAR CMAKE_ANDROID_API) +elseif(_ANDROID_SYSROOT_API) + set(CMAKE_SYSTEM_VERSION "${_ANDROID_SYSROOT_API}") + set(_ANDROID_API_VAR CMAKE_SYSROOT) +elseif(_ANDROID_STANDALONE_TOOLCHAIN_API) + set(CMAKE_SYSTEM_VERSION "${_ANDROID_STANDALONE_TOOLCHAIN_API}") +endif() +if(CMAKE_SYSTEM_VERSION) + if(CMAKE_ANDROID_API AND NOT "x${CMAKE_ANDROID_API}" STREQUAL "x${CMAKE_SYSTEM_VERSION}") + message(FATAL_ERROR + "Android: The API specified by CMAKE_ANDROID_API='${CMAKE_ANDROID_API}' is not consistent with CMAKE_SYSTEM_VERSION='${CMAKE_SYSTEM_VERSION}'." + ) + endif() + if(_ANDROID_SYSROOT_API) + foreach(v CMAKE_ANDROID_API CMAKE_SYSTEM_VERSION) + if(${v} AND NOT "x${_ANDROID_SYSROOT_API}" STREQUAL "x${${v}}") + message(FATAL_ERROR + "Android: The API specified by ${v}='${${v}}' is not consistent with CMAKE_SYSROOT:\n" + " ${CMAKE_SYSROOT}" + ) + endif() + endforeach() + endif() + if(CMAKE_ANDROID_NDK AND NOT IS_DIRECTORY "${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}") + message(FATAL_ERROR + "Android: The API specified by ${_ANDROID_API_VAR}='${${_ANDROID_API_VAR}}' does not exist in the NDK. " + "The directory:\n" + " ${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}\n" + "does not exist." + ) + endif() +elseif(CMAKE_ANDROID_NDK) + file(GLOB _ANDROID_APIS_1 RELATIVE "${CMAKE_ANDROID_NDK}/platforms" "${CMAKE_ANDROID_NDK}/platforms/android-[0-9]") + file(GLOB _ANDROID_APIS_2 RELATIVE "${CMAKE_ANDROID_NDK}/platforms" "${CMAKE_ANDROID_NDK}/platforms/android-[0-9][0-9]") + list(SORT _ANDROID_APIS_1) + list(SORT _ANDROID_APIS_2) + set(_ANDROID_APIS ${_ANDROID_APIS_1} ${_ANDROID_APIS_2}) + unset(_ANDROID_APIS_1) + unset(_ANDROID_APIS_2) + if(_ANDROID_APIS STREQUAL "") + message(FATAL_ERROR + "Android: No APIs found in the NDK. No\n" + " ${CMAKE_ANDROID_NDK}/platforms/android-*\n" + "directories exist." + ) + endif() + string(REPLACE "android-" "" _ANDROID_APIS "${_ANDROID_APIS}") + list(REVERSE _ANDROID_APIS) + list(GET _ANDROID_APIS 0 CMAKE_SYSTEM_VERSION) + unset(_ANDROID_APIS) +endif() +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() + +# 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_armeabi-v7a_PROC "armv7-a") +set(_ANDROID_ABI_armeabi-v7a_ARCH "arm") +set(_ANDROID_ABI_armeabi-v6_PROC "armv6") +set(_ANDROID_ABI_armeabi-v6_ARCH "arm") +set(_ANDROID_ABI_armeabi_PROC "armv5te") +set(_ANDROID_ABI_armeabi_ARCH "arm") +set(_ANDROID_ABI_mips_PROC "mips") +set(_ANDROID_ABI_mips_ARCH "mips") +set(_ANDROID_ABI_mips64_PROC "mips64") +set(_ANDROID_ABI_mips64_ARCH "mips64") +set(_ANDROID_ABI_x86_PROC "i686") +set(_ANDROID_ABI_x86_ARCH "x86") +set(_ANDROID_ABI_x86_64_PROC "x86_64") +set(_ANDROID_ABI_x86_64_ARCH "x86_64") + +set(_ANDROID_PROC_aarch64_ARCH_ABI "arm64-v8a") +set(_ANDROID_PROC_armv7-a_ARCH_ABI "armeabi-v7a") +set(_ANDROID_PROC_armv6_ARCH_ABI "armeabi-v6") +set(_ANDROID_PROC_armv5te_ARCH_ABI "armeabi") +set(_ANDROID_PROC_i686_ARCH_ABI "x86") +set(_ANDROID_PROC_mips_ARCH_ABI "mips") +set(_ANDROID_PROC_mips64_ARCH_ABI "mips64") +set(_ANDROID_PROC_x86_64_ARCH_ABI "x86_64") + +set(_ANDROID_ARCH_arm64_ABI "arm64-v8a") +set(_ANDROID_ARCH_arm_ABI "armeabi") +set(_ANDROID_ARCH_mips_ABI "mips") +set(_ANDROID_ARCH_mips64_ABI "mips64") +set(_ANDROID_ARCH_x86_ABI "x86") +set(_ANDROID_ARCH_x86_64_ABI "x86_64") + +# Validate inputs. +if(CMAKE_ANDROID_ARCH_ABI AND NOT DEFINED "_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC") + message(FATAL_ERROR "Android: Unknown ABI CMAKE_ANDROID_ARCH_ABI='${CMAKE_ANDROID_ARCH_ABI}'.") +endif() +if(CMAKE_SYSTEM_PROCESSOR AND NOT DEFINED "_ANDROID_PROC_${CMAKE_SYSTEM_PROCESSOR}_ARCH_ABI") + message(FATAL_ERROR "Android: Unknown processor CMAKE_SYSTEM_PROCESSOR='${CMAKE_SYSTEM_PROCESSOR}'.") +endif() +if(_ANDROID_SYSROOT_ARCH AND NOT DEFINED "_ANDROID_ARCH_${_ANDROID_SYSROOT_ARCH}_ABI") + message(FATAL_ERROR + "Android: Unknown architecture '${_ANDROID_SYSROOT_ARCH}' specified in CMAKE_SYSROOT:\n" + " ${CMAKE_SYSROOT}" + ) +endif() + +# Select an ABI. +if(NOT CMAKE_ANDROID_ARCH_ABI) + if(CMAKE_SYSTEM_PROCESSOR) + set(CMAKE_ANDROID_ARCH_ABI "${_ANDROID_PROC_${CMAKE_SYSTEM_PROCESSOR}_ARCH_ABI}") + elseif(_ANDROID_SYSROOT_ARCH) + set(CMAKE_ANDROID_ARCH_ABI "${_ANDROID_ARCH_${_ANDROID_SYSROOT_ARCH}_ABI}") + else() + # https://developer.android.com/ndk/guides/application_mk.html + # Default is the oldest ARM ABI. + set(CMAKE_ANDROID_ARCH_ABI "armeabi") + endif() +endif() +set(CMAKE_ANDROID_ARCH "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_ARCH}") +if(_ANDROID_SYSROOT_ARCH AND NOT "x${_ANDROID_SYSROOT_ARCH}" STREQUAL "x${CMAKE_ANDROID_ARCH}") + message(FATAL_ERROR + "Android: Architecture '${_ANDROID_SYSROOT_ARCH}' specified in CMAKE_SYSROOT:\n" + " ${CMAKE_SYSROOT}\n" + "does not match architecture '${CMAKE_ANDROID_ARCH}' for the ABI '${CMAKE_ANDROID_ARCH_ABI}'." + ) +endif() + +# Select a processor. +if(NOT CMAKE_SYSTEM_PROCESSOR) + set(CMAKE_SYSTEM_PROCESSOR "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC}") +endif() + +# If the user specified both an ABI and a processor then they might not match. +if(NOT _ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC STREQUAL CMAKE_SYSTEM_PROCESSOR) + message(FATAL_ERROR "Android: The specified CMAKE_ANDROID_ARCH_ABI='${CMAKE_ANDROID_ARCH_ABI}' and CMAKE_SYSTEM_PROCESSOR='${CMAKE_SYSTEM_PROCESSOR}' is not a valid combination.") +endif() + +# Save the Android-specific information in CMakeSystem.cmake. +set(CMAKE_SYSTEM_CUSTOM_CODE " +set(CMAKE_ANDROID_NDK \"${CMAKE_ANDROID_NDK}\") +set(CMAKE_ANDROID_STANDALONE_TOOLCHAIN \"${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}\") +set(CMAKE_ANDROID_ARCH \"${CMAKE_ANDROID_ARCH}\") +set(CMAKE_ANDROID_ARCH_ABI \"${CMAKE_ANDROID_ARCH_ABI}\") +") + +# Select an ARM variant. +if(CMAKE_ANDROID_ARCH_ABI MATCHES "^armeabi") + if(CMAKE_ANDROID_ARM_MODE) + set(CMAKE_ANDROID_ARM_MODE 1) + else() + set(CMAKE_ANDROID_ARM_MODE 0) + endif() + string(APPEND CMAKE_SYSTEM_CUSTOM_CODE + "set(CMAKE_ANDROID_ARM_MODE \"${CMAKE_ANDROID_ARM_MODE}\")\n" + ) +elseif(DEFINED CMAKE_ANDROID_ARM_MODE) + message(FATAL_ERROR "Android: CMAKE_ANDROID_ARM_MODE is set but is valid only for 'armeabi' architectures.") +endif() + +if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a") + if(CMAKE_ANDROID_ARM_NEON) + set(CMAKE_ANDROID_ARM_NEON 1) + else() + set(CMAKE_ANDROID_ARM_NEON 0) + endif() + string(APPEND CMAKE_SYSTEM_CUSTOM_CODE + "set(CMAKE_ANDROID_ARM_NEON \"${CMAKE_ANDROID_ARM_NEON}\")\n" + ) +elseif(DEFINED CMAKE_ANDROID_ARM_NEON) + message(FATAL_ERROR "Android: CMAKE_ANDROID_ARM_NEON is set but is valid only for 'armeabi-v7a' architecture.") +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}'") diff --git a/Modules/Platform/Android-GNU-C.cmake b/Modules/Platform/Android-GNU-C.cmake new file mode 100644 index 0000000..78a6a50 --- /dev/null +++ b/Modules/Platform/Android-GNU-C.cmake @@ -0,0 +1,2 @@ +include(Platform/Android-GNU) +__android_compiler_gnu(C) diff --git a/Modules/Platform/Android-GNU-CXX.cmake b/Modules/Platform/Android-GNU-CXX.cmake new file mode 100644 index 0000000..41279d1 --- /dev/null +++ b/Modules/Platform/Android-GNU-CXX.cmake @@ -0,0 +1,2 @@ +include(Platform/Android-GNU) +__android_compiler_gnu(CXX) diff --git a/Modules/Platform/Android-GNU.cmake b/Modules/Platform/Android-GNU.cmake new file mode 100644 index 0000000..58943d0 --- /dev/null +++ b/Modules/Platform/Android-GNU.cmake @@ -0,0 +1,43 @@ +#============================================================================= +# Copyright 2015-2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# This module is shared by multiple languages; use include blocker. +if(__ANDROID_COMPILER_GNU) + return() +endif() +set(__ANDROID_COMPILER_GNU 1) + +# Support for NVIDIA Nsight Tegra Visual Studio Edition was previously +# implemented in the CMake VS IDE generators. Avoid interfering with +# that functionality for now. Later we may try to integrate this. +if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android") + macro(__android_compiler_gnu lang) + endmacro() + return() +endif() + +# Commonly used Android toolchain files that pre-date CMake upstream support +# set CMAKE_SYSTEM_VERSION to 1. Avoid interfering with them. +if(CMAKE_SYSTEM_VERSION EQUAL 1) + macro(__android_compiler_gnu lang) + endmacro() + return() +endif() + +include(Platform/Android-Common) + +include(Platform/Android/abi-${CMAKE_ANDROID_ARCH_ABI}-GNU) + +macro(__android_compiler_gnu lang) + __android_compiler_common(${lang}) +endmacro() diff --git a/Modules/Platform/Android-Initialize.cmake b/Modules/Platform/Android-Initialize.cmake new file mode 100644 index 0000000..353dd0d --- /dev/null +++ b/Modules/Platform/Android-Initialize.cmake @@ -0,0 +1,51 @@ +#============================================================================= +# Copyright 2015-2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# When CMAKE_SYSTEM_NAME is "Android", CMakeSystemSpecificInitialize loads this +# module. + +# Support for NVIDIA Nsight Tegra Visual Studio Edition was previously +# implemented in the CMake VS IDE generators. Avoid interfering with +# that functionality for now. Later we may try to integrate this. +if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android") + return() +endif() + +# Commonly used Android toolchain files that pre-date CMake upstream support +# set CMAKE_SYSTEM_VERSION to 1. Avoid interfering with them. +if(CMAKE_SYSTEM_VERSION EQUAL 1) + return() +endif() + +if(NOT CMAKE_SYSROOT) + if(CMAKE_ANDROID_NDK) + set(CMAKE_SYSROOT "${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}/arch-${CMAKE_ANDROID_ARCH}") + elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN) + set(CMAKE_SYSROOT "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot") + endif() +endif() + +if(CMAKE_SYSROOT) + if(NOT IS_DIRECTORY "${CMAKE_SYSROOT}") + message(FATAL_ERROR + "Android: The system root directory needed for the selected Android version and architecture does not exist:\n" + " ${CMAKE_SYSROOT}\n" + ) + endif() +else() + message(FATAL_ERROR + "Android: No CMAKE_SYSROOT was selected." + ) +endif() + +set(CMAKE_BUILD_TYPE_INIT Debug) diff --git a/Modules/Platform/Android.cmake b/Modules/Platform/Android.cmake index 1bdad04..3d69733 100644 --- a/Modules/Platform/Android.cmake +++ b/Modules/Platform/Android.cmake @@ -1,5 +1,7 @@ include(Platform/Linux) +set(ANDROID 1) + # Android has soname, but binary names must end in ".so" so we cannot append # a version number. Also we cannot portably represent symlinks on the host. set(CMAKE_PLATFORM_NO_VERSIONED_SONAME 1) diff --git a/Modules/Platform/Android/Determine-Compiler-NDK.cmake b/Modules/Platform/Android/Determine-Compiler-NDK.cmake new file mode 100644 index 0000000..8bd0de9 --- /dev/null +++ b/Modules/Platform/Android/Determine-Compiler-NDK.cmake @@ -0,0 +1,256 @@ +#============================================================================= +# Copyright 2015-2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# In Android NDK releases there is build system toolchain selection logic in +# these files: +# +# * <ndk>/build/core/init.mk +# * <ndk>/build/core/setup-toolchain.mk +# * <ndk>/[build/core/]toolchains/<toolchain>/{config.mk,setup.mk} +# +# We parse information out of the ``config.mk`` and ``setup.mk`` files below. +# +# There is also a "toolchains" directory with the prebuilt toolchains themselves: +# +# * <triple-or-arch>-<gcc-version>/prebuilt/<host>/bin/<triple>-gcc(.exe)? +# The gcc compiler to be invoked. +# +# * llvm*/prebuilt/<host>/bin/clang +# The clang compiler to be invoked with flags: +# -target <triple> +# -gcc-toolchain <ndk>/toolchains/<triple-or-arch>-<gcc-version> + +# Glob available toolchains in the NDK, restricted by any version request. +if(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION STREQUAL "clang") + set(_ANDROID_TOOL_PATTERNS "*-clang" "*-clang[0-9].[0-9]") +elseif(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION) + if(NOT CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION MATCHES "^(clang)?[0-9]\\.[0-9]$") + message(FATAL_ERROR + "Android: The CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION value '${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}' " + "is not one of the allowed forms:\n" + " <major>.<minor> = GCC of specified version\n" + " clang<major>.<minor> = Clang of specified version\n" + " clang = Clang of most recent available version\n" + ) + endif() + set(_ANDROID_TOOL_PATTERNS "*-${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}") +else() + set(_ANDROID_TOOL_PATTERNS "*-[0-9].[0-9]") +endif() +set(_ANDROID_CONFIG_MK_PATTERNS) +foreach(base "build/core/toolchains" "toolchains") + foreach(pattern IN LISTS _ANDROID_TOOL_PATTERNS) + list(APPEND _ANDROID_CONFIG_MK_PATTERNS + "${CMAKE_ANDROID_NDK}/${base}/${pattern}/config.mk" + ) + endforeach() +endforeach() +unset(_ANDROID_TOOL_PATTERNS) +file(GLOB _ANDROID_CONFIG_MKS ${_ANDROID_CONFIG_MK_PATTERNS}) +unset(_ANDROID_CONFIG_MK_PATTERNS) + +# Find the newest toolchain version matching the ABI. +set(_ANDROID_TOOL_NAME "") +set(_ANDROID_TOOL_VERS 0) +set(_ANDROID_TOOL_SETUP_MK "") +foreach(config_mk IN LISTS _ANDROID_CONFIG_MKS) + # Check that the toolchain matches the ABI. + file(STRINGS "${config_mk}" _ANDROID_TOOL_ABIS REGEX "^TOOLCHAIN_ABIS :=.* ${CMAKE_ANDROID_ARCH_ABI}( |$)") + if(NOT _ANDROID_TOOL_ABIS) + continue() + endif() + unset(_ANDROID_TOOL_ABIS) + + # Check the version. + if("${config_mk}" MATCHES [[/([^/]+-(clang)?([0-9]\.[0-9]|))/config.mk$]]) + set(_ANDROID_CUR_NAME "${CMAKE_MATCH_1}") + set(_ANDROID_CUR_VERS "${CMAKE_MATCH_3}") + if(_ANDROID_TOOL_VERS STREQUAL "") + # already the latest possible + elseif(_ANDROID_CUR_VERS STREQUAL "" OR _ANDROID_CUR_VERS VERSION_GREATER _ANDROID_TOOL_VERS) + set(_ANDROID_TOOL_NAME "${_ANDROID_CUR_NAME}") + set(_ANDROID_TOOL_VERS "${_ANDROID_CUR_VERS}") + string(REPLACE "/config.mk" "/setup.mk" _ANDROID_TOOL_SETUP_MK "${config_mk}") + endif() + unset(_ANDROID_CUR_TOOL) + unset(_ANDROID_CUR_VERS) + endif() +endforeach() + +# Verify that we have a suitable toolchain. +if(NOT _ANDROID_TOOL_NAME) + if(_ANDROID_CONFIG_MKS) + string(REPLACE ";" "\n " _ANDROID_TOOLS_MSG "after considering:;${_ANDROID_CONFIG_MKS}") + else() + set(_ANDROID_TOOLS_MSG "") + endif() + if(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION) + string(CONCAT _ANDROID_TOOLS_MSG + "of the version specified by CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION:\n" + " ${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}\n" + "${_ANDROID_TOOLS_MSG}") + endif() + message(FATAL_ERROR + "Android: No toolchain for ABI '${CMAKE_ANDROID_ARCH_ABI}' found in the NDK:\n" + " ${CMAKE_ANDROID_NDK}\n" + "${_ANDROID_TOOLS_MSG}" + ) +endif() +unset(_ANDROID_CONFIG_MKS) + +# For clang toolchains we still need to find a gcc toolchain. +if(_ANDROID_TOOL_NAME MATCHES "-clang") + set(_ANDROID_TOOL_CLANG_NAME "${_ANDROID_TOOL_NAME}") + set(_ANDROID_TOOL_CLANG_VERS "${_ANDROID_TOOL_VERS}") + set(_ANDROID_TOOL_NAME "") + set(_ANDROID_TOOL_VERS "") +else() + set(_ANDROID_TOOL_CLANG_NAME "") + set(_ANDROID_TOOL_CLANG_VERS "") +endif() + +# Parse the toolchain setup.mk file to extract information we need. +# Their content is not standardized across toolchains or NDK versions, +# so we match known cases. Note that the parsing is stateful across +# lines because we need to substitute for some Make variable references. +if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG) + message(STATUS "loading: ${_ANDROID_TOOL_SETUP_MK}") +endif() +file(STRINGS "${_ANDROID_TOOL_SETUP_MK}" _ANDROID_TOOL_SETUP REGEX "^(LLVM|TOOLCHAIN)_[A-Z_]+ +:= +.*$") +unset(_ANDROID_TOOL_SETUP_MK) +set(_ANDROID_TOOL_PREFIX "") +set(_ANDROID_TOOL_NAME_ONLY "") +set(_ANDROID_TOOL_LLVM_NAME "") +set(_ANDROID_TOOL_LLVM_VERS "") +foreach(line IN LISTS _ANDROID_TOOL_SETUP) + if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG) + message(STATUS "setup.mk: ${line}") + endif() + + if(line MATCHES [[^TOOLCHAIN_PREFIX +:= +.*/bin/([^$/ ]*) *$]]) + # We just matched the toolchain prefix with no Make variable references. + set(_ANDROID_TOOL_PREFIX "${CMAKE_MATCH_1}") + elseif(_ANDROID_TOOL_CLANG_NAME) + # For clang toolchains we need to find more information. + if(line MATCHES [[^TOOLCHAIN_VERSION +:= +([0-9.]+) *$]]) + # We just matched the gcc toolchain version number. Save it for later. + set(_ANDROID_TOOL_VERS "${CMAKE_MATCH_1}") + elseif(line MATCHES [[^TOOLCHAIN_NAME +:= +(.*\$\(TOOLCHAIN_VERSION\)) *$]]) + # We just matched the gcc toolchain name with a version number placeholder, so substitute it. + # The gcc toolchain version number will have already been extracted from a TOOLCHAIN_VERSION line. + string(REPLACE "$(TOOLCHAIN_VERSION)" "${_ANDROID_TOOL_VERS}" _ANDROID_TOOL_NAME "${CMAKE_MATCH_1}") + elseif(line MATCHES [[^TOOLCHAIN_NAME +:= +([^$/ ]+) *$]]) + # We just matched the gcc toolchain name without version number. Save it for later. + set(_ANDROID_TOOL_NAME_ONLY "${CMAKE_MATCH_1}") + elseif(line MATCHES [[^TOOLCHAIN_PREFIX +:= +.*/bin/(\$\(TOOLCHAIN_NAME\)-) *$]]) + # We just matched the toolchain prefix with a name placholder, so substitute it. + # The gcc toolchain name will have already been extracted without version number from a TOOLCHAIN_NAME line. + string(REPLACE "$(TOOLCHAIN_NAME)" "${_ANDROID_TOOL_NAME_ONLY}" _ANDROID_TOOL_PREFIX "${CMAKE_MATCH_1}") + elseif(line MATCHES [[^LLVM_VERSION +:= +([0-9.]+)$]]) + # We just matched the llvm prebuilt binary toolchain version number. Save it for later. + set(_ANDROID_TOOL_LLVM_VERS "${CMAKE_MATCH_1}") + elseif(line MATCHES [[^LLVM_NAME +:= +(llvm-\$\(LLVM_VERSION\)) *$]]) + # We just matched the llvm prebuilt binary toolchain directory name with a version number placeholder, + # so substitute it. The llvm prebuilt binary toolchain version number will have already been extracted + # from a LLVM_VERSION line. + string(REPLACE "$(LLVM_VERSION)" "${_ANDROID_TOOL_LLVM_VERS}" _ANDROID_TOOL_LLVM_NAME "${CMAKE_MATCH_1}") + elseif(line MATCHES [[^LLVM_TOOLCHAIN_PREBUILT_ROOT +:= +\$\(call get-toolchain-root.*,([^$ ]+)\) *$]]) + # We just matched the llvm prebuilt binary toolchain directory name. + set(_ANDROID_TOOL_LLVM_NAME "${CMAKE_MATCH_1}") + elseif(line MATCHES [[^TOOLCHAIN_ROOT +:= +\$\(call get-toolchain-root.*,(\$\(TOOLCHAIN_NAME\)-[0-9.]+)\) *$]]) + # We just matched a placeholder for the name followed by a version number. + # The gcc toolchain name will have already been extracted without version number from a TOOLCHAIN_NAME line. + # Substitute for the placeholder to get the full gcc toolchain name. + string(REPLACE "$(TOOLCHAIN_NAME)" "${_ANDROID_TOOL_NAME_ONLY}" _ANDROID_TOOL_NAME "${CMAKE_MATCH_1}") + elseif(line MATCHES [[^TOOLCHAIN_ROOT +:= +\$\(call get-toolchain-root.*,([^$ ]+)\) *$]]) + # We just matched the full gcc toolchain name without placeholder. + set(_ANDROID_TOOL_NAME "${CMAKE_MATCH_1}") + endif() + endif() +endforeach() +unset(_ANDROID_TOOL_NAME_ONLY) +unset(_ANDROID_TOOL_LLVM_VERS) +unset(_ANDROID_TOOL_SETUP) + +# Fall back to parsing the version and prefix from the tool name. +if(NOT _ANDROID_TOOL_VERS AND "${_ANDROID_TOOL_NAME}" MATCHES "-([0-9.]+)$") + set(_ANDROID_TOOL_VERS "${CMAKE_MATCH_1}") +endif() +if(NOT _ANDROID_TOOL_PREFIX AND "${_ANDROID_TOOL_NAME}" MATCHES "^(.*-)[0-9.]+$") + set(_ANDROID_TOOL_PREFIX "${CMAKE_MATCH_1}") +endif() + +# Identify the host platform. +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(_ANDROID_HOST_DIR "darwin-x86_64") + else() + set(_ANDROID_HOST_DIR "darwin-x86") + endif() +elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(_ANDROID_HOST_DIR "linux-x86_64") + else() + set(_ANDROID_HOST_DIR "linux-x86") + endif() +elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64") + set(_ANDROID_HOST_DIR "windows-x86_64") + else() + set(_ANDROID_HOST_DIR "windows") + endif() +else() + message(FATAL_ERROR "Android: Builds hosted on '${CMAKE_HOST_SYSTEM_NAME}' not supported.") +endif() + +# Help CMakeFindBinUtils locate things. +set(_CMAKE_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_PREFIX}") + +set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "${_ANDROID_TOOL_VERS}") +set(_ANDROID_TOOL_C_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${_ANDROID_HOST_DIR}/bin/${_ANDROID_TOOL_PREFIX}") +set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "${_ANDROID_HOST_EXT}") + +set(_ANDROID_TOOL_CXX_TOOLCHAIN_VERSION "${_ANDROID_TOOL_C_TOOLCHAIN_VERSION}") +set(_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_C_TOOLCHAIN_PREFIX}") +set(_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX "${_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX}") + +if(_ANDROID_TOOL_CLANG_NAME) + message(STATUS "Android: Selected Clang toolchain '${_ANDROID_TOOL_CLANG_NAME}' with GCC toolchain '${_ANDROID_TOOL_NAME}'") + set(_ANDROID_TOOL_C_COMPILER "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_LLVM_NAME}/prebuilt/${_ANDROID_HOST_DIR}/bin/clang${_ANDROID_HOST_EXT}") + set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN ${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${_ANDROID_HOST_DIR}) + set(_ANDROID_TOOL_CXX_COMPILER "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_LLVM_NAME}/prebuilt/${_ANDROID_HOST_DIR}/bin/clang++${_ANDROID_HOST_EXT}") + set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN}") +else() + message(STATUS "Android: Selected GCC toolchain '${_ANDROID_TOOL_NAME}'") + set(_ANDROID_TOOL_C_COMPILER "${_ANDROID_TOOL_C_TOOLCHAIN_PREFIX}gcc${_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX}") + set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN "") + set(_ANDROID_TOOL_CXX_COMPILER "${_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX}g++${_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX}") + set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "") +endif() + +if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG) + message(STATUS "_ANDROID_TOOL_NAME=${_ANDROID_TOOL_NAME}") + message(STATUS "_ANDROID_TOOL_VERS=${_ANDROID_TOOL_VERS}") + message(STATUS "_ANDROID_TOOL_PREFIX=${_ANDROID_TOOL_PREFIX}") + message(STATUS "_ANDROID_TOOL_CLANG_NAME=${_ANDROID_TOOL_CLANG_NAME}") + message(STATUS "_ANDROID_TOOL_CLANG_VERS=${_ANDROID_TOOL_CLANG_VERS}") + message(STATUS "_ANDROID_TOOL_LLVM_NAME=${_ANDROID_TOOL_LLVM_NAME}") +endif() + +unset(_ANDROID_TOOL_NAME) +unset(_ANDROID_TOOL_VERS) +unset(_ANDROID_TOOL_PREFIX) +unset(_ANDROID_TOOL_CLANG_NAME) +unset(_ANDROID_TOOL_CLANG_VERS) +unset(_ANDROID_TOOL_LLVM_NAME) +unset(_ANDROID_HOST_DIR) diff --git a/Modules/Platform/Android/Determine-Compiler-Standalone.cmake b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake new file mode 100644 index 0000000..64d4ccf --- /dev/null +++ b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake @@ -0,0 +1,69 @@ +#============================================================================= +# Copyright 2015-2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +set(_ANDROID_TOOL_C_COMPILER "") +set(_ANDROID_TOOL_CXX_COMPILER "") +set(_ANDROID_TOOL_PREFIX "") +file(GLOB _gcc "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/*-gcc${_ANDROID_HOST_EXT}") +foreach(gcc IN LISTS _gcc) + if("${gcc}" MATCHES "/bin/([^/]*)gcc${_ANDROID_HOST_EXT}$") + set(_ANDROID_TOOL_PREFIX "${CMAKE_MATCH_1}") + break() + endif() +endforeach() + +if(NOT _ANDROID_TOOL_PREFIX) + message(FATAL_ERROR + "Android: No '*-gcc' compiler found in CMAKE_ANDROID_STANDALONE_TOOLCHAIN:\n" + " ${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}" + ) +endif() + +# Help CMakeFindBinUtils locate things. +set(_CMAKE_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_PREFIX}") + +execute_process( + COMMAND "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/${_ANDROID_TOOL_PREFIX}gcc${_ANDROID_HOST_EXT}" -dumpversion + OUTPUT_VARIABLE _gcc_version + ERROR_VARIABLE _gcc_error + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +if(_gcc_version MATCHES "^([0-9]+\\.[0-9]+)") + set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "${CMAKE_MATCH_1}") +else() + message(FATAL_ERROR + "Android: Failed to extract the standalone toolchain version. The command:\n" + " '${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/${_ANDROID_TOOL_PREFIX}gcc${_ANDROID_HOST_EXT}' '-dumpversion'\n" + "produced output:\n" + " ${_gcc_version}\n" + ) +endif() + +set(_ANDROID_TOOL_C_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/${_ANDROID_TOOL_PREFIX}") +set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "${_ANDROID_HOST_EXT}") + +set(_ANDROID_TOOL_CXX_TOOLCHAIN_VERSION "${_ANDROID_TOOL_C_TOOLCHAIN_VERSION}") +set(_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_C_TOOLCHAIN_PREFIX}") +set(_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX "${_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX}") + +if(EXISTS "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${_ANDROID_HOST_EXT}") + set(_ANDROID_TOOL_C_COMPILER "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${_ANDROID_HOST_EXT}") + set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}") + set(_ANDROID_TOOL_CXX_COMPILER "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/clang++${_ANDROID_HOST_EXT}") + set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}") +else() + set(_ANDROID_TOOL_C_COMPILER "${_ANDROID_TOOL_C_TOOLCHAIN_PREFIX}gcc${_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX}") + set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN "") + set(_ANDROID_TOOL_CXX_COMPILER "${_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX}g++${_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX}") + set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "") +endif() diff --git a/Modules/Platform/Android/Determine-Compiler.cmake b/Modules/Platform/Android/Determine-Compiler.cmake new file mode 100644 index 0000000..65223dc --- /dev/null +++ b/Modules/Platform/Android/Determine-Compiler.cmake @@ -0,0 +1,80 @@ +#============================================================================= +# Copyright 2015-2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# This module is shared by multiple languages; use include blocker. +if(__ANDROID_DETERMINE_COMPILER) + return() +endif() +set(__ANDROID_DETERMINE_COMPILER 1) + +# Support for NVIDIA Nsight Tegra Visual Studio Edition was previously +# implemented in the CMake VS IDE generators. Avoid interfering with +# that functionality for now. Later we may try to integrate this. +if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android") + macro(__android_determine_compiler lang) + endmacro() + return() +endif() + +# Commonly used Android toolchain files that pre-date CMake upstream support +# set CMAKE_SYSTEM_VERSION to 1. Avoid interfering with them. +if(CMAKE_SYSTEM_VERSION EQUAL 1) + macro(__android_determine_compiler lang) + endmacro() + return() +endif() + +# Identify the host platform. +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + set(_ANDROID_HOST_EXT "") +elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + set(_ANDROID_HOST_EXT "") +elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(_ANDROID_HOST_EXT ".exe") +else() + message(FATAL_ERROR "Android: Builds hosted on '${CMAKE_HOST_SYSTEM_NAME}' not supported.") +endif() + +if(CMAKE_ANDROID_NDK) + include(Platform/Android/Determine-Compiler-NDK) +elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN) + include(Platform/Android/Determine-Compiler-Standalone) +else() + set(_ANDROID_TOOL_C_COMPILER "") + set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "") + set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN "") + set(_ANDROID_TOOL_C_TOOLCHAIN_PREFIX "") + set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "") + set(_ANDROID_TOOL_CXX_COMPILER "") + set(_ANDROID_TOOL_CXX_TOOLCHAIN_VERSION "") + set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "") + set(_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX "") + set(_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX "") +endif() + +unset(_ANDROID_HOST_EXT) + +macro(__android_determine_compiler lang) + if(_ANDROID_TOOL_${lang}_COMPILER) + set(CMAKE_${lang}_COMPILER "${_ANDROID_TOOL_${lang}_COMPILER}") + set(CMAKE_${lang}_COMPILER_EXTERNAL_TOOLCHAIN "${_ANDROID_TOOL_${lang}_COMPILER_EXTERNAL_TOOLCHAIN}") + + # Save the Android-specific information in CMake${lang}Compiler.cmake. + set(CMAKE_${lang}_COMPILER_CUSTOM_CODE " +set(CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_VERSION}\") +set(CMAKE_${lang}_COMPILER_EXTERNAL_TOOLCHAIN \"${_ANDROID_TOOL_${lang}_COMPILER_EXTERNAL_TOOLCHAIN}\") +set(CMAKE_${lang}_ANDROID_TOOLCHAIN_PREFIX \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_PREFIX}\") +set(CMAKE_${lang}_ANDROID_TOOLCHAIN_SUFFIX \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_SUFFIX}\") +") + endif() +endmacro() diff --git a/Modules/Platform/Android/abi-arm64-v8a-Clang.cmake b/Modules/Platform/Android/abi-arm64-v8a-Clang.cmake new file mode 100644 index 0000000..3ff1fe5 --- /dev/null +++ b/Modules/Platform/Android/abi-arm64-v8a-Clang.cmake @@ -0,0 +1,8 @@ +# <ndk>/build/core/toolchains/aarch64-linux-android-clang/setup.mk +set(_ANDROID_ABI_CLANG_TARGET "aarch64-none-linux-android") + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -fpic" + ) + +include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-arm64-v8a-GNU.cmake b/Modules/Platform/Android/abi-arm64-v8a-GNU.cmake new file mode 100644 index 0000000..538ec2f --- /dev/null +++ b/Modules/Platform/Android/abi-arm64-v8a-GNU.cmake @@ -0,0 +1,6 @@ +# <ndk>/build/core/toolchains/aarch64-linux-android-4.9/setup.mk +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -fpic" + ) + +include(Platform/Android/abi-common-GNU) diff --git a/Modules/Platform/Android/abi-armeabi-Clang.cmake b/Modules/Platform/Android/abi-armeabi-Clang.cmake new file mode 100644 index 0000000..4fc3009 --- /dev/null +++ b/Modules/Platform/Android/abi-armeabi-Clang.cmake @@ -0,0 +1,20 @@ +# <ndk>/build/core/toolchains/arm-linux-androideabi-clang/setup.mk +set(_ANDROID_ABI_CLANG_TARGET "armv5te-none-linux-androideabi") + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -march=armv5te" + ) + +if(CMAKE_ANDROID_ARM_MODE) + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm") +else() + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb") +endif() + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -msoft-float" + " -mtune=xscale" + " -fpic" + ) + +include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-armeabi-GNU.cmake b/Modules/Platform/Android/abi-armeabi-GNU.cmake new file mode 100644 index 0000000..10cac00 --- /dev/null +++ b/Modules/Platform/Android/abi-armeabi-GNU.cmake @@ -0,0 +1,18 @@ +# <ndk>/build/core/toolchains/arm-linux-androideabi-4.9/setup.mk +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -march=armv5te" + ) + +if(CMAKE_ANDROID_ARM_MODE) + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm") +else() + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb") +endif() + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -msoft-float" + " -mtune=xscale" + " -fpic" + ) + +include(Platform/Android/abi-common-GNU) diff --git a/Modules/Platform/Android/abi-armeabi-v6-Clang.cmake b/Modules/Platform/Android/abi-armeabi-v6-Clang.cmake new file mode 100644 index 0000000..15f1d4a --- /dev/null +++ b/Modules/Platform/Android/abi-armeabi-v6-Clang.cmake @@ -0,0 +1,19 @@ +# <ndk>/build/core/toolchains/arm-linux-androideabi-clang/setup.mk +set(_ANDROID_ABI_CLANG_TARGET "armv6-none-linux-androideabi") + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -march=armv6" + ) + +if(CMAKE_ANDROID_ARM_MODE) + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm") +else() + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb") +endif() + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -mfloat-abi=softfp" + " -fpic" + ) + +include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-armeabi-v6-GNU.cmake b/Modules/Platform/Android/abi-armeabi-v6-GNU.cmake new file mode 100644 index 0000000..7492de0 --- /dev/null +++ b/Modules/Platform/Android/abi-armeabi-v6-GNU.cmake @@ -0,0 +1,17 @@ +# <ndk>/build/core/toolchains/arm-linux-androideabi-4.9/setup.mk +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -march=armv6" + ) + +if(CMAKE_ANDROID_ARM_MODE) + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm") +else() + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb") +endif() + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -mfloat-abi=softfp" + " -fpic" + ) + +include(Platform/Android/abi-common-GNU) diff --git a/Modules/Platform/Android/abi-armeabi-v7a-Clang.cmake b/Modules/Platform/Android/abi-armeabi-v7a-Clang.cmake new file mode 100644 index 0000000..3a3efb3 --- /dev/null +++ b/Modules/Platform/Android/abi-armeabi-v7a-Clang.cmake @@ -0,0 +1,29 @@ +# <ndk>/build/core/toolchains/arm-linux-androideabi-clang/setup.mk +set(_ANDROID_ABI_CLANG_TARGET "armv7-none-linux-androideabi") + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -march=armv7-a" + ) + +if(CMAKE_ANDROID_ARM_MODE) + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm") +else() + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb") +endif() + +if(CMAKE_ANDROID_ARM_NEON) + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mfpu=neon") +else() + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mfpu=vfpv3-d16") +endif() + +string(APPEND _ANDROID_ABI_INIT_LDFLAGS + " -Wl,--fix-cortex-a8" + ) + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -mfloat-abi=softfp" + " -fpic" + ) + +include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-armeabi-v7a-GNU.cmake b/Modules/Platform/Android/abi-armeabi-v7a-GNU.cmake new file mode 100644 index 0000000..d27e37e --- /dev/null +++ b/Modules/Platform/Android/abi-armeabi-v7a-GNU.cmake @@ -0,0 +1,27 @@ +# <ndk>/build/core/toolchains/arm-linux-androideabi-4.9/setup.mk +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -march=armv7-a" + ) + +if(CMAKE_ANDROID_ARM_MODE) + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm") +else() + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb") +endif() + +if(CMAKE_ANDROID_ARM_NEON) + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mfpu=neon") +else() + string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mfpu=vfpv3-d16") +endif() + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -mfloat-abi=softfp" + " -fpic" + ) + +string(APPEND _ANDROID_ABI_INIT_LDFLAGS + " -Wl,--fix-cortex-a8" + ) + +include(Platform/Android/abi-common-GNU) diff --git a/Modules/Platform/Android/abi-common-Clang.cmake b/Modules/Platform/Android/abi-common-Clang.cmake new file mode 100644 index 0000000..6025170 --- /dev/null +++ b/Modules/Platform/Android/abi-common-Clang.cmake @@ -0,0 +1,6 @@ +string(APPEND _ANDROID_ABI_INIT_CFLAGS + #" -Wno-invalid-command-line-argument" + #" -Wno-unused-command-line-argument" + ) + +include(Platform/Android/abi-common) diff --git a/Modules/Platform/Android/abi-common-GNU.cmake b/Modules/Platform/Android/abi-common-GNU.cmake new file mode 100644 index 0000000..40d829f --- /dev/null +++ b/Modules/Platform/Android/abi-common-GNU.cmake @@ -0,0 +1 @@ +include(Platform/Android/abi-common) diff --git a/Modules/Platform/Android/abi-common.cmake b/Modules/Platform/Android/abi-common.cmake new file mode 100644 index 0000000..12d8e5c --- /dev/null +++ b/Modules/Platform/Android/abi-common.cmake @@ -0,0 +1,4 @@ +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -funwind-tables" + " -no-canonical-prefixes" + ) diff --git a/Modules/Platform/Android/abi-mips-Clang.cmake b/Modules/Platform/Android/abi-mips-Clang.cmake new file mode 100644 index 0000000..bf6b9fc --- /dev/null +++ b/Modules/Platform/Android/abi-mips-Clang.cmake @@ -0,0 +1,8 @@ +# <ndk>/build/core/toolchains/mipsel-linux-android-clang/setup.mk +set(_ANDROID_ABI_CLANG_TARGET "mipsel-none-linux-android") + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -fpic" + ) + +include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-mips-GNU.cmake b/Modules/Platform/Android/abi-mips-GNU.cmake new file mode 100644 index 0000000..d380440 --- /dev/null +++ b/Modules/Platform/Android/abi-mips-GNU.cmake @@ -0,0 +1,6 @@ +# <ndk>/build/core/toolchains/mipsel-linux-android-4.9/setup.mk +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -fpic" + ) + +include(Platform/Android/abi-common-GNU) diff --git a/Modules/Platform/Android/abi-mips64-Clang.cmake b/Modules/Platform/Android/abi-mips64-Clang.cmake new file mode 100644 index 0000000..1a94107 --- /dev/null +++ b/Modules/Platform/Android/abi-mips64-Clang.cmake @@ -0,0 +1,8 @@ +# <ndk>/build/core/toolchains/mips64el-linux-android-clang/setup.mk +set(_ANDROID_ABI_CLANG_TARGET "mips64el-none-linux-android") + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -fpic" + ) + +include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-mips64-GNU.cmake b/Modules/Platform/Android/abi-mips64-GNU.cmake new file mode 100644 index 0000000..4525d40 --- /dev/null +++ b/Modules/Platform/Android/abi-mips64-GNU.cmake @@ -0,0 +1,6 @@ +# <ndk>/build/core/toolchains/mips64el-linux-android-4.9/setup.mk +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -fpic" + ) + +include(Platform/Android/abi-common-GNU) diff --git a/Modules/Platform/Android/abi-x86-Clang.cmake b/Modules/Platform/Android/abi-x86-Clang.cmake new file mode 100644 index 0000000..f63ed36 --- /dev/null +++ b/Modules/Platform/Android/abi-x86-Clang.cmake @@ -0,0 +1,8 @@ +# <ndk>/build/core/toolchains/x86-clang/setup.mk +set(_ANDROID_ABI_CLANG_TARGET "i686-none-linux-android") + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -fPIC" + ) + +include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-x86-GNU.cmake b/Modules/Platform/Android/abi-x86-GNU.cmake new file mode 100644 index 0000000..76ea5ca --- /dev/null +++ b/Modules/Platform/Android/abi-x86-GNU.cmake @@ -0,0 +1,2 @@ +# <ndk>/build/core/toolchains/x86-4.9/setup.mk +include(Platform/Android/abi-common-GNU) diff --git a/Modules/Platform/Android/abi-x86_64-Clang.cmake b/Modules/Platform/Android/abi-x86_64-Clang.cmake new file mode 100644 index 0000000..c15042b --- /dev/null +++ b/Modules/Platform/Android/abi-x86_64-Clang.cmake @@ -0,0 +1,8 @@ +# <ndk>/build/core/toolchains/x86_64-clang/setup.mk +set(_ANDROID_ABI_CLANG_TARGET "x86_64-none-linux-android") + +string(APPEND _ANDROID_ABI_INIT_CFLAGS + " -fPIC" + ) + +include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-x86_64-GNU.cmake b/Modules/Platform/Android/abi-x86_64-GNU.cmake new file mode 100644 index 0000000..441bdcd --- /dev/null +++ b/Modules/Platform/Android/abi-x86_64-GNU.cmake @@ -0,0 +1,2 @@ +# <ndk>/build/core/toolchains/x86_64-4.9/setup.mk +include(Platform/Android/abi-common-GNU) diff --git a/Modules/Platform/Android/ndk-stl-c++.cmake b/Modules/Platform/Android/ndk-stl-c++.cmake new file mode 100644 index 0000000..14748a1 --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-c++.cmake @@ -0,0 +1,13 @@ +# <ndk>/sources/cxx-stl/llvm-libc++/Android.mk +set(_ANDROID_STL_RTTI 1) +set(_ANDROID_STL_EXCEPTIONS 1) +macro(__android_stl_cxx lang filename) + # Add the include directory. + __android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libcxx/include" 1) + + # Add a secondary include directory if it exists. + __android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/android/support/include" 0) + + # Add the library file. + __android_stl_lib(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${CMAKE_ANDROID_ARCH_ABI}/${filename}" 1) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-c++_shared.cmake b/Modules/Platform/Android/ndk-stl-c++_shared.cmake new file mode 100644 index 0000000..f585adb --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-c++_shared.cmake @@ -0,0 +1,4 @@ +include(Platform/Android/ndk-stl-c++) +macro(__android_stl lang) + __android_stl_cxx(${lang} libc++_shared.so) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-c++_static.cmake b/Modules/Platform/Android/ndk-stl-c++_static.cmake new file mode 100644 index 0000000..8e562f8 --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-c++_static.cmake @@ -0,0 +1,6 @@ +include(Platform/Android/ndk-stl-c++) +macro(__android_stl lang) + __android_stl_cxx(${lang} libc++_static.a) + __android_stl_lib(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${CMAKE_ANDROID_ARCH_ABI}/libc++abi.a" 0) + __android_stl_lib(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${CMAKE_ANDROID_ARCH_ABI}/libandroid_support.a" 0) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-gabi++.cmake b/Modules/Platform/Android/ndk-stl-gabi++.cmake new file mode 100644 index 0000000..850a47a --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-gabi++.cmake @@ -0,0 +1,7 @@ +# <ndk>/sources/cxx-stl/gabi++/Android.mk +set(_ANDROID_STL_RTTI 1) +set(_ANDROID_STL_EXCEPTIONS 1) +macro(__android_stl_gabixx lang filename) + __android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gabi++/include" 1) + __android_stl_lib(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${CMAKE_ANDROID_ARCH_ABI}/${filename}" 1) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-gabi++_shared.cmake b/Modules/Platform/Android/ndk-stl-gabi++_shared.cmake new file mode 100644 index 0000000..314c1e0 --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-gabi++_shared.cmake @@ -0,0 +1,4 @@ +include(Platform/Android/ndk-stl-gabi++) +macro(__android_stl lang) + __android_stl_gabixx(${lang} libgabi++_shared.so) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-gabi++_static.cmake b/Modules/Platform/Android/ndk-stl-gabi++_static.cmake new file mode 100644 index 0000000..f4a1d3c --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-gabi++_static.cmake @@ -0,0 +1,4 @@ +include(Platform/Android/ndk-stl-gabi++) +macro(__android_stl lang) + __android_stl_gabixx(${lang} libgabi++_static.a) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-gnustl.cmake b/Modules/Platform/Android/ndk-stl-gnustl.cmake new file mode 100644 index 0000000..b3226ee --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-gnustl.cmake @@ -0,0 +1,9 @@ +# <ndk>/sources/cxx-stl/gnu-libstdc++/Android.mk +set(_ANDROID_STL_RTTI 1) +set(_ANDROID_STL_EXCEPTIONS 1) +macro(__android_stl_gnustl lang filename) + __android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION}/include" 1) + __android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION}/libs/${CMAKE_ANDROID_ARCH_ABI}/include" 1) + __android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION}/include/backward" 1) + __android_stl_lib(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION}/libs/${CMAKE_ANDROID_ARCH_ABI}/${filename}" 1) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-gnustl_shared.cmake b/Modules/Platform/Android/ndk-stl-gnustl_shared.cmake new file mode 100644 index 0000000..f20cc4d --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-gnustl_shared.cmake @@ -0,0 +1,4 @@ +include(Platform/Android/ndk-stl-gnustl) +macro(__android_stl lang) + __android_stl_gnustl(${lang} libgnustl_shared.so) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-gnustl_static.cmake b/Modules/Platform/Android/ndk-stl-gnustl_static.cmake new file mode 100644 index 0000000..af4cc2a --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-gnustl_static.cmake @@ -0,0 +1,4 @@ +include(Platform/Android/ndk-stl-gnustl) +macro(__android_stl lang) + __android_stl_gnustl(${lang} libgnustl_static.a) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-none.cmake b/Modules/Platform/Android/ndk-stl-none.cmake new file mode 100644 index 0000000..9049c91 --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-none.cmake @@ -0,0 +1,2 @@ +macro(__android_stl lang) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-stlport.cmake b/Modules/Platform/Android/ndk-stl-stlport.cmake new file mode 100644 index 0000000..eab6b94 --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-stlport.cmake @@ -0,0 +1,7 @@ +# <ndk>/sources/cxx-stl/stlport/Android.mk +set(_ANDROID_STL_RTTI 1) +set(_ANDROID_STL_EXCEPTIONS 1) +macro(__android_stl_stlport lang filename) + __android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/stlport/stlport" 1) + __android_stl_lib(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/stlport/libs/${CMAKE_ANDROID_ARCH_ABI}/${filename}" 1) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-stlport_shared.cmake b/Modules/Platform/Android/ndk-stl-stlport_shared.cmake new file mode 100644 index 0000000..2b5846b --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-stlport_shared.cmake @@ -0,0 +1,4 @@ +include(Platform/Android/ndk-stl-stlport) +macro(__android_stl lang) + __android_stl_stlport(${lang} libstlport_shared.so) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-stlport_static.cmake b/Modules/Platform/Android/ndk-stl-stlport_static.cmake new file mode 100644 index 0000000..bf60307 --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-stlport_static.cmake @@ -0,0 +1,4 @@ +include(Platform/Android/ndk-stl-stlport) +macro(__android_stl lang) + __android_stl_stlport(${lang} libstlport_static.a) +endmacro() diff --git a/Modules/Platform/Android/ndk-stl-system.cmake b/Modules/Platform/Android/ndk-stl-system.cmake new file mode 100644 index 0000000..dd554fe --- /dev/null +++ b/Modules/Platform/Android/ndk-stl-system.cmake @@ -0,0 +1,6 @@ +# <ndk>/android-ndk-r11c/sources/cxx-stl/system/Android.mk +set(_ANDROID_STL_RTTI 0) +set(_ANDROID_STL_EXCEPTIONS 0) +macro(__android_stl lang) + __android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/system/include" 1) +endmacro() |