1 ocv_check_dependencies(opencv_java ${OPENCV_MODULE_opencv_java_OPT_DEPS} ${OPENCV_MODULE_opencv_java_REQ_DEPS})
3 if(NOT OCV_DEPENDENCIES_FOUND)
7 project(opencv_test_java)
9 set(opencv_test_java_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/.build")
10 set(android_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../android_test")
11 set(java_source_dir ${CMAKE_CURRENT_SOURCE_DIR})
13 # make sure the build directory exists
14 file(MAKE_DIRECTORY "${opencv_test_java_bin_dir}")
17 file(GLOB_RECURSE opencv_test_java_files RELATIVE "${android_source_dir}" "${android_source_dir}/res/*" "${android_source_dir}/src/*.java")
18 # These are the files that need to be updated for pure Java.
19 ocv_list_filterout(opencv_test_java_files "OpenCVTest(Case|Runner).java")
20 # These files aren't for desktop Java.
21 ocv_list_filterout(opencv_test_java_files "/android/")
23 ocv_list_filterout(opencv_test_java_files "/ml/")
25 # These are files updated for pure Java.
26 file(GLOB_RECURSE modified_files RELATIVE "${java_source_dir}" "${java_source_dir}/src/*")
28 # These are extra jars needed to run the tests.
29 file(GLOB_RECURSE lib_files RELATIVE "${java_source_dir}" "${java_source_dir}/lib/*.jar")
31 # copy sources out from the build tree
32 set(opencv_test_java_file_deps "")
33 foreach(f ${opencv_test_java_files})
34 add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/${f}"
35 COMMAND ${CMAKE_COMMAND} -E copy "${android_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}"
36 DEPENDS "${android_source_dir}/${f}"
37 COMMENT "Copying ${f}"
39 list(APPEND opencv_test_java_file_deps "${android_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}")
42 # Overwrite select Android sources with Java-specific sources.
43 # Also, copy over the libs we'll need for testing.
44 foreach(f ${modified_files} ${lib_files})
45 add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/${f}"
46 COMMAND ${CMAKE_COMMAND} -E copy "${java_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}"
47 DEPENDS "${java_source_dir}/${f}"
48 COMMENT "Copying ${f}"
50 list(APPEND opencv_test_java_file_deps "${java_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}")
53 # Copy the OpenCV jar after it has been generated.
54 add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/bin/${JAR_NAME}"
55 COMMAND ${CMAKE_COMMAND} -E copy "${JAR_FILE}" "${opencv_test_java_bin_dir}/bin/${JAR_NAME}"
57 COMMENT "Copying the OpenCV jar"
60 add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/build.xml"
61 COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/build.xml" "${opencv_test_java_bin_dir}/build.xml"
62 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build.xml"
63 COMMENT "Copying build.xml"
66 add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar"
67 COMMAND "${ANT_EXECUTABLE}" build
68 WORKING_DIRECTORY "${opencv_test_java_bin_dir}"
69 DEPENDS ${opencv_test_java_file_deps} "${opencv_test_java_bin_dir}/build.xml" "${CMAKE_CURRENT_SOURCE_DIR}/build.xml" "${JAR_FILE}" "${opencv_test_java_bin_dir}/bin/${JAR_NAME}"
70 COMMENT "Build Java tests"
73 # Not add_custom_command because generator expressions aren't supported in
74 # OUTPUT file names, and we need to generate different files for different
76 add_custom_target(${PROJECT_NAME}_properties
77 COMMAND "${CMAKE_COMMAND}" -E echo "opencv.lib.path = $<TARGET_FILE_DIR:${the_module}>"
78 > "${opencv_test_java_bin_dir}/ant-$<CONFIGURATION>.properties"
82 add_custom_target(${PROJECT_NAME} ALL
83 DEPENDS ${the_module} ${PROJECT_NAME}_properties
84 SOURCES "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar"
87 if(ENABLE_SOLUTION_FOLDERS)
88 set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "tests accuracy")