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
...
This commit is contained in:
Brad King 2016-08-24 09:45:50 -04:00 committed by CMake Topic Stage
commit 96de37092a
124 changed files with 2264 additions and 28 deletions

View File

@ -290,12 +290,206 @@ Windows Store may look like this:
set(CMAKE_SYSTEM_NAME WindowsStore)
set(CMAKE_SYSTEM_VERSION 8.1)
Cross Compiling using NVIDIA Nsight Tegra
-----------------------------------------
.. _`Cross Compiling for Android`:
A toolchain file to configure a Visual Studio generator to
build using NVIDIA Nsight Tegra targeting Android may look
like this:
Cross Compiling for Android
---------------------------
A toolchain file may configure cross-compiling for Android by setting the
:variable:`CMAKE_SYSTEM_NAME` variable to ``Android``. Further configuration
is specific to the Android development environment to be used.
For :ref:`Visual Studio Generators`, CMake expects :ref:`NVIDIA Nsight Tegra
Visual Studio Edition <Cross Compiling for Android with NVIDIA Nsight Tegra
Visual Studio Edition>` to be installed. See that section for further
configuration details.
For :ref:`Makefile Generators` and the :generator:`Ninja` generator,
CMake expects one of these environments:
* :ref:`NDK <Cross Compiling for Android with the NDK>`
* :ref:`Standalone Toolchain <Cross Compiling for Android with a Standalone Toolchain>`
CMake uses the following steps to select one of the environments:
* If the :variable:`CMAKE_ANDROID_NDK` variable is set, the NDK at the
specified location will be used.
* Else, if the :variable:`CMAKE_ANDROID_STANDALONE_TOOLCHAIN` variable
is set, the Standalone Toolchain at the specified location will be used.
* Else, if the :variable:`CMAKE_SYSROOT` variable is set to a directory
of the form ``<ndk>/platforms/android-<api>/arch-<arch>``, the ``<ndk>``
part will be used as the value of :variable:`CMAKE_ANDROID_NDK` and the
NDK will be used.
* Else, if the :variable:`CMAKE_SYSROOT` variable is set to a directory of the
form ``<standalone-toolchain>/sysroot``, the ``<standalone-toolchain>`` part
will be used as the value of :variable:`CMAKE_ANDROID_STANDALONE_TOOLCHAIN`
and the Standalone Toolchain will be used.
* Else, if a cmake variable ``ANDROID_NDK`` is set it will be used
as the value of :variable:`CMAKE_ANDROID_NDK`, and the NDK will be used.
* Else, if a cmake variable ``ANDROID_STANDALONE_TOOLCHAIN`` is set, it will be
used as the value of :variable:`CMAKE_ANDROID_STANDALONE_TOOLCHAIN`, and the
Standalone Toolchain will be used.
* Else, if an environment variable ``ANDROID_NDK_ROOT`` or
``ANDROID_NDK`` is set, it will be used as the value of
:variable:`CMAKE_ANDROID_NDK`, and the NDK will be used.
* Else, if an environment variable ``ANDROID_STANDALONE_TOOLCHAIN`` is
set then it will be used as the value of
:variable:`CMAKE_ANDROID_STANDALONE_TOOLCHAIN`, and the Standalone
Toolchain will be used.
* Else, an error diagnostic will be issued that neither the NDK or
Standalone Toolchain can be found.
.. _`Cross Compiling for Android with the NDK`:
Cross Compiling for Android with the NDK
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A toolchain file may configure :ref:`Makefile Generators` or the
:generator:`Ninja` generator to target Android for cross-compiling.
Configure use of an Android NDK with the following variables:
:variable:`CMAKE_SYSTEM_NAME`
Set to ``Android``. Must be specified to enable cross compiling
for Android.
:variable:`CMAKE_SYSTEM_VERSION`
Set to the Android API level. If not specified, the value is
determined as follows:
* If the :variable:`CMAKE_ANDROID_API` variable is set, its value
is used as the API level.
* If the :variable:`CMAKE_SYSROOT` variable is set, the API level is
detected from the NDK directory structure containing the sysroot.
* Otherwise, the latest API level available in the NDK is used.
:variable:`CMAKE_ANDROID_ARCH_ABI`
Set to the Android ABI (architecture). If not specified, this
variable will default to ``armeabi``.
The :variable:`CMAKE_ANDROID_ARCH` variable will be computed
from ``CMAKE_ANDROID_ARCH_ABI`` automatically.
Also see the :variable:`CMAKE_ANDROID_ARM_MODE` and
:variable:`CMAKE_ANDROID_ARM_NEON` variables.
:variable:`CMAKE_ANDROID_NDK`
Set to the absolute path to the Android NDK root directory.
A ``${CMAKE_ANDROID_NDK}/platforms`` directory must exist.
If not specified, a default for this variable will be chosen
as specified :ref:`above <Cross Compiling for Android>`.
:variable:`CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION`
Set to the version of the NDK toolchain to be selected as the compiler.
If not specified, the latest available GCC toolchain will be used.
:variable:`CMAKE_ANDROID_STL_TYPE`
Set to specify which C++ standard library to use. If not specified,
a default will be selected as described in the variable documentation.
The following variables will be computed and provided automatically:
:variable:`CMAKE_<LANG>_ANDROID_TOOLCHAIN_PREFIX`
The absolute path prefix to the binutils in the NDK toolchain.
:variable:`CMAKE_<LANG>_ANDROID_TOOLCHAIN_SUFFIX`
The host platform suffix of the binutils in the NDK toolchain.
For example, a toolchain file might contain:
.. code-block:: cmake
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 21) # API level
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
set(CMAKE_ANDROID_NDK /path/to/android-ndk)
set(CMAKE_ANDROID_STL_TYPE gnustl_static)
Alternatively one may specify the values without a toolchain file:
.. code-block:: console
$ cmake ../src \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=21 \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_ANDROID_NDK=/path/to/android-ndk \
-DCMAKE_ANDROID_STL_TYPE=gnustl_static
.. _`Cross Compiling for Android with a Standalone Toolchain`:
Cross Compiling for Android with a Standalone Toolchain
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A toolchain file may configure :ref:`Makefile Generators` or the
:generator:`Ninja` generator to target Android for cross-compiling
using a standalone toolchain.
Configure use of an Android standalone toolchain with the following variables:
:variable:`CMAKE_SYSTEM_NAME`
Set to ``Android``. Must be specified to enable cross compiling
for Android.
:variable:`CMAKE_ANDROID_STANDALONE_TOOLCHAIN`
Set to the absolute path to the standalone toolchain root directory.
A ``${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot`` directory
must exist.
If not specified, a default for this variable will be chosen
as specified :ref:`above <Cross Compiling for Android>`.
:variable:`CMAKE_ANDROID_ARM_MODE`
When the standalone toolchain targets ARM, optionally set this to ``ON``
to target 32-bit ARM instead of 16-bit Thumb.
See variable documentation for details.
:variable:`CMAKE_ANDROID_ARM_NEON`
When the standalone toolchain targets ARM v7, optionally set thisto ``ON``
to target ARM NEON devices. See variable documentation for details.
The following variables will be computed and provided automatically:
:variable:`CMAKE_SYSTEM_VERSION`
The Android API level detected from the standalone toolchain.
:variable:`CMAKE_ANDROID_ARCH_ABI`
The Android ABI detected from the standalone toolchain.
:variable:`CMAKE_<LANG>_ANDROID_TOOLCHAIN_PREFIX`
The absolute path prefix to the binutils in the standalone toolchain.
:variable:`CMAKE_<LANG>_ANDROID_TOOLCHAIN_SUFFIX`
The host platform suffix of the binutils in the standalone toolchain.
For example, a toolchain file might contain:
.. code-block:: cmake
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_ANDROID_STANDALONE_TOOLCHAIN /path/to/android-toolchain)
Alternatively one may specify the values without a toolchain file:
.. code-block:: console
$ cmake ../src \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=/path/to/android-toolchain
.. _`Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio Edition`:
Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio Edition
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A toolchain file to configure one of the :ref:`Visual Studio Generators`
to build using NVIDIA Nsight Tegra targeting Android may look like this:
.. code-block:: cmake

View File

@ -173,6 +173,7 @@ Variables that Describe the System
.. toctree::
:maxdepth: 1
/variable/ANDROID
/variable/APPLE
/variable/BORLAND
/variable/CMAKE_CL_64
@ -225,6 +226,9 @@ Variables that Control the Build
/variable/CMAKE_ANDROID_API
/variable/CMAKE_ANDROID_API_MIN
/variable/CMAKE_ANDROID_ARCH
/variable/CMAKE_ANDROID_ARCH_ABI
/variable/CMAKE_ANDROID_ARM_MODE
/variable/CMAKE_ANDROID_ARM_NEON
/variable/CMAKE_ANDROID_ASSETS_DIRECTORIES
/variable/CMAKE_ANDROID_GUI
/variable/CMAKE_ANDROID_JAR_DEPENDENCIES
@ -232,11 +236,14 @@ Variables that Control the Build
/variable/CMAKE_ANDROID_JAVA_SOURCE_DIR
/variable/CMAKE_ANDROID_NATIVE_LIB_DEPENDENCIES
/variable/CMAKE_ANDROID_NATIVE_LIB_DIRECTORIES
/variable/CMAKE_ANDROID_NDK
/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION
/variable/CMAKE_ANDROID_PROCESS_MAX
/variable/CMAKE_ANDROID_PROGUARD
/variable/CMAKE_ANDROID_PROGUARD_CONFIG_PATH
/variable/CMAKE_ANDROID_SECURE_PROPS_PATH
/variable/CMAKE_ANDROID_SKIP_ANT_STEP
/variable/CMAKE_ANDROID_STANDALONE_TOOLCHAIN
/variable/CMAKE_ANDROID_STL_TYPE
/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY
/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY_CONFIG
@ -337,6 +344,8 @@ Variables for Languages
/variable/CMAKE_Fortran_MODDIR_FLAG
/variable/CMAKE_Fortran_MODOUT_FLAG
/variable/CMAKE_INTERNAL_PLATFORM_ABI
/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_PREFIX
/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_SUFFIX
/variable/CMAKE_LANG_ARCHIVE_APPEND
/variable/CMAKE_LANG_ARCHIVE_CREATE
/variable/CMAKE_LANG_ARCHIVE_FINISH

View File

@ -1,7 +1,8 @@
ANDROID_API
-----------
Set the Android Target API version (e.g. ``15``). The version number
must be a positive decimal integer. This property is initialized by
the value of the :variable:`CMAKE_ANDROID_API` variable if it is set
when a target is created.
When :ref:`Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio
Edition`, this property sets the Android target API version (e.g. ``15``).
The version number must be a positive decimal integer. This property is
initialized by the value of the :variable:`CMAKE_ANDROID_API` variable if
it is set when a target is created.

View File

@ -1,7 +1,8 @@
ANDROID_ARCH
------------
Set the Android target architecture.
When :ref:`Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio
Edition`, this property sets the Android target architecture.
This is a string property that could be set to the one of
the following values:

View File

@ -1,7 +1,9 @@
ANDROID_GUI
-----------
Build an executable as an application package on Android.
When :ref:`Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio
Edition`, this property specifies whether to build an executable as an
application package on Android.
When this property is set to true the executable when built for Android
will be created as an application package. This property is initialized

View File

@ -1,15 +1,27 @@
ANDROID_STL_TYPE
----------------
Set the Android property that defines the type of STL support for the project.
When :ref:`Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio
Edition`, this property specifies the type of STL support for the project.
This is a string property that could set to the one of the following values:
``none`` e.g. "No C++ Support"
``system`` e.g. "Minimal C++ without STL"
``gabi++_static`` e.g. "GAbi++ Static"
``gabi++_shared`` e.g. "GAbi++ Shared"
``gnustl_static`` e.g. "GNU libstdc++ Static"
``gnustl_shared`` e.g. "GNU libstdc++ Shared"
``stlport_static`` e.g. "STLport Static"
``stlport_shared`` e.g. "STLport Shared"
``none``
No C++ Support
``system``
Minimal C++ without STL
``gabi++_static``
GAbi++ Static
``gabi++_shared``
GAbi++ Shared
``gnustl_static``
GNU libstdc++ Static
``gnustl_shared``
GNU libstdc++ Shared
``stlport_static``
STLport Static
``stlport_shared``
STLport Shared
This property is initialized by the value of the
variable:`CMAKE_ANDROID_STL_TYPE` variable if it is set when a target is created.
:variable:`CMAKE_ANDROID_STL_TYPE` variable if it is set when a target is
created.

View File

@ -0,0 +1,5 @@
android-platform-modules
------------------------
* CMake now supports :ref:`Cross Compiling for Android` with simple
toolchain files.

View File

@ -0,0 +1,5 @@
ANDROID
-------
Set to ``1`` when the target system (:variable:`CMAKE_SYSTEM_NAME`) is
``Android``.

View File

@ -1,5 +1,11 @@
CMAKE_ANDROID_API
-----------------
Default value for the :prop_tgt:`ANDROID_API` target property.
See that target property for additional information.
When :ref:`Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio
Edition`, this variable may be set to specify the default value for the
:prop_tgt:`ANDROID_API` target property. See that target property for
additional information.
Otherwise, when :ref:`Cross Compiling for Android`, this variable provides
the Android API version number targeted. This will be the same value as
the :variable:`CMAKE_SYSTEM_VERSION` variable for ``Android`` platforms.

View File

@ -1,5 +1,19 @@
CMAKE_ANDROID_ARCH
------------------
Default value for the :prop_tgt:`ANDROID_ARCH` target property.
See that target property for additional information.
When :ref:`Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio
Edition`, this variable may be set to specify the default value for the
:prop_tgt:`ANDROID_ARCH` target property. See that target property for
additional information.
Otherwise, when :ref:`Cross Compiling for Android`, this variable provides
the name of the Android architecture corresponding to the value of the
:variable:`CMAKE_ANDROID_ARCH_ABI` variable. The architecture name
may be one of:
* ``arm``
* ``arm64``
* ``mips``
* ``mips64``
* ``x86``
* ``x86_64``

View File

@ -0,0 +1,17 @@
CMAKE_ANDROID_ARCH_ABI
----------------------
When :ref:`Cross Compiling for Android`, this variable specifies the
target architecture and ABI to be used. Valid values are:
* ``arm64-v8a``
* ``armeabi-v7a``
* ``armeabi-v6``
* ``armeabi``
* ``mips``
* ``mips64``
* ``x86``
* ``x86_64``
See also the :variable:`CMAKE_ANDROID_ARM_MODE` and
:variable:`CMAKE_ANDROID_ARM_NEON` variables.

View File

@ -0,0 +1,7 @@
CMAKE_ANDROID_ARM_MODE
----------------------
When :ref:`Cross Compiling for Android` and :variable:`CMAKE_ANDROID_ARCH_ABI`
is set to one of the ``armeabi`` architectures, set ``CMAKE_ANDROID_ARM_MODE``
to ``ON`` to target 32-bit ARM processors (``-marm``). Otherwise, the
default is to target the 16-bit Thumb processors (``-mthumb``).

View File

@ -0,0 +1,6 @@
CMAKE_ANDROID_ARM_NEON
----------------------
When :ref:`Cross Compiling for Android` and :variable:`CMAKE_ANDROID_ARCH_ABI`
is set to ``armeabi-v7a`` set ``CMAKE_ANDROID_ARM_NEON`` to ``ON`` to target
ARM NEON devices.

View File

@ -0,0 +1,7 @@
CMAKE_ANDROID_NDK
-----------------
When :ref:`Cross Compiling for Android with the NDK`, this variable holds
the absolute path to the root directory of the NDK. The directory must
contain a ``platforms`` subdirectory holding the ``android-<api>``
directories.

View File

@ -0,0 +1,13 @@
CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION
-----------------------------------
When :ref:`Cross Compiling for Android with the NDK`, this variable
may be set to specify the version of the toolchain to be used
as the compiler. The variable must be set to one of these forms:
* ``<major>.<minor>``: GCC of specified version
* ``clang<major>.<minor>``: Clang of specified version
* ``clang``: Clang of most recent available version
A toolchain of the requested version will be selected automatically to
match the ABI named in the :variable:`CMAKE_ANDROID_ARCH_ABI` variable.

View File

@ -0,0 +1,6 @@
CMAKE_ANDROID_STANDALONE_TOOLCHAIN
----------------------------------
When :ref:`Cross Compiling for Android with a Standalone Toolchain`, this
variable holds the absolute path to the root directory of the toolchain.
The specified directory must contain a ``sysroot`` subdirectory.

View File

@ -1,5 +1,36 @@
CMAKE_ANDROID_STL_TYPE
----------------------
Default value for the :prop_tgt:`ANDROID_STL_TYPE` target property.
See that target property for additional information.
When :ref:`Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio
Edition`, this variable may be set to specify the default value for the
:prop_tgt:`ANDROID_STL_TYPE` target property. See that target property
for additional information.
When :ref:`Cross Compiling for Android with the NDK`, this variable may be
set to specify the STL variant to be used. The value may be one of:
``none``
No C++ Support
``system``
Minimal C++ without STL
``gabi++_static``
GAbi++ Static
``gabi++_shared``
GAbi++ Shared
``gnustl_static``
GNU libstdc++ Static
``gnustl_shared``
GNU libstdc++ Shared
``c++_static``
LLVM libc++ Static
``c++_shared``
LLVM libc++ Shared
``stlport_static``
STLport Static
``stlport_shared``
STLport Shared
The default value is ``gnustl_static``. Note that this default differs from
the native NDK build system because CMake may be used to build projects for
Android that are not natively implemented for it and use the C++ standard
library.

View File

@ -0,0 +1,11 @@
CMAKE_<LANG>_ANDROID_TOOLCHAIN_PREFIX
-------------------------------------
When :ref:`Cross Compiling for Android` this variable contains the absolute
path prefixing the toolchain GNU compiler and its binutils.
See also :variable:`CMAKE_<LANG>_ANDROID_TOOLCHAIN_SUFFIX`.
For example, the path to the linker is::
${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}ld${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}

View File

@ -0,0 +1,7 @@
CMAKE_<LANG>_ANDROID_TOOLCHAIN_SUFFIX
-------------------------------------
When :ref:`Cross Compiling for Android` this variable contains the
host platform suffix of the toolchain GNU compiler and its binutils.
See also :variable:`CMAKE_<LANG>_ANDROID_TOOLCHAIN_PREFIX`.

View File

@ -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@

View File

@ -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@

View File

@ -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)

View File

@ -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@")

View File

@ -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)

View File

@ -0,0 +1,2 @@
include(Platform/Android-Clang)
__android_compiler_clang(C)

View File

@ -0,0 +1,2 @@
include(Platform/Android-Clang)
__android_compiler_clang(CXX)

View File

@ -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()

View File

@ -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()

View File

@ -0,0 +1,2 @@
include(Platform/Android/Determine-Compiler)
__android_determine_compiler(C)

View File

@ -0,0 +1,2 @@
include(Platform/Android/Determine-Compiler)
__android_determine_compiler(CXX)

View File

@ -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}'")

View File

@ -0,0 +1,2 @@
include(Platform/Android-GNU)
__android_compiler_gnu(C)

View File

@ -0,0 +1,2 @@
include(Platform/Android-GNU)
__android_compiler_gnu(CXX)

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1 @@
include(Platform/Android/abi-common)

View File

@ -0,0 +1,4 @@
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -funwind-tables"
" -no-canonical-prefixes"
)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1,2 @@
# <ndk>/build/core/toolchains/x86-4.9/setup.mk
include(Platform/Android/abi-common-GNU)

View File

@ -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)

View File

@ -0,0 +1,2 @@
# <ndk>/build/core/toolchains/x86_64-4.9/setup.mk
include(Platform/Android/abi-common-GNU)

View File

@ -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()

View File

@ -0,0 +1,4 @@
include(Platform/Android/ndk-stl-c++)
macro(__android_stl lang)
__android_stl_cxx(${lang} libc++_shared.so)
endmacro()

View File

@ -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()

View File

@ -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()

View File

@ -0,0 +1,4 @@
include(Platform/Android/ndk-stl-gabi++)
macro(__android_stl lang)
__android_stl_gabixx(${lang} libgabi++_shared.so)
endmacro()

View File

@ -0,0 +1,4 @@
include(Platform/Android/ndk-stl-gabi++)
macro(__android_stl lang)
__android_stl_gabixx(${lang} libgabi++_static.a)
endmacro()

View File

@ -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()

View File

@ -0,0 +1,4 @@
include(Platform/Android/ndk-stl-gnustl)
macro(__android_stl lang)
__android_stl_gnustl(${lang} libgnustl_shared.so)
endmacro()

View File

@ -0,0 +1,4 @@
include(Platform/Android/ndk-stl-gnustl)
macro(__android_stl lang)
__android_stl_gnustl(${lang} libgnustl_static.a)
endmacro()

View File

@ -0,0 +1,2 @@
macro(__android_stl lang)
endmacro()

View File

@ -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()

View File

@ -0,0 +1,4 @@
include(Platform/Android/ndk-stl-stlport)
macro(__android_stl lang)
__android_stl_stlport(${lang} libstlport_shared.so)
endmacro()

View File

@ -0,0 +1,4 @@
include(Platform/Android/ndk-stl-stlport)
macro(__android_stl lang)
__android_stl_stlport(${lang} libstlport_static.a)
endmacro()

View File

@ -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()

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,20 @@
^CMake Error at .*/Modules/Platform/Android-Determine.cmake:[0-9]+ \(message\):
The value of CMAKE_SYSROOT:
.*
does not match any of the forms:
<ndk>/platforms/android-<api>/arch-<arch>
<standalone-toolchain>/sysroot
where:
<ndk> = Android NDK directory \(with forward slashes\)
<api> = Android API version number \(decimal digits\)
<arch> = Android ARCH name \(lower case\)
<standalone-toolchain> = Path to standalone toolchain prefix
Call Stack \(most recent call first\):
.*/Modules/CMakeDetermineSystem.cmake:[0-9]+ \(include\)
CMakeLists.txt:2 \(project\)$

View File

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.6)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@ -0,0 +1,218 @@
cmake_minimum_required(VERSION 3.6)
include(RunCMake)
foreach(v TEST_ANDROID_NDK TEST_ANDROID_STANDALONE_TOOLCHAIN)
string(REPLACE "|" ";" ${v} "${${v}}")
endforeach()
function(run_Android case)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
${RunCMake_TEST_OPTIONS}
${ARGN}
)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(${case})
run_cmake_command(${case}-build ${CMAKE_COMMAND} --build .)
endfunction()
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_SYSROOT=${CMAKE_CURRENT_SOURCE_DIR}
)
run_cmake(BadSYSROOT)
unset(RunCMake_TEST_OPTIONS)
foreach(ndk IN LISTS TEST_ANDROID_NDK)
# Load available toolchain versions and abis.
file(GLOB _config_mks
"${ndk}/build/core/toolchains/*/config.mk"
"${ndk}/toolchains/*/config.mk"
)
set(_versions "")
set(_latest_gcc 0)
set(_latest_clang "")
set(_latest_clang_vers 0)
foreach(config_mk IN LISTS _config_mks)
file(STRINGS "${config_mk}" _abis REGEX "^TOOLCHAIN_ABIS +:= +[^ ].*( |$)")
if(_abis AND "${config_mk}" MATCHES [[-((clang)?([0-9]\.[0-9]|))/config\.mk$]])
set(_version "${CMAKE_MATCH_1}")
set(_is_clang "${CMAKE_MATCH_2}")
set(_cur_vers "${CMAKE_MATCH_3}")
if(_is_clang)
if(_latest_clang_vers STREQUAL "")
# already the latest possible
elseif(_cur_vers STREQUAL "" OR _cur_vers VERSION_GREATER _latest_clang_vers)
set(_latest_clang_vers "${_cur_vers}")
set(_latest_clang "${_version}")
endif()
else()
if(_version VERSION_GREATER _latest_gcc)
set(_latest_gcc ${_version})
endif()
endif()
list(APPEND _versions "${_version}")
string(REGEX MATCHALL "[a-z][a-z0-9_-]+" _abis "${_abis}")
list(APPEND _abis_${_version} ${_abis})
endif()
endforeach()
set(_abis_ ${_abis_${_latest_gcc}})
set(_abis_clang ${_abis_${_latest_clang}})
if(_versions MATCHES "clang")
set(_versions "clang" ${_versions})
endif()
list(REMOVE_DUPLICATES _versions)
list(SORT _versions)
set(_versions ";${_versions}")
foreach(vers IN LISTS _versions)
list(REMOVE_DUPLICATES _abis_${vers})
endforeach()
# Test failure cases.
message(STATUS "ndk='${ndk}'")
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_ARCH_ABI=badabi
)
run_cmake(ndk-badabi)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_ARCH_ABI=x86
-DCMAKE_ANDROID_ARM_MODE=0
)
run_cmake(ndk-badarm)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_ARM_NEON=0
)
run_cmake(ndk-badneon)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=badver
)
run_cmake(ndk-badver)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=1.0
)
run_cmake(ndk-badvernum)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_STL_TYPE=badstl
)
run_cmake(ndk-badstl)
unset(RunCMake_TEST_OPTIONS)
# Find a sysroot to test.
file(GLOB _sysroots "${ndk}/platforms/android-[0-9][0-9]/arch-arm")
if(_sysroots)
list(GET _sysroots 0 _sysroot)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_SYSROOT=${_sysroot}
)
run_cmake(ndk-sysroot-armeabi)
unset(RunCMake_TEST_OPTIONS)
endif()
# Find available STLs.
set(stl_types
none
system
gnustl_static
gnustl_shared
)
if(IS_DIRECTORY "${ndk}/sources/cxx-stl/gabi++/libs")
list(APPEND stl_types gabi++_static gabi++_shared)
endif()
if(IS_DIRECTORY "${ndk}/sources/cxx-stl/stlport/libs")
list(APPEND stl_types stlport_static stlport_shared)
endif()
if(IS_DIRECTORY "${ndk}/sources/cxx-stl/llvm-libc++/libs")
list(APPEND stl_types c++_static c++_shared)
endif()
# List possible ABIs.
set(abi_names
armeabi
armeabi-v6
armeabi-v7a
arm64-v8a
mips
mips64
x86
x86_64
)
# Test all combinations.
foreach(vers IN LISTS _versions)
foreach(stl IN LISTS stl_types)
foreach(config Release Debug)
# Test this combination for all available abis.
message(STATUS "ndk='${ndk}' vers='${vers}' stl='${stl}' config='${config}'")
set(RunCMake_TEST_OPTIONS
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=${vers}
-DCMAKE_ANDROID_STL_TYPE=${stl}
-DCMAKE_BUILD_TYPE=${config}
)
foreach(abi IN LISTS abi_names)
# Skip ABIs not supported by this compiler.
if(NOT ";${_abis_${vers}};" MATCHES ";${abi};")
continue()
endif()
# Skip combinations that seem to be broken.
if("${stl};${abi}" MATCHES [[^c\+\+_static;armeabi]])
continue()
endif()
# Run the tests for this combination.
if("${abi}" STREQUAL "armeabi")
run_Android(ndk-armeabi-thumb) # default: -DCMAKE_ANDROID_ARCH_ABI=armeabi -DCMAKE_ANDROID_ARM_MODE=0
run_Android(ndk-armeabi-arm -DCMAKE_ANDROID_ARM_MODE=1) # default: -DCMAKE_ANDROID_ARCH_ABI=armeabi
else()
run_Android(ndk-${abi} -DCMAKE_ANDROID_ARCH_ABI=${abi})
if("${abi}" STREQUAL "armeabi-v7a")
run_Android(ndk-${abi}-neon -DCMAKE_ANDROID_ARCH_ABI=${abi} -DCMAKE_ANDROID_ARM_NEON=1)
endif()
endif()
endforeach()
unset(RunCMake_TEST_OPTIONS)
endforeach()
endforeach()
endforeach()
endforeach()
foreach(toolchain IN LISTS TEST_ANDROID_STANDALONE_TOOLCHAIN)
message(STATUS "toolchain='${toolchain}'")
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_SYSROOT=${toolchain}/sysroot
)
run_cmake(standalone-sysroot)
unset(RunCMake_TEST_OPTIONS)
foreach(config Release Debug)
message(STATUS "toolchain='${toolchain}' config='${config}'")
set(RunCMake_TEST_OPTIONS
-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=${toolchain}
-DCMAKE_BUILD_TYPE=${config}
)
run_Android(standalone)
unset(RunCMake_TEST_OPTIONS)
endforeach()
endforeach()

View File

@ -0,0 +1,6 @@
#include "android.h"
int main(void)
{
return 0;
}

View File

@ -0,0 +1,45 @@
#include "android.h"
#ifndef STL_NONE
#include <cmath>
#include <cstdio>
#ifndef STL_SYSTEM
#include <exception>
#include <typeinfo>
#ifndef STL_GABI
#include <iostream>
#include <string>
#endif
#endif
#endif
int main()
{
#if !defined(STL_NONE)
// Require -lm implied by linking as C++.
std::printf("%p\n", static_cast<double (*)(double)>(&std::sin));
#endif
#if defined(STL_NONE)
return 0;
#elif defined(STL_SYSTEM)
return 0;
#else
try {
delete (new int);
} catch (std::exception const& e) {
#if defined(STL_GABI)
e.what();
typeid(e).name();
#else
std::cerr << e.what() << std::endl;
std::cerr << typeid(e).name() << std::endl;
#endif
}
#if defined(STL_GABI)
return 0;
#else
std::string s;
return static_cast<int>(s.size());
#endif
#endif
}

View File

@ -0,0 +1,103 @@
#ifndef __ANDROID__
#error "__ANDROID__ not defined"
#endif
#include <android/api-level.h>
#if API_LEVEL != __ANDROID_API__
#error "API levels do not match"
#endif
#ifdef COMPILER_IS_CLANG
#ifndef __clang__
#error "COMPILER_IS_CLANG but __clang__ is not defined"
#endif
#else
#ifdef __clang__
#error "!COMPILER_IS_CLANG but __clang__ is defined"
#endif
#endif
#ifdef ARM_MODE
#if ARM_MODE == 1 && defined(__thumb__)
#error "ARM_MODE==1 but __thumb__ is defined"
#elif ARM_MODE == 0 && !defined(__thumb__)
#error "ARM_MODE==0 but __thumb__ is not defined"
#endif
#endif
#ifdef ARM_NEON
#if ARM_NEON == 0 && defined(__ARM_NEON__)
#error "ARM_NEON==0 but __ARM_NEON__ is defined"
#elif ARM_NEON == 1 && !defined(__ARM_NEON__)
#error "ARM_NEON==1 but __ARM_NEON__ is not defined"
#endif
#endif
#ifdef ABI_armeabi
#ifndef __ARM_EABI__
#error "ABI_armeabi: __ARM_EABI__ not defined"
#endif
#if __ARM_ARCH != 5
#error "ABI_armeabi: __ARM_ARCH is not 5"
#endif
#endif
#ifdef ABI_armeabi_v6
#ifndef __ARM_EABI__
#error "ABI_armeabi_v6: __ARM_EABI__ not defined"
#endif
#if __ARM_ARCH != 6
#error "ABI_armeabi_v6: __ARM_ARCH is not 6"
#endif
#endif
#ifdef ABI_armeabi_v7a
#ifndef __ARM_EABI__
#error "ABI_armeabi_v7a: __ARM_EABI__ not defined"
#endif
#if __ARM_ARCH != 7
#error "ABI_armeabi_v7a: __ARM_ARCH is not 7"
#endif
#endif
#ifdef ABI_arm64_v8a
#ifdef __ARM_EABI__
#error "ABI_arm64_v8a: __ARM_EABI__ defined"
#endif
#ifndef __aarch64__
#error "ABI_arm64_v8a: __aarch64__ not defined"
#endif
#endif
#ifdef ABI_mips
#if __mips != 32
#error "ABI_mips: __mips != 32"
#endif
#ifndef _ABIO32
#error "ABI_mips: _ABIO32 not defined"
#endif
#endif
#ifdef ABI_mips64
#if __mips != 64
#error "ABI_mips64: __mips != 64"
#endif
#ifndef _ABI64
#error "ABI_mips: _ABI64 not defined"
#endif
#endif
#ifdef ABI_x86
#ifndef __i686__
#error "ABI_x86: __i686__ not defined"
#endif
#endif
#ifdef ABI_x86_64
#ifndef __x86_64__
#error "ABI_x86_64: __x86_64__ not defined"
#endif
#endif
#include <stddef.h>

View File

@ -0,0 +1,60 @@
enable_language(C)
enable_language(CXX)
if(NOT ANDROID)
message(SEND_ERROR "CMake variable 'ANDROID' is not set to a true value.")
endif()
foreach(f
"${CMAKE_C_ANDROID_TOOLCHAIN_PREFIX}gcc${CMAKE_C_ANDROID_TOOLCHAIN_SUFFIX}"
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}g++${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}cpp${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}ar${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}ld${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
)
if(NOT EXISTS "${f}")
message(SEND_ERROR "Expected file does not exist:\n \"${f}\"")
endif()
endforeach()
string(APPEND CMAKE_C_FLAGS " -Werror")
string(APPEND CMAKE_CXX_FLAGS " -Werror")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-no-undefined")
if(CMAKE_ANDROID_NDK)
if(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION MATCHES "clang")
add_definitions(-DCOMPILER_IS_CLANG)
endif()
elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
execute_process(
COMMAND ${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/clang --version
OUTPUT_VARIABLE _out
ERROR_VARIABLE _err
RESULT_VARIABLE _res
)
if(_res EQUAL 0)
add_definitions(-DCOMPILER_IS_CLANG)
endif()
endif()
if(CMAKE_ANDROID_STL_TYPE STREQUAL "none")
add_definitions(-DSTL_NONE)
elseif(CMAKE_ANDROID_STL_TYPE STREQUAL "system")
add_definitions(-DSTL_SYSTEM)
elseif(CMAKE_ANDROID_STL_TYPE MATCHES [[^gabi\+\+]])
add_definitions(-DSTL_GABI)
endif()
string(REPLACE "-" "_" abi "${CMAKE_ANDROID_ARCH_ABI}")
add_definitions(-DABI_${abi})
add_definitions(-DAPI_LEVEL=${CMAKE_SYSTEM_VERSION})
if(CMAKE_ANDROID_ARCH_ABI MATCHES "^armeabi")
add_definitions(-DARM_MODE=${CMAKE_ANDROID_ARM_MODE})
message(STATUS "CMAKE_ANDROID_ARM_MODE=${CMAKE_ANDROID_ARM_MODE}")
endif()
if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a")
add_definitions(-DARM_NEON=${CMAKE_ANDROID_ARM_NEON})
message(STATUS "CMAKE_ANDROID_ARM_NEON=${CMAKE_ANDROID_ARM_NEON}")
endif()
add_executable(android_c android.c)
add_executable(android_cxx android.cxx)

View File

@ -0,0 +1,2 @@
-- Android: Targeting API '[0-9]+' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64'
-- Android: Selected (Clang toolchain '[^']+' with )?GCC toolchain '[^']+'

View File

@ -0,0 +1 @@
include(common.cmake)

View File

@ -0,0 +1,3 @@
-- Android: Targeting API '[0-9]+' with architecture 'arm', ABI 'armeabi', and processor 'armv5te'
-- Android: Selected (Clang toolchain '[^']+' with )?GCC toolchain '[^']+'
.*-- CMAKE_ANDROID_ARM_MODE=1

View File

@ -0,0 +1 @@
include(common.cmake)

View File

@ -0,0 +1,3 @@
-- Android: Targeting API '[0-9]+' with architecture 'arm', ABI 'armeabi', and processor 'armv5te'
-- Android: Selected (Clang toolchain '[^']+' with )?GCC toolchain '[^']+'
.*-- CMAKE_ANDROID_ARM_MODE=0

View File

@ -0,0 +1 @@
include(common.cmake)

View File

@ -0,0 +1,3 @@
-- Android: Targeting API '[0-9]+' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
-- Android: Selected (Clang toolchain '[^']+' with )?GCC toolchain '[^']+'
.*-- CMAKE_ANDROID_ARM_NEON=1

View File

@ -0,0 +1 @@
include(common.cmake)

View File

@ -0,0 +1,3 @@
-- Android: Targeting API '[0-9]+' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
-- Android: Selected (Clang toolchain '[^']+' with )?GCC toolchain '[^']+'
.*-- CMAKE_ANDROID_ARM_NEON=0

View File

@ -0,0 +1 @@
include(common.cmake)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,5 @@
^CMake Error at .*/Modules/Platform/Android-Determine.cmake:[0-9]+ \(message\):
Android: Unknown ABI CMAKE_ANDROID_ARCH_ABI='badabi'.
Call Stack \(most recent call first\):
.*/Modules/CMakeDetermineSystem.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(project\)$

View File

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
^CMake Error at .*/Modules/Platform/Android-Determine.cmake:[0-9]+ \(message\):
Android: CMAKE_ANDROID_ARM_MODE is set but is valid only for 'armeabi'
architectures.
Call Stack \(most recent call first\):
.*/Modules/CMakeDetermineSystem.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(project\)$

View File

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
^CMake Error at .*/Modules/Platform/Android-Determine.cmake:[0-9]+ \(message\):
Android: CMAKE_ANDROID_ARM_NEON is set but is valid only for 'armeabi-v7a'
architecture.
Call Stack \(most recent call first\):
.*/Modules/CMakeDetermineSystem.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(project\)$

View File

Some files were not shown because too many files have changed in this diff Show More