From 3bdb53e484a66c0c3f5e1b46e42b376ac72eb115 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 16 Nov 2011 14:32:10 +0000 Subject: [PATCH] Android cmake toolchain is reworked for NDK r7; added experimental Android x86 support. --- CMakeLists.txt | 22 +- OpenCVAndroidProject.cmake | 4 +- android/android.toolchain.cmake | 868 +++++++++++++----- android/scripts/build.cmd | 10 +- android/scripts/cmake_android_armeabi.sh | 2 +- android/scripts/cmake_android_neon.sh | 2 +- android/scripts/package.sh | 6 +- android/scripts/wincfg.cmd.tmpl | 18 +- modules/androidcamera/CMakeLists.txt | 2 +- modules/ts/include/opencv2/ts/ts.hpp | 2 +- modules/ts/misc/run.py | 12 +- .../android/hello-android/cmake_android.cmd | 2 +- 12 files changed, 684 insertions(+), 266 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e77f474d76..f07be0e0bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,7 @@ else() endif() if(ANDROID) - set(OPENCV_LIB_INSTALL_PATH libs/${ARMEABI_NDK_NAME}) + set(OPENCV_LIB_INSTALL_PATH libs/${ANDROID_NDK_ABI_NAME}) else() set(OPENCV_LIB_INSTALL_PATH lib${LIB_SUFFIX}) endif() @@ -745,7 +745,7 @@ endif() # Java support # =================================================== -if (PYTHON_EXECUTABLE AND ANDROID AND ANDROID_API_LEVEL GREATER 7) +if (PYTHON_EXECUTABLE AND ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7) option(BUILD_JAVA_SUPPORT "Build with Java support" TRUE) endif() @@ -815,7 +815,7 @@ if (BUILD_JAVA_SUPPORT) # detect ANDROID_SDK_TARGET if no target is provided by user if (NOT ANDROID_SDK_TARGET) - set(desired_android_target_level ${ANDROID_API_LEVEL}) + set(desired_android_target_level ${ANDROID_NATIVE_API_LEVEL}) if (desired_android_target_level LESS 8) set(desired_android_target_level 8) endif() @@ -1124,7 +1124,7 @@ if(WIN32) endif() ############## Android source tree for native camera ############### -if(ANDROID AND ANDROID_API_LEVEL GREATER 7) +if(ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7) option(WITH_ANDROID_CAMERA "Build with native Android camera support" TRUE) SET (ANDROID_SOURCE_TREE "ANDROID_SOURCE_TREE-NOTFOUND" CACHE PATH @@ -1398,8 +1398,8 @@ set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_P set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "") if(ANDROID) - set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/libs/\${ARMEABI_NDK_NAME}\"") - set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/libs/\${ARMEABI_NDK_NAME}\"") + set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/libs/\${ANDROID_NDK_ABI_NAME}\"") + set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/libs/\${ANDROID_NDK_ABI_NAME}\"") else() set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_LIB_INSTALL_PATH}\"") set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") @@ -1462,7 +1462,7 @@ if(ANDROID) set(CMAKE_CAMERA_LIBS_CONFIGCMAKE "native_camera_r${ANDROID_VERSION}") elseif(WITH_ANDROID_CAMERA) SET(CMAKE_CAMERA_LIBS_CONFIGCMAKE "") - file(GLOB CMAKE_CAMERA_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/lib/${ARMEABI_NDK_NAME}/libnative_camera_r*.so") + file(GLOB CMAKE_CAMERA_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/lib/${ANDROID_NDK_ABI_NAME}/libnative_camera_r*.so") foreach(cam_lib ${CMAKE_CAMERA_LIBS}) get_filename_component(cam_lib "${cam_lib}" NAME) string(REGEX REPLACE "lib(native_camera_r[0-9]+\\.[0-9]+\\.[0-9]+)\\.so" "\\1" cam_lib "${cam_lib}") @@ -1671,8 +1671,8 @@ else() endif() if(ANDROID) - status(" Floating point type:" ${ARM_TARGET}) - status(" Native API level:" android-${ANDROID_API_LEVEL}) + status(" Android ABI:" ${ANDROID_ABI}) + status(" Native API level:" android-${ANDROID_NATIVE_API_LEVEL}) status(" SDK target:" "${ANDROID_SDK_TARGET}") endif() @@ -1735,7 +1735,7 @@ if(UNIX AND NOT APPLE) if(ANDROID) if(WITH_ANDROID_CAMERA) - status(" AndroidNativeCamera:" BUILD_ANDROID_CAMERA_WRAPPER THEN "build for Android ${ANDROID_VERSION}" ELSE "use prebuilt libraries") + status(" AndroidNativeCamera:" BUILD_ANDROID_CAMERA_WRAPPER THEN "YES, build for Android ${ANDROID_VERSION}" ELSE "YES, use prebuilt libraries") else() status(" AndroidNativeCamera:" "NO (native camera requires Android API level 8 or higher)") endif() @@ -1776,7 +1776,7 @@ status(" Interfaces:") status(" Python:" BUILD_NEW_PYTHON_SUPPORT THEN YES ELSE NO) status(" Python interpreter:" PYTHON_EXECUTABLE THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_MAJOR_MINOR})" ELSE NO) status(" Python numpy:" PYTHON_USE_NUMPY THEN YES ELSE "NO (Python wrappers will not be generated)") -if(ANDROID AND ANDROID_API_LEVEL LESS 8) +if(ANDROID AND ANDROID_NATIVE_API_LEVEL LESS 8) status(" Java:" "NO (Java API requires Android API level 8 or higher)") else() status(" Java:" BUILD_JAVA_SUPPORT THEN YES ELSE NO) diff --git a/OpenCVAndroidProject.cmake b/OpenCVAndroidProject.cmake index d3f3b6c17a..5fc454b7a8 100644 --- a/OpenCVAndroidProject.cmake +++ b/OpenCVAndroidProject.cmake @@ -106,13 +106,13 @@ macro(add_android_project _target _path) set_target_properties(${JNI_LIB_NAME} PROPERTIES OUTPUT_NAME "${JNI_LIB_NAME}" - LIBRARY_OUTPUT_DIRECTORY "${build_path}/libs/${ARMEABI_NDK_NAME}" + LIBRARY_OUTPUT_DIRECTORY "${build_path}/libs/${ANDROID_NDK_ABI_NAME}" ) ADD_CUSTOM_COMMAND( TARGET ${JNI_LIB_NAME} POST_BUILD - COMMAND ${CMAKE_STRIP} "${build_path}/libs/${ARMEABI_NDK_NAME}/*.so" + COMMAND ${CMAKE_STRIP} "${build_path}/libs/${ANDROID_NDK_ABI_NAME}/*.so" ) else() SET(JNI_LIB_NAME) diff --git a/android/android.toolchain.cmake b/android/android.toolchain.cmake index fdabbfcac0..8bc81fc274 100644 --- a/android/android.toolchain.cmake +++ b/android/android.toolchain.cmake @@ -1,5 +1,5 @@ # ---------------------------------------------------------------------------- -# Android CMake toolchain file, for use with the ndk r5,r6 +# Android CMake toolchain file, for use with the ndk r5,r6,r7 # See home page: http://code.google.com/p/android-cmake/ # # Usage Linux: @@ -8,56 +8,63 @@ # $ make # # Usage Linux (using standalone toolchain): -# $ export ANDROID_NDK_TOOLCHAIN_ROOT=/ +# $ export ANDROID_STANDALONE_TOOLCHAIN=/ # $ cmake -DCMAKE_TOOLCHAIN_FILE=/android.toolchain.cmake .. # $ make # # Usage Windows: # You need native port of make to build your project. +# NDK r7 already has make.exe on board. For older versions you need to intall it seperately. # For example this one: http://gnuwin32.sourceforge.net/packages/make.htm # -# $ SET ANDROID_NDK=C:\\android-ndk-r6b -# $ cmake.exe -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=C:\\make.exe .. -# $ C:\\make.exe +# $ SET ANDROID_NDK=C:\\android-ndk-r7 +# $ cmake.exe -G"MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=\android.toolchain.cmake -DCMAKE_BUILD_TOOL="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" .. +# $ "%ANDROID_NDK%\prebuilt\windows\bin\make.exe" # # # Toolchain options (can be set as cmake parameters: -D=): -# ANDROID_NDK=/opt/android-ndk-r6b - path to NDK root. -# Can be set as environment variable. +# ANDROID_NDK=/opt/android-ndk-r7 - path to NDK root. +# Can be set as environment variable. Can be set only at first cmake run. # -# ANDROID_NDK_TOOLCHAIN_ROOT=/opt/android-toolchain - path to standalone toolchain. +# ANDROID_STANDALONE_TOOLCHAIN=/opt/android-toolchain - path to standalone toolchain. # Option is not used if full NDK is found. Can be set as environment variable. +# Can be set only at first cmake run. # -# ANDROID_API_LEVEL=android-8 - level of android API to use. -# Option is ignored when build uses stanalone toolchain. +# ANDROID_ABI=armeabi-v7a - type of floating point support. +# Other possible values are: "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86" # -# ARM_TARGET=armeabi-v7a - type of floating point support. -# Other possible values are: "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3" +# ANDROID_NATIVE_API_LEVEL=android-8 - level of android API to use. +# Option is read-only when build uses stanalone toolchain. # -# FORCE_ARM=false - set true to generate 32-bit ARM instructions instead of Thumb-1. +# ANDROID_FORCE_ARM_BUILD=OFF - set true to generate 32-bit ARM instructions instead of Thumb-1. +# Is not available for "x86" (missing) and "armeabi-v6 with VFP" (forced) ABIs. # -# NO_UNDEFINED=true - set true to show all undefined symbols will as linker errors even if they are not used. +# ANDROID_NO_UNDEFINED=ON - set true to show all undefined symbols as linker errors even if they are not used. # +# LIBRARY_OUTPUT_PATH_ROOT=${CMAKE_SOURCE_DIR} - where to output binary files. See details below. # -# Toolcahin will search for NDK/toolchain in following order: +# ANDROID_SET_OBSOLETE_VARIABLES=ON - it set, then toolchain define some obsolete variables which +# was set by previous versions of this file for backward compatibility. +# +# android-cmake toolcahain will search 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 location -# ANDROID_NDK_TOOLCHAIN_ROOT - cmake parameter -# ANDROID_NDK_TOOLCHAIN_ROOT - environment variable -# ANDROID_NDK_TOOLCHAIN_ROOT - default location +# ANDROID_STANDALONE_TOOLCHAIN - default location # # # What?: # 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}") +# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" ) +# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" ) # The flags will be prepopulated with critical flags, so don't loose them. # # ANDROID and BUILD_ANDROID will be set to true, you may test these # variables to make necessary changes. # -# Also ARMEABI and ARMEABI_V7A will be set true, mutually exclusive. V7A is +# Also ARMEABI or ARMEABI_V7A or X86 will be set true, mutually exclusive. V7A is # for floating point. NEON option will be set true if fpu is set to neon. # # LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where android @@ -101,6 +108,16 @@ # [~] allowed spaces in NDK path # - modified September 2011 Andrey Kamaev andrey.kamaev@itseez.com # [~] updated for NDK r6b +# - modified November 2011 Andrey Kamaev andrey.kamaev@itseez.com +# [~] rewritten for NDK r7 +# [+] x86 toolchain support (experimental) +# [~] improved compiler and linker flags management +# [+] support different build flags for Release and Debug configurations +# [~] by default compiler flags the same as used by ndk-build (but only where reasonable) +# [~] ANDROID_NDK_TOOLCHAIN_ROOT is splitted to ANDROID_STANDALONE_TOOLCHAIN and ANDROID_TOOLCHAIN_ROOT +# [~] ARM_TARGET is remaned to ANDROID_ABI +# [~] ARMEABI_NDK_NAME is renamed to ANDROID_NDK_ABI_NAME +# [~] ANDROID_API_LEVEL is renamed to ANDROID_NATIVE_API_LEVEL # ---------------------------------------------------------------------------- # this one is important @@ -108,269 +125,606 @@ set( CMAKE_SYSTEM_NAME Linux ) #this one not so much set( CMAKE_SYSTEM_VERSION 1 ) -set( ANDROID_NDK_DEFAULT_SEARCH_PATH /opt/android-ndk ) -set( ANDROID_NDK_SUPPORTED_VERSIONS -r6b -r6 -r5c -r5b -r5 "") -set( ANDROID_NDK_TOOLCHAIN_DEFAULT_SEARCH_PATH /opt/android-toolchain ) -set( TOOL_OS_SUFFIX "" ) - -macro( __TOOLCHAIN_DETECT_API_LEVEL _path ) - SET( _expected ${ARGV1} ) - if( NOT EXISTS ${_path} ) - message( FATAL_ERROR "Could not verify Android API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) - endif() - SET( API_LEVEL_REGEX "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*$" ) - FILE( STRINGS ${_path} API_FILE_CONTENT REGEX "${API_LEVEL_REGEX}") - if( NOT API_FILE_CONTENT ) - message( FATAL_ERROR "Could not verify Android API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) - endif() - string( REGEX REPLACE "${API_LEVEL_REGEX}" "\\1" ANDROID_LEVEL_FOUND "${API_FILE_CONTENT}" ) - if( DEFINED _expected ) - if( NOT ${ANDROID_LEVEL_FOUND} EQUAL ${_expected} ) - message( FATAL_ERROR "Specified Android API level does not match level found. Probably your copy of NDK/toolchain is broken." ) - endif() - endif() - set( ANDROID_API_LEVEL ${ANDROID_LEVEL_FOUND} CACHE STRING "android API level" FORCE ) -endmacro() - -if( NOT DEFINED ANDROID_NDK ) - set( ANDROID_NDK $ENV{ANDROID_NDK} ) -endif() - -if( NOT DEFINED ANDROID_NDK_TOOLCHAIN_ROOT ) - set( ANDROID_NDK_TOOLCHAIN_ROOT $ENV{ANDROID_NDK_TOOLCHAIN_ROOT} ) +set( ANDROID_SUPPORTED_NDK_VERSIONS -r7 -r6b -r6 -r5c -r5b -r5 "" ) +if( CMAKE_HOST_WIN32 ) + file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATH ) + set( ANDROID_NDK_SEARCH_PATH "${ANDROID_NDK_SEARCH_PATH}/android-ndk" ) +else() + set( ANDROID_NDK_SEARCH_PATH /opt/android-ndk ) endif() - -#set path for android NDK -- look -if( NOT EXISTS "${ANDROID_NDK}" AND NOT DEFINED ANDROID_NDK_TOOLCHAIN_ROOT ) - foreach(ndk_version ${ANDROID_NDK_SUPPORTED_VERSIONS}) - if( EXISTS ${ANDROID_NDK_DEFAULT_SEARCH_PATH}${ndk_version} ) - set ( ANDROID_NDK ${ANDROID_NDK_DEFAULT_SEARCH_PATH}${ndk_version} ) - message( STATUS "Using default path for android NDK ${ANDROID_NDK}" ) - message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_NDK" ) +set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain ) +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_DEFAULT_NDK_API_LEVEL 8 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 ) + +macro( __INIT_VARIABLE var_name ) + set( __test_path 0 ) + foreach( __var ${ARGN} ) + if( __var STREQUAL "PATH" ) + set( __test_path 1 ) break() endif() endforeach() -endif() + 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}" ) + set( ${var_name} "${__value}" ) + if( __obsolete ) + 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 ) + 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() + endif() + endif() + endforeach() + unset( __value ) + unset( __values ) + unset( __obsolete ) + endif() + unset( __test_path ) +endmacro() + +macro( __DETECT_NATIVE_API_LEVEL _var _path ) + SET( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*$" ) + FILE( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) + if( NOT __apiFileContent ) + message( FATAL_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 ) +endmacro() -if( EXISTS "${ANDROID_NDK}" ) - set( ANDROID_NDK "${ANDROID_NDK}" CACHE PATH "root of the android ndk" FORCE ) - - if( APPLE ) - set( NDKSYSTEM "darwin-x86" ) - elseif( WIN32 ) - set( NDKSYSTEM "windows" ) - set( TOOL_OS_SUFFIX ".exe" ) - elseif( UNIX ) - set( NDKSYSTEM "linux-x86" ) +macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) + file( GLOB __gccExePath "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) + list( LENGTH __gccExePath __gccExePathsCount ) + if( NOT __gccExePathsCount EQUAL 1 ) + message( SEND_ERROR "Could not uniquely determine machine name for compiler from ${_root}." ) + set( ${_var} "" ) else() - message( FATAL_ERROR "Your platform is not supported" ) + get_filename_component( __gccExeName "${__gccExePath}" NAME_WE ) + string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" ) endif() + unset( __gccExePath ) + unset( __gccExePathsCount ) + unset( __gccExeName ) +endmacro() - set( ANDROID_API_LEVEL $ENV{ANDROID_API_LEVEL} ) - string( REGEX REPLACE "[\t ]*android-([0-9]+)[\t ]*" "\\1" ANDROID_API_LEVEL "${ANDROID_API_LEVEL}" ) - string( REGEX REPLACE "[\t ]*([0-9]+)[\t ]*" "\\1" ANDROID_API_LEVEL "${ANDROID_API_LEVEL}" ) +#detect current host platform +set( TOOL_OS_SUFFIX "" ) +if( CMAKE_HOST_APPLE ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" ) +elseif( CMAKE_HOST_WIN32 ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "windows" ) + set( TOOL_OS_SUFFIX ".exe" ) +elseif( CMAKE_HOST_UNIX ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" ) +else() + message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) +endif() - set( PossibleAndroidLevels "3;4;5;8;9" ) - set( ANDROID_API_LEVEL ${ANDROID_API_LEVEL} CACHE STRING "android API level" ) - if( CMAKE_VERSION VERSION_GREATER "2.8") - set_property( CACHE ANDROID_API_LEVEL PROPERTY STRINGS ${PossibleAndroidLevels} ) - endif() - - if( NOT ANDROID_API_LEVEL GREATER 2 ) - set( ANDROID_API_LEVEL 8) - message( STATUS "Using default android API level android-${ANDROID_API_LEVEL}" ) - message( STATUS " If you prefer to use a different API level, please define the variable: ANDROID_API_LEVEL" ) +#see if we have path to Android NDK +__INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) +if( NOT ANDROID_NDK ) + #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 ) + + if( NOT ANDROID_STANDALONE_TOOLCHAIN ) + #try to find Android NDK in one of the the default locations + set( __ndkSearchPaths ) + foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} ) + list( APPEND __ndkSearchPaths "${ANDROID_NDK_SEARCH_PATH}${suffix}" ) + 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 ) + +#remember found paths +if( ANDROID_NDK ) + get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE ) + #try to detect change + if( CMAKE_AR ) + string( LENGTH "${ANDROID_NDK}" __length ) + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath ) + if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK ) + message( FATAL_ERROR "It is not possible to change path to the NDK on subsequent run." ) + endif() + unset( __androidNdkPreviousPath ) + unset( __length ) endif() - - set( ANDROID_NDK_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/${NDKSYSTEM}" ) - set( ANDROID_NDK_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_API_LEVEL}/arch-arm" ) - - __TOOLCHAIN_DETECT_API_LEVEL( "${ANDROID_NDK_SYSROOT}/usr/include/android/api-level.h" ${ANDROID_API_LEVEL} ) - - #message( STATUS "Using android NDK from ${ANDROID_NDK}" ) + set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" ) set( BUILD_WITH_ANDROID_NDK True ) -else() - #try to find toolchain - if( NOT EXISTS "${ANDROID_NDK_TOOLCHAIN_ROOT}" ) - set( ANDROID_NDK_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAIN_DEFAULT_SEARCH_PATH}" ) - message( STATUS "Using default path for toolchain ${ANDROID_NDK_TOOLCHAIN_ROOT}" ) - message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_NDK_TOOLCHAIN_ROOT" ) +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() - - set( ANDROID_NDK_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAIN_ROOT}" CACHE PATH "root of the Android NDK standalone toolchain" FORCE ) - set( ANDROID_NDK_SYSROOT "${ANDROID_NDK_TOOLCHAIN_ROOT}/sysroot" ) - - if( NOT EXISTS "${ANDROID_NDK_TOOLCHAIN_ROOT}" ) - message( FATAL_ERROR "neither ${ANDROID_NDK} nor ${ANDROID_NDK_TOOLCHAIN_ROOT} does not exist! + set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" ) + set( BUILD_WITH_STANDALONE_TOOLCHAIN True ) +else() + message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolcahin. You should either set an environment variable: export ANDROID_NDK=~/my-android-ndk or - export ANDROID_NDK_TOOLCHAIN_ROOT=~/my-android-toolchain + export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain or put the toolchain or NDK in the default path: - sudo ln -s ~/my-android-ndk ${ANDROID_NDK_DEFAULT_SEARCH_PATH} - sudo ln -s ~/my-android-toolchain ${ANDROID_NDK_TOOLCHAIN_DEFAULT_SEARCH_PATH}" ) - endif() - - __TOOLCHAIN_DETECT_API_LEVEL( "${ANDROID_NDK_SYSROOT}/usr/include/android/api-level.h" ) + sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH} + sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) +endif() - #message( STATUS "Using android NDK standalone toolchain from ${ANDROID_NDK_TOOLCHAIN_ROOT}" ) - set( BUILD_WITH_ANDROID_NDK_TOOLCHAIN True ) +#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( __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() + if( __availableToolchainMachines MATCHES i686 ) + set( __availableToolchainArchs "x86" ) + elseif( __availableToolchainMachines MATCHES arm ) + set( __availableToolchainArchs "arm" ) + endif() + if( ANDROID_COMPILER_VERSION ) + #do not run gcc every time because it is relatevely expencive + set( __availableToolchainCompilerVersions "${ANDROID_COMPILER_VERSION}" ) + else() + execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version + OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) + endif() endif() -# specify the cross compiler -set( CMAKE_C_COMPILER "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" FORCE ) -set( CMAKE_CXX_COMPILER "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" FORCE ) -#there may be a way to make cmake deduce these TODO deduce the rest of the tools -set( CMAKE_AR "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" FORCE ) -set( CMAKE_LINKER "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" FORCE ) -set( CMAKE_NM "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" FORCE ) -set( CMAKE_OBJCOPY "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" FORCE ) -set( CMAKE_OBJDUMP "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" FORCE ) -set( CMAKE_STRIP "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" FORCE ) -set( CMAKE_RANLIB "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" FORCE ) - -#setup build targets, mutually exclusive -set( PossibleArmTargets "armeabi;armeabi-v7a;armeabi-v7a with NEON;armeabi-v7a with VFPV3" ) -#compatibility junk for previous version of toolchain -if( DEFINED ARM_TARGETS AND NOT DEFINED ARM_TARGET ) - set( ARM_TARGET "${ARM_TARGETS}" ) +#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}" ) + file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" ) + set( __availableToolchainMachines "" ) + set( __availableToolchainArchs "" ) + set( __availableToolchainCompilerVersions "" ) + foreach( __toolchain ${__availableToolchains} ) + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + if( __machine ) + string( REGEX MATCH "[0-9]+.[0-9]+.[0-9]+$" __version "${__toolchain}" ) + string( REGEX MATCH "^[^-]+" __arch "${__toolchain}" ) + list( APPEND __availableToolchainMachines ${__machine} ) + list( APPEND __availableToolchainArchs ${__arch} ) + list( APPEND __availableToolchainCompilerVersions ${__version} ) + else() + list( REMOVE_ITEM __availableToolchains "${__toolchain}" ) + endif() + endforeach() + if( NOT __availableToolchains ) + message( FATAL_ERROR "Could not any working toolchain in the NDK. Probably your Android NDK is broken." ) + endif() endif() -IF( NOT ARM_TARGET) - set( ARM_TARGET armeabi-v7a ) -ENDIF() -set( ARM_TARGET "${ARM_TARGET}" CACHE INTERNAL "the arm target for android, recommend armeabi-v7a for floating point support and NEON." ) -if( CMAKE_VERSION VERSION_GREATER "2.8") - set_property( CACHE ARM_TARGET PROPERTY STRINGS ${PossibleArmTargets} ) + +#build list of available ABIs +if( NOT ANDROID_SUPPORTED_ABIS ) + 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 ) + if( NOT ANDROID_SUPPORTED_ABIS ) + message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) + endif() endif() -#set these flags for client use -if( ARM_TARGET STREQUAL "armeabi" ) +#choose target ABI +__INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${ANDROID_SUPPORTED_ABIS} ) +#verify that target ABI is supported +list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) +if( __androidAbiIdx EQUAL -1 ) + string( REPLACE ";" "\", \"", PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" ) + message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain. + Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\" + " ) +endif() +unset( __androidAbiIdx ) + +#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 ) + +#set target ABI options +if( ANDROID_ABI STREQUAL "x86" ) + set( X86 true ) + set( ANDROID_NDK_ABI_NAME "x86" ) + set( ANDROID_ARCH_NAME "x86" ) + set( CMAKE_SYSTEM_PROCESSOR "i686" ) +elseif( ANDROID_ABI STREQUAL "armeabi" ) set( ARMEABI true ) - set( ARMEABI_NDK_NAME "armeabi" ) - set( NEON false ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) -else() - if( ARM_TARGET STREQUAL "armeabi-v7a with NEON" ) - set( NEON true ) - set( VFPV3 true ) - elseif( ARM_TARGET STREQUAL "armeabi-v7a with VFPV3" ) - set( VFPV3 true ) - elseif( NOT ARM_TARGET STREQUAL "armeabi-v7a") - message( FATAL_ERROR "Unsupported ARM_TARGET=${ARM_TARGET} is specified. -Supported values are: \"armeabi\", \"armeabi-v7a\", \"armeabi-v7a with NEON\", \"armeabi-v7a with VFPV3\" -" ) - endif() +elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) + set( ARMEABI_V6 true ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) + 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" ) + 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" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) set( ARMEABI_V7A true ) - set( ARMEABI_NDK_NAME "armeabi-v7a" ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) + set( NEON true ) +else() + message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." ) +endif() + +set( ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} CACHE INTERNAL "ANDROID_ABI can be changed only to one of these ABIs. Changing to any other ABI requires to reset cmake cache." ) +if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} ) + set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} ) endif() +if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) + __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF ) + 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 ) + message( FATAL_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing. You need to remove CMakeCache.txt and rerun cmake manually to change the toolchain" ) + endif() + list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) + if( NOT __toolchainArch STREQUAL ANDROID_ARCH_NAME ) + message( FATAL_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) + 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 ) + if( __toolchainArch STREQUAL ANDROID_ARCH_NAME ) + list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion ) + 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 ) +set( ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" CACHE INTERNAL "Name of toolchain used" ) +set( ANDROID_COMPILER_VERSION "${ANDROID_COMPILER_VERSION}" CACHE INTERNAL "compiler version from selected toolchain" ) +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_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL ) +string( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) +#validate +list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) +if( __levelIdx EQUAL -1 ) + message( FATAL_ERROR "Specified Android native API level (${ANDROID_NATIVE_API_LEVEL}) is not supported by your NDK/toolchain." ) +endif() +unset( __levelIdx ) +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 ) + message( FATAL_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 ) +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() + +#setup paths +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) + set( __stlLibPath "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) +endif() +if( BUILD_WITH_ANDROID_NDK ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include" ) + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}" ) +endif() + +# specify the cross compiler +set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" ) +set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" ) +set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) +#there may be a way to make cmake deduce these TODO deduce the rest of the tools +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" ) + #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( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS OFF CACHE BOOL "") +set( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS OFF CACHE BOOL "" ) if( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS ) if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) - set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ARMEABI_NDK_NAME}" CACHE PATH "Output directory for applications") + 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") + 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/${ARMEABI_NDK_NAME}" CACHE PATH "path for android libs") - set( CMAKE_INSTALL_PREFIX "${ANDROID_NDK_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) + set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) endif() -SET( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS ON CACHE INTERNAL "" FORCE) - -# where is the target environment -set( CMAKE_FIND_ROOT_PATH "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin" "${ANDROID_NDK_TOOLCHAIN_ROOT}/arm-linux-androideabi" "${ANDROID_NDK_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) +set( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS ON CACHE INTERNAL "" FORCE ) -if( BUILD_WITH_ANDROID_NDK ) - set( STL_PATH "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" ) - set( STL_LIBRARIES_PATH "${STL_PATH}/libs/${ARMEABI_NDK_NAME}" ) - include_directories(SYSTEM "${STL_PATH}/include" "${STL_LIBRARIES_PATH}/include" ) -# if ( NOT ARMEABI AND NOT FORCE_ARM ) -# set( STL_LIBRARIES_PATH "${ANDROID_NDK_TOOLCHAIN_ROOT}/arm-linux-androideabi/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) -# endif() +#includes +include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ) +if( __stlIncludePath AND EXISTS "${__stlIncludePath}" ) + include_directories( SYSTEM "${__stlIncludePath}" ) endif() -if( BUILD_WITH_ANDROID_NDK_TOOLCHAIN ) - set( STL_LIBRARIES_PATH "${ANDROID_NDK_TOOLCHAIN_ROOT}/arm-linux-androideabi/lib" ) - if( NOT ARMEABI ) - set( STL_LIBRARIES_PATH "${STL_LIBRARIES_PATH}/${CMAKE_SYSTEM_PROCESSOR}" ) - endif() - if( NOT FORCE_ARM ) - set( STL_LIBRARIES_PATH "${STL_LIBRARIES_PATH}/thumb" ) - endif() - #for some reason this is needed? TODO figure out why... - include_directories(SYSTEM "${ANDROID_NDK_TOOLCHAIN_ROOT}/arm-linux-androideabi/include/c++/4.4.3/arm-linux-androideabi" ) +#STL bits includes +if( __stlLibPath AND EXISTS "${__stlLibPath}/include" ) + include_directories( SYSTEM "${__stlLibPath}/include" ) +endif() +if( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/thumb/bits" ) + include_directories( SYSTEM "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) +elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) + include_directories( SYSTEM "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) +elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) + include_directories( SYSTEM "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) +elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/bits" ) + include_directories( SYSTEM "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) endif() -# 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 ) - -set( CMAKE_CXX_FLAGS "-fPIC -DANDROID -Wno-psabi -fsigned-char" ) -set( CMAKE_C_FLAGS "-fPIC -DANDROID -Wno-psabi -fsigned-char" ) - -set( FORCE_ARM OFF CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" ) -if( NOT FORCE_ARM ) - #It is recommended to use the -mthumb compiler flag to force the generation - #of 16-bit Thumb-1 instructions (the default being 32-bit ARM ones). - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb" ) - set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb" ) +#flags and definitions +set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" ) +remove_definitions( -DANDROID ) +add_definitions( -DANDROID ) + +# NDK flags +if( ARMEABI OR ARMEABI_V7A ) + # NDK also defines -ffunction-sections -funwind-tables but they result in worse OpenCV performance + set( CMAKE_CXX_FLAGS "-fPIC -Wno-psabi -frtti -fexceptions" ) + set( CMAKE_CXX_FLAGS "-fPIC -Wno-psabi -fexceptions" ) + remove_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ) + add_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ) + # extra arm-specific flags + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) +elseif( X86 ) + set( CMAKE_CXX_FLAGS "-ffunction-sections -funwind-tables -frtti -fexceptions" ) + set( CMAKE_C_FLAGS "-ffunction-sections -funwind-tables -fexceptions" ) else() - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm" ) - set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm" ) + set( CMAKE_CXX_FLAGS "" ) + set( CMAKE_C_FLAGS "" ) endif() -if( BUILD_WITH_ANDROID_NDK ) - set( CMAKE_CXX_FLAGS "--sysroot=\"${ANDROID_NDK_SYSROOT}\" ${CMAKE_CXX_FLAGS}" ) - set( CMAKE_C_FLAGS "--sysroot=\"${ANDROID_NDK_SYSROOT}\" ${CMAKE_C_FLAGS}" ) - - # workaround for ugly cmake bug - compiler identification replaces all spaces (and somethimes " !!!) in compiler flags with ; symbol - # as result identification fails if ANDROID_NDK_SYSROOT contain spaces - include(CMakeForceCompiler) - CMAKE_FORCE_C_COMPILER("${CMAKE_C_COMPILER}" GNU) - CMAKE_FORCE_CXX_COMPILER("${CMAKE_CXX_COMPILER}" GNU) +#release and debug flags +if( ARMEABI OR ARMEABI_V7A ) + if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 ) + #It is recommended to use the -mthumb compiler flag to force the generation + #of 16-bit Thumb-1 instructions (the default being 32-bit ARM ones). + # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc + set( CMAKE_CXX_FLAGS_RELEASE "-mthumb -O3" ) + set( CMAKE_C_FLAGS_RELEASE "-mthumb -O3" ) + set( CMAKE_CXX_FLAGS_DEBUG "-marm -Os -finline-limit=64" ) + set( CMAKE_C_FLAGS_DEBUG "-marm -Os -finline-limit=64" ) + else() + # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI + # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc + set( CMAKE_CXX_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" ) + set( CMAKE_C_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" ) + set( CMAKE_CXX_FLAGS_DEBUG "-marm -O0 -finline-limit=300" ) + set( CMAKE_C_FLAGS_DEBUG "-marm -O0 -finline-limit=300" ) + endif() +elseif( X86 ) + set( CMAKE_CXX_FLAGS_RELEASE "-O3 -fstrict-aliasing" ) + set( CMAKE_C_FLAGS_RELEASE "-O3 -fstrict-aliasing" ) + set( CMAKE_CXX_FLAGS_DEBUG "-O0 -finline-limit=300" ) + set( CMAKE_C_FLAGS_DEBUG "-O0 -finline-limit=300" ) endif() +set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" ) +set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" ) +set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" ) +set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" ) +#ABI-specific flags if( ARMEABI_V7A ) - #these are required flags for android armv7-a - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) - set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) if( NEON ) - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon" ) - set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" ) elseif( VFPV3 ) - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfpv3" ) - set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfpv3" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfp" ) endif() +elseif( ARMEABI_V6 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) +elseif( ARMEABI ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) +elseif( X86 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" )#sse? endif() -set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" ) -set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags" ) - -#-Wl,-L${LIBCPP_LINK_DIR},-lstdc++,-lsupc++ -#-L${LIBCPP_LINK_DIR} -lstdc++ -lsupc++ -#Also, this is *required* to use the following linker flags that routes around -#a CPU bug in some Cortex-A8 implementations: -set( LINKER_FLAGS "-Wl,--fix-cortex-a8 -L\"${STL_LIBRARIES_PATH}\" -L\"${CMAKE_INSTALL_PREFIX}/libs/${ARMEABI_NDK_NAME}\" -lstdc++ -lsupc++ " ) - -set( NO_UNDEFINED ON CACHE BOOL "Don't all undefined symbols" ) -if( NO_UNDEFINED ) +#linker flags +set( LINKER_FLAGS "-L\"${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}\" -L\"${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}\"" ) +#STL +if( NOT EXISTS "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" ) + if( EXISTS "${__stlLibPath}/libgnustl_static.a" ) + file( COPY "${__stlLibPath}/libgnustl_static.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + file( RENAME "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) + file( COPY "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) + file( COPY "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/thumb/libstdc++.a" ) + file( COPY "${__stlLibPath}/thumb/libstdc++.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + elseif( EXISTS "${__stlLibPath}/libstdc++.a" ) + file( COPY "${__stlLibPath}/libstdc++.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + endif() +endif() +if( EXISTS "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" ) + set( LINKER_FLAGS "${LINKER_FLAGS} -lstdc++" ) +endif() + +if( NOT EXISTS "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) + if( EXISTS "${__stlLibPath}/libsupc++.a" ) + file( COPY "${__stlLibPath}/libsupc++.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" ) + file( COPY "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" ) + file( COPY "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" ) + file( COPY "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" ) + file( COPY "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" DESTINATION "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}" ) + endif() +endif() +if( EXISTS "${CMAKE_BINARY_DIR}/systemlibs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) + set( LINKER_FLAGS "${LINKER_FLAGS} -lsupc++" ) +endif() + +#cleanup for STL search +unset( __stlIncludePath ) +unset( __stlLibPath ) + +#other linker flags +__INIT_VARIABLE( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON ) +set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Don't all undefined symbols" FORCE ) +MARK_AS_ADVANCED( ANDROID_NO_UNDEFINED ) +if( ANDROID_NO_UNDEFINED ) set( LINKER_FLAGS "-Wl,--no-undefined ${LINKER_FLAGS}" ) endif() +if( ARMEABI_V7A ) + # this is *required* to use the following linker flags that routes around + # a CPU bug in some Cortex-A8 implementations: + set( LINKER_FLAGS "-Wl,--fix-cortex-a8 ${LINKER_FLAGS}" ) +endif() -set( CMAKE_SHARED_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE ) -set( CMAKE_MODULE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE ) -set( CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE ) +#cache flags +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" ) +set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c flags" ) +set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "c++ Release flags" ) +set( CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "c Release flags" ) +set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "c++ Debug flags" ) +set( CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "c Debug flags" ) +set( CMAKE_SHARED_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" ) +set( CMAKE_MODULE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" ) +set( CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections -Wl,-z,nocopyreloc ${LINKER_FLAGS}" CACHE STRING "linker flags" ) + +#finish flags +set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) +set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" ) +# workaround for ugly cmake bug - compiler identification replaces all spaces (and somethimes " (quote symbol)) in the compiler flags with ; symbol +# as result identification fails if ANDROID_SYSROOT contain spaces +include( CMakeForceCompiler ) +CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) +CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) #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) +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 ) @@ -384,13 +738,13 @@ macro(find_host_package) find_package( ${ARGN} ) SET( WIN32 ) SET( APPLE ) - SET( UNIX 1) + 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) +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 ) @@ -404,10 +758,70 @@ macro(find_host_program) find_program( ${ARGN} ) SET( WIN32 ) SET( APPLE ) - SET( UNIX 1) + 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() -MARK_AS_ADVANCED(FORCE_ARM NO_UNDEFINED) +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 of cmake toolchain: +# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86" +# ANDROID_FORCE_ARM_BUILD : ON/OFF +# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14 (depends on NDK version) +# ANDROID_NO_UNDEFINED : ON/OFF +# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF +# LIBRARY_OUTPUT_PATH_ROOT : +# Can be set only at the first run: +# ANDROID_NDK +# 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_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL (completely removed) +# +# 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 +# NEON : TRUE if NEON unit is enabled +# VFPV3 : TRUE if VFP versiuon 3 is enabled +# X86 : TRUE if configured for x86 +# BUILD_ANDROID : always TRUE +# 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 +# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a" or "x86" depending on ANDROID_ABI +# ANDROID_ARCH_NAME : "arm" or "x86" depending on ANDROID_ABI +# TOOL_OS_SUFFIX: "" or ".exe" depending on host platform +# Obsolete: +# ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME +# +# Secondary (less stable) read-only variables: +# ANDROID_COMPILER_VERSION : GCC version used +# ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform +# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI +# ANDROID_SYSROOT : path to the compiler sysroot +# ANDROID_TOOLCHAIN_NAME : "standalone", "arm-linux-androideabi-4.4.3" or "x86-4.4.3" or something similar. +# 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) +# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK +# +# Defaults: +# ANDROID_DEFAULT_NDK_API_LEVEL +# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH} +# ANDROID_NDK_SEARCH_PATH +# ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH +# ANDROID_SUPPORTED_ABIS_${ARCH} +# ANDROID_SUPPORTED_NDK_VERSIONS + diff --git a/android/scripts/build.cmd b/android/scripts/build.cmd index 97b9cd96b8..6c40166e29 100644 --- a/android/scripts/build.cmd +++ b/android/scripts/build.cmd @@ -17,7 +17,7 @@ POPD :: defaults IF NOT DEFINED BUILD_DIR SET BUILD_DIR=build -IF NOT DEFINED ARM_TARGET SET ARM_TARGET=armeabi-v7a +IF NOT DEFINED ANDROID_ABI SET ANDROID_ABI=armeabi-v7a SET OPENCV_BUILD_DIR=%SCRIPTS_DIR%\..\%BUILD_DIR% :: check that all required variables defined @@ -49,14 +49,14 @@ PUSHD "%BUILD_DIR%" || (ECHO. & ECHO Directory "%BUILD_DIR%" is not found & GOTO :: run cmake ECHO. & ECHO Runnning cmake... -ECHO ARM_TARGET=%ARM_TARGET% +ECHO ANDROID_ABI=%ANDROID_ABI% ECHO. IF NOT %BUILD_OPENCV%==1 GOTO other-cmake :opencv-cmake -("%CMAKE_EXE%" -G"MinGW Makefiles" -DARM_TARGET="%ARM_TARGET%" -C "%SOURCE_DIR%\CMakeCache.android.initial.cmake" -DCMAKE_TOOLCHAIN_FILE="%SOURCE_DIR%"\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM="%MAKE_EXE%" %* "%SOURCE_DIR%\..") && GOTO cmakefin +("%CMAKE_EXE%" -G"MinGW Makefiles" -DANDROID_ABI="%ANDROID_ABI%" -C "%SOURCE_DIR%\CMakeCache.android.initial.cmake" -DCMAKE_TOOLCHAIN_FILE="%SOURCE_DIR%"\android.toolchain.cmake -DCMAKE_BUILD_TOOL="%MAKE_EXE%" %* "%SOURCE_DIR%\..") && GOTO cmakefin ECHO. & ECHO cmake failed & GOTO end :other-cmake -("%CMAKE_EXE%" -G"MinGW Makefiles" -DARM_TARGET="%ARM_TARGET%" -DOpenCV_DIR="%OPENCV_BUILD_DIR%" -DCMAKE_TOOLCHAIN_FILE="%OPENCV_BUILD_DIR%\..\android.toolchain.cmake" -DCMAKE_MAKE_PROGRAM="%MAKE_EXE%" %* "%SOURCE_DIR%") && GOTO cmakefin +("%CMAKE_EXE%" -G"MinGW Makefiles" -DANDROID_ABI="%ANDROID_ABI%" -DOpenCV_DIR="%OPENCV_BUILD_DIR%" -DCMAKE_TOOLCHAIN_FILE="%OPENCV_BUILD_DIR%\..\android.toolchain.cmake" -DCMAKE_BUILD_TOOL="%MAKE_EXE%" %* "%SOURCE_DIR%") && GOTO cmakefin ECHO. & ECHO cmake failed & GOTO end :cmakefin @@ -77,4 +77,4 @@ ECHO. & ECHO Compiling Android project... :end POPD -ENDLOCAL \ No newline at end of file +ENDLOCAL diff --git a/android/scripts/cmake_android_armeabi.sh b/android/scripts/cmake_android_armeabi.sh index 961c9d685f..8652d6919b 100644 --- a/android/scripts/cmake_android_armeabi.sh +++ b/android/scripts/cmake_android_armeabi.sh @@ -4,5 +4,5 @@ cd `dirname $0`/.. mkdir -p build_armeabi cd build_armeabi -cmake -C ../CMakeCache.android.initial.cmake -DARM_TARGET=armeabi -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake $@ ../.. +cmake -C ../CMakeCache.android.initial.cmake -DANDROID_ABI=armeabi -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake $@ ../.. diff --git a/android/scripts/cmake_android_neon.sh b/android/scripts/cmake_android_neon.sh index 4212210491..ebd9dd0759 100644 --- a/android/scripts/cmake_android_neon.sh +++ b/android/scripts/cmake_android_neon.sh @@ -4,5 +4,5 @@ cd `dirname $0`/.. mkdir -p build_neon cd build_neon -cmake -C ../CMakeCache.android.initial.cmake -DARM_TARGET="armeabi-v7a with NEON" -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake $@ ../.. +cmake -C ../CMakeCache.android.initial.cmake -DANDROID_ABI="armeabi-v7a with NEON" -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake $@ ../.. diff --git a/android/scripts/package.sh b/android/scripts/package.sh index a941d20025..32ad00a157 100644 --- a/android/scripts/package.sh +++ b/android/scripts/package.sh @@ -15,7 +15,7 @@ mkdir opencv #mkdir build-neon #cd build-neon -#cmake -C "$ANDROID_DIR/CMakeCache.android.initial.cmake" -DARM_TARGET="armeabi-v7a with NEON" -DBUILD_DOCS=OFF -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DCMAKE_TOOLCHAIN_FILE="$ANDROID_DIR/android.toolchain.cmake" -DCMAKE_INSTALL_PREFIX="$PRG_DIR/opencv" "$ANDROID_DIR/.." || exit 1 +#cmake -C "$ANDROID_DIR/CMakeCache.android.initial.cmake" -DANDROID_ABI="armeabi-v7a with NEON" -DBUILD_DOCS=OFF -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DCMAKE_TOOLCHAIN_FILE="$ANDROID_DIR/android.toolchain.cmake" -DCMAKE_INSTALL_PREFIX="$PRG_DIR/opencv" "$ANDROID_DIR/.." || exit 1 #make -j8 install/strip || exit 1 #cd "$PRG_DIR/opencv" @@ -29,7 +29,7 @@ cd "$PRG_DIR" mkdir build cd build -cmake -C "$ANDROID_DIR/CMakeCache.android.initial.cmake" -DARM_TARGET="armeabi-v7a" -DBUILD_DOCS=OFF -DBUILD_TESTS=ON -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=ON -DCMAKE_TOOLCHAIN_FILE="$ANDROID_DIR/android.toolchain.cmake" -DCMAKE_INSTALL_PREFIX="$PRG_DIR/opencv" "$ANDROID_DIR/.." || exit 1 +cmake -C "$ANDROID_DIR/CMakeCache.android.initial.cmake" -DANDROID_ABI="armeabi-v7a" -DBUILD_DOCS=OFF -DBUILD_TESTS=ON -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=ON -DCMAKE_TOOLCHAIN_FILE="$ANDROID_DIR/android.toolchain.cmake" -DCMAKE_INSTALL_PREFIX="$PRG_DIR/opencv" "$ANDROID_DIR/.." || exit 1 make -j8 install/strip || exit 1 cd "$PRG_DIR/opencv" @@ -40,7 +40,7 @@ rm -rf doc include src .classpath .project AndroidManifest.xml default.propertie cd "$PRG_DIR/build" rm -rf CMakeCache.txt -cmake -C "$ANDROID_DIR/CMakeCache.android.initial.cmake" -DARM_TARGET="armeabi" -DBUILD_DOCS=ON -DBUILD_TESTS=ON -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=ON -DINSTALL_ANDROID_EXAMPLES=ON -DCMAKE_TOOLCHAIN_FILE="$ANDROID_DIR/android.toolchain.cmake" -DCMAKE_INSTALL_PREFIX="$PRG_DIR/opencv" "$ANDROID_DIR/.." || exit 1 +cmake -C "$ANDROID_DIR/CMakeCache.android.initial.cmake" -DANDROID_ABI="armeabi" -DBUILD_DOCS=ON -DBUILD_TESTS=ON -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=ON -DINSTALL_ANDROID_EXAMPLES=ON -DCMAKE_TOOLCHAIN_FILE="$ANDROID_DIR/android.toolchain.cmake" -DCMAKE_INSTALL_PREFIX="$PRG_DIR/opencv" "$ANDROID_DIR/.." || exit 1 make -j8 install/strip docs || exit 1 find doc -name "*.pdf" -exec cp {} $PRG_DIR/opencv/doc \; diff --git a/android/scripts/wincfg.cmd.tmpl b/android/scripts/wincfg.cmd.tmpl index 2cc59178a6..20404ecf43 100644 --- a/android/scripts/wincfg.cmd.tmpl +++ b/android/scripts/wincfg.cmd.tmpl @@ -1,8 +1,8 @@ :: variables required for OpenCV build :: :: Note: all pathes should be specified without tailing slashes! -SET ANDROID_NDK=C:\full\path\to\your\copy\of\android\NDK\android-ndk-r6b +SET ANDROID_NDK=C:\full\path\to\your\copy\of\android\NDK\android-ndk-r7 SET CMAKE_EXE=C:\full\path\to\cmake\utility\cmake.exe -SET MAKE_EXE=C:\full\path\to\native\port\of\make\utility\make.exe +SET MAKE_EXE=%ANDROID_NDK%\prebuilt\windows\bin\make.exe :: variables required for android-opencv build :: SET ANDROID_SDK=C:\full\path\to\your\copy\of\android\SDK\android-sdk-windows @@ -11,16 +11,20 @@ SET JAVA_HOME=C:\full\path\to\JDK\jdk1.6.0_25 :: configuration options :: :::: general ARM-V7 settings -SET ARM_TARGET=armeabi-v7a +SET ANDROID_ABI=armeabi-v7a SET BUILD_DIR=build -:::: uncomment following lines to compile for emulator or old device -::SET ARM_TARGET=armeabi +:::: uncomment following lines to compile for old emulator or old device +::SET ANDROID_ABI=armeabi ::SET BUILD_DIR=build_armeabi :::: uncomment following lines to compile for ARM-V7 with NEON support -::SET ARM_TARGET=armeabi-v7a with NEON +::SET ANDROID_ABI=armeabi-v7a with NEON ::SET BUILD_DIR=build_neon +:::: uncomment following lines to compile for x86 +::SET ANDROID_ABI=x86 +::SET BUILD_DIR=build_x86 + :::: other options -::SET ANDROID_API_LEVEL=8 &:: android-3 is enough for native part of OpenCV but android-8 is required for Java API and samples +::SET ANDROID_NATIVE_API_LEVEL=8 &:: android-3 is enough for native part of OpenCV but android-8 is required for Java API and samples diff --git a/modules/androidcamera/CMakeLists.txt b/modules/androidcamera/CMakeLists.txt index 3f712cbc22..1d53a856ed 100644 --- a/modules/androidcamera/CMakeLists.txt +++ b/modules/androidcamera/CMakeLists.txt @@ -38,7 +38,7 @@ IF (NOT BUILD_SHARED_LIBS) ENDIF() if (NOT BUILD_ANDROID_CAMERA_WRAPPER) - file(GLOB camera_wrappers "${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/lib/${ARMEABI_NDK_NAME}/libnative_camera_r*.so") + file(GLOB camera_wrappers "${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/lib/${ANDROID_NDK_ABI_NAME}/libnative_camera_r*.so") foreach(wrapper ${camera_wrappers}) ADD_CUSTOM_COMMAND( diff --git a/modules/ts/include/opencv2/ts/ts.hpp b/modules/ts/include/opencv2/ts/ts.hpp index c3603d287e..9f3bcd2d62 100644 --- a/modules/ts/include/opencv2/ts/ts.hpp +++ b/modules/ts/include/opencv2/ts/ts.hpp @@ -12,7 +12,7 @@ #ifdef ANDROID # include -# define GTEST_HAS_CLONE (__ANDROID_API__ > 7) +# define GTEST_HAS_CLONE (__ANDROID_API__ > 7 && __arm__) # define GTEST_HAS_POSIX_RE (__ANDROID_API__ > 7) # define GTEST_HAS_STD_WSTRING _GLIBCXX_USE_WCHAR_T #endif diff --git a/modules/ts/misc/run.py b/modules/ts/misc/run.py index 36465744c3..7b7979c60b 100644 --- a/modules/ts/misc/run.py +++ b/modules/ts/misc/run.py @@ -16,8 +16,8 @@ parse_patterns = ( {'name': "cxx_flags", 'default': None, 'pattern': re.compile("^CMAKE_CXX_FLAGS:STRING=(.*)$")}, {'name': "cxx_flags_debug", 'default': None, 'pattern': re.compile("^CMAKE_CXX_FLAGS_DEBUG:STRING=(.*)$")}, {'name': "cxx_flags_release", 'default': None, 'pattern': re.compile("^CMAKE_CXX_FLAGS_RELEASE:STRING=(.*)$")}, - {'name': "ndk_path", 'default': None, 'pattern': re.compile("^ANDROID_NDK(?:_TOOLCHAIN_ROOT)?:PATH=(.*)$")}, - {'name': "arm_target", 'default': None, 'pattern': re.compile("^ARM_TARGET:INTERNAL=(.*)$")}, + {'name': "ndk_path", 'default': None, 'pattern': re.compile("^(?:ANDROID_NDK|ANDROID_STANDALONE_TOOLCHAIN)?:PATH=(.*)$")}, + {'name': "android_abi", 'default': None, 'pattern': re.compile("^ANDROID_ABI:STRING=(.*)$")}, {'name': "android_executable", 'default': None, 'pattern': re.compile("^ANDROID_EXECUTABLE:FILEPATH=(.*android.*)$")}, {'name': "is_x64", 'default': "OFF", 'pattern': re.compile("^CUDA_64_BIT_DEVICE_CODE:BOOL=(ON)$")},#ugly( {'name': "cmake_generator", 'default': None, 'pattern': re.compile("^CMAKE_GENERATOR:INTERNAL=(.+)$")}, @@ -181,7 +181,7 @@ class RunInfo(object): self.adb = None # detect target platform - if self.android_executable or self.arm_target or self.ndk_path: + if self.android_executable or self.android_abi or self.ndk_path: self.targetos = "android" else: self.targetos = hostos @@ -405,7 +405,7 @@ class RunInfo(object): if connected_devices > 1: self.error = "Too many (%s) devices are connected. Single device is required. (for %s)" % (connected_devices, self.path) return False - if "armeabi-v7a" in self.arm_target: + if "armeabi-v7a" in self.android_abi: adb_res = self.runAdb("shell", "cat /proc/cpuinfo") if not adb_res: self.error = "Could not get info about Android platform: %s (for %s)" % (self.error, self.path) @@ -413,8 +413,8 @@ class RunInfo(object): if "ARMv7" not in adb_res: self.error = "Android device does not support ARMv7 commands, but tests are built for armeabi-v7a (for %s)" % self.path return False - if "NEON" in self.arm_target and "neon" not in adb_res: - self.error = "Android device has no NEON, but tests are built for %s (for %s)" % (self.arm_target, self.path) + if "NEON" in self.android_abi and "neon" not in adb_res: + self.error = "Android device has no NEON, but tests are built for %s (for %s)" % (self.android_abi, self.path) return False hw = re.search(r"^Hardware[ \t]*:[ \t]*(.*?)$", adb_res, re.MULTILINE) if hw: diff --git a/samples/android/hello-android/cmake_android.cmd b/samples/android/hello-android/cmake_android.cmd index e9daa27655..abc474eb10 100644 --- a/samples/android/hello-android/cmake_android.cmd +++ b/samples/android/hello-android/cmake_android.cmd @@ -3,7 +3,7 @@ SETLOCAL PUSHD %~dp0 SET PROJECT_NAME=hello-android SET BUILD_DIR=build_armeabi -SET ARM_TARGET=armeabi +SET ANDROID_ABI=armeabi CALL ..\..\..\android\scripts\build.cmd %* POPD ENDLOCAL