2013-04-13 20:09:05 +00:00
# Copyright (c) 2010-2011, Ethan Rublee
2014-03-07 05:59:12 +00:00
# Copyright (c) 2011-2014, Andrey Kamaev
2013-04-13 20:09:05 +00:00
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
2014-03-07 05:59:12 +00:00
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
2013-04-13 20:09:05 +00:00
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
2013-03-20 02:53:09 +00:00
# ------------------------------------------------------------------------------
2015-01-27 03:26:54 +00:00
# Android CMake toolchain file, for use with the Android NDK r5-r10d
# Requires cmake 2.6.3 or newer (2.8.9 or newer is recommended).
2013-04-13 20:09:05 +00:00
# See home page: https://github.com/taka-no-me/android-cmake
2013-03-20 02:53:09 +00:00
#
# Usage Linux:
# $ export ANDROID_NDK=/absolute/path/to/the/android-ndk
# $ mkdir build && cd build
# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
# $ make -j8
#
# Usage Windows:
# You need native port of make to build your project.
2014-11-30 07:05:37 +00:00
# Android NDK r7 (and newer) already has make.exe on board.
2013-03-20 02:53:09 +00:00
# For older NDK you have to install it separately.
# For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm
#
# $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk
# $ mkdir build && cd build
# $ cmake.exe -G"MinGW Makefiles"
# -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake
# -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" ..
2013-04-13 20:09:05 +00:00
# $ cmake.exe --build .
2013-03-20 02:53:09 +00:00
#
#
# Options (can be set as cmake parameters: -D<option_name>=<value>):
# ANDROID_NDK=/opt/android-ndk - path to the NDK root.
# Can be set as environment variable. Can be set only at first cmake run.
#
2013-04-13 20:09:05 +00:00
# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary
2013-03-20 02:53:09 +00:00
# Interface (ABI). This option nearly matches to the APP_ABI variable
# used by ndk-build tool from Android NDK.
#
# Possible targets are:
2014-11-30 07:05:37 +00:00
# "armeabi" - ARMv5TE based CPU with software floating point operations
# "armeabi-v7a" - ARMv7 based devices with hardware FPU instructions
# this ABI target is used by default
2013-03-20 02:53:09 +00:00
# "armeabi-v7a with NEON" - same as armeabi-v7a, but
# sets NEON as floating-point unit
# "armeabi-v7a with VFPV3" - same as armeabi-v7a, but
2014-11-30 07:05:37 +00:00
# sets VFPV3 as floating-point unit (has 32 registers instead of 16)
# "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP
# "x86" - IA-32 instruction set
# "mips" - MIPS32 instruction set
#
# 64-bit ABIs for NDK r10 and newer:
# "arm64-v8a" - ARMv8 AArch64 instruction set
# "x86_64" - Intel64 instruction set (r1)
# "mips64" - MIPS64 instruction set (r6)
2013-03-20 02:53:09 +00:00
#
# ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for.
2013-04-13 20:09:05 +00:00
# Option is read-only when standalone toolchain is used.
2014-11-30 07:05:37 +00:00
# Note: building for "android-L" requires explicit configuration.
2013-04-13 20:09:05 +00:00
#
2014-11-30 07:05:37 +00:00
# ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 - the name of compiler
2013-04-13 20:09:05 +00:00
# toolchain to be used. The list of possible values depends on the NDK
2014-11-30 07:05:37 +00:00
# version. For NDK r10c the possible values are:
2013-04-13 20:09:05 +00:00
#
2014-11-30 07:05:37 +00:00
# * aarch64-linux-android-4.9
# * aarch64-linux-android-clang3.4
# * aarch64-linux-android-clang3.5
2013-04-13 20:09:05 +00:00
# * arm-linux-androideabi-4.6
2014-11-30 07:05:37 +00:00
# * arm-linux-androideabi-4.8
# * arm-linux-androideabi-4.9 (default)
# * arm-linux-androideabi-clang3.4
# * arm-linux-androideabi-clang3.5
# * mips64el-linux-android-4.9
# * mips64el-linux-android-clang3.4
# * mips64el-linux-android-clang3.5
2013-04-13 20:09:05 +00:00
# * mipsel-linux-android-4.6
2014-11-30 07:05:37 +00:00
# * mipsel-linux-android-4.8
# * mipsel-linux-android-4.9
# * mipsel-linux-android-clang3.4
# * mipsel-linux-android-clang3.5
2013-04-13 20:09:05 +00:00
# * x86-4.6
2014-11-30 07:05:37 +00:00
# * x86-4.8
# * x86-4.9
# * x86-clang3.4
# * x86-clang3.5
# * x86_64-4.9
# * x86_64-clang3.4
# * x86_64-clang3.5
2013-03-20 02:53:09 +00:00
#
2013-04-13 20:09:05 +00:00
# ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions
2015-01-27 03:26:54 +00:00
# instead of Thumb. Is not available for "armeabi-v6 with VFP"
# (is forced to be ON) ABI.
2013-03-20 02:53:09 +00:00
#
2013-04-13 20:09:05 +00:00
# ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker
2013-03-20 02:53:09 +00:00
# errors even if they are not used.
#
2013-04-13 20:09:05 +00:00
# ANDROID_SO_UNDEFINED=OFF - set ON to allow undefined symbols in shared
# libraries. Automatically turned for NDK r5x and r6x due to GLESv2
2013-03-20 02:53:09 +00:00
# problems.
#
2013-04-13 20:09:05 +00:00
# ANDROID_STL=gnustl_static - specify the runtime to use.
#
# Possible values are:
# none -> Do not configure the runtime.
# system -> Use the default minimal system C++ runtime library.
# Implies -fno-rtti -fno-exceptions.
# Is not available for standalone toolchain.
# system_re -> Use the default minimal system C++ runtime library.
# Implies -frtti -fexceptions.
# Is not available for standalone toolchain.
# gabi++_static -> Use the GAbi++ runtime as a static library.
# Implies -frtti -fno-exceptions.
# Available for NDK r7 and newer.
# Is not available for standalone toolchain.
# gabi++_shared -> Use the GAbi++ runtime as a shared library.
# Implies -frtti -fno-exceptions.
# Available for NDK r7 and newer.
# Is not available for standalone toolchain.
# stlport_static -> Use the STLport runtime as a static library.
# Implies -fno-rtti -fno-exceptions for NDK before r7.
# Implies -frtti -fno-exceptions for NDK r7 and newer.
# Is not available for standalone toolchain.
# stlport_shared -> Use the STLport runtime as a shared library.
# Implies -fno-rtti -fno-exceptions for NDK before r7.
# Implies -frtti -fno-exceptions for NDK r7 and newer.
# Is not available for standalone toolchain.
# gnustl_static -> Use the GNU STL as a static library.
# Implies -frtti -fexceptions.
# gnustl_shared -> Use the GNU STL as a shared library.
# Implies -frtti -fno-exceptions.
# Available for NDK r7b and newer.
# Silently degrades to gnustl_static if not available.
#
# ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on
# chosen runtime. If disabled, then the user is responsible for settings
# these options.
2013-03-20 02:53:09 +00:00
#
# What?:
# android-cmake toolchain searches for NDK/toolchain in the following order:
# ANDROID_NDK - cmake parameter
# ANDROID_NDK - environment variable
# ANDROID_STANDALONE_TOOLCHAIN - cmake parameter
# ANDROID_STANDALONE_TOOLCHAIN - environment variable
# ANDROID_NDK - default locations
# ANDROID_STANDALONE_TOOLCHAIN - default locations
#
# Make sure to do the following in your scripts:
# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" )
# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" )
2013-04-13 20:09:05 +00:00
# The flags will be prepopulated with critical flags, so don't loose them.
# Also be aware that toolchain also sets configuration-specific compiler
# flags and linker flags.
2013-03-20 02:53:09 +00:00
#
# ANDROID and BUILD_ANDROID will be set to true, you may test any of these
# variables to make necessary Android-specific configuration changes.
#
2014-11-30 07:05:37 +00:00
# Also ARMEABI or ARMEABI_V7A or X86 or MIPS or ARM64_V8A or X86_64 or MIPS64
# will be set true, mutually exclusive. NEON option will be set true
# if VFP is set to NEON.
2013-03-20 02:53:09 +00:00
#
# ------------------------------------------------------------------------------
cmake_minimum_required ( VERSION 2.6.3 )
if ( DEFINED CMAKE_CROSSCOMPILING )
# subsequent toolchain loading is not really needed
return ( )
endif ( )
2013-04-13 20:09:05 +00:00
if ( CMAKE_TOOLCHAIN_FILE )
2014-11-30 07:05:37 +00:00
# touch toolchain variable to suppress "unused variable" warning
2013-04-13 20:09:05 +00:00
endif ( )
2014-11-30 07:05:37 +00:00
# inherit settings in recursive loads
2013-04-13 20:09:05 +00:00
get_property ( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
2013-03-20 02:53:09 +00:00
if ( _CMAKE_IN_TRY_COMPILE )
include ( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL )
endif ( )
# this one is important
2014-11-30 07:05:37 +00:00
if ( CMAKE_VERSION VERSION_GREATER "3.0.99" )
set ( CMAKE_SYSTEM_NAME Android )
else ( )
set ( CMAKE_SYSTEM_NAME Linux )
endif ( )
2013-03-20 02:53:09 +00:00
# this one not so much
set ( CMAKE_SYSTEM_VERSION 1 )
2015-01-27 03:26:54 +00:00
# rpath makes low sense for Android
2014-11-30 07:05:37 +00:00
set ( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "" )
2013-04-13 20:09:05 +00:00
set ( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." )
2014-11-30 07:05:37 +00:00
# NDK search paths
2015-01-27 03:26:54 +00:00
set ( ANDROID_SUPPORTED_NDK_VERSIONS ${ ANDROID_EXTRA_NDK_VERSIONS } -r10d -r10c -r10b -r10 -r9d -r9c -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" )
if ( NOT DEFINED ANDROID_NDK_SEARCH_PATHS )
2013-03-20 02:53:09 +00:00
if ( CMAKE_HOST_WIN32 )
file ( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS )
2015-01-27 03:26:54 +00:00
set ( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}" "$ENV{SystemDrive}/NVPACK" )
2013-03-20 02:53:09 +00:00
else ( )
file ( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS )
2015-01-27 03:26:54 +00:00
set ( ANDROID_NDK_SEARCH_PATHS /opt "${ANDROID_NDK_SEARCH_PATHS}/NVPACK" )
2013-03-20 02:53:09 +00:00
endif ( )
endif ( )
2015-01-27 03:26:54 +00:00
if ( NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )
2013-03-20 02:53:09 +00:00
set ( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain )
endif ( )
2014-11-30 07:05:37 +00:00
# known ABIs
2013-03-20 02:53:09 +00:00
set ( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" )
2014-08-28 21:57:48 +00:00
set ( ANDROID_SUPPORTED_ABIS_arm64 "arm64-v8a" )
2013-03-20 02:53:09 +00:00
set ( ANDROID_SUPPORTED_ABIS_x86 "x86" )
2014-08-28 21:57:48 +00:00
set ( ANDROID_SUPPORTED_ABIS_x86_64 "x86_64" )
2014-11-30 07:05:37 +00:00
set ( ANDROID_SUPPORTED_ABIS_mips "mips" )
set ( ANDROID_SUPPORTED_ABIS_mips64 "mips64" )
2013-03-20 02:53:09 +00:00
2014-11-30 07:05:37 +00:00
# API level defaults
2013-04-13 20:09:05 +00:00
set ( ANDROID_DEFAULT_NDK_API_LEVEL 8 )
2014-11-30 07:05:37 +00:00
set ( ANDROID_DEFAULT_NDK_API_LEVEL_arm64 21 )
2013-03-20 02:53:09 +00:00
set ( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 )
2014-11-30 07:05:37 +00:00
set ( ANDROID_DEFAULT_NDK_API_LEVEL_x86_64 21 )
2013-03-20 02:53:09 +00:00
set ( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 )
2014-11-30 07:05:37 +00:00
set ( ANDROID_DEFAULT_NDK_API_LEVEL_mips64 21 )
2013-03-20 02:53:09 +00:00
macro ( __LIST_FILTER listvar regex )
2015-01-27 03:26:54 +00:00
if ( ${ listvar } )
foreach ( __val ${ ${listvar } } )
if ( __val MATCHES "${regex}" )
list ( REMOVE_ITEM ${ listvar } "${__val}" )
endif ( )
endforeach ( )
endif ( )
2013-03-20 02:53:09 +00:00
endmacro ( )
macro ( __INIT_VARIABLE var_name )
2015-01-27 03:26:54 +00:00
set ( __test_path 0 )
2013-03-20 02:53:09 +00:00
foreach ( __var ${ ARGN } )
2015-01-27 03:26:54 +00:00
if ( __var STREQUAL "PATH" )
set ( __test_path 1 )
2013-03-20 02:53:09 +00:00
break ( )
endif ( )
endforeach ( )
2015-01-27 03:26:54 +00:00
if ( __test_path AND NOT EXISTS "${${var_name}}" )
unset ( ${ var_name } CACHE )
endif ( )
if ( " ${${var_name}}" STREQUAL " " )
set ( __values 0 )
foreach ( __var ${ ARGN } )
if ( __var STREQUAL "VALUES" )
set ( __values 1 )
elseif ( NOT __var STREQUAL "PATH" )
if ( __var MATCHES "^ENV_.*$" )
string ( REPLACE "ENV_" "" __var "${__var}" )
set ( __value "$ENV{${__var}}" )
elseif ( DEFINED ${ __var } )
set ( __value "${${__var}}" )
elseif ( __values )
set ( __value "${__var}" )
else ( )
set ( __value "" )
endif ( )
if ( NOT " ${__value}" STREQUAL " " AND ( NOT __test_path OR EXISTS "${__value}" ) )
set ( ${ var_name } "${__value}" )
break ( )
endif ( )
endif ( )
endforeach ( )
unset ( __value )
unset ( __values )
endif ( )
if ( __test_path )
file ( TO_CMAKE_PATH "${${var_name}}" ${ var_name } )
endif ( )
unset ( __test_path )
2013-03-20 02:53:09 +00:00
endmacro ( )
macro ( __DETECT_NATIVE_API_LEVEL _var _path )
2015-01-27 03:26:54 +00:00
set ( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*.*$" )
file ( STRINGS ${ _path } __apiFileContent REGEX "${__ndkApiLevelRegex}" )
if ( NOT __apiFileContent )
message ( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." )
endif ( )
string ( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${ _var } "${__apiFileContent}" )
unset ( __apiFileContent )
unset ( __ndkApiLevelRegex )
2013-03-20 02:53:09 +00:00
endmacro ( )
macro ( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root )
2013-04-13 20:09:05 +00:00
if ( EXISTS "${_root}" )
2015-01-27 03:26:54 +00:00
file ( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" )
__LIST_FILTER ( __gccExePath "^[.].*" )
list ( LENGTH __gccExePath __gccExePathsCount )
if ( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE )
message ( WARNING "Could not determine machine name for compiler from ${_root}" )
set ( ${ _var } "" )
else ( )
get_filename_component ( __gccExeName "${__gccExePath}" NAME_WE )
string ( REPLACE "-gcc" "" ${ _var } "${__gccExeName}" )
endif ( )
unset ( __gccExePath )
unset ( __gccExePathsCount )
unset ( __gccExeName )
2013-04-13 20:09:05 +00:00
else ( )
2015-01-27 03:26:54 +00:00
set ( ${ _var } "" )
2013-04-13 20:09:05 +00:00
endif ( )
2013-03-20 02:53:09 +00:00
endmacro ( )
# fight against cygwin
set ( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools" )
mark_as_advanced ( ANDROID_FORBID_SYGWIN )
if ( ANDROID_FORBID_SYGWIN )
if ( CYGWIN )
message ( FATAL_ERROR "Android NDK and android-cmake toolchain are not welcome Cygwin. It is unlikely that this cmake toolchain will work under cygwin. But if you want to try then you can set cmake variable ANDROID_FORBID_SYGWIN to FALSE and rerun cmake." )
endif ( )
if ( CMAKE_HOST_WIN32 )
# remove cygwin from PATH
set ( __new_path "$ENV{PATH}" )
__LIST_FILTER ( __new_path "cygwin" )
set ( ENV{PATH} "${__new_path}" )
unset ( __new_path )
endif ( )
endif ( )
2013-04-13 20:09:05 +00:00
2013-03-20 02:53:09 +00:00
# detect current host platform
2014-03-07 05:59:12 +00:00
if ( NOT DEFINED ANDROID_NDK_HOST_X64 AND ( CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64" OR CMAKE_HOST_APPLE ) )
2013-04-13 20:09:05 +00:00
set ( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain" )
mark_as_advanced ( ANDROID_NDK_HOST_X64 )
endif ( )
2013-03-20 02:53:09 +00:00
set ( TOOL_OS_SUFFIX "" )
if ( CMAKE_HOST_APPLE )
2013-04-13 20:09:05 +00:00
set ( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" )
set ( ANDROID_NDK_HOST_SYSTEM_NAME2 "darwin-x86" )
2013-03-20 02:53:09 +00:00
elseif ( CMAKE_HOST_WIN32 )
2013-04-13 20:09:05 +00:00
set ( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" )
set ( ANDROID_NDK_HOST_SYSTEM_NAME2 "windows" )
2013-03-20 02:53:09 +00:00
set ( TOOL_OS_SUFFIX ".exe" )
elseif ( CMAKE_HOST_UNIX )
2013-04-13 20:09:05 +00:00
set ( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" )
set ( ANDROID_NDK_HOST_SYSTEM_NAME2 "linux-x86" )
2013-03-20 02:53:09 +00:00
else ( )
message ( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
endif ( )
2013-04-13 20:09:05 +00:00
if ( NOT ANDROID_NDK_HOST_X64 )
set ( ANDROID_NDK_HOST_SYSTEM_NAME ${ ANDROID_NDK_HOST_SYSTEM_NAME2 } )
endif ( )
2013-03-20 02:53:09 +00:00
# see if we have path to Android NDK
2015-01-27 03:26:54 +00:00
if ( NOT ANDROID_NDK AND NOT ANDROID_STANDALONE_TOOLCHAIN )
__INIT_VARIABLE ( ANDROID_NDK PATH ENV_ANDROID_NDK )
endif ( )
2013-03-20 02:53:09 +00:00
if ( NOT ANDROID_NDK )
# see if we have path to Android standalone toolchain
2015-01-27 03:26:54 +00:00
__INIT_VARIABLE ( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN )
2013-03-20 02:53:09 +00:00
if ( NOT ANDROID_STANDALONE_TOOLCHAIN )
#try to find Android NDK in one of the the default locations
set ( __ndkSearchPaths )
foreach ( __ndkSearchPath ${ ANDROID_NDK_SEARCH_PATHS } )
foreach ( suffix ${ ANDROID_SUPPORTED_NDK_VERSIONS } )
2015-01-27 03:26:54 +00:00
list ( APPEND __ndkSearchPaths "${__ndkSearchPath}/android-ndk${suffix}" )
2013-03-20 02:53:09 +00:00
endforeach ( )
endforeach ( )
__INIT_VARIABLE ( ANDROID_NDK PATH VALUES ${ __ndkSearchPaths } )
unset ( __ndkSearchPaths )
if ( ANDROID_NDK )
message ( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" )
message ( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" )
else ( )
#try to find Android standalone toolchain in one of the the default locations
__INIT_VARIABLE ( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )
if ( ANDROID_STANDALONE_TOOLCHAIN )
message ( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" )
message ( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" )
endif ( ANDROID_STANDALONE_TOOLCHAIN )
endif ( ANDROID_NDK )
endif ( NOT ANDROID_STANDALONE_TOOLCHAIN )
endif ( NOT ANDROID_NDK )
2014-03-07 05:59:12 +00:00
2013-03-20 02:53:09 +00:00
# remember found paths
if ( ANDROID_NDK )
get_filename_component ( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE )
2013-04-13 20:09:05 +00:00
set ( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE )
2013-03-20 02:53:09 +00:00
set ( BUILD_WITH_ANDROID_NDK True )
2014-03-07 05:59:12 +00:00
if ( EXISTS "${ANDROID_NDK}/RELEASE.TXT" )
2014-11-30 07:05:37 +00:00
file ( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE_FULL LIMIT_COUNT 1 REGEX "r[0-9]+[a-z]?" )
string ( REGEX MATCH "r([0-9]+)([a-z]?)" ANDROID_NDK_RELEASE "${ANDROID_NDK_RELEASE_FULL}" )
2014-03-07 05:59:12 +00:00
else ( )
set ( ANDROID_NDK_RELEASE "r1x" )
set ( ANDROID_NDK_RELEASE_FULL "unreleased" )
endif ( )
2014-11-30 07:05:37 +00:00
string ( REGEX REPLACE "r([0-9]+)([a-z]?)" "\\1*1000" ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE}" )
string ( FIND " abcdefghijklmnopqastuvwxyz" "${CMAKE_MATCH_2}" __ndkReleaseLetterNum )
math ( EXPR ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE_NUM}+${__ndkReleaseLetterNum}" )
2013-03-20 02:53:09 +00:00
elseif ( ANDROID_STANDALONE_TOOLCHAIN )
get_filename_component ( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE )
# try to detect change
if ( CMAKE_AR )
string ( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length )
string ( SUBSTRING "${CMAKE_AR}" 0 ${ __length } __androidStandaloneToolchainPreviousPath )
if ( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN )
message ( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." )
endif ( )
unset ( __androidStandaloneToolchainPreviousPath )
unset ( __length )
endif ( )
2013-04-13 20:09:05 +00:00
set ( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" FORCE )
2013-03-20 02:53:09 +00:00
set ( BUILD_WITH_STANDALONE_TOOLCHAIN True )
else ( )
list ( GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH )
2013-04-13 20:09:05 +00:00
message ( FATAL_ERROR " Could not find neither Android NDK nor Android standalone toolchain.
2013-03-20 02:53:09 +00:00
Y o u s h o u l d e i t h e r s e t a n e n v i r o n m e n t v a r i a b l e :
e x p o r t A N D R O I D _ N D K = ~ / m y - a n d r o i d - n d k
o r
e x p o r t A N D R O I D _ S T A N D A L O N E _ T O O L C H A I N = ~ / m y - a n d r o i d - t o o l c h a i n
o r p u t t h e t o o l c h a i n o r N D K i n t h e d e f a u l t p a t h :
2015-01-27 03:26:54 +00:00
s u d o l n - s ~ / m y - a n d r o i d - n d k $ { A N D R O I D _ N D K _ S E A R C H _ P A T H } / a n d r o i d - n d k
2013-03-20 02:53:09 +00:00
s u d o l n - s ~ / m y - a n d r o i d - t o o l c h a i n $ { A N D R O I D _ S T A N D A L O N E _ T O O L C H A I N _ S E A R C H _ P A T H } " )
endif ( )
2014-03-07 05:59:12 +00:00
# android NDK layout
if ( BUILD_WITH_ANDROID_NDK )
if ( NOT DEFINED ANDROID_NDK_LAYOUT )
# try to automatically detect the layout
if ( EXISTS "${ANDROID_NDK}/RELEASE.TXT" )
set ( ANDROID_NDK_LAYOUT "RELEASE" )
elseif ( EXISTS "${ANDROID_NDK}/../../linux-x86/toolchain/" )
set ( ANDROID_NDK_LAYOUT "LINARO" )
elseif ( EXISTS "${ANDROID_NDK}/../../gcc/" )
set ( ANDROID_NDK_LAYOUT "ANDROID" )
endif ( )
endif ( )
set ( ANDROID_NDK_LAYOUT "${ANDROID_NDK_LAYOUT}" CACHE STRING "The inner layout of NDK" )
mark_as_advanced ( ANDROID_NDK_LAYOUT )
if ( ANDROID_NDK_LAYOUT STREQUAL "LINARO" )
set ( ANDROID_NDK_HOST_SYSTEM_NAME ${ ANDROID_NDK_HOST_SYSTEM_NAME2 } ) # only 32-bit at the moment
set ( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../${ANDROID_NDK_HOST_SYSTEM_NAME}/toolchain" )
set ( ANDROID_NDK_TOOLCHAINS_SUBPATH "" )
set ( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" )
elseif ( ANDROID_NDK_LAYOUT STREQUAL "ANDROID" )
set ( ANDROID_NDK_HOST_SYSTEM_NAME ${ ANDROID_NDK_HOST_SYSTEM_NAME2 } ) # only 32-bit at the moment
set ( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../gcc/${ANDROID_NDK_HOST_SYSTEM_NAME}/arm" )
set ( ANDROID_NDK_TOOLCHAINS_SUBPATH "" )
set ( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" )
else ( ) # ANDROID_NDK_LAYOUT STREQUAL "RELEASE"
set ( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/toolchains" )
set ( ANDROID_NDK_TOOLCHAINS_SUBPATH "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" )
set ( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME2}" )
endif ( )
get_filename_component ( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK_TOOLCHAINS_PATH}" ABSOLUTE )
# try to detect change of NDK
if ( CMAKE_AR )
string ( LENGTH "${ANDROID_NDK_TOOLCHAINS_PATH}" __length )
string ( SUBSTRING "${CMAKE_AR}" 0 ${ __length } __androidNdkPreviousPath )
if ( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK_TOOLCHAINS_PATH )
message ( FATAL_ERROR " It is not possible to change the path to the NDK on subsequent CMake run. You must remove all generated files from your build folder first.
" )
endif ( )
unset ( __androidNdkPreviousPath )
unset ( __length )
endif ( )
endif ( )
2013-03-20 02:53:09 +00:00
# get all the details about standalone toolchain
if ( BUILD_WITH_STANDALONE_TOOLCHAIN )
__DETECT_NATIVE_API_LEVEL ( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" )
set ( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ ANDROID_SUPPORTED_NATIVE_API_LEVELS } )
set ( __availableToolchains "standalone" )
__DETECT_TOOLCHAIN_MACHINE_NAME ( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" )
if ( NOT __availableToolchainMachines )
message ( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." )
endif ( )
2014-11-30 07:05:37 +00:00
if ( __availableToolchainMachines MATCHES x86_64 )
set ( __availableToolchainArchs "x86_64" )
elseif ( __availableToolchainMachines MATCHES i686 )
2013-03-20 02:53:09 +00:00
set ( __availableToolchainArchs "x86" )
2014-11-30 07:05:37 +00:00
elseif ( __availableToolchainMachines MATCHES aarch64 )
set ( __availableToolchainArchs "arm64" )
2013-03-20 02:53:09 +00:00
elseif ( __availableToolchainMachines MATCHES arm )
set ( __availableToolchainArchs "arm" )
2014-11-30 07:05:37 +00:00
elseif ( __availableToolchainMachines MATCHES mips64el )
set ( __availableToolchainArchs "mips64" )
2013-03-20 02:53:09 +00:00
elseif ( __availableToolchainMachines MATCHES mipsel )
2014-11-30 07:05:37 +00:00
set ( __availableToolchainArchs "mips" )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
execute_process ( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" -dumpversion
O U T P U T _ V A R I A B L E _ _ a v a i l a b l e T o o l c h a i n C o m p i l e r V e r s i o n s O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
string ( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" )
if ( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}" )
list ( APPEND __availableToolchains "standalone-clang" )
list ( APPEND __availableToolchainMachines ${ __availableToolchainMachines } )
list ( APPEND __availableToolchainArchs ${ __availableToolchainArchs } )
list ( APPEND __availableToolchainCompilerVersions ${ __availableToolchainCompilerVersions } )
2013-03-20 02:53:09 +00:00
endif ( )
endif ( )
2014-03-07 05:59:12 +00:00
macro ( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath )
2013-04-13 20:09:05 +00:00
foreach ( __toolchain ${ ${__availableToolchainsLst } } )
2014-03-07 05:59:12 +00:00
if ( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" )
2014-11-30 07:05:37 +00:00
SET ( __toolchainVersionRegex "^TOOLCHAIN_VERSION[\t ]+:=[\t ]+(.*)$" )
FILE ( STRINGS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}/setup.mk" __toolchainVersionStr REGEX "${__toolchainVersionRegex}" )
if ( __toolchainVersionStr )
string ( REGEX REPLACE "${__toolchainVersionRegex}" "\\1" __toolchainVersionStr "${__toolchainVersionStr}" )
string ( REGEX REPLACE "-clang3[.][0-9]$" "-${__toolchainVersionStr}" __gcc_toolchain "${__toolchain}" )
else ( )
string ( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" )
endif ( )
unset ( __toolchainVersionStr )
unset ( __toolchainVersionRegex )
2013-04-13 20:09:05 +00:00
else ( )
set ( __gcc_toolchain "${__toolchain}" )
endif ( )
2014-03-07 05:59:12 +00:00
__DETECT_TOOLCHAIN_MACHINE_NAME ( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" )
2013-04-13 20:09:05 +00:00
if ( __machine )
2014-03-07 05:59:12 +00:00
string ( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" )
2014-11-30 07:05:37 +00:00
if ( __machine MATCHES x86_64 )
2014-08-28 21:57:48 +00:00
set ( __arch "x86_64" )
2014-11-30 07:05:37 +00:00
elseif ( __machine MATCHES i686 )
set ( __arch "x86" )
2014-08-28 21:57:48 +00:00
elseif ( __machine MATCHES aarch64 )
set ( __arch "arm64" )
2014-11-30 07:05:37 +00:00
elseif ( __machine MATCHES arm )
set ( __arch "arm" )
2014-08-28 21:57:48 +00:00
elseif ( __machine MATCHES mips64el )
2014-11-30 07:05:37 +00:00
set ( __arch "mips64" )
elseif ( __machine MATCHES mipsel )
set ( __arch "mips" )
else ( )
set ( __arch "" )
endif ( )
#message("machine: !${__machine}!\narch: !${__arch}!\nversion: !${__version}!\ntoolchain: !${__toolchain}!\n")
if ( __arch )
list ( APPEND __availableToolchainMachines "${__machine}" )
list ( APPEND __availableToolchainArchs "${__arch}" )
list ( APPEND __availableToolchainCompilerVersions "${__version}" )
list ( APPEND ${ __availableToolchainsVar } "${__toolchain}" )
2014-03-07 05:59:12 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
endif ( )
unset ( __gcc_toolchain )
endforeach ( )
endmacro ( )
2013-03-20 02:53:09 +00:00
# get all the details about NDK
if ( BUILD_WITH_ANDROID_NDK )
file ( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" )
string ( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" )
2013-04-13 20:09:05 +00:00
set ( __availableToolchains "" )
2013-03-20 02:53:09 +00:00
set ( __availableToolchainMachines "" )
set ( __availableToolchainArchs "" )
set ( __availableToolchainCompilerVersions "" )
2014-03-07 05:59:12 +00:00
if ( ANDROID_TOOLCHAIN_NAME AND EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_TOOLCHAIN_NAME}/" )
2013-04-13 20:09:05 +00:00
# do not go through all toolchains if we know the name
set ( __availableToolchainsLst "${ANDROID_TOOLCHAIN_NAME}" )
2014-03-07 05:59:12 +00:00
__GLOB_NDK_TOOLCHAINS ( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
if ( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 )
__GLOB_NDK_TOOLCHAINS ( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" )
2013-04-13 20:09:05 +00:00
if ( __availableToolchains )
2014-03-07 05:59:12 +00:00
set ( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ ANDROID_NDK_TOOLCHAINS_SUBPATH2 } )
2013-04-13 20:09:05 +00:00
endif ( )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
endif ( )
if ( NOT __availableToolchains )
2014-03-07 05:59:12 +00:00
file ( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" )
2013-04-13 20:09:05 +00:00
if ( __availableToolchains )
list ( SORT __availableToolchainsLst ) # we need clang to go after gcc
endif ( )
__LIST_FILTER ( __availableToolchainsLst "^[.]" )
__LIST_FILTER ( __availableToolchainsLst "llvm" )
2014-03-07 05:59:12 +00:00
__LIST_FILTER ( __availableToolchainsLst "renderscript" )
__GLOB_NDK_TOOLCHAINS ( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
if ( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 )
__GLOB_NDK_TOOLCHAINS ( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" )
2013-04-13 20:09:05 +00:00
if ( __availableToolchains )
2014-03-07 05:59:12 +00:00
set ( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ ANDROID_NDK_TOOLCHAINS_SUBPATH2 } )
2013-04-13 20:09:05 +00:00
endif ( )
endif ( )
endif ( )
2013-03-20 02:53:09 +00:00
if ( NOT __availableToolchains )
2013-04-13 20:09:05 +00:00
message ( FATAL_ERROR "Could not find any working toolchain in the NDK. Probably your Android NDK is broken." )
2013-03-20 02:53:09 +00:00
endif ( )
endif ( )
# build list of available ABIs
2013-04-13 20:09:05 +00:00
set ( ANDROID_SUPPORTED_ABIS "" )
set ( __uniqToolchainArchNames ${ __availableToolchainArchs } )
list ( REMOVE_DUPLICATES __uniqToolchainArchNames )
list ( SORT __uniqToolchainArchNames )
foreach ( __arch ${ __uniqToolchainArchNames } )
list ( APPEND ANDROID_SUPPORTED_ABIS ${ ANDROID_SUPPORTED_ABIS_${__arch } } )
endforeach ( )
unset ( __uniqToolchainArchNames )
2013-03-20 02:53:09 +00:00
if ( NOT ANDROID_SUPPORTED_ABIS )
2013-04-13 20:09:05 +00:00
message ( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." )
2013-03-20 02:53:09 +00:00
endif ( )
# choose target ABI
2015-01-27 03:26:54 +00:00
__INIT_VARIABLE ( ANDROID_ABI VALUES ${ ANDROID_SUPPORTED_ABIS } )
2013-03-20 02:53:09 +00:00
# verify that target ABI is supported
list ( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx )
if ( __androidAbiIdx EQUAL -1 )
2014-03-07 05:59:12 +00:00
string ( REPLACE ";" "\" , \"" PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" )
2013-03-20 02:53:09 +00:00
message ( FATAL_ERROR "Specified ANDROID_ABI = \" ${ ANDROID_ABI } \" is not supported by this cmake toolchain or your NDK/toolchain.
S u p p o r t e d v a l u e s a r e : \ " $ { P R I N T A B L E _ A N D R O I D _ S U P P O R T E D _ A B I S } \ "
" )
endif ( )
unset ( __androidAbiIdx )
# set target ABI options
if ( ANDROID_ABI STREQUAL "x86" )
set ( X86 true )
set ( ANDROID_NDK_ABI_NAME "x86" )
set ( ANDROID_ARCH_NAME "x86" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_LLVM_TRIPLE "i686-none-linux-android" )
2013-03-20 02:53:09 +00:00
set ( CMAKE_SYSTEM_PROCESSOR "i686" )
2014-08-28 21:57:48 +00:00
elseif ( ANDROID_ABI STREQUAL "x86_64" )
2014-11-30 07:05:37 +00:00
set ( X86 true )
2014-08-28 21:57:48 +00:00
set ( X86_64 true )
set ( ANDROID_NDK_ABI_NAME "x86_64" )
set ( ANDROID_ARCH_NAME "x86_64" )
set ( CMAKE_SYSTEM_PROCESSOR "x86_64" )
2014-11-30 07:05:37 +00:00
set ( ANDROID_LLVM_TRIPLE "x86_64-none-linux-android" )
2014-08-28 21:57:48 +00:00
elseif ( ANDROID_ABI STREQUAL "mips64" )
set ( MIPS64 true )
set ( ANDROID_NDK_ABI_NAME "mips64" )
set ( ANDROID_ARCH_NAME "mips64" )
set ( ANDROID_LLVM_TRIPLE "mips64el-none-linux-android" )
set ( CMAKE_SYSTEM_PROCESSOR "mips64" )
2014-11-30 07:05:37 +00:00
elseif ( ANDROID_ABI STREQUAL "mips" )
set ( MIPS true )
set ( ANDROID_NDK_ABI_NAME "mips" )
set ( ANDROID_ARCH_NAME "mips" )
set ( ANDROID_LLVM_TRIPLE "mipsel-none-linux-android" )
set ( CMAKE_SYSTEM_PROCESSOR "mips" )
elseif ( ANDROID_ABI STREQUAL "arm64-v8a" )
set ( ARM64_V8A true )
set ( ANDROID_NDK_ABI_NAME "arm64-v8a" )
set ( ANDROID_ARCH_NAME "arm64" )
set ( ANDROID_LLVM_TRIPLE "aarch64-none-linux-android" )
set ( CMAKE_SYSTEM_PROCESSOR "aarch64" )
set ( VFPV3 true )
set ( NEON true )
2013-03-20 02:53:09 +00:00
elseif ( ANDROID_ABI STREQUAL "armeabi" )
set ( ARMEABI true )
set ( ANDROID_NDK_ABI_NAME "armeabi" )
set ( ANDROID_ARCH_NAME "arm" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" )
2013-03-20 02:53:09 +00:00
set ( CMAKE_SYSTEM_PROCESSOR "armv5te" )
elseif ( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" )
set ( ARMEABI_V6 true )
set ( ANDROID_NDK_ABI_NAME "armeabi" )
set ( ANDROID_ARCH_NAME "arm" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" )
2013-03-20 02:53:09 +00:00
set ( CMAKE_SYSTEM_PROCESSOR "armv6" )
# need always fallback to older platform
set ( ARMEABI true )
elseif ( ANDROID_ABI STREQUAL "armeabi-v7a" )
set ( ARMEABI_V7A true )
set ( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
set ( ANDROID_ARCH_NAME "arm" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" )
2013-03-20 02:53:09 +00:00
set ( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
elseif ( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" )
set ( ARMEABI_V7A true )
set ( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
set ( ANDROID_ARCH_NAME "arm" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" )
2013-03-20 02:53:09 +00:00
set ( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
set ( VFPV3 true )
elseif ( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" )
set ( ARMEABI_V7A true )
set ( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
set ( ANDROID_ARCH_NAME "arm" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" )
2013-03-20 02:53:09 +00:00
set ( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
set ( VFPV3 true )
set ( NEON true )
else ( )
message ( SEND_ERROR "Unknown ANDROID_ABI=\" ${ ANDROID_ABI } \" is specified. " )
endif ( )
if ( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" )
# really dirty hack
# it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run...
file ( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \" ${ CMAKE_SYSTEM_PROCESSOR } \")\n" )
endif ( )
if ( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 )
2015-01-27 03:26:54 +00:00
__INIT_VARIABLE ( ANDROID_FORCE_ARM_BUILD VALUES OFF )
2013-03-20 02:53:09 +00:00
set ( ANDROID_FORCE_ARM_BUILD ${ ANDROID_FORCE_ARM_BUILD } CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE )
mark_as_advanced ( ANDROID_FORCE_ARM_BUILD )
else ( )
unset ( ANDROID_FORCE_ARM_BUILD CACHE )
endif ( )
# choose toolchain
if ( ANDROID_TOOLCHAIN_NAME )
list ( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx )
if ( __toolchainIdx EQUAL -1 )
2013-04-13 20:09:05 +00:00
list ( SORT __availableToolchains )
string ( REPLACE ";" "\n * " toolchains_list "${__availableToolchains}" )
set ( toolchains_list " * ${toolchains_list}" )
message ( FATAL_ERROR "Specified toolchain \" ${ ANDROID_TOOLCHAIN_NAME } \" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain.
T o c o n f i g u r e t h e t o o l c h a i n s e t C M a k e v a r i a b l e A N D R O I D _ T O O L C H A I N _ N A M E t o o n e o f t h e f o l l o w i n g v a l u e s : \ n $ { t o o l c h a i n s _ l i s t } \ n " )
2013-03-20 02:53:09 +00:00
endif ( )
list ( GET __availableToolchainArchs ${ __toolchainIdx } __toolchainArch )
2014-11-30 07:05:37 +00:00
if ( NOT __toolchainArch STREQUAL ANDROID_ARCH_NAME )
2013-04-13 20:09:05 +00:00
message ( SEND_ERROR "Selected toolchain \" ${ ANDROID_TOOLCHAIN_NAME } \" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform. " )
2013-03-20 02:53:09 +00:00
endif ( )
else ( )
set ( __toolchainIdx -1 )
set ( __applicableToolchains "" )
set ( __toolchainMaxVersion "0.0.0" )
list ( LENGTH __availableToolchains __availableToolchainsCount )
math ( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" )
foreach ( __idx RANGE ${ __availableToolchainsCount } )
list ( GET __availableToolchainArchs ${ __idx } __toolchainArch )
2014-11-30 07:05:37 +00:00
if ( __toolchainArch STREQUAL ANDROID_ARCH_NAME )
2013-03-20 02:53:09 +00:00
list ( GET __availableToolchainCompilerVersions ${ __idx } __toolchainVersion )
2014-03-07 05:59:12 +00:00
string ( REPLACE "x" "99" __toolchainVersion "${__toolchainVersion}" )
2013-03-20 02:53:09 +00:00
if ( __toolchainVersion VERSION_GREATER __toolchainMaxVersion )
set ( __toolchainMaxVersion "${__toolchainVersion}" )
set ( __toolchainIdx ${ __idx } )
endif ( )
endif ( )
endforeach ( )
unset ( __availableToolchainsCount )
unset ( __toolchainMaxVersion )
unset ( __toolchainVersion )
endif ( )
unset ( __toolchainArch )
if ( __toolchainIdx EQUAL -1 )
message ( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." )
endif ( )
list ( GET __availableToolchains ${ __toolchainIdx } ANDROID_TOOLCHAIN_NAME )
list ( GET __availableToolchainMachines ${ __toolchainIdx } ANDROID_TOOLCHAIN_MACHINE_NAME )
list ( GET __availableToolchainCompilerVersions ${ __toolchainIdx } ANDROID_COMPILER_VERSION )
2013-04-13 20:09:05 +00:00
2013-03-20 02:53:09 +00:00
unset ( __toolchainIdx )
unset ( __availableToolchains )
unset ( __availableToolchainMachines )
unset ( __availableToolchainArchs )
unset ( __availableToolchainCompilerVersions )
# choose native API level
__INIT_VARIABLE ( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_ ${ ANDROID_ARCH_NAME } ANDROID_DEFAULT_NDK_API_LEVEL )
2014-11-30 07:05:37 +00:00
string ( REPLACE "android-" "" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" )
string ( STRIP "${ANDROID_NATIVE_API_LEVEL}" ANDROID_NATIVE_API_LEVEL )
# adjust API level
set ( __real_api_level ${ ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME } } )
foreach ( __level ${ ANDROID_SUPPORTED_NATIVE_API_LEVELS } )
if ( ( __level LESS ANDROID_NATIVE_API_LEVEL OR __level STREQUAL ANDROID_NATIVE_API_LEVEL ) AND NOT __level LESS __real_api_level )
set ( __real_api_level ${ __level } )
endif ( )
endforeach ( )
if ( __real_api_level AND NOT ANDROID_NATIVE_API_LEVEL STREQUAL __real_api_level )
message ( STATUS "Adjusting Android API level 'android-${ANDROID_NATIVE_API_LEVEL}' to 'android-${__real_api_level}'" )
set ( ANDROID_NATIVE_API_LEVEL ${ __real_api_level } )
endif ( )
unset ( __real_api_level )
# validate
list ( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx )
if ( __levelIdx EQUAL -1 )
message ( SEND_ERROR "Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain." )
else ( )
if ( BUILD_WITH_ANDROID_NDK )
__DETECT_NATIVE_API_LEVEL ( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" )
if ( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL AND NOT __realApiLevel GREATER 9000 )
message ( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." )
2013-04-13 20:09:05 +00:00
endif ( )
2014-11-30 07:05:37 +00:00
unset ( __realApiLevel )
endif ( )
set ( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
2015-01-27 03:26:54 +00:00
set ( CMAKE_ANDROID_API ${ ANDROID_NATIVE_API_LEVEL } )
2014-11-30 07:05:37 +00:00
if ( CMAKE_VERSION VERSION_GREATER "2.8" )
list ( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS )
set_property ( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ ANDROID_SUPPORTED_NATIVE_API_LEVELS } )
endif ( )
2013-03-20 02:53:09 +00:00
endif ( )
2014-11-30 07:05:37 +00:00
unset ( __levelIdx )
2013-04-13 20:09:05 +00:00
# remember target ABI
set ( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE )
if ( CMAKE_VERSION VERSION_GREATER "2.8" )
2014-11-30 07:05:37 +00:00
list ( SORT ANDROID_SUPPORTED_ABIS_ ${ ANDROID_ARCH_NAME } )
set_property ( CACHE ANDROID_ABI PROPERTY STRINGS ${ ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME } } )
2013-04-13 20:09:05 +00:00
endif ( )
# runtime choice (STL, rtti, exceptions)
if ( NOT ANDROID_STL )
set ( ANDROID_STL gnustl_static )
endif ( )
set ( ANDROID_STL "${ANDROID_STL}" CACHE STRING "C++ runtime" )
set ( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and exceptions support based on C++ runtime" )
mark_as_advanced ( ANDROID_STL ANDROID_STL_FORCE_FEATURES )
2013-03-20 02:53:09 +00:00
if ( BUILD_WITH_ANDROID_NDK )
2013-04-13 20:09:05 +00:00
if ( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared)$" )
message ( FATAL_ERROR "ANDROID_STL is set to invalid value \" ${ ANDROID_STL } \".
T h e p o s s i b l e v a l u e s a r e :
n o n e - > D o n o t c o n f i g u r e t h e r u n t i m e .
s y s t e m - > U s e t h e d e f a u l t m i n i m a l s y s t e m C + + r u n t i m e l i b r a r y .
s y s t e m _ r e - > S a m e a s s y s t e m b u t w i t h r t t i a n d e x c e p t i o n s .
g a b i + + _ s t a t i c - > U s e t h e G A b i + + r u n t i m e a s a s t a t i c l i b r a r y .
g a b i + + _ s h a r e d - > U s e t h e G A b i + + r u n t i m e a s a s h a r e d l i b r a r y .
s t l p o r t _ s t a t i c - > U s e t h e S T L p o r t r u n t i m e a s a s t a t i c l i b r a r y .
s t l p o r t _ s h a r e d - > U s e t h e S T L p o r t r u n t i m e a s a s h a r e d l i b r a r y .
g n u s t l _ s t a t i c - > ( d e f a u l t ) U s e t h e G N U S T L a s a s t a t i c l i b r a r y .
g n u s t l _ s h a r e d - > U s e t h e G N U S T L a s a s h a r e d l i b r a r y .
" )
endif ( )
elseif ( BUILD_WITH_STANDALONE_TOOLCHAIN )
if ( NOT "${ANDROID_STL}" MATCHES "^(none|gnustl_static|gnustl_shared)$" )
message ( FATAL_ERROR "ANDROID_STL is set to invalid value \" ${ ANDROID_STL } \".
T h e p o s s i b l e v a l u e s a r e :
n o n e - > D o n o t c o n f i g u r e t h e r u n t i m e .
g n u s t l _ s t a t i c - > ( d e f a u l t ) U s e t h e G N U S T L a s a s t a t i c l i b r a r y .
g n u s t l _ s h a r e d - > U s e t h e G N U S T L a s a s h a r e d l i b r a r y .
" )
2013-03-20 02:53:09 +00:00
endif ( )
endif ( )
2013-04-13 20:09:05 +00:00
unset ( ANDROID_RTTI )
unset ( ANDROID_EXCEPTIONS )
unset ( ANDROID_STL_INCLUDE_DIRS )
unset ( __libstl )
unset ( __libsupcxx )
if ( NOT _CMAKE_IN_TRY_COMPILE AND ANDROID_NDK_RELEASE STREQUAL "r7b" AND ARMEABI_V7A AND NOT VFPV3 AND ANDROID_STL MATCHES "gnustl" )
message ( WARNING " The GNU STL armeabi-v7a binaries from NDK r7b can crash non-NEON devices. The files provided with NDK r7b were not configured properly, resulting in crashes on Tegra2-based devices and others when trying to use certain floating-point functions ( e.g., cosf, sinf, expf ) .
Y o u a r e s t r o n g l y r e c o m m e n d e d t o s w i t c h t o a n o t h e r N D K r e l e a s e .
" )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
if ( NOT _CMAKE_IN_TRY_COMPILE AND X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" )
message ( WARNING " The x86 system header file from NDK r6 has incorrect definition for ptrdiff_t. You are recommended to upgrade to a newer NDK release or manually patch the header:
S e e h t t p s : / / a n d r o i d . g o o g l e s o u r c e . c o m / p l a t f o r m / d e v e l o p m e n t . g i t f 9 0 7 f 4 f 9 d 4 e 5 6 c c c 8 0 9 3 d f 6 f e e 5 4 4 5 4 b 8 b c a b 6 c 2
d i f f - - g i t a / n d k / p l a t f o r m s / a n d r o i d - 9 / a r c h - x 8 6 / i n c l u d e / m a c h i n e / _ t y p e s . h b / n d k / p l a t f o r m s / a n d r o i d - 9 / a r c h - x 8 6 / i n c l u d e / m a c h i n e / _ t y p e s . h
i n d e x 5 e 2 8 c 6 4 . . 6 5 8 9 2 a 1 1 0 0 6 4 4
- - - a / n d k / p l a t f o r m s / a n d r o i d - 9 / a r c h - x 8 6 / i n c l u d e / m a c h i n e / _ t y p e s . h
+ + + b / n d k / p l a t f o r m s / a n d r o i d - 9 / a r c h - x 8 6 / i n c l u d e / m a c h i n e / _ t y p e s . h
@ @ - 5 1 , 7 + 5 1 , 1 1 @ @ t y p e d e f l o n g i n t s s i z e _ t ;
#endif
#ifndef _PTRDIFF_T
#define _PTRDIFF_T
- t y p e d e f l o n g p t r d i f f _ t ;
+ # ifdef __ANDROID__
+ t y p e d e f i n t p t r d i f f _ t ;
+ # else
+ t y p e d e f l o n g p t r d i f f _ t ;
+ # endif
#endif
" )
endif ( )
# setup paths and STL for standalone toolchain
2013-03-20 02:53:09 +00:00
if ( BUILD_WITH_STANDALONE_TOOLCHAIN )
set ( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" )
2013-03-20 02:53:09 +00:00
set ( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" )
2013-04-13 20:09:05 +00:00
if ( NOT ANDROID_STL STREQUAL "none" )
2014-03-07 05:59:12 +00:00
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" )
if ( NOT EXISTS "${ANDROID_STL_INCLUDE_DIRS}" )
# old location ( pre r8c )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" )
endif ( )
2013-04-13 20:09:05 +00:00
if ( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" )
list ( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" )
elseif ( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" )
list ( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" )
2013-03-20 02:53:09 +00:00
else ( )
2013-04-13 20:09:05 +00:00
list ( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" )
endif ( )
# always search static GNU STL to get the location of libsupc++.a
if ( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" )
elseif ( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" )
elseif ( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" )
elseif ( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" )
endif ( )
if ( __libstl )
set ( __libsupcxx "${__libstl}/libsupc++.a" )
set ( __libstl "${__libstl}/libstdc++.a" )
endif ( )
if ( NOT EXISTS "${__libsupcxx}" )
message ( FATAL_ERROR " The required libstdsupc++.a is missing in your standalone toolchain.
U s u a l l y i t h a p p e n s b e c a u s e o f b u g i n m a k e - s t a n d a l o n e - t o o l c h a i n . s h s c r i p t f r o m N D K r 7 , r 7 b a n d r 7 c .
Y o u n e e d t o e i t h e r u p g r a d e t o n e w e r N D K o r m a n u a l l y c o p y
$ A N D R O I D _ N D K / s o u r c e s / c x x - s t l / g n u - l i b s t d c + + / l i b s / $ { A N D R O I D _ N D K _ A B I _ N A M E } / l i b s u p c + + . a
t o
$ { _ _ l i b s u p c x x }
" )
endif ( )
if ( ANDROID_STL STREQUAL "gnustl_shared" )
if ( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" )
elseif ( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" )
elseif ( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" )
endif ( )
2013-03-20 02:53:09 +00:00
endif ( )
endif ( )
endif ( )
2013-04-13 20:09:05 +00:00
# clang
if ( "${ANDROID_TOOLCHAIN_NAME}" STREQUAL "standalone-clang" )
set ( ANDROID_COMPILER_IS_CLANG 1 )
execute_process ( COMMAND "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE )
string ( REGEX MATCH "[0-9]+[.][0-9]+" ANDROID_CLANG_VERSION "${ANDROID_CLANG_VERSION}" )
elseif ( "${ANDROID_TOOLCHAIN_NAME}" MATCHES "-clang3[.][0-9]?$" )
string ( REGEX MATCH "3[.][0-9]$" ANDROID_CLANG_VERSION "${ANDROID_TOOLCHAIN_NAME}" )
2014-11-30 07:05:37 +00:00
string ( REGEX REPLACE "-clang${ANDROID_CLANG_VERSION}$" "-${ANDROID_COMPILER_VERSION}" ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" )
2014-03-07 05:59:12 +00:00
if ( NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}/bin/clang${TOOL_OS_SUFFIX}" )
2013-04-13 20:09:05 +00:00
message ( FATAL_ERROR "Could not find the Clang compiler driver" )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
set ( ANDROID_COMPILER_IS_CLANG 1 )
2014-03-07 05:59:12 +00:00
set ( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
2013-04-13 20:09:05 +00:00
else ( )
set ( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" )
unset ( ANDROID_COMPILER_IS_CLANG CACHE )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
string ( REPLACE "." "" _clang_name "clang${ANDROID_CLANG_VERSION}" )
if ( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" )
set ( _clang_name "clang" )
endif ( )
2013-03-20 02:53:09 +00:00
2013-04-13 20:09:05 +00:00
# setup paths and STL for NDK
if ( BUILD_WITH_ANDROID_NDK )
2014-03-07 05:59:12 +00:00
set ( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" )
if ( ANDROID_STL STREQUAL "none" )
# do nothing
elseif ( ANDROID_STL STREQUAL "system" )
set ( ANDROID_RTTI OFF )
set ( ANDROID_EXCEPTIONS OFF )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" )
elseif ( ANDROID_STL STREQUAL "system_re" )
set ( ANDROID_RTTI ON )
set ( ANDROID_EXCEPTIONS ON )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" )
elseif ( ANDROID_STL MATCHES "gabi" )
2014-11-30 07:05:37 +00:00
if ( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7
2013-04-13 20:09:05 +00:00
message ( FATAL_ERROR "gabi++ is not awailable in your NDK. You have to upgrade to NDK r7 or newer to use gabi++." )
endif ( )
set ( ANDROID_RTTI ON )
set ( ANDROID_EXCEPTIONS OFF )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/gabi++/include" )
set ( __libstl "${ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${ANDROID_NDK_ABI_NAME}/libgabi++_static.a" )
elseif ( ANDROID_STL MATCHES "stlport" )
2014-11-30 07:05:37 +00:00
if ( NOT ANDROID_NDK_RELEASE_NUM LESS 8004 ) # before r8d
2013-04-13 20:09:05 +00:00
set ( ANDROID_EXCEPTIONS ON )
else ( )
set ( ANDROID_EXCEPTIONS OFF )
endif ( )
2014-11-30 07:05:37 +00:00
if ( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7
2013-04-13 20:09:05 +00:00
set ( ANDROID_RTTI OFF )
else ( )
set ( ANDROID_RTTI ON )
endif ( )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" )
set ( __libstl "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}/libstlport_static.a" )
elseif ( ANDROID_STL MATCHES "gnustl" )
set ( ANDROID_EXCEPTIONS ON )
set ( ANDROID_RTTI ON )
if ( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" )
if ( ARMEABI_V7A AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.7" AND ANDROID_NDK_RELEASE STREQUAL "r8d" )
# gnustl binary for 4.7 compiler is buggy :(
# TODO: look for right fix
set ( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.6" )
else ( )
set ( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" )
endif ( )
else ( )
set ( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" )
endif ( )
2015-01-27 03:26:54 +00:00
set ( ANDROID_STL_INCLUDE_DIRS "${__libstl}/include" "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/include" "${__libstl}/include/backward" )
2013-04-13 20:09:05 +00:00
if ( EXISTS "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" )
set ( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" )
else ( )
set ( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" )
endif ( )
2013-03-20 02:53:09 +00:00
else ( )
2013-04-13 20:09:05 +00:00
message ( FATAL_ERROR "Unknown runtime: ${ANDROID_STL}" )
endif ( )
# find libsupc++.a - rtti & exceptions
if ( ANDROID_STL STREQUAL "system_re" OR ANDROID_STL MATCHES "gnustl" )
2014-03-07 05:59:12 +00:00
set ( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r8b or newer
if ( NOT EXISTS "${__libsupcxx}" )
set ( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r7-r8
endif ( )
if ( NOT EXISTS "${__libsupcxx}" ) # before r7
2013-04-13 20:09:05 +00:00
if ( ARMEABI_V7A )
if ( ANDROID_FORCE_ARM_BUILD )
set ( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" )
else ( )
set ( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" )
endif ( )
elseif ( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD )
set ( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" )
else ( )
set ( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" )
endif ( )
endif ( )
if ( NOT EXISTS "${__libsupcxx}" )
message ( ERROR "Could not find libsupc++.a for a chosen platform. Either your NDK is not supported or is broken." )
endif ( )
2013-03-20 02:53:09 +00:00
endif ( )
endif ( )
2013-04-13 20:09:05 +00:00
# case of shared STL linkage
if ( ANDROID_STL MATCHES "shared" AND DEFINED __libstl )
string ( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" )
2014-03-07 05:59:12 +00:00
# TODO: check if .so file exists before the renaming
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
# ccache support
__INIT_VARIABLE ( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE )
if ( _ndk_ccache )
if ( DEFINED NDK_CCACHE AND NOT EXISTS NDK_CCACHE )
unset ( NDK_CCACHE CACHE )
endif ( )
find_program ( NDK_CCACHE "${_ndk_ccache}" DOC "The path to ccache binary" )
2013-03-20 02:53:09 +00:00
else ( )
2013-04-13 20:09:05 +00:00
unset ( NDK_CCACHE CACHE )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
unset ( _ndk_ccache )
2013-03-20 02:53:09 +00:00
2013-04-13 20:09:05 +00:00
# setup the cross-compiler
if ( NOT CMAKE_C_COMPILER )
2014-03-07 05:59:12 +00:00
if ( NDK_CCACHE AND NOT ANDROID_SYSROOT MATCHES "[ ;\" ] " )
2013-04-13 20:09:05 +00:00
set ( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" )
set ( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" )
if ( ANDROID_COMPILER_IS_CLANG )
set ( CMAKE_C_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" )
set ( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" )
else ( )
set ( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" )
set ( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" )
endif ( )
else ( )
if ( ANDROID_COMPILER_IS_CLANG )
set ( CMAKE_C_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" )
set ( CMAKE_CXX_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" )
else ( )
set ( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" )
set ( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" )
endif ( )
endif ( )
set ( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" )
set ( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" )
set ( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
set ( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" )
set ( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" )
set ( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" )
set ( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" )
set ( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" )
endif ( )
set ( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" )
if ( CMAKE_VERSION VERSION_LESS 2.8.5 )
set ( CMAKE_ASM_COMPILER_ARG1 "-c" )
endif ( )
if ( APPLE )
find_program ( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool )
if ( NOT CMAKE_INSTALL_NAME_TOOL )
message ( FATAL_ERROR "Could not find install_name_tool, please check your installation." )
endif ( )
mark_as_advanced ( CMAKE_INSTALL_NAME_TOOL )
endif ( )
2013-03-20 02:53:09 +00:00
# Force set compilers because standard identification works badly for us
include ( CMakeForceCompiler )
CMAKE_FORCE_C_COMPILER ( "${CMAKE_C_COMPILER}" GNU )
2013-04-13 20:09:05 +00:00
if ( ANDROID_COMPILER_IS_CLANG )
2015-01-27 03:26:54 +00:00
set ( CMAKE_C_COMPILER_ID Clang )
2013-04-13 20:09:05 +00:00
endif ( )
2013-03-20 02:53:09 +00:00
set ( CMAKE_C_PLATFORM_ID Linux )
2014-11-30 07:05:37 +00:00
if ( X86_64 OR MIPS64 OR ARM64_V8A )
2014-08-28 21:57:48 +00:00
set ( CMAKE_C_SIZEOF_DATA_PTR 8 )
2014-09-08 04:18:43 +00:00
else ( )
set ( CMAKE_C_SIZEOF_DATA_PTR 4 )
2014-08-28 21:57:48 +00:00
endif ( )
2013-03-20 02:53:09 +00:00
set ( CMAKE_C_HAS_ISYSROOT 1 )
set ( CMAKE_C_COMPILER_ABI ELF )
CMAKE_FORCE_CXX_COMPILER ( "${CMAKE_CXX_COMPILER}" GNU )
2013-04-13 20:09:05 +00:00
if ( ANDROID_COMPILER_IS_CLANG )
set ( CMAKE_CXX_COMPILER_ID Clang )
endif ( )
2013-03-20 02:53:09 +00:00
set ( CMAKE_CXX_PLATFORM_ID Linux )
2014-11-30 07:05:37 +00:00
set ( CMAKE_CXX_SIZEOF_DATA_PTR ${ CMAKE_C_SIZEOF_DATA_PTR } )
2013-03-20 02:53:09 +00:00
set ( CMAKE_CXX_HAS_ISYSROOT 1 )
set ( CMAKE_CXX_COMPILER_ABI ELF )
2013-04-13 20:09:05 +00:00
set ( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C )
2013-03-20 02:53:09 +00:00
# force ASM compiler (required for CMake < 2.8.5)
set ( CMAKE_ASM_COMPILER_ID_RUN TRUE )
set ( CMAKE_ASM_COMPILER_ID GNU )
set ( CMAKE_ASM_COMPILER_WORKS TRUE )
set ( CMAKE_ASM_COMPILER_FORCED TRUE )
set ( CMAKE_COMPILER_IS_GNUASM 1 )
2013-04-13 20:09:05 +00:00
set ( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s S asm )
2013-03-20 02:53:09 +00:00
2015-01-27 03:26:54 +00:00
foreach ( lang C CXX ASM )
if ( ANDROID_COMPILER_IS_CLANG )
set ( CMAKE_ ${ lang } _COMPILER_VERSION ${ ANDROID_CLANG_VERSION } )
else ( )
set ( CMAKE_ ${ lang } _COMPILER_VERSION ${ ANDROID_COMPILER_VERSION } )
endif ( )
endforeach ( )
2013-04-13 20:09:05 +00:00
# flags and definitions
remove_definitions ( -DANDROID )
add_definitions ( -DANDROID )
2013-03-20 02:53:09 +00:00
2014-03-07 05:59:12 +00:00
if ( ANDROID_SYSROOT MATCHES "[ ;\" ] " )
if ( CMAKE_HOST_WIN32 )
# try to convert path to 8.3 form
file ( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "@echo %~s1" )
execute_process ( COMMAND "$ENV{ComSpec}" /c "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "${ANDROID_SYSROOT}"
O U T P U T _ V A R I A B L E _ _ p a t h O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
R E S U L T _ V A R I A B L E _ _ r e s u l t E R R O R _ Q U I E T )
if ( __result EQUAL 0 )
file ( TO_CMAKE_PATH "${__path}" ANDROID_SYSROOT )
set ( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" )
else ( )
set ( ANDROID_CXX_FLAGS "--sysroot=\" ${ ANDROID_SYSROOT } \"" )
endif ( )
else ( )
set ( ANDROID_CXX_FLAGS "'--sysroot=${ANDROID_SYSROOT}'" )
endif ( )
2013-04-13 20:09:05 +00:00
if ( NOT _CMAKE_IN_TRY_COMPILE )
2014-03-07 05:59:12 +00:00
# quotes can break try_compile and compiler identification
message ( WARNING "Path to your Android NDK (or toolchain) has non-alphanumeric symbols.\nThe build might be broken.\n" )
2013-04-13 20:09:05 +00:00
endif ( )
2013-03-20 02:53:09 +00:00
else ( )
2013-04-13 20:09:05 +00:00
set ( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
# NDK flags
2014-11-30 07:05:37 +00:00
if ( ARM64_V8A )
2015-01-27 03:26:54 +00:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" )
2014-11-30 07:05:37 +00:00
set ( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" )
set ( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" )
if ( NOT ANDROID_COMPILER_IS_CLANG )
set ( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" )
endif ( )
elseif ( ARMEABI OR ARMEABI_V7A )
2015-01-27 03:26:54 +00:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" )
2013-03-20 02:53:09 +00:00
if ( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 )
2013-04-13 20:09:05 +00:00
set ( ANDROID_CXX_FLAGS_RELEASE "-mthumb -fomit-frame-pointer -fno-strict-aliasing" )
set ( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" )
if ( NOT ANDROID_COMPILER_IS_CLANG )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -finline-limit=64" )
endif ( )
2013-03-20 02:53:09 +00:00
else ( )
# always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI
2013-04-13 20:09:05 +00:00
set ( ANDROID_CXX_FLAGS_RELEASE "-marm -fomit-frame-pointer -fstrict-aliasing" )
set ( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" )
if ( NOT ANDROID_COMPILER_IS_CLANG )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" )
endif ( )
2013-03-20 02:53:09 +00:00
endif ( )
2014-08-28 21:57:48 +00:00
elseif ( X86 OR X86_64 )
2013-04-13 20:09:05 +00:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" )
if ( NOT ANDROID_COMPILER_IS_CLANG )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" )
endif ( )
set ( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" )
set ( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" )
2014-08-28 21:57:48 +00:00
elseif ( MIPS OR MIPS64 )
2015-01-27 03:26:54 +00:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-strict-aliasing -finline-functions -funwind-tables -fmessage-length=0" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer" )
set ( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer" )
if ( NOT ANDROID_COMPILER_IS_CLANG )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" )
set ( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" )
endif ( )
elseif ( )
set ( ANDROID_CXX_FLAGS_RELEASE "" )
set ( ANDROID_CXX_FLAGS_DEBUG "" )
endif ( )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) # good/necessary when porting desktop libraries
if ( NOT X86 AND NOT ANDROID_COMPILER_IS_CLANG )
set ( ANDROID_CXX_FLAGS "-Wno-psabi ${ANDROID_CXX_FLAGS}" )
endif ( )
if ( NOT ANDROID_COMPILER_VERSION VERSION_LESS "4.6" )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -no-canonical-prefixes" ) # see https://android-review.googlesource.com/#/c/47564/
2013-03-20 02:53:09 +00:00
endif ( )
# ABI-specific flags
if ( ARMEABI_V7A )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" )
if ( NEON )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" )
elseif ( VFPV3 )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" )
else ( )
2013-04-13 20:09:05 +00:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" )
2013-03-20 02:53:09 +00:00
endif ( )
elseif ( ARMEABI_V6 )
2013-04-13 20:09:05 +00:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) # vfp == vfpv2
2013-03-20 02:53:09 +00:00
elseif ( ARMEABI )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" )
endif ( )
2014-03-07 05:59:12 +00:00
if ( ANDROID_STL MATCHES "gnustl" AND ( EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}" ) )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
set ( CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
else ( )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
set ( CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
endif ( )
2013-03-20 02:53:09 +00:00
# STL
2013-04-13 20:09:05 +00:00
if ( EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}" )
if ( EXISTS "${__libstl}" )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \" ${ __libstl } \"" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \" ${ __libstl } \"" )
set ( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \" ${ __libstl } \"" )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
if ( EXISTS "${__libsupcxx}" )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \" ${ __libsupcxx } \"" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \" ${ __libsupcxx } \"" )
set ( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \" ${ __libsupcxx } \"" )
# C objects:
set ( CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
set ( CMAKE_C_CREATE_SHARED_MODULE "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
set ( CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
set ( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} \" ${ __libsupcxx } \"" )
set ( CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE} \" ${ __libsupcxx } \"" )
set ( CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} \" ${ __libsupcxx } \"" )
endif ( )
if ( ANDROID_STL MATCHES "gnustl" )
2014-03-07 05:59:12 +00:00
if ( NOT EXISTS "${ANDROID_LIBM_PATH}" )
set ( ANDROID_LIBM_PATH -lm )
endif ( )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} ${ANDROID_LIBM_PATH}" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} ${ANDROID_LIBM_PATH}" )
set ( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${ANDROID_LIBM_PATH}" )
2013-04-13 20:09:05 +00:00
endif ( )
endif ( )
2013-03-20 02:53:09 +00:00
2013-04-13 20:09:05 +00:00
# variables controlling optional build flags
2014-11-30 07:05:37 +00:00
if ( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7
2013-04-13 20:09:05 +00:00
# libGLESv2.so in NDK's prior to r7 refers to missing external symbols.
# So this flag option is required for all projects using OpenGL from native.
__INIT_VARIABLE ( ANDROID_SO_UNDEFINED VALUES ON )
else ( )
__INIT_VARIABLE ( ANDROID_SO_UNDEFINED VALUES OFF )
endif ( )
2015-01-27 03:26:54 +00:00
__INIT_VARIABLE ( ANDROID_NO_UNDEFINED VALUES ON )
2013-04-13 20:09:05 +00:00
__INIT_VARIABLE ( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON )
__INIT_VARIABLE ( ANDROID_GOLD_LINKER VALUES ON )
__INIT_VARIABLE ( ANDROID_NOEXECSTACK VALUES ON )
__INIT_VARIABLE ( ANDROID_RELRO VALUES ON )
set ( ANDROID_NO_UNDEFINED ${ ANDROID_NO_UNDEFINED } CACHE BOOL "Show all undefined symbols as linker errors" )
set ( ANDROID_SO_UNDEFINED ${ ANDROID_SO_UNDEFINED } CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
2015-01-27 03:26:54 +00:00
set ( ANDROID_FUNCTION_LEVEL_LINKING ${ ANDROID_FUNCTION_LEVEL_LINKING } CACHE BOOL "Put each function in separate section and enable garbage collection of unused input sections at link time" )
2014-11-30 07:05:37 +00:00
set ( ANDROID_GOLD_LINKER ${ ANDROID_GOLD_LINKER } CACHE BOOL "Enables gold linker" )
2013-04-13 20:09:05 +00:00
set ( ANDROID_NOEXECSTACK ${ ANDROID_NOEXECSTACK } CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
set ( ANDROID_RELRO ${ ANDROID_RELRO } CACHE BOOL "Enables RELRO - a memory corruption mitigation technique" )
mark_as_advanced ( ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_FUNCTION_LEVEL_LINKING ANDROID_GOLD_LINKER ANDROID_NOEXECSTACK ANDROID_RELRO )
# linker flags
set ( ANDROID_LINKER_FLAGS "" )
if ( ARMEABI_V7A )
# this is *required* to use the following linker flags that routes around
# a CPU bug in some Cortex-A8 implementations:
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
if ( ANDROID_NO_UNDEFINED )
2014-03-07 05:59:12 +00:00
if ( MIPS )
# there is some sysroot-related problem in mips linker...
if ( NOT ANDROID_SYSROOT MATCHES "[ ;\" ] " )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib" )
endif ( )
else ( )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" )
endif ( )
2013-03-20 02:53:09 +00:00
endif ( )
if ( ANDROID_SO_UNDEFINED )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" )
endif ( )
if ( ANDROID_FUNCTION_LEVEL_LINKING )
2013-04-13 20:09:05 +00:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" )
2013-03-20 02:53:09 +00:00
endif ( )
2013-04-13 20:09:05 +00:00
if ( ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" )
2014-11-30 07:05:37 +00:00
if ( ANDROID_GOLD_LINKER AND ( CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE_NUM GREATER 8002 ) AND ( ARMEABI OR ARMEABI_V7A OR X86 ) )
2013-04-13 20:09:05 +00:00
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" )
2014-11-30 07:05:37 +00:00
elseif ( ANDROID_NDK_RELEASE_NUM GREATER 8002 ) # after r8b
2013-04-13 20:09:05 +00:00
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=bfd" )
elseif ( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE )
message ( WARNING " The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342
O n L i n u x a n d O S X h o s t p l a t f o r m y o u c a n w o r k a r o u n d t h i s p r o b l e m u s i n g g o l d linker ( default ) .
R e r u n c m a k e w i t h - D A N D R O I D _ G O L D _ L I N K E R = O N o p t i o n i n c a s e o f p r o b l e m s .
" )
endif ( )
endif ( ) # version 4.6
if ( ANDROID_NOEXECSTACK )
if ( ANDROID_COMPILER_IS_CLANG )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack" )
else ( )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" )
endif ( )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" )
endif ( )
if ( ANDROID_RELRO )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" )
endif ( )
if ( ANDROID_COMPILER_IS_CLANG )
2014-11-30 07:05:37 +00:00
set ( ANDROID_CXX_FLAGS "-target ${ANDROID_LLVM_TRIPLE} -Qunused-arguments ${ANDROID_CXX_FLAGS}" )
2013-04-13 20:09:05 +00:00
if ( BUILD_WITH_ANDROID_NDK )
set ( ANDROID_CXX_FLAGS "-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}" )
endif ( )
2013-03-20 02:53:09 +00:00
endif ( )
# cache flags
2013-04-13 20:09:05 +00:00
set ( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" )
set ( CMAKE_C_FLAGS "" CACHE STRING "c flags" )
set ( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c++ Release flags" )
set ( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c Release flags" )
set ( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c++ Debug flags" )
set ( CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c Debug flags" )
set ( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags" )
set ( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags" )
set ( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker flags" )
# put flags to cache (for debug purpose only)
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Android specific c/c++ flags" )
set ( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE}" CACHE INTERNAL "Android specific c/c++ Release flags" )
set ( ANDROID_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG}" CACHE INTERNAL "Android specific c/c++ Debug flags" )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Android specific c/c++ linker flags" )
2013-03-20 02:53:09 +00:00
# finish flags
set ( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" )
set ( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" )
2013-04-13 20:09:05 +00:00
set ( CMAKE_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}" )
set ( CMAKE_C_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}" )
set ( CMAKE_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}" )
set ( CMAKE_C_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}" )
set ( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" )
set ( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" )
set ( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" )
if ( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" )
2014-03-07 05:59:12 +00:00
set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" )
set ( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" )
set ( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" )
2013-04-13 20:09:05 +00:00
endif ( )
2015-01-27 03:26:54 +00:00
# pie/pic
if ( NOT ( ANDROID_NATIVE_API_LEVEL LESS 16 ) AND ( NOT DEFINED ANDROID_APP_PIE OR ANDROID_APP_PIE ) AND ( CMAKE_VERSION VERSION_GREATER 2.8.8 ) )
set ( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie" )
else ( )
set ( CMAKE_POSITION_INDEPENDENT_CODE FALSE )
set ( CMAKE_CXX_FLAGS "-fpic ${CMAKE_CXX_FLAGS}" )
set ( CMAKE_C_FLAGS "-fpic ${CMAKE_C_FLAGS}" )
endif ( )
2013-04-13 20:09:05 +00:00
# configure rtti
if ( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES )
if ( ANDROID_RTTI )
set ( CMAKE_CXX_FLAGS "-frtti ${CMAKE_CXX_FLAGS}" )
else ( )
set ( CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}" )
endif ( )
endif ( )
# configure exceptios
if ( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES )
if ( ANDROID_EXCEPTIONS )
set ( CMAKE_CXX_FLAGS "-fexceptions ${CMAKE_CXX_FLAGS}" )
set ( CMAKE_C_FLAGS "-fexceptions ${CMAKE_C_FLAGS}" )
else ( )
set ( CMAKE_CXX_FLAGS "-fno-exceptions ${CMAKE_CXX_FLAGS}" )
set ( CMAKE_C_FLAGS "-fno-exceptions ${CMAKE_C_FLAGS}" )
endif ( )
endif ( )
# global includes and link directories
include_directories ( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ ANDROID_STL_INCLUDE_DIRS } )
2014-03-07 05:59:12 +00:00
get_filename_component ( __android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE ) # avoid CMP0015 policy warning
link_directories ( "${__android_install_path}" )
# detect if need link crtbegin_so.o explicitly
if ( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK )
set ( __cmd "${CMAKE_CXX_CREATE_SHARED_LIBRARY}" )
string ( REPLACE "<CMAKE_CXX_COMPILER>" "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" __cmd "${__cmd}" )
string ( REPLACE "<CMAKE_C_COMPILER>" "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" __cmd "${__cmd}" )
string ( REPLACE "<CMAKE_SHARED_LIBRARY_CXX_FLAGS>" "${CMAKE_CXX_FLAGS}" __cmd "${__cmd}" )
string ( REPLACE "<LANGUAGE_COMPILE_FLAGS>" "" __cmd "${__cmd}" )
string ( REPLACE "<LINK_FLAGS>" "${CMAKE_SHARED_LINKER_FLAGS}" __cmd "${__cmd}" )
string ( REPLACE "<CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>" "-shared" __cmd "${__cmd}" )
string ( REPLACE "<CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG>" "" __cmd "${__cmd}" )
string ( REPLACE "<TARGET_SONAME>" "" __cmd "${__cmd}" )
string ( REPLACE "<TARGET>" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toolchain_crtlink_test.so" __cmd "${__cmd}" )
string ( REPLACE "<OBJECTS>" "\" ${ ANDROID_SYSROOT } /usr/lib/crtbegin_so.o\ "" __cmd "${__cmd}" )
string ( REPLACE "<LINK_LIBRARIES>" "" __cmd "${__cmd}" )
separate_arguments ( __cmd )
foreach ( __var ANDROID_NDK ANDROID_NDK_TOOLCHAINS_PATH ANDROID_STANDALONE_TOOLCHAIN )
if ( ${ __var } )
set ( __tmp "${${__var}}" )
separate_arguments ( __tmp )
string ( REPLACE "${__tmp}" "${${__var}}" __cmd "${__cmd}" )
endif ( )
endforeach ( )
string ( REPLACE "'" "" __cmd "${__cmd}" )
string ( REPLACE "\" " " " __cmd " ${ __cmd } " )
execute_process ( COMMAND ${ __cmd } RESULT_VARIABLE __cmd_result OUTPUT_QUIET ERROR_QUIET )
if ( __cmd_result EQUAL 0 )
set ( ANDROID_EXPLICIT_CRT_LINK ON )
else ( )
set ( ANDROID_EXPLICIT_CRT_LINK OFF )
endif ( )
endif ( )
if ( ANDROID_EXPLICIT_CRT_LINK )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \" ${ ANDROID_SYSROOT } /usr/lib/crtbegin_so.o\ "" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \" ${ ANDROID_SYSROOT } /usr/lib/crtbegin_so.o\ "" )
endif ( )
2013-04-13 20:09:05 +00:00
# setup output directories
set ( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
2015-02-24 08:58:55 +00:00
if ( NOT DEFINED LIBRARY_OUTPUT_PATH_ROOT
2015-01-27 03:26:54 +00:00
O R E X I S T S " $ { C M A K E _ S O U R C E _ D I R } / A n d r o i d M a n i f e s t . x m l "
OR ( EXISTS "${CMAKE_SOURCE_DIR}/../AndroidManifest.xml" AND EXISTS "${CMAKE_SOURCE_DIR}/../jni/" ) )
set ( LIBRARY_OUTPUT_PATH_ROOT ${ CMAKE_SOURCE_DIR } CACHE PATH "Root for binaries output, set this to change where Android libs are installed to" )
if ( NOT _CMAKE_IN_TRY_COMPILE )
if ( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" )
set ( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" )
else ( )
set ( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" )
endif ( )
set ( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for Android libs" )
endif ( )
2013-03-20 02:53:09 +00:00
endif ( )
2014-03-07 05:59:12 +00:00
# copy shaed stl library to build directory
2015-01-27 03:26:54 +00:00
if ( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" AND DEFINED LIBRARY_OUTPUT_PATH )
get_filename_component ( __libstlname "${__libstl}" NAME )
execute_process ( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess )
if ( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}" )
message ( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" )
endif ( )
unset ( __fileCopyProcess )
unset ( __libstlname )
2014-03-07 05:59:12 +00:00
endif ( )
2013-03-20 02:53:09 +00:00
# set these global flags for cmake client scripts to change behavior
set ( ANDROID True )
set ( BUILD_ANDROID True )
# where is the target environment
set ( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" )
# only search for libraries and includes in the ndk toolchain
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
# macro to find packages on the host OS
macro ( find_host_package )
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
if ( CMAKE_HOST_WIN32 )
SET ( WIN32 1 )
SET ( UNIX )
elseif ( CMAKE_HOST_APPLE )
SET ( APPLE 1 )
SET ( UNIX )
endif ( )
find_package ( ${ ARGN } )
SET ( WIN32 )
SET ( APPLE )
SET ( UNIX 1 )
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
endmacro ( )
# macro to find programs on the host OS
macro ( find_host_program )
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
if ( CMAKE_HOST_WIN32 )
SET ( WIN32 1 )
SET ( UNIX )
elseif ( CMAKE_HOST_APPLE )
SET ( APPLE 1 )
SET ( UNIX )
endif ( )
find_program ( ${ ARGN } )
SET ( WIN32 )
SET ( APPLE )
SET ( UNIX 1 )
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
endmacro ( )
# export toolchain settings for the try_compile() command
2015-01-27 03:26:54 +00:00
if ( NOT _CMAKE_IN_TRY_COMPILE )
2013-03-20 02:53:09 +00:00
set ( __toolchain_config "" )
2015-01-27 03:26:54 +00:00
foreach ( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN
2013-04-13 20:09:05 +00:00
A N D R O I D _ N D K _ H O S T _ X 6 4
A N D R O I D _ N D K
2014-03-07 05:59:12 +00:00
A N D R O I D _ N D K _ L A Y O U T
2013-04-13 20:09:05 +00:00
A N D R O I D _ S T A N D A L O N E _ T O O L C H A I N
A N D R O I D _ T O O L C H A I N _ N A M E
A N D R O I D _ A B I
A N D R O I D _ N A T I V E _ A P I _ L E V E L
A N D R O I D _ S T L
A N D R O I D _ S T L _ F O R C E _ F E A T U R E S
A N D R O I D _ F O R C E _ A R M _ B U I L D
A N D R O I D _ N O _ U N D E F I N E D
A N D R O I D _ S O _ U N D E F I N E D
A N D R O I D _ F U N C T I O N _ L E V E L _ L I N K I N G
A N D R O I D _ G O L D _ L I N K E R
A N D R O I D _ N O E X E C S T A C K
A N D R O I D _ R E L R O
2014-03-07 05:59:12 +00:00
A N D R O I D _ L I B M _ P A T H
A N D R O I D _ E X P L I C I T _ C R T _ L I N K
2015-01-27 03:26:54 +00:00
A N D R O I D _ A P P _ P I E
2013-04-13 20:09:05 +00:00
)
2013-03-20 02:53:09 +00:00
if ( DEFINED ${ __var } )
2015-01-27 03:26:54 +00:00
if ( ${ __var } MATCHES " " )
2013-03-20 02:53:09 +00:00
set ( __toolchain_config "${__toolchain_config}set( ${__var} \" ${ ${__var } }\ " CACHE INTERNAL \" \" ) \ n " )
else ( )
set ( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \" \" ) \ n " )
endif ( )
endif ( )
endforeach ( )
file ( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" )
unset ( __toolchain_config )
endif ( )
2014-03-07 05:59:12 +00:00
# force cmake to produce / instead of \ in build commands for Ninja generator
if ( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 )
# it is a bad hack after all
# CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW
set ( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW
set ( CMAKE_CROSSCOMPILING TRUE ) # stop recursion
enable_language ( C )
enable_language ( CXX )
# unset( CMAKE_COMPILER_IS_MINGW ) # can't unset because CMake does not convert back-slashes in response files without it
unset ( MINGW )
endif ( )
2013-03-20 02:53:09 +00:00
# Variables controlling behavior or set by cmake toolchain:
2014-11-30 07:05:37 +00:00
# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips", "arm64-v8a", "x86_64", "mips64"
# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14,15,16,17,18,19,21 (depends on NDK version)
2013-04-13 20:09:05 +00:00
# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none
2013-03-20 02:53:09 +00:00
# ANDROID_FORBID_SYGWIN : ON/OFF
# ANDROID_NO_UNDEFINED : ON/OFF
# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version)
# ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF
2013-04-13 20:09:05 +00:00
# ANDROID_GOLD_LINKER : ON/OFF
# ANDROID_NOEXECSTACK : ON/OFF
# ANDROID_RELRO : ON/OFF
2013-03-20 02:53:09 +00:00
# ANDROID_FORCE_ARM_BUILD : ON/OFF
2013-04-13 20:09:05 +00:00
# ANDROID_STL_FORCE_FEATURES : ON/OFF
2015-01-27 03:26:54 +00:00
# ANDROID_LIBM_PATH : path to libm.so (set to something like $(TOP)/out/target/product/<product_name>/obj/lib/libm.so) to workaround unresolved `sincos`
2013-03-20 02:53:09 +00:00
# Can be set only at the first run:
2015-01-27 03:26:54 +00:00
# ANDROID_NDK : path to your NDK install
# NDK_CCACHE : path to your ccache executable
2013-04-13 20:09:05 +00:00
# ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain
# ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems)
2014-03-07 05:59:12 +00:00
# ANDROID_NDK_LAYOUT : the inner NDK structure (RELEASE, LINARO, ANDROID)
2013-04-13 20:09:05 +00:00
# LIBRARY_OUTPUT_PATH_ROOT : <any valid path>
2015-01-27 03:26:54 +00:00
# ANDROID_STANDALONE_TOOLCHAIN
2013-03-20 02:53:09 +00:00
#
# Primary read-only variables:
# ANDROID : always TRUE
# ARMEABI : TRUE for arm v6 and older devices
# ARMEABI_V6 : TRUE for arm v6
# ARMEABI_V7A : TRUE for arm v7a
2014-11-30 07:05:37 +00:00
# ARM64_V8A : TRUE for arm64-v8a
2013-03-20 02:53:09 +00:00
# NEON : TRUE if NEON unit is enabled
# VFPV3 : TRUE if VFP version 3 is enabled
# X86 : TRUE if configured for x86
2014-08-28 21:57:48 +00:00
# X86_64 : TRUE if configured for x86_64
2013-04-13 20:09:05 +00:00
# MIPS : TRUE if configured for mips
2014-08-28 21:57:48 +00:00
# MIPS64 : TRUE if configured for mips64
2013-03-20 02:53:09 +00:00
# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used
# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used
# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform
2014-11-30 07:05:37 +00:00
# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86", "mips", "arm64-v8a", "x86_64", "mips64" depending on ANDROID_ABI
2015-01-27 03:26:54 +00:00
# ANDROID_NDK_RELEASE : from r5 to r10d; set only for NDK
2014-11-30 07:05:37 +00:00
# ANDROID_NDK_RELEASE_NUM : numeric ANDROID_NDK_RELEASE version (1000*major+minor)
# ANDROID_ARCH_NAME : "arm", "x86", "mips", "arm64", "x86_64", "mips64" depending on ANDROID_ABI
2013-03-20 02:53:09 +00:00
# ANDROID_SYSROOT : path to the compiler sysroot
2013-04-13 20:09:05 +00:00
# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform
# ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used
2013-03-20 02:53:09 +00:00
#
# Secondary (less stable) read-only variables:
2014-11-30 07:05:37 +00:00
# ANDROID_COMPILER_VERSION : GCC version used (not Clang version)
# ANDROID_CLANG_VERSION : version of clang compiler if clang is used
2013-03-20 02:53:09 +00:00
# ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform
# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI
# ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux"
# ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK)
2013-04-13 20:09:05 +00:00
# ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools
2013-03-20 02:53:09 +00:00
# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK
2013-04-13 20:09:05 +00:00
# ANDROID_STL_INCLUDE_DIRS : stl include paths
# ANDROID_RTTI : if rtti is enabled by the runtime
# ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime
# ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used
2013-03-20 02:53:09 +00:00
#
# Defaults:
# ANDROID_DEFAULT_NDK_API_LEVEL
# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH}
# ANDROID_NDK_SEARCH_PATHS
# ANDROID_SUPPORTED_ABIS_${ARCH}
# ANDROID_SUPPORTED_NDK_VERSIONS