CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. project(${the_module})
  2. glob_more_specific_sources(H "${CMAKE_CURRENT_SOURCE_DIR}/../generator/src" handwritten_h_sources)
  3. glob_more_specific_sources(CPP "${CMAKE_CURRENT_SOURCE_DIR}/../generator/src" handwritten_cpp_sources)
  4. # grab C++ files from misc/java
  5. foreach(m ${OPENCV_MODULES_BUILD})
  6. if (";${OPENCV_MODULE_${m}_WRAPPERS};" MATCHES ";java;" AND HAVE_${m})
  7. set(module_java_dir "${OPENCV_MODULE_${m}_LOCATION}/misc/java")
  8. include_directories("${module_java_dir}/src/cpp")
  9. file(GLOB _result "${module_java_dir}/src/cpp/*.h" "${module_java_dir}/src/cpp/*.hpp" "${module_java_dir}/src/cpp/*.cpp")
  10. list(APPEND handwritten_cpp_sources ${_result})
  11. endif()
  12. endforeach()
  13. if(ANDROID)
  14. ocv_update(JNI_OUTPUT_PATH "${OpenCV_BINARY_DIR}/jni/${ANDROID_NDK_ABI_NAME}")
  15. else()
  16. ocv_update(JNI_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH}")
  17. endif()
  18. set(__type MODULE)
  19. if(BUILD_FAT_JAVA_LIB)
  20. set(__type SHARED) # samples link to libopencv_java
  21. elseif(APPLE)
  22. set(CMAKE_SHARED_MODULE_SUFFIX ".dylib") # Java is not able to load .so files
  23. endif()
  24. ocv_add_library(${the_module} ${__type}
  25. ${handwritten_h_sources} ${handwritten_cpp_sources} ${generated_cpp_sources}
  26. ${copied_files}
  27. )
  28. add_dependencies(${the_module} gen_opencv_java_source)
  29. ocv_target_include_directories(${the_module} "${CMAKE_CURRENT_SOURCE_DIR}/../generator/src/cpp")
  30. ocv_target_include_directories(${the_module} "${OPENCV_JAVA_BINDINGS_DIR}/gen/cpp")
  31. ocv_target_include_modules(${the_module} ${OPENCV_MODULE_${the_module}_DEPS})
  32. if(NOT ANDROID)
  33. ocv_target_include_directories(${the_module} SYSTEM ${JNI_INCLUDE_DIRS})
  34. endif()
  35. set(__deps ${OPENCV_MODULE_${the_module}_DEPS})
  36. list(REMOVE_ITEM __deps opencv_java_bindings_generator) # don't add dummy module to target_link_libraries list
  37. if(BUILD_FAT_JAVA_LIB)
  38. ocv_list_unique(__deps)
  39. set(__extradeps ${__deps})
  40. ocv_list_filterout(__extradeps "^opencv_")
  41. if(__extradeps)
  42. list(REMOVE_ITEM __deps ${__extradeps})
  43. endif()
  44. if(APPLE)
  45. foreach(_dep ${__deps})
  46. ocv_target_link_libraries(${the_module} PRIVATE -Wl,-force_load "${_dep}")
  47. endforeach()
  48. elseif(((CV_GCC OR CV_CLANG OR UNIX) OR (OPENCV_FORCE_FAT_JAVA_LIB_LD_RULES)) AND (NOT OPENCV_SKIP_FAT_JAVA_LIB_LD_RULES))
  49. ocv_target_link_libraries(${the_module} PRIVATE -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive)
  50. else()
  51. ocv_target_link_libraries(${the_module} PRIVATE ${__deps})
  52. endif()
  53. ocv_target_link_libraries(${the_module} PRIVATE ${__extradeps} ${OPENCV_LINKER_LIBS})
  54. else()
  55. ocv_target_link_libraries(${the_module} PRIVATE ${__deps} ${OPENCV_LINKER_LIBS})
  56. endif()
  57. # Additional target properties
  58. set_target_properties(${the_module} PROPERTIES
  59. OUTPUT_NAME "${the_module}${OPENCV_JAVA_LIB_NAME_SUFFIX}"
  60. ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
  61. LIBRARY_OUTPUT_DIRECTORY ${JNI_OUTPUT_PATH}
  62. RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
  63. DEFINE_SYMBOL CVAPI_EXPORTS
  64. )
  65. if(ANDROID)
  66. ocv_target_link_libraries(${the_module} PUBLIC jnigraphics # for Mat <=> Bitmap converters
  67. INTERFACE jnigraphics
  68. )
  69. ocv_target_link_libraries(${the_module} PUBLIC log dl z
  70. INTERFACE log dl z
  71. )
  72. # force strip library after the build command
  73. # because samples and tests will make a copy of the library before install
  74. if(NOT BUILD_WITH_DEBUG_INFO AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
  75. add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$<TARGET_FILE:${the_module}>")
  76. endif()
  77. endif()
  78. if(ENABLE_SOLUTION_FOLDERS)
  79. set_target_properties(${the_module} PROPERTIES FOLDER "bindings")
  80. endif()
  81. set(__install_export "")
  82. if(BUILD_FAT_JAVA_LIB)
  83. set(__install_export EXPORT OpenCVModules)
  84. endif()
  85. ocv_install_target(${the_module} OPTIONAL ${__install_export}
  86. RUNTIME DESTINATION ${OPENCV_JNI_BIN_INSTALL_PATH} COMPONENT java
  87. LIBRARY DESTINATION ${OPENCV_JNI_INSTALL_PATH} COMPONENT java
  88. ARCHIVE DESTINATION ${OPENCV_JNI_INSTALL_PATH} COMPONENT java
  89. )