1if(NOT ANT_EXECUTABLE)
2  return()
3endif()
4
5project(opencv_test_java)
6
7set(opencv_test_java_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/.build")
8set(test_dir ${CMAKE_CURRENT_SOURCE_DIR})
9set(test_common_dir "${CMAKE_CURRENT_SOURCE_DIR}/../common_test")
10
11set(opencv_test_java_file_deps "")
12
13# make sure the build directory exists
14file(MAKE_DIRECTORY "${opencv_test_java_bin_dir}")
15
16# 1. gather and copy common test files (resources, utils, etc.)
17copy_common_tests(test_common_dir opencv_test_java_bin_dir opencv_test_java_file_deps)
18
19# 2. gather and copy tests from each module
20copy_modules_tests(OPENCV_JAVA_MODULES opencv_test_java_bin_dir opencv_test_java_file_deps)
21
22# 3. gather and copy specific files for pure java
23file(GLOB_RECURSE test_files RELATIVE "${test_dir}" "${test_dir}/src/*")
24file(GLOB_RECURSE test_lib_files RELATIVE "${test_dir}" "${test_dir}/lib/*.jar")
25foreach(f ${test_files} ${test_lib_files})
26  add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/${f}"
27                     COMMAND ${CMAKE_COMMAND} -E copy "${test_dir}/${f}" "${opencv_test_java_bin_dir}/${f}"
28                     DEPENDS "${test_dir}/${f}"
29                     COMMENT "Copying ${f}"
30                    )
31  list(APPEND opencv_test_java_file_deps "${test_dir}/${f}" "${opencv_test_java_bin_dir}/${f}")
32endforeach()
33
34# Copy the OpenCV jar after it has been generated.
35add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/bin/${JAR_NAME}"
36                   COMMAND ${CMAKE_COMMAND} -E copy "${JAR_FILE}" "${opencv_test_java_bin_dir}/bin/${JAR_NAME}"
37                   DEPENDS "${JAR_FILE}"
38                   COMMENT "Copying the OpenCV jar"
39                  )
40
41add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/build.xml"
42                   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/build.xml" "${opencv_test_java_bin_dir}/build.xml"
43                   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build.xml"
44                   COMMENT "Copying build.xml"
45                  )
46
47add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar"
48                   COMMAND "${ANT_EXECUTABLE}" build
49                   WORKING_DIRECTORY "${opencv_test_java_bin_dir}"
50                   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}"
51                   COMMENT "Build Java tests"
52                  )
53
54# Not add_custom_command because generator expressions aren't supported in
55# OUTPUT file names, and we need to generate different files for different
56# configurations.
57add_custom_target(${PROJECT_NAME}_properties
58                  COMMAND "${CMAKE_COMMAND}" -E echo "opencv.lib.path = $<TARGET_FILE_DIR:${the_module}>"
59                    > "${opencv_test_java_bin_dir}/ant-$<CONFIGURATION>.properties"
60                  VERBATIM
61                 )
62
63add_custom_target(${PROJECT_NAME} ALL
64                  DEPENDS ${the_module} ${PROJECT_NAME}_properties
65                  SOURCES "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar"
66                 )
67
68if(ENABLE_SOLUTION_FOLDERS)
69  set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "tests accuracy")
70endif()
71