Updated android toolchain

pull/4132/head
Maksim Shabunin 10 years ago
parent f63dde2f43
commit 48cc53bf2e
  1. 322
      platforms/android/android.toolchain.cmake

@ -30,7 +30,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Android CMake toolchain file, for use with the Android NDK r5-r10d # Android CMake toolchain file, for use with the Android NDK r5-r10d
# Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended). # Requires cmake 2.6.3 or newer (2.8.9 or newer is recommended).
# See home page: https://github.com/taka-no-me/android-cmake # See home page: https://github.com/taka-no-me/android-cmake
# #
# Usage Linux: # Usage Linux:
@ -39,12 +39,6 @@
# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. # $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
# $ make -j8 # $ make -j8
# #
# Usage Linux (using standalone toolchain):
# $ export ANDROID_STANDALONE_TOOLCHAIN=/absolute/path/to/android-toolchain
# $ mkdir build && cd build
# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
# $ make -j8
#
# Usage Windows: # Usage Windows:
# You need native port of make to build your project. # You need native port of make to build your project.
# Android NDK r7 (and newer) already has make.exe on board. # Android NDK r7 (and newer) already has make.exe on board.
@ -63,11 +57,6 @@
# ANDROID_NDK=/opt/android-ndk - path to the NDK root. # ANDROID_NDK=/opt/android-ndk - path to the NDK root.
# Can be set as environment variable. Can be set only at first cmake run. # Can be set as environment variable. Can be set only at first cmake run.
# #
# ANDROID_STANDALONE_TOOLCHAIN=/opt/android-toolchain - path to the
# standalone toolchain. This option is not used if full NDK is found
# (ignored if ANDROID_NDK is set).
# Can be set as environment variable. Can be set only at first cmake run.
#
# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary # ANDROID_ABI=armeabi-v7a - specifies the target Application Binary
# Interface (ABI). This option nearly matches to the APP_ABI variable # Interface (ABI). This option nearly matches to the APP_ABI variable
# used by ndk-build tool from Android NDK. # used by ndk-build tool from Android NDK.
@ -123,8 +112,8 @@
# * x86_64-clang3.5 # * x86_64-clang3.5
# #
# ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions # ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions
# instead of Thumb. Is not available for "x86" (inapplicable) and # instead of Thumb. Is not available for "armeabi-v6 with VFP"
# "armeabi-v6 with VFP" (is forced to be ON) ABIs. # (is forced to be ON) ABI.
# #
# ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker # ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker
# errors even if they are not used. # errors even if they are not used.
@ -133,13 +122,6 @@
# libraries. Automatically turned for NDK r5x and r6x due to GLESv2 # libraries. Automatically turned for NDK r5x and r6x due to GLESv2
# problems. # problems.
# #
# LIBRARY_OUTPUT_PATH_ROOT=${CMAKE_SOURCE_DIR} - where to output binary
# files. See additional details below.
#
# ANDROID_SET_OBSOLETE_VARIABLES=ON - if set, then toolchain defines some
# obsolete variables which were used by previous versions of this file for
# backward compatibility.
#
# ANDROID_STL=gnustl_static - specify the runtime to use. # ANDROID_STL=gnustl_static - specify the runtime to use.
# #
# Possible values are: # Possible values are:
@ -200,12 +182,6 @@
# will be set true, mutually exclusive. NEON option will be set true # will be set true, mutually exclusive. NEON option will be set true
# if VFP is set to NEON. # if VFP is set to NEON.
# #
# LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where Android
# libraries will be installed.
# Default is ${CMAKE_SOURCE_DIR}, and the android libs will always be
# under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}
# (depending on the target ABI). This is convenient for Android packaging.
#
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
cmake_minimum_required( VERSION 2.6.3 ) cmake_minimum_required( VERSION 2.6.3 )
@ -235,22 +211,22 @@ endif()
# this one not so much # this one not so much
set( CMAKE_SYSTEM_VERSION 1 ) set( CMAKE_SYSTEM_VERSION 1 )
# rpath makes low sence for Android # rpath makes low sense for Android
set( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "" ) set( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "" )
set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." )
# NDK search paths # NDK search paths
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 "" ) 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) if( NOT DEFINED ANDROID_NDK_SEARCH_PATHS )
if( CMAKE_HOST_WIN32 ) if( CMAKE_HOST_WIN32 )
file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS )
set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}/android-ndk" "$ENV{SystemDrive}/NVPACK/android-ndk" ) set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}" "$ENV{SystemDrive}/NVPACK" )
else() else()
file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS ) file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS )
set( ANDROID_NDK_SEARCH_PATHS /opt/android-ndk "${ANDROID_NDK_SEARCH_PATHS}/NVPACK/android-ndk" ) set( ANDROID_NDK_SEARCH_PATHS /opt "${ANDROID_NDK_SEARCH_PATHS}/NVPACK" )
endif() endif()
endif() endif()
if(NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH) if( NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )
set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain ) set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain )
endif() endif()
@ -272,106 +248,90 @@ set( ANDROID_DEFAULT_NDK_API_LEVEL_mips64 21 )
macro( __LIST_FILTER listvar regex ) macro( __LIST_FILTER listvar regex )
if( ${listvar} ) if( ${listvar} )
foreach( __val ${${listvar}} ) foreach( __val ${${listvar}} )
if( __val MATCHES "${regex}" ) if( __val MATCHES "${regex}" )
list( REMOVE_ITEM ${listvar} "${__val}" ) list( REMOVE_ITEM ${listvar} "${__val}" )
endif() endif()
endforeach() endforeach()
endif() endif()
endmacro() endmacro()
macro( __INIT_VARIABLE var_name ) macro( __INIT_VARIABLE var_name )
set( __test_path 0 ) 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} ) foreach( __var ${ARGN} )
if( __var STREQUAL "VALUES" ) if( __var STREQUAL "PATH" )
set( __values 1 ) set( __test_path 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." )
endif()
break() break()
endif()
endif() endif()
endif()
endforeach() endforeach()
unset( __value )
unset( __values ) if( __test_path AND NOT EXISTS "${${var_name}}" )
unset( __obsolete ) unset( ${var_name} CACHE )
elseif( __test_path ) endif()
file( TO_CMAKE_PATH "${${var_name}}" ${var_name} )
endif() if( " ${${var_name}}" STREQUAL " " )
unset( __test_path ) 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 )
endmacro() endmacro()
macro( __DETECT_NATIVE_API_LEVEL _var _path ) macro( __DETECT_NATIVE_API_LEVEL _var _path )
SET( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*.*$" ) set( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*.*$" )
FILE( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) file( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" )
if( NOT __apiFileContent ) 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." ) 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() endif()
string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" )
unset( __apiFileContent ) unset( __apiFileContent )
unset( __ndkApiLevelRegex ) unset( __ndkApiLevelRegex )
endmacro() endmacro()
macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root )
if( EXISTS "${_root}" ) if( EXISTS "${_root}" )
file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" )
__LIST_FILTER( __gccExePath "^[.].*" ) __LIST_FILTER( __gccExePath "^[.].*" )
list( LENGTH __gccExePath __gccExePathsCount ) list( LENGTH __gccExePath __gccExePathsCount )
if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE ) if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE )
message( WARNING "Could not determine machine name for compiler from ${_root}" ) message( WARNING "Could not determine machine name for compiler from ${_root}" )
set( ${_var} "" ) set( ${_var} "" )
else()
get_filename_component( __gccExeName "${__gccExePath}" NAME_WE )
string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" )
endif()
unset( __gccExePath )
unset( __gccExePathsCount )
unset( __gccExeName )
else() else()
get_filename_component( __gccExeName "${__gccExePath}" NAME_WE ) set( ${_var} "" )
string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" )
endif() endif()
unset( __gccExePath )
unset( __gccExePathsCount )
unset( __gccExeName )
else()
set( ${_var} "" )
endif()
endmacro() endmacro()
@ -419,17 +379,19 @@ if( NOT ANDROID_NDK_HOST_X64 )
endif() endif()
# see if we have path to Android NDK # see if we have path to Android NDK
__INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) if( NOT ANDROID_NDK AND NOT ANDROID_STANDALONE_TOOLCHAIN )
__INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK )
endif()
if( NOT ANDROID_NDK ) if( NOT ANDROID_NDK )
# see if we have path to Android standalone toolchain # see if we have path to Android standalone toolchain
__INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN OBSOLETE_ANDROID_NDK_TOOLCHAIN_ROOT OBSOLETE_ENV_ANDROID_NDK_TOOLCHAIN_ROOT ) __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN )
if( NOT ANDROID_STANDALONE_TOOLCHAIN ) if( NOT ANDROID_STANDALONE_TOOLCHAIN )
#try to find Android NDK in one of the the default locations #try to find Android NDK in one of the the default locations
set( __ndkSearchPaths ) set( __ndkSearchPaths )
foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} ) foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} )
foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} ) foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} )
list( APPEND __ndkSearchPaths "${__ndkSearchPath}${suffix}" ) list( APPEND __ndkSearchPaths "${__ndkSearchPath}/android-ndk${suffix}" )
endforeach() endforeach()
endforeach() endforeach()
__INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} ) __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} )
@ -487,7 +449,7 @@ else()
or or
export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain
or put the toolchain or NDK in the default path: or put the toolchain or NDK in the default path:
sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH} sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH}/android-ndk
sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" )
endif() endif()
@ -636,7 +598,7 @@ if( BUILD_WITH_ANDROID_NDK )
endif() endif()
if( NOT __availableToolchains ) if( NOT __availableToolchains )
file( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" ) file( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" )
if( __availableToolchains ) if( __availableToolchainsLst )
list(SORT __availableToolchainsLst) # we need clang to go after gcc list(SORT __availableToolchainsLst) # we need clang to go after gcc
endif() endif()
__LIST_FILTER( __availableToolchainsLst "^[.]" ) __LIST_FILTER( __availableToolchainsLst "^[.]" )
@ -669,7 +631,7 @@ if( NOT ANDROID_SUPPORTED_ABIS )
endif() endif()
# choose target ABI # choose target ABI
__INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${ANDROID_SUPPORTED_ABIS} ) __INIT_VARIABLE( ANDROID_ABI VALUES ${ANDROID_SUPPORTED_ABIS} )
# verify that target ABI is supported # verify that target ABI is supported
list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx )
if( __androidAbiIdx EQUAL -1 ) if( __androidAbiIdx EQUAL -1 )
@ -760,7 +722,7 @@ if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMa
endif() endif()
if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 )
__INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF ) __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD VALUES OFF )
set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) 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 ) mark_as_advanced( ANDROID_FORCE_ARM_BUILD )
else() else()
@ -845,6 +807,7 @@ else()
unset( __realApiLevel ) unset( __realApiLevel )
endif() endif()
set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
set( CMAKE_ANDROID_API ${ANDROID_NATIVE_API_LEVEL} )
if( CMAKE_VERSION VERSION_GREATER "2.8" ) if( CMAKE_VERSION VERSION_GREATER "2.8" )
list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS )
set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
@ -863,16 +826,7 @@ endif()
# runtime choice (STL, rtti, exceptions) # runtime choice (STL, rtti, exceptions)
if( NOT ANDROID_STL ) if( NOT ANDROID_STL )
# honor legacy ANDROID_USE_STLPORT
if( DEFINED ANDROID_USE_STLPORT )
if( ANDROID_USE_STLPORT )
set( ANDROID_STL stlport_static )
endif()
message( WARNING "You are using an obsolete variable ANDROID_USE_STLPORT to select the STL variant. Use -DANDROID_STL=stlport_static instead." )
endif()
if( NOT ANDROID_STL )
set( ANDROID_STL gnustl_static ) set( ANDROID_STL gnustl_static )
endif()
endif() endif()
set( ANDROID_STL "${ANDROID_STL}" CACHE STRING "C++ runtime" ) 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" ) set( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and exceptions support based on C++ runtime" )
@ -1033,7 +987,7 @@ if( BUILD_WITH_ANDROID_NDK )
set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" )
elseif( ANDROID_STL MATCHES "gabi" ) elseif( ANDROID_STL MATCHES "gabi" )
if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7
message( FATAL_ERROR "gabi++ is not awailable in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.") message( FATAL_ERROR "gabi++ is not available in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.")
endif() endif()
set( ANDROID_RTTI ON ) set( ANDROID_RTTI ON )
set( ANDROID_EXCEPTIONS OFF ) set( ANDROID_EXCEPTIONS OFF )
@ -1144,7 +1098,12 @@ if( NOT CMAKE_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_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_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" ) if( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" )
# Use gcc-ar if we have it for better LTO support.
set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
else()
set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
endif()
set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) 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_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_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" )
@ -1233,7 +1192,7 @@ endif()
# NDK flags # NDK flags
if (ARM64_V8A ) if (ARM64_V8A )
set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -ffunction-sections -funwind-tables" ) set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" )
set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" )
set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" )
if( NOT ANDROID_COMPILER_IS_CLANG ) if( NOT ANDROID_COMPILER_IS_CLANG )
@ -1263,7 +1222,7 @@ elseif( X86 OR X86_64 )
set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" )
set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" )
elseif( MIPS OR MIPS64 ) elseif( MIPS OR MIPS64 )
set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0" ) set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-strict-aliasing -finline-functions -funwind-tables -fmessage-length=0" )
set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer" ) set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer" )
set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer" ) set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer" )
if( NOT ANDROID_COMPILER_IS_CLANG ) if( NOT ANDROID_COMPILER_IS_CLANG )
@ -1348,7 +1307,7 @@ if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7
else() else()
__INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF ) __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF )
endif() endif()
__INIT_VARIABLE( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON ) __INIT_VARIABLE( ANDROID_NO_UNDEFINED VALUES ON )
__INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON ) __INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON )
__INIT_VARIABLE( ANDROID_GOLD_LINKER VALUES ON ) __INIT_VARIABLE( ANDROID_GOLD_LINKER VALUES ON )
__INIT_VARIABLE( ANDROID_NOEXECSTACK VALUES ON ) __INIT_VARIABLE( ANDROID_NOEXECSTACK VALUES ON )
@ -1356,7 +1315,7 @@ __INIT_VARIABLE( ANDROID_RELRO VALUES ON )
set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" ) 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_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_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" )
set( ANDROID_GOLD_LINKER ${ANDROID_GOLD_LINKER} CACHE BOOL "Enables gold linker" ) set( ANDROID_GOLD_LINKER ${ANDROID_GOLD_LINKER} CACHE BOOL "Enables gold linker" )
set( ANDROID_NOEXECSTACK ${ANDROID_NOEXECSTACK} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) 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" ) set( ANDROID_RELRO ${ANDROID_RELRO} CACHE BOOL "Enables RELRO - a memory corruption mitigation technique" )
@ -1531,27 +1490,31 @@ if( ANDROID_EXPLICIT_CRT_LINK )
endif() endif()
# setup output directories # setup output directories
set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" )
set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
if(NOT _CMAKE_IN_TRY_COMPILE) if( DEFINED LIBRARY_OUTPUT_PATH_ROOT
if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) OR EXISTS "${CMAKE_SOURCE_DIR}/AndroidManifest.xml"
set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) OR (EXISTS "${CMAKE_SOURCE_DIR}/../AndroidManifest.xml" AND EXISTS "${CMAKE_SOURCE_DIR}/../jni/") )
else() set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "Root for binaries output, set this to change where Android libs are installed to" )
set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) if( NOT _CMAKE_IN_TRY_COMPILE )
endif() if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" )
set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) 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()
endif() endif()
# copy shaed stl library to build directory # copy shaed stl library to build directory
if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" ) if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" AND DEFINED LIBRARY_OUTPUT_PATH )
get_filename_component( __libstlname "${__libstl}" NAME ) get_filename_component( __libstlname "${__libstl}" NAME )
execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess ) 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}") 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}" ) message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" )
endif() endif()
unset( __fileCopyProcess ) unset( __fileCopyProcess )
unset( __libstlname ) unset( __libstlname )
endif() endif()
@ -1612,25 +1575,10 @@ macro( find_host_program )
endmacro() endmacro()
macro( ANDROID_GET_ABI_RAWNAME TOOLCHAIN_FLAG VAR )
if( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI" )
set( ${VAR} "armeabi" )
elseif( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI_V7A" )
set( ${VAR} "armeabi-v7a" )
elseif( "${TOOLCHAIN_FLAG}" STREQUAL "X86" )
set( ${VAR} "x86" )
elseif( "${TOOLCHAIN_FLAG}" STREQUAL "MIPS" )
set( ${VAR} "mips" )
else()
set( ${VAR} "unknown" )
endif()
endmacro()
# export toolchain settings for the try_compile() command # export toolchain settings for the try_compile() command
if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" ) if( NOT _CMAKE_IN_TRY_COMPILE )
set( __toolchain_config "") set( __toolchain_config "")
foreach( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN ANDROID_SET_OBSOLETE_VARIABLES foreach( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN
ANDROID_NDK_HOST_X64 ANDROID_NDK_HOST_X64
ANDROID_NDK ANDROID_NDK
ANDROID_NDK_LAYOUT ANDROID_NDK_LAYOUT
@ -1652,7 +1600,7 @@ if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" )
ANDROID_APP_PIE ANDROID_APP_PIE
) )
if( DEFINED ${__var} ) if( DEFINED ${__var} )
if( "${__var}" MATCHES " ") if( ${__var} MATCHES " ")
set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" ) set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" )
else() else()
set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" ) set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" )
@ -1677,16 +1625,6 @@ if( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 )
endif() endif()
# set some obsolete variables for backward compatibility
set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" )
mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES )
if( ANDROID_SET_OBSOLETE_VARIABLES )
set( ANDROID_API_LEVEL ${ANDROID_NATIVE_API_LEVEL} )
set( ARM_TARGET "${ANDROID_ABI}" )
set( ARMEABI_NDK_NAME "${ANDROID_NDK_ABI_NAME}" )
endif()
# Variables controlling behavior or set by cmake toolchain: # Variables controlling behavior or set by cmake toolchain:
# 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_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) # ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14,15,16,17,18,19,21 (depends on NDK version)
@ -1700,22 +1638,15 @@ endif()
# ANDROID_RELRO : ON/OFF # ANDROID_RELRO : ON/OFF
# ANDROID_FORCE_ARM_BUILD : ON/OFF # ANDROID_FORCE_ARM_BUILD : ON/OFF
# ANDROID_STL_FORCE_FEATURES : ON/OFF # ANDROID_STL_FORCE_FEATURES : ON/OFF
# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF # 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`
# Can be set only at the first run: # Can be set only at the first run:
# ANDROID_NDK # ANDROID_NDK : path to your NDK install
# ANDROID_STANDALONE_TOOLCHAIN # NDK_CCACHE : path to your ccache executable
# ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain # ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain
# ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems) # ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems)
# ANDROID_NDK_LAYOUT : the inner NDK structure (RELEASE, LINARO, ANDROID) # ANDROID_NDK_LAYOUT : the inner NDK structure (RELEASE, LINARO, ANDROID)
# LIBRARY_OUTPUT_PATH_ROOT : <any valid path> # LIBRARY_OUTPUT_PATH_ROOT : <any valid path>
# NDK_CCACHE : <path to your ccache executable> # ANDROID_STANDALONE_TOOLCHAIN
# Obsolete:
# ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL
# ARM_TARGET : superseded by ANDROID_ABI
# ARM_TARGETS : superseded by ANDROID_ABI (can be set only)
# ANDROID_NDK_TOOLCHAIN_ROOT : superseded by ANDROID_STANDALONE_TOOLCHAIN (can be set only)
# ANDROID_USE_STLPORT : superseded by ANDROID_STL=stlport_static
# ANDROID_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL (completely removed)
# #
# Primary read-only variables: # Primary read-only variables:
# ANDROID : always TRUE # ANDROID : always TRUE
@ -1729,7 +1660,6 @@ endif()
# X86_64 : TRUE if configured for x86_64 # X86_64 : TRUE if configured for x86_64
# MIPS : TRUE if configured for mips # MIPS : TRUE if configured for mips
# MIPS64 : TRUE if configured for mips64 # MIPS64 : TRUE if configured for mips64
# BUILD_ANDROID : always TRUE
# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used # BUILD_WITH_ANDROID_NDK : TRUE if NDK is used
# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain 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 # ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform
@ -1740,8 +1670,6 @@ endif()
# ANDROID_SYSROOT : path to the compiler sysroot # ANDROID_SYSROOT : path to the compiler sysroot
# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform
# ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used # ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used
# Obsolete:
# ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME
# #
# Secondary (less stable) read-only variables: # Secondary (less stable) read-only variables:
# ANDROID_COMPILER_VERSION : GCC version used (not Clang version) # ANDROID_COMPILER_VERSION : GCC version used (not Clang version)
@ -1756,12 +1684,10 @@ endif()
# ANDROID_RTTI : if rtti is enabled by the runtime # ANDROID_RTTI : if rtti is enabled by the runtime
# ANDROID_EXCEPTIONS : if exceptions are 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 # ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used
# 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`
# #
# Defaults: # Defaults:
# ANDROID_DEFAULT_NDK_API_LEVEL # ANDROID_DEFAULT_NDK_API_LEVEL
# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH} # ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH}
# ANDROID_NDK_SEARCH_PATHS # ANDROID_NDK_SEARCH_PATHS
# ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH
# ANDROID_SUPPORTED_ABIS_${ARCH} # ANDROID_SUPPORTED_ABIS_${ARCH}
# ANDROID_SUPPORTED_NDK_VERSIONS # ANDROID_SUPPORTED_NDK_VERSIONS

Loading…
Cancel
Save