2015-02-19 21:17:19 +08:00
|
|
|
if(NOT ANT_EXECUTABLE OR NOT ANDROID_EXECUTABLE OR NOT ANDROID_TOOLS_Pkg_Revision GREATER 13)
|
2012-03-28 00:05:52 +08:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
project(opencv_test_java)
|
|
|
|
|
|
|
|
set(opencv_test_java_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/.build")
|
2015-02-19 21:17:19 +08:00
|
|
|
set(test_dir "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
|
|
set(test_common_dir "${CMAKE_CURRENT_SOURCE_DIR}/../common_test")
|
2012-03-28 00:05:52 +08:00
|
|
|
|
|
|
|
set(opencv_test_java_file_deps "")
|
2015-02-19 21:17:19 +08:00
|
|
|
|
|
|
|
# 1. gather and copy common test files (resources, utils, etc.)
|
|
|
|
copy_common_tests(test_common_dir opencv_test_java_bin_dir opencv_test_java_file_deps)
|
|
|
|
|
|
|
|
# 2. gather and copy tests from each module
|
|
|
|
copy_modules_tests(OPENCV_JAVA_MODULES opencv_test_java_bin_dir opencv_test_java_file_deps)
|
|
|
|
|
|
|
|
# 3. gather and copy specific files for Android
|
|
|
|
file(GLOB_RECURSE test_files RELATIVE "${test_dir}" "${test_dir}/res/*" "${test_dir}/src/*")
|
|
|
|
foreach(f ${test_files} ${ANDROID_MANIFEST_FILE} ".classpath" ".project")
|
2012-03-28 00:05:52 +08:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${opencv_test_java_bin_dir}/${f}"
|
2015-09-09 03:42:05 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${test_dir}/${f}" "${opencv_test_java_bin_dir}/${f}"
|
2015-02-19 21:17:19 +08:00
|
|
|
MAIN_DEPENDENCY "${test_dir}/${f}"
|
2012-03-28 00:05:52 +08:00
|
|
|
COMMENT "Copying ${f}")
|
2015-02-19 21:17:19 +08:00
|
|
|
list(APPEND opencv_test_java_file_deps "${test_dir}/${f}" "${opencv_test_java_bin_dir}/${f}")
|
2012-03-28 00:05:52 +08:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# fix Android project
|
|
|
|
set(android_proj_target_files ${ANDROID_PROJECT_FILES})
|
|
|
|
ocv_list_add_prefix(android_proj_target_files "${opencv_test_java_bin_dir}/")
|
|
|
|
file(RELATIVE_PATH __dep "${opencv_test_java_bin_dir}" "${OpenCV_BINARY_DIR}")
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${android_proj_target_files}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove ${android_proj_target_files}
|
|
|
|
COMMAND ${ANDROID_EXECUTABLE} --silent update test-project --path "${opencv_test_java_bin_dir}" --main "${OpenCV_BINARY_DIR}"
|
|
|
|
COMMAND ${ANDROID_EXECUTABLE} --silent update project --path "${opencv_test_java_bin_dir}" --library "${__dep}"
|
|
|
|
MAIN_DEPENDENCY "${opencv_test_java_bin_dir}/${ANDROID_MANIFEST_FILE}"
|
|
|
|
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}"
|
|
|
|
COMMENT "Updating Android Java API test project")
|
|
|
|
|
|
|
|
list(APPEND opencv_test_java_file_deps ${android_proj_target_files})
|
|
|
|
|
|
|
|
# build java part
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk"
|
2017-08-17 06:49:17 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:opencv_java>" "${opencv_test_java_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/$<TARGET_FILE_NAME:opencv_java>"
|
2015-11-11 21:12:35 +08:00
|
|
|
COMMAND ${ANT_EXECUTABLE} -q -noinput -k debug -Djava.target=1.6 -Djava.source=1.6
|
2012-03-28 00:05:52 +08:00
|
|
|
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
|
|
|
|
WORKING_DIRECTORY "${opencv_test_java_bin_dir}"
|
|
|
|
MAIN_DEPENDENCY "${opencv_test_java_bin_dir}/${ANDROID_MANIFEST_FILE}"
|
2013-01-22 21:56:04 +08:00
|
|
|
DEPENDS "${JAR_FILE}.dephelper" opencv_java
|
2012-09-04 17:26:08 +08:00
|
|
|
DEPENDS ${opencv_test_java_file_deps})
|
2012-03-28 00:05:52 +08:00
|
|
|
|
|
|
|
add_custom_target(${PROJECT_NAME} ALL SOURCES "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" )
|
2012-09-04 17:26:08 +08:00
|
|
|
add_dependencies(${PROJECT_NAME} opencv_java ${__android_project_chain})
|
|
|
|
set(__android_project_chain ${PROJECT_NAME} CACHE INTERNAL "auxiliary variable used for Android progects chaining" FORCE)
|
2012-03-28 00:05:52 +08:00
|
|
|
|
|
|
|
# put the final .apk to the OpenCV's bin folder
|
2015-09-09 03:42:05 +08:00
|
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" "${OpenCV_BINARY_DIR}/bin/${PROJECT_NAME}.apk")
|
2012-03-28 00:05:52 +08:00
|
|
|
|
|
|
|
add_dependencies(opencv_tests ${PROJECT_NAME})
|
|
|
|
|
2014-06-30 04:45:24 +08:00
|
|
|
if(PYTHON_DEFAULT_AVAILABLE)
|
2012-03-28 05:27:27 +08:00
|
|
|
set(CHECK_TEST_COVERAGE "${OPENCV_MODULE_opencv_java_LOCATION}/check-tests.py")
|
|
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
2014-06-30 04:45:24 +08:00
|
|
|
COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CHECK_TEST_COVERAGE} "${CMAKE_CURRENT_SOURCE_DIR}/src" "${OpenCV_BINARY_DIR}/src" > "${CMAKE_CURRENT_BINARY_DIR}/tests_coverage.log"
|
2012-03-28 05:27:27 +08:00
|
|
|
)
|
|
|
|
endif()
|