CMakeLists.txt 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. if(NOT ANT_EXECUTABLE
  2. OR NOT BUILD_opencv_imgcodecs
  3. OR NOT BUILD_opencv_calib3d)
  4. return()
  5. endif()
  6. project(opencv_test_java)
  7. set(OPENCV_JAR_FILE "${OPENCV_JAR_FILE}")
  8. get_filename_component(JAR_NAME "${OPENCV_JAR_FILE}" NAME)
  9. set(OPENCV_JAVA_TEST_DIR "${OpenCV_BINARY_DIR}/java_test" CACHE INTERNAL "")
  10. file(REMOVE_RECURSE "${OPENCV_JAVA_TEST_DIR}")
  11. file(MAKE_DIRECTORY "${OPENCV_JAVA_TEST_DIR}")
  12. file(REMOVE "${OPENCV_DEPHELPER}/${the_module}_test_source_copy")
  13. set(test_dir ${CMAKE_CURRENT_SOURCE_DIR})
  14. set(depends "")
  15. # 1. gather and copy common test files (resources, utils, etc.)
  16. copy_common_tests("${CMAKE_CURRENT_SOURCE_DIR}/../common_test" "${OPENCV_JAVA_TEST_DIR}" depends)
  17. # 2. gather and copy tests from each module
  18. ocv_copyfiles_append_dir(JAVA_TEST_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/test" "${OPENCV_JAVA_TEST_DIR}/src")
  19. list(APPEND depends gen_opencv_java_source "${OPENCV_DEPHELPER}/gen_opencv_java_source")
  20. ocv_copyfiles_add_target(${the_module}_test_source_copy JAVA_TEST_SRC_COPY "Copy Java(Test) source files" ${depends})
  21. set(depends ${the_module}_test_source_copy "${OPENCV_DEPHELPER}/${the_module}_test_source_copy")
  22. # 3. gather and copy specific files for pure java
  23. file(GLOB_RECURSE test_files RELATIVE "${test_dir}" "${test_dir}/src/*")
  24. file(GLOB_RECURSE test_lib_files RELATIVE "${test_dir}" "${test_dir}/lib/*.jar")
  25. foreach(f ${test_files} ${test_lib_files})
  26. add_custom_command(OUTPUT "${OPENCV_JAVA_TEST_DIR}/${f}"
  27. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${test_dir}/${f}" "${OPENCV_JAVA_TEST_DIR}/${f}"
  28. DEPENDS "${test_dir}/${f}"
  29. COMMENT "Copying ${f}"
  30. )
  31. list(APPEND depends "${test_dir}/${f}" "${OPENCV_JAVA_TEST_DIR}/${f}")
  32. endforeach()
  33. # Copy the OpenCV jar after it has been generated.
  34. add_custom_command(OUTPUT "${OPENCV_JAVA_TEST_DIR}/bin/${JAR_NAME}"
  35. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENCV_JAR_FILE}" "${OPENCV_JAVA_TEST_DIR}/bin/${JAR_NAME}"
  36. DEPENDS "${OPENCV_JAR_FILE}" "${OPENCV_DEPHELPER}/${the_module}_jar"
  37. COMMENT "Copying the OpenCV jar"
  38. )
  39. add_custom_command(OUTPUT "${OPENCV_JAVA_TEST_DIR}/build.xml"
  40. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/build.xml" "${OPENCV_JAVA_TEST_DIR}/build.xml"
  41. DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build.xml"
  42. COMMENT "Copying build.xml"
  43. )
  44. add_custom_command(OUTPUT "${OPENCV_JAVA_TEST_DIR}/build/jar/opencv-test.jar"
  45. COMMAND "${ANT_EXECUTABLE}" -noinput -k build
  46. WORKING_DIRECTORY "${OPENCV_JAVA_TEST_DIR}"
  47. DEPENDS ${depends} "${OPENCV_JAVA_TEST_DIR}/build.xml" "${CMAKE_CURRENT_SOURCE_DIR}/build.xml" "${OPENCV_JAR_FILE}" "${OPENCV_JAVA_TEST_DIR}/bin/${JAR_NAME}"
  48. COMMENT "Build Java tests"
  49. )
  50. file(GENERATE OUTPUT "${OPENCV_JAVA_TEST_DIR}/ant-$<CONFIGURATION>.properties" CONTENT "opencv.lib.path=$<TARGET_FILE_DIR:${the_module}>")
  51. add_custom_target(${PROJECT_NAME} ALL
  52. DEPENDS ${the_module} "${OPENCV_JAVA_TEST_DIR}/build/jar/opencv-test.jar"
  53. SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/build.xml"
  54. )
  55. if(ENABLE_SOLUTION_FOLDERS)
  56. set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "tests accuracy")
  57. endif()
  58. add_dependencies(opencv_tests ${PROJECT_NAME})