CMakeLists.txt 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. project(${the_module}_jar)
  2. set(OPENCV_JAVA_DIR "${CMAKE_CURRENT_BINARY_DIR}/opencv" CACHE INTERNAL "")
  3. file(REMOVE_RECURSE "${OPENCV_JAVA_DIR}")
  4. file(REMOVE "${OPENCV_DEPHELPER}/${the_module}_jar_source_copy")
  5. file(MAKE_DIRECTORY "${OPENCV_JAVA_DIR}/build/classes")
  6. set(java_src_dir "${OPENCV_JAVA_DIR}/java")
  7. file(MAKE_DIRECTORY "${java_src_dir}")
  8. set(JAR_NAME opencv-${OPENCV_JAVA_LIB_NAME_SUFFIX}.jar)
  9. set(OPENCV_JAR_FILE "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}" CACHE INTERNAL "")
  10. ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/java" "${java_src_dir}")
  11. set(depends gen_opencv_java_source "${OPENCV_DEPHELPER}/gen_opencv_java_source")
  12. ocv_copyfiles_add_target(${the_module}_jar_source_copy JAVA_SRC_COPY "Copy Java(JAR) source files" ${depends})
  13. set(depends ${the_module}_jar_source_copy "${OPENCV_DEPHELPER}/${the_module}_jar_source_copy")
  14. if(OPENCV_JAVA_SOURCE_VERSION)
  15. set(OPENCV_ANT_JAVAC_EXTRA_ATTRS "${OPENCV_ANT_JAVAC_EXTRA_ATTRS} source=\"${OPENCV_JAVA_SOURCE_VERSION}\"")
  16. endif()
  17. if(OPENCV_JAVA_TARGET_VERSION)
  18. set(OPENCV_ANT_JAVAC_EXTRA_ATTRS "${OPENCV_ANT_JAVAC_EXTRA_ATTRS} target=\"${OPENCV_JAVA_TARGET_VERSION}\"")
  19. endif()
  20. set(OPENCV_JAVADOC_DESTINATION "${OpenCV_BINARY_DIR}/doc/doxygen/html/javadoc" CACHE STRING "")
  21. # Old Javadoc URL looks like this: https://docs.oracle.com/javase/6/docs/api/
  22. # New Javadoc URL looks like this: https://docs.oracle.com/en/java/javase/11/docs/api/
  23. set(OPENCV_JAVADOC_LINK_URL "" CACHE STRING "See details in modules/java/jar/CMakeLists.txt")
  24. if(OPENCV_JAVADOC_LINK_URL)
  25. set(CMAKE_CONFIG_OPENCV_JAVADOC_LINK "link=\"${OPENCV_JAVADOC_LINK_URL}\"")
  26. endif()
  27. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.xml.in" "${OPENCV_JAVA_DIR}/build.xml" @ONLY)
  28. list(APPEND depends "${OPENCV_JAVA_DIR}/build.xml")
  29. ocv_cmake_byproducts(__byproducts BYPRODUCTS "${OPENCV_JAR_FILE}")
  30. add_custom_command(OUTPUT "${OPENCV_DEPHELPER}/${the_module}_jar"
  31. ${__byproducts} # required for add_custom_target() by ninja
  32. COMMAND ${ANT_EXECUTABLE} -noinput -k jar
  33. COMMAND ${CMAKE_COMMAND} -E touch "${OPENCV_DEPHELPER}/${the_module}_jar"
  34. WORKING_DIRECTORY "${OPENCV_JAVA_DIR}"
  35. DEPENDS ${depends}
  36. COMMENT "Generating ${JAR_NAME}"
  37. )
  38. add_custom_target(${the_module}_jar DEPENDS "${OPENCV_DEPHELPER}/${the_module}_jar")
  39. install(FILES ${OPENCV_JAR_FILE} OPTIONAL DESTINATION ${OPENCV_JAR_INSTALL_PATH} COMPONENT java)
  40. add_dependencies(${the_module} ${the_module}_jar)
  41. if(BUILD_DOCS)
  42. add_custom_command(OUTPUT "${OPENCV_DEPHELPER}/${the_module}doc"
  43. COMMAND ${ANT_EXECUTABLE} -noinput -k javadoc
  44. COMMAND ${CMAKE_COMMAND} -E touch "${OPENCV_DEPHELPER}/${the_module}doc"
  45. WORKING_DIRECTORY "${OPENCV_JAVA_DIR}"
  46. DEPENDS ${depends}
  47. COMMENT "Generating Javadoc"
  48. )
  49. add_custom_target(${the_module}doc DEPENDS "${OPENCV_DEPHELPER}/${the_module}doc")
  50. install(DIRECTORY ${OpenCV_BINARY_DIR}/doc/doxygen/html/javadoc
  51. DESTINATION "${OPENCV_DOC_INSTALL_PATH}/html"
  52. COMPONENT "docs" OPTIONAL
  53. ${compatible_MESSAGE_NEVER}
  54. )
  55. set(CMAKE_DOXYGEN_JAVADOC_NODE
  56. "<tab type=\"user\" url=\"./javadoc/index.html\" title=\"Java documentation\"/>"
  57. CACHE INTERNAL "Link to the Java documentation") # set to the cache to make it global
  58. add_custom_target(doxygen_javadoc DEPENDS ${the_module}doc)
  59. add_dependencies(opencv_docs ${the_module}doc)
  60. else()
  61. unset(CMAKE_DOXYGEN_JAVADOC_NODE CACHE)
  62. endif()