Updated Android cross-compilation on Windows.

This commit is contained in:
Andrey Kamaev 2011-05-09 23:22:46 +00:00
parent f8e4b10248
commit 4c7a8f8d24
7 changed files with 136 additions and 41 deletions

View File

@ -0,0 +1,5 @@
@ECHO OFF
PUSHD %~dp0
SET PROJECT_NAME=android-opencv
CALL ..\scripts\cmake_android.cmd
POPD

View File

@ -7,7 +7,5 @@
# "build.properties", and override values to adapt the script to your
# project structure.
#android.library=true
# Project target.
target=android-7
android.library=true

View File

@ -148,20 +148,21 @@ if( EXISTS ${ANDROID_NDK} )
endif()
set( ANDROID_API_LEVEL $ENV{ANDROID_API_LEVEL} )
string( REGEX REPLACE "android-([0-9]+)" "\\1" ANDROID_API_LEVEL "${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}" )
set( PossibleAndroidLevels "3;4;5;8;9" )
set( ANDROID_API_LEVEL ${ANDROID_API_LEVEL} CACHE STRING "android API level" )
set_property( CACHE ANDROID_API_LEVEL PROPERTY STRINGS ${PossibleAndroidLevels} )
if( NOT ANDROID_API_LEVEL GREATER 2 )
set( ANDROID_API_LEVEL 8 )
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 environment variable: ANDROID_API_LEVEL" )
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/" )
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} )
@ -180,6 +181,7 @@ else()
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!
@ -192,7 +194,7 @@ else()
sudo ln -s ~/my-android-toolchain ${ANDROID_NDK_TOOLCHAIN_DEFAULT_SEARCH_PATH}" )
endif()
__TOOLCHAIN_DETECT_API_LEVEL( "${ANDROID_NDK_TOOLCHAIN_ROOT}/sysroot/usr/include/android/api-level.h" )
__TOOLCHAIN_DETECT_API_LEVEL( "${ANDROID_NDK_SYSROOT}/usr/include/android/api-level.h" )
#message( STATUS "Using android NDK standalone toolchain from ${ANDROID_NDK_TOOLCHAIN_ROOT}" )
set( BUILD_WITH_ANDROID_NDK_TOOLCHAIN True )
@ -253,15 +255,16 @@ 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 )
if( BUILD_WITH_ANDROID_NDK )
set( STL_LIBRARIES_PATH "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ARMEABI_NDK_NAME}" )
set( CMAKE_FIND_ROOT_PATH ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin ${ANDROID_NDK_TOOLCHAIN_ROOT}/arm-linux-androideabi ${ANDROID_NDK_SYSROOT} )
include_directories( ${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include ${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ARMEABI_NDK_NAME}/include )
set( STL_PATH "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" )
set( STL_LIBRARIES_PATH "${STL_PATH}/libs/${ARMEABI_NDK_NAME}" )
include_directories( ${STL_PATH}/include ${STL_LIBRARIES_PATH}/include )
endif()
if( BUILD_WITH_ANDROID_NDK_TOOLCHAIN )
set( STL_LIBRARIES_PATH "${CMAKE_INSTALL_PREFIX}/lib" )
set( CMAKE_FIND_ROOT_PATH ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin ${ANDROID_NDK_TOOLCHAIN_ROOT}/arm-linux-androideabi ${ANDROID_NDK_TOOLCHAIN_ROOT}/sysroot ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_PREFIX}/share )
#for some reason this is needed? TODO figure out why...
include_directories( ${ANDROID_NDK_TOOLCHAIN_ROOT}/arm-linux-androideabi/include/c++/4.4.3/arm-linux-androideabi )
endif()
@ -345,7 +348,7 @@ if( NOT NO_SWIG )
macro( SET_SWIG_JAVA_PACKAGE package_name )
string( REGEX REPLACE "[.]" "/" package_name_output ${package_name} )
set( CMAKE_SWIG_OUTDIR ${SWIG_OUTPUT_ROOT}/${package_name_output} )
set( CMAKE_SWIG_FLAGS "-package" "'${package_name}'" )
set( CMAKE_SWIG_FLAGS "-package" "\"${package_name}\"" )
endmacro()
else()
message( STATUS "SWIG is not found" )

View File

@ -1,11 +1,96 @@
cd %~dp0\..
@ECHO OFF
::rmdir /S /Q build
mkdir build 2>nul
:: don't modify the caller's environment
SETLOCAL
SET ANDROID_NDK=C:\apps\android-ndk-r5b
SET CMAKE_EXE=C:\apps\cmake\bin\cmake.exe
SET MAKE_EXE=C:\apps\gnuport\make.exe
:: enable command extensions
VERIFY BADVALUE 2>NUL
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 ECHO Unable to enable command extensions.
cd build
%CMAKE_EXE% -C ../CMakeCache.android.initial.cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=..\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=%MAKE_EXE% ..\..
:: load configuration
PUSHD %~dp0
IF NOT EXIST .\wincfg.cmd GOTO nocfg
CALL .\wincfg.cmd
SET OPENCV_BUILD_DIR="%cd%"\..\%BUILD_DIR%
POPD
:: path to project root
SET SOURCE_DIR="%cd%"
:: create build dir
::rmdir /S /Q %BUILD_DIR% &:: uncomment this line to rebuild instead of build
MKDIR %BUILD_DIR% 2>NUL
PUSHD %BUILD_DIR%
:: run cmake
ECHO.
ECHO Runnning cmake...
ECHO ARM_TARGET=%ARM_TARGET%
ECHO.
IF NOT EXIST %SOURCE_DIR%\CMakeCache.android.initial.cmake 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%\..
IF ERRORLEVEL 1 GOTO cmakefails
GOTO cmakefin
:other-cmake
%CMAKE_EXE% -G"MinGW Makefiles" -DARM_TARGET="%ARM_TARGET%" -DOpenCV_DIR=%OPENCV_BUILD_DIR% -DCMAKE_PROGRAM_PATH=%SWIG_DIR% -DCMAKE_TOOLCHAIN_FILE=%OPENCV_BUILD_DIR%\..\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM="%MAKE_EXE%" %SOURCE_DIR%
IF ERRORLEVEL 1 GOTO cmakefails
GOTO cmakefin
:cmakefin
:: run make
ECHO.
ECHO Building native libs...
%MAKE_EXE% -j %NUMBER_OF_PROCESSORS% &:: VERBOSE=1
IF ERRORLEVEL 1 GOTO makefail
IF NOT EXIST ..\jni GOTO fin
:: configure java part
POPD
PUSHD .
ECHO.
ECHO Updating Android project...
CALL %ANDROID_SDK%\tools\android update project --name %PROJECT_NAME% --path .
IF ERRORLEVEL 1 GOTO androidfail
:: compile java part
ECHO.
ECHO Compiling Android project...
CALL %ANT_DIR%\bin\ant compile
IF ERRORLEVEL 1 GOTO antfail
GOTO fin
:nocfg
ECHO.
ECHO Could not find wincfg.cmd file.
ECHO.
ECHO You should create opencv\android\scripts\wincfg.cmd
ECHO from template opencv\android\scripts\wincfg.cmd.tmpl
GOTO fin
:antfail
ECHO.
ECHO failed to compile android project
GOTO fin
:androidfail
ECHO.
ECHO failed to update android project
GOTO fin
:makefail
ECHO.
ECHO make failed
GOTO fin
:cmakefail
ECHO.
ECHO cmake failed
GOTO fin
:fin
POPD
ENDLOCAL

View File

@ -1,11 +0,0 @@
cd %~dp0\..
::rmdir /S /Q build
mkdir build 2>nul
SET ANDROID_NDK=C:\apps\android-ndk-r5b
SET CMAKE_EXE=C:\apps\cmake\bin\cmake.exe
SET MAKE_EXE=C:\apps\gnuport\make.exe
cd build
%CMAKE_EXE% -C ../CMakeCache.android.initial.cmake -G"Unix Makefiles" -DARM_TARGET=armeabi -DCMAKE_TOOLCHAIN_FILE=..\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=%MAKE_EXE% ..\..

View File

@ -1,11 +0,0 @@
cd %~dp0\..
::rmdir /S /Q build
mkdir build 2>nul
SET ANDROID_NDK=C:\apps\android-ndk-r5b
SET CMAKE_EXE=C:\apps\cmake\bin\cmake.exe
SET MAKE_EXE=C:\apps\gnuport\make.exe
cd build
%CMAKE_EXE% -C ../CMakeCache.android.initial.cmake -G"Unix Makefiles" -DARM_TARGET="armeabi-v7a with NEON" -DCMAKE_TOOLCHAIN_FILE=..\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=%MAKE_EXE% ..\..

View File

@ -0,0 +1,26 @@
:: variables required for OpenCV build ::
SET ANDROID_NDK=C:\full\path\to\your\copy\of\android\NDK\android-ndk-r5b
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
:: variables required for android-opencv build ::
SET SWIG_DIR=C:\full\path\to\SWIG\directory\swigwin-2.0.3
SET ANDROID_SDK=C:\full\path\to\your\copy\of\android\SDK\android-sdk-windows
SET ANT_DIR=C:\full\path\to\ant\directory\apache-ant-1.8.2
SET JAVA_HOME=C:\full\path\to\JDK\jdk1.6.0_25
:: configuration options ::
:::: general ARM-V7 settings
SET ARM_TARGET=armeabi-v7a
SET BUILD_DIR=build
:::: uncomment following lines to compile for emulator or old device
::SET ARM_TARGET=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 BUILD_DIR=build_neon
:::: other options
::SET ANDROID_API_LEVEL=8 &:: android-3 is enough for OpenCV but android-8 is recommended