仅做记录,未涉及背景相关内容
#!/bin/sh
export ANDROID_NDK=/home/mytest/android-ndk-r13b
export ANDROID_NATIVE_API_LEVEL=21
export ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9
export ANDROID_ABI=armeabi-v7a
export ANDROID_STL=gnustl_static
cmake \
-DBUILD_SHARED_LIBS=ON \
-DWITH_OPENGL=ON \
-DBUILD_opencv_apps=ON \
-DBUILD_ANDROID_EXAMPLES=ON \
-DBUILD_DOCS=ON \
-DBUILD_EXAMPLES=ON \
-DBUILD_PERF_TESTS=ON \
-DBUILD_TESTS=ON \
-DENABLE_VFPV3=ON \
-DENABLE_NEON=ON \
-DINSTALL_C_EXAMPLES=ON \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DINSTALL_ANDROID_EXAMPLES=ON \
-DINSTALL_TESTS=ON \
-DDOXYGEN_EXECUTABLE=/usr/bin/doxygen \
-DPLANTUML_JAR=../plantuml.8033.jar \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DCMAKE_TOOLCHAIN_FILE=../platforms/android/android.toolchain.cmake ..
这样配置是比较大而全的,执行make编译,执行make package生成sdk
=====================================
20170711补充:原始linux(armv7-a/neon/vfp3)下的配置会有一点不同:
export CROSSTOOL_PATH=/home/mytest/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf
export CROSSTOOL_COMPILER=${CROSSTOOL_PATH}/bin/arm-linux-gnueabihf-
export CROSSTOOL_SYSROOT=${CROSSTOOL_PATH}/arm-linux-gnueabihf/libc
cmake \
-DBUILD_SHARED_LIBS=ON \
-DWITH_OPENGL=ON \
-DBUILD_opencv_apps=ON \
-DBUILD_ANDROID_EXAMPLES=ON \
-DBUILD_DOCS=ON \
-DBUILD_EXAMPLES=ON \
-DBUILD_PERF_TESTS=ON \
-DBUILD_TESTS=ON \
-DENABLE_VFPV3=ON \
-DENABLE_NEON=ON \
-DINSTALL_C_EXAMPLES=ON \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DINSTALL_ANDROID_EXAMPLES=ON \
-DINSTALL_TESTS=ON \
-DDOXYGEN_EXECUTABLE=/usr/bin/doxygen \
-DPLANTUML_JAR=../plantuml.8033.jar \
-DCMAKE_C_COMPILER=${CROSSTOOL_COMPILER}gcc \
-DCMAKE_CXX_COMPILER=${CROSSTOOL_COMPILER}g++ \
-DCMAKE_LINKER=${CROSSTOOL_COMPILER}ld \
-DCMAKE_STRIP=${CROSSTOOL_COMPILER}strip \
-DCMAKE_RANLIB=${CROSSTOOL_COMPILER}ranlib \
-DCMAKE_AR=${CROSSTOOL_COMPILER}ar \
-DCMAKE_FIND_ROOT_PATH=${CROSSTOOL_SYSROOT} \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
-DCMAKE_C_FLAGS="-march=armv7-a -mcpu=cortex-a8 -mfpu=neon" \
-DCMAKE_CXX_FLAGS="-march=armv7-a -mcpu=cortex-a8 -mfpu=neon" \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DCMAKE_TOOLCHAIN_FILE=../platforms/android/android.toolchain.cmake ..
说明:同样的测试程序在原始linux下居然慢一倍的速度,通过对比cmake输出信息增加了sysroot配置项(否则提示找不到libm,关闭浮点运算功能)、增加了clags配置(指定架构和浮点运算支持)