set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP")
set( ANDROID_SUPPORTED_ABIS_x86 "x86")
set( ANDROID_SUPPORTED_ABIS_mipsel "mips")
set( ANDROID_DEFAULT_NDK_API_LEVEL 8 )
set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 )
set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 )
macro( __LIST_FILTER listvar regex )
if(${listvar})
foreach( __val ${${listvar}})
if( __val MATCHES "${regex}")
list( REMOVE_ITEM ${listvar}"${__val}")
endif()
endforeach()
endif()
endmacro()
macro( __INIT_VARIABLE var_name )
set( __test_path 0 )
foreach( __var ${ARGN})
if( __var STREQUAL "PATH")
set( __test_path 1 )
break()
endif()
endforeach()
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")
set( __obsolete 0 )
if( __var MATCHES "^OBSOLETE_.*$")
string( REPLACE "OBSOLETE_""" __var "${__var}")
set( __obsolete 1 )
endif()
if( __var MATCHES "^ENV_.*$")
string( REPLACE "ENV_""" __var "${__var}")
set( __value "$ENV{${__var}}")
elseif( DEFINED ${__var})
set( __value "${${__var}}")
else()
if( __values )
set( __value "${__var}")
else()
set( __value "")
endif()
endif()
if( NOT "${__value}" STREQUAL "")
if( __test_path )
if( EXISTS "${__value}")
file( TO_CMAKE_PATH "${__value}"${var_name})
if( __obsolete AND NOT _CMAKE_IN_TRY_COMPILE )
message( WARNING "Using value of obsolete variable ${__var} as initial value for ${var_name}. Please note, that ${__var} can be completely removed in future versions of the toolchain.")
endif()
break()
endif()
else()
set(${var_name}"${__value}")
if( __obsolete AND NOT _CMAKE_IN_TRY_COMPILE )
message( WARNING "Using value of obsolete variable ${__var} as initial value for ${var_name}. Please note, that ${__var} can be completely removed in future versions of the toolchain.")
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.")
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()
# detect current host platform
if( NOT DEFINED ANDROID_NDK_HOST_X64 AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64")
set( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain")
if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK )
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()
set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE )
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.
To configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\n${toolchains_list}\n")
endif()
list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch )
if( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME )
message( SEND_ERROR "Selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform.")
if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL )
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.")
endif()
unset( __realApiLevel )
endif()
set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
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( 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}\".
The possible values are:
none -> Do not configure the runtime.
system -> Use the default minimal system C++ runtime library.
system_re -> Same as system but with rtti and exceptions.
gabi++_static -> Use the GAbi++ runtime as a static library.
gabi++_shared -> Use the GAbi++ runtime as a shared library.
stlport_static -> Use the STLport runtime as a static library.
stlport_shared -> Use the STLport runtime as a shared library.
gnustl_static -> (default) Use the GNU STL as a static library.
gnustl_shared -> Use the GNU STL as a shared library.
")
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}\".
The possible values are:
none -> Do not configure the runtime.
gnustl_static -> (default) Use the GNU STL as a static library.
gnustl_shared -> Use the GNU STL as a shared library.
")
endif()
endif()
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).
You are strongly recommended to switch to another NDK release.
")
endif()
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:
See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc8093df6fee54454b8bcab6c2
# 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")
elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so")
# 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()
__INIT_VARIABLE( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON )
__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")
set( ANDROID_FUNCTION_LEVEL_LINKING ${ANDROID_FUNCTION_LEVEL_LINKING} CACHE BOOL "Allows or disallows undefined symbols in shared libraries")
set( ANDROID_GOLD_LINKER ${ANDROID_GOLD_LINKER} CACHE BOOL "Enables gold linker (only avaialble for NDK r8b for ARM and x86 architectures on linux-86 and darwin-x86 hosts)")
set( ANDROID_NOEXECSTACK ${ANDROID_NOEXECSTACK} CACHE BOOL "Allows or disallows undefined symbols in shared libraries")
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
On Linux and OS X host platform you can workaround this problem using gold linker (default).
Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems.