Android cmake toolchain is reworked for NDK r7; added experimental Android x86 support.

pull/13383/head
Andrey Kamaev 13 years ago
parent d51a5262b3
commit 3bdb53e484
  1. 22
      CMakeLists.txt
  2. 4
      OpenCVAndroidProject.cmake
  3. 868
      android/android.toolchain.cmake
  4. 10
      android/scripts/build.cmd
  5. 2
      android/scripts/cmake_android_armeabi.sh
  6. 2
      android/scripts/cmake_android_neon.sh
  7. 6
      android/scripts/package.sh
  8. 18
      android/scripts/wincfg.cmd.tmpl
  9. 2
      modules/androidcamera/CMakeLists.txt
  10. 2
      modules/ts/include/opencv2/ts/ts.hpp
  11. 12
      modules/ts/misc/run.py
  12. 2
      samples/android/hello-android/cmake_android.cmd

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

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

File diff suppressed because it is too large Load Diff

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

@ -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 $@ ../..

@ -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 $@ ../..

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

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

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

@ -12,7 +12,7 @@
#ifdef ANDROID
# include <android/api-level.h>
# 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

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

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

Loading…
Cancel
Save