1 if(NOT ANT_EXECUTABLE OR NOT ANDROID_EXECUTABLE OR NOT ANDROID_TOOLS_Pkg_Revision GREATER 13) 2 return() 3 endif() 4 5 project(opencv_test_java) 6 7 set(opencv_test_java_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/.build") 8 set(test_dir "${CMAKE_CURRENT_SOURCE_DIR}") 9 set(test_common_dir "${CMAKE_CURRENT_SOURCE_DIR}/../common_test") 10 11 set(opencv_test_java_file_deps "") 12 13 # 1. gather and copy common test files (resources, utils, etc.) 14 copy_common_tests(test_common_dir opencv_test_java_bin_dir opencv_test_java_file_deps) 15 16 # 2. gather and copy tests from each module 17 copy_modules_tests(OPENCV_JAVA_MODULES opencv_test_java_bin_dir opencv_test_java_file_deps) 18 19 # 3. gather and copy specific files for Android 20 file(GLOB_RECURSE test_files RELATIVE "${test_dir}" "${test_dir}/res/*" "${test_dir}/src/*") 21 foreach(f ${test_files} ${ANDROID_MANIFEST_FILE} ".classpath" ".project") 22 add_custom_command( 23 OUTPUT "${opencv_test_java_bin_dir}/${f}" 24 COMMAND ${CMAKE_COMMAND} -E copy "${test_dir}/${f}" "${opencv_test_java_bin_dir}/${f}" 25 MAIN_DEPENDENCY "${test_dir}/${f}" 26 COMMENT "Copying ${f}") 27 list(APPEND opencv_test_java_file_deps "${test_dir}/${f}" "${opencv_test_java_bin_dir}/${f}") 28 endforeach() 29 30 # fix Android project 31 set(android_proj_target_files ${ANDROID_PROJECT_FILES}) 32 ocv_list_add_prefix(android_proj_target_files "${opencv_test_java_bin_dir}/") 33 file(RELATIVE_PATH __dep "${opencv_test_java_bin_dir}" "${OpenCV_BINARY_DIR}") 34 35 add_custom_command( 36 OUTPUT ${android_proj_target_files} 37 COMMAND ${CMAKE_COMMAND} -E remove ${android_proj_target_files} 38 COMMAND ${ANDROID_EXECUTABLE} --silent update test-project --path "${opencv_test_java_bin_dir}" --main "${OpenCV_BINARY_DIR}" 39 COMMAND ${ANDROID_EXECUTABLE} --silent update project --path "${opencv_test_java_bin_dir}" --library "${__dep}" 40 MAIN_DEPENDENCY "${opencv_test_java_bin_dir}/${ANDROID_MANIFEST_FILE}" 41 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}" 42 COMMENT "Updating Android Java API test project") 43 44 list(APPEND opencv_test_java_file_deps ${android_proj_target_files}) 45 46 get_target_property(java_location opencv_java LOCATION) 47 get_filename_component(java_name "${java_location}" NAME) 48 49 # build java part 50 add_custom_command( 51 OUTPUT "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" 52 COMMAND ${CMAKE_COMMAND} -E copy "${java_location}" "${opencv_test_java_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${java_name}" 53 COMMAND ${ANT_EXECUTABLE} -q -noinput -k debug 54 COMMAND ${CMAKE_COMMAND} -E touch "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" # needed because ant does not update the timestamp of updated apk 55 WORKING_DIRECTORY "${opencv_test_java_bin_dir}" 56 MAIN_DEPENDENCY "${opencv_test_java_bin_dir}/${ANDROID_MANIFEST_FILE}" 57 DEPENDS "${JAR_FILE}.dephelper" opencv_java 58 DEPENDS ${opencv_test_java_file_deps}) 59 60 add_custom_target(${PROJECT_NAME} ALL SOURCES "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" ) 61 add_dependencies(${PROJECT_NAME} opencv_java ${__android_project_chain}) 62 set(__android_project_chain ${PROJECT_NAME} CACHE INTERNAL "auxiliary variable used for Android progects chaining" FORCE) 63 64 # put the final .apk to the OpenCV's bin folder 65 add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" "${OpenCV_BINARY_DIR}/bin/${PROJECT_NAME}.apk") 66 67 add_dependencies(opencv_tests ${PROJECT_NAME}) 68 69 if(PYTHON_DEFAULT_AVAILABLE) 70 set(CHECK_TEST_COVERAGE "${OPENCV_MODULE_opencv_java_LOCATION}/check-tests.py") 71 add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 72 COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CHECK_TEST_COVERAGE} "${CMAKE_CURRENT_SOURCE_DIR}/src" "${OpenCV_BINARY_DIR}/src" > "${CMAKE_CURRENT_BINARY_DIR}/tests_coverage.log" 73 ) 74 endif() 75