diff --git a/CMakeLists.txt b/CMakeLists.txt index 59a3e316d1..372b7f0559 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -317,6 +317,9 @@ endif() set(BUILD_EXAMPLES OFF CACHE BOOL "Build all examples") set(INSTALL_C_EXAMPLES OFF CACHE BOOL "Install C examples") set(INSTALL_PYTHON_EXAMPLES OFF CACHE BOOL "Install Python examples") +if(ANDROID) + set(INSTALL_ANDROID_EXAMPLES OFF CACHE BOOL "Install Android examples") +endif() # Build tests: # =================================================== @@ -722,6 +725,41 @@ if (BUILD_JAVA_SUPPORT) "/opt/android-sdk-mac_86/tools/" ) if(ANDROID_EXECUTABLE) + get_filename_component(ANDROID_SDK_TOOLS_PATH "${ANDROID_EXECUTABLE}" PATH) + + #read source.properties + file(STRINGS "${ANDROID_SDK_TOOLS_PATH}/source.properties" ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES REGEX "^[ ]*[^#].*$") + foreach(line ${ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES}) + string(REPLACE "\\:" ":" line ${line}) + string(REPLACE "=" ";" line ${line}) + list(GET line 0 line_name) + list(GET line 1 line_value) + string(REPLACE "." "_" line_name ${line_name}) + SET(ANDROID_TOOLS_${line_name} "${line_value}") + MARK_AS_ADVANCED(ANDROID_TOOLS_${line_name}) + endforeach() + + #get installed targets + execute_process(COMMAND ${ANDROID_EXECUTABLE} list target -c + RESULT_VARIABLE ANDROID_PROCESS + OUTPUT_VARIABLE ANDROID_SDK_TARGETS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + string(REPLACE "\n" ";" ANDROID_SDK_TARGETS ${ANDROID_SDK_TARGETS}) + if (NOT ANDROID_SDK_TARGET) + foreach(target ${ANDROID_SDK_TARGETS}) + string(REGEX MATCH "[0-9]+$" target_level "${target}") + if (target_level GREATER 7) + set(ANDROID_SDK_TARGET "${target}") + break() + endif() + endforeach() + endif() + + SET(ANDROID_SDK_TARGET ${ANDROID_SDK_TARGET} CACHE STRING "SDK target for Android tests and samples") + set_property( CACHE ANDROID_SDK_TARGET PROPERTY STRINGS ${ANDROID_SDK_TARGETS} ) + string(REGEX MATCH "[0-9]+$" ANDROID_SDK_TARGET_LEVEL "${ANDROID_SDK_TARGET}") + message(STATUS " Found android tool: ${ANDROID_EXECUTABLE}") endif() endif() @@ -740,8 +778,7 @@ if (BUILD_JAVA_SUPPORT) message(STATUS " Found apache ant ${ANT_VERSION}: ${ANT_EXECUTABLE}") endif() - - if (ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7)) + if (ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_SDK_TARGET_LEVEL GREATER 7)) SET(CAN_BUILD_ANDROID_PROJECTS TRUE) else() SET(CAN_BUILD_ANDROID_PROJECTS FALSE) @@ -998,6 +1035,7 @@ libnative_camera_rx.x.x.so for your Android") SET(BUILD_ANDROID_CAMERA_WRAPPER ON) endif() endif() + MARK_AS_ADVANCED(ANDROID_SOURCE_TREE) endif() # ---------------------------------------------------------------------------- @@ -1511,6 +1549,7 @@ endif() if(ANDROID) status(" Floating point type:" ${ARM_TARGET}) status(" Native API level:" android-${ANDROID_API_LEVEL}) + status(" SDK target:" "${ANDROID_SDK_TARGET}") endif() #YV @@ -1619,7 +1658,7 @@ else() endif() if(ANDROID) - status(" android tool:" ANDROID_EXECUTABLE THEN "${ANDROID_EXECUTABLE}" ELSE NO) + status(" android tool:" ANDROID_EXECUTABLE THEN "${ANDROID_EXECUTABLE} (${ANDROID_TOOLS_Pkg_Desc})" ELSE NO) status(" ant:" ANT_EXECUTABLE THEN "${ANT_EXECUTABLE} (ver ${ANT_VERSION})" ELSE NO) endif() diff --git a/android/CMakeCache.android.initial.cmake b/android/CMakeCache.android.initial.cmake index d10b53406f..b934915056 100644 --- a/android/CMakeCache.android.initial.cmake +++ b/android/CMakeCache.android.initial.cmake @@ -3,11 +3,6 @@ # run cmake with: # cmake -C ######################## -#Build all examples -set(BUILD_EXAMPLES OFF CACHE BOOL "" ) - -#Build a installer with the SDK -set(BUILD_PACKAGE OFF CACHE BOOL "" ) #Build shared libraries (.dll/.so CACHE BOOL "" ) instead of static ones (.lib/.a CACHE BOOL "" ) set(BUILD_SHARED_LIBS OFF CACHE BOOL "" ) @@ -78,6 +73,9 @@ set(WITH_V4L OFF CACHE BOOL "" ) #Include Xine support (GPL CACHE BOOL "" ) set(WITH_XINE OFF CACHE BOOL "" ) +#no python available on Android +set(BUILD_NEW_PYTHON_SUPPORT OFF CACHE INTERNAL "" FORCE) + #Enable SSE instructions SET( ENABLE_SSE OFF CACHE INTERNAL "" FORCE ) diff --git a/android/android.toolchain.cmake b/android/android.toolchain.cmake index f48849d24a..b10c526e6c 100644 --- a/android/android.toolchain.cmake +++ b/android/android.toolchain.cmake @@ -221,7 +221,7 @@ set( CMAKE_RANLIB ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi- #setup build targets, mutually exclusive set( PossibleArmTargets "armeabi;armeabi-v7a;armeabi-v7a with NEON;armeabi-v7a with VFPV3" ) -set( ARM_TARGET "armeabi-v7a" CACHE STRING "the arm target for android, recommend armeabi-v7a for floating point support and NEON." ) +set( ARM_TARGET "armeabi-v7a" CACHE INTERNAL "the arm target for android, recommend armeabi-v7a for floating point support and NEON." ) set_property( CACHE ARM_TARGET PROPERTY STRINGS ${PossibleArmTargets} ) #compatibility junk for previous version of toolchain @@ -232,7 +232,7 @@ endif() #set these flags for client use if( ARM_TARGET STREQUAL "armeabi" ) set( ARMEABI true ) - set( ARMEABI_NDK_NAME "armeabi" CACHE STRING "NDK eabi name" FORCE) + set( ARMEABI_NDK_NAME "armeabi" ) set( NEON false ) set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) else() @@ -247,7 +247,7 @@ Supported values are: \"armeabi\", \"armeabi-v7a\", \"armeabi-v7a with NEON\", \ " ) endif() set( ARMEABI_V7A true ) - set( ARMEABI_NDK_NAME "armeabi-v7a" CACHE STRING "NDK eabi name" FORCE) + set( ARMEABI_NDK_NAME "armeabi-v7a" ) set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) endif() @@ -389,3 +389,5 @@ macro(find_host_program) set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) endmacro() + +MARK_AS_ADVANCED(FORCE_ARM NO_UNDEFINED) diff --git a/android/scripts/package.sh b/android/scripts/package.sh index 1eb6c4d700..18ec9414c6 100644 --- a/android/scripts/package.sh +++ b/android/scripts/package.sh @@ -23,12 +23,12 @@ rm -rf doc include src .classpath .project AndroidManifest.xml default.propertie mv libs/armeabi-v7a libs/armeabi-v7a-neon mv share/OpenCV/3rdparty/libs/armeabi-v7a share/OpenCV/3rdparty/libs/armeabi-v7a-neon -# armeabi build +# armeabi-v7a build cd "$PRG_DIR" mkdir build cd build -cmake -C "$ANDROID_DIR/CMakeCache.android.initial.cmake" -DARM_TARGET="armeabi" -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" -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 make -j8 install/strip || exit 1 cd "$PRG_DIR/opencv" @@ -39,7 +39,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-v7a" -DBUILD_DOCS=ON -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" -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 make -j8 install/strip docs || exit 1 find doc -name "*.pdf" -exec cp {} $PRG_DIR/opencv/doc \; diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index 578e4e744a..69ba164724 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -187,7 +187,7 @@ if(ANDROID AND BUILD_TESTS AND CAN_BUILD_ANDROID_PROJECTS) WORKING_DIRECTORY ${test_dir} COMMAND ${CMAKE_COMMAND} -E remove -f "${test_dir}/default.properties" COMMAND ${CMAKE_COMMAND} -E touch "${test_dir}/default.properties" - COMMAND ${ANDROID_EXECUTABLE} update project --name "${test_name}" --target android-8 --library "${OPENCV_REFERENCE_PATH}" --path . + COMMAND ${ANDROID_EXECUTABLE} update project --name "${test_name}" --target "${ANDROID_SDK_TARGET}" --library "${OPENCV_REFERENCE_PATH}" --path . COMMAND ${ANT_EXECUTABLE} debug COMMAND ${CMAKE_COMMAND} -E copy "${test_dir}/bin/${test_name}-debug.apk" "${CMAKE_BINARY_DIR}/bin/${test_name}.apk" ) diff --git a/samples/android/CMakeLists.txt b/samples/android/CMakeLists.txt index 7c524b9e40..22acbbe9f3 100644 --- a/samples/android/CMakeLists.txt +++ b/samples/android/CMakeLists.txt @@ -51,7 +51,7 @@ if (BUILD_ANDROID_EXAMPLES) WORKING_DIRECTORY ${sample_dir} COMMAND ${CMAKE_COMMAND} -E remove -f "${sample_dir}/default.properties" COMMAND ${CMAKE_COMMAND} -E touch "${sample_dir}/default.properties" - COMMAND ${ANDROID_EXECUTABLE} update project --name "${sample}" --target android-8 ${opencv_reference} --path . + COMMAND ${ANDROID_EXECUTABLE} update project --name "${sample}" --target "${ANDROID_SDK_TARGET}" ${opencv_reference} --path . COMMAND ${ANT_EXECUTABLE} debug COMMAND ${CMAKE_COMMAND} -E copy "${sample_dir}/bin/${sample}-debug.apk" "${CMAKE_BINARY_DIR}/bin/${sample}.apk" ) @@ -83,6 +83,10 @@ if (BUILD_ANDROID_EXAMPLES) add_dependencies(${sample} ${JNI_LIB_NAME}) endif() + + if(INSTALL_ANDROID_EXAMPLES) + install(FILES "${CMAKE_BINARY_DIR}/bin/${sample}.apk" DESTINATION bin COMPONENT main) + endif() endmacro() file(GLOB android_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *) @@ -102,7 +106,9 @@ if (BUILD_ANDROID_EXAMPLES) ADD_DEPENDENCIES(hello-android ${sample_dependencies}) TARGET_LINK_LIBRARIES(hello-android ${OPENCV_LINKER_LIBS} ${sample_dependencies}) set_target_properties(hello-android PROPERTIES OUTPUT_NAME hello-android RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") - + if(INSTALL_ANDROID_EXAMPLES) + install(TARGETS hello-android DESTINATION bin COMPONENT main) + endif() set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${additional_clean_files}") endif()