From 78ee81c40910bca0e1569cf2e3fa7957d26fb449 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 18 Apr 2012 12:58:42 +0000 Subject: [PATCH] Fixed dependency from opencv_nonfree in Java bindings --- modules/java/CMakeLists.txt | 34 +++++++++++++++------------- modules/java/config/nonfree.filelist | 0 modules/java/src/cpp/jni_part.cpp | 14 +++++++++++- 3 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 modules/java/config/nonfree.filelist diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index 2968af59c0..4a777f4bd8 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -6,7 +6,7 @@ if(NOT ANDROID OR NOT PYTHON_EXECUTABLE OR ANDROID_NATIVE_API_LEVEL LESS 8) endif() set(the_description "The java bindings") -ocv_add_module(java BINDINGS opencv_core opencv_imgproc OPTIONAL opencv_objdetect opencv_features2d opencv_video opencv_highgui opencv_ml opencv_calib3d opencv_photo) +ocv_add_module(java BINDINGS opencv_core opencv_imgproc OPTIONAL opencv_objdetect opencv_features2d opencv_video opencv_highgui opencv_ml opencv_calib3d opencv_photo opencv_nonfree) ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/cpp") # get list of modules to wrap @@ -56,23 +56,25 @@ foreach(module ${OPENCV_JAVA_MODULES}) endforeach() # first run (to get list of generated files) - file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/") - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out") - execute_process(COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVA}" "${HDR_PARSER}" ${module} ${module_headers} - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out" - OUTPUT_QUIET ERROR_QUIET) - file(GLOB_RECURSE ${module}_generated_java_sources RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/" "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/*.java") - ocv_list_add_prefix(${module}_generated_java_sources "${CMAKE_CURRENT_BINARY_DIR}/") + if(module_headers) + file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/") + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out") + execute_process(COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVA}" "${HDR_PARSER}" ${module} ${module_headers} + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out" + OUTPUT_QUIET ERROR_QUIET) + file(GLOB_RECURSE ${module}_generated_java_sources RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/" "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/*.java") + ocv_list_add_prefix(${module}_generated_java_sources "${CMAKE_CURRENT_BINARY_DIR}/") - # second run (at build time) - add_custom_command(OUTPUT ${${module}_generated_java_sources} "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp" - COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVA}" "${HDR_PARSER}" ${module} ${module_headers} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS "${GEN_JAVA}" "${HDR_PARSER}" ${module_headers}) + # second run (at build time) + add_custom_command(OUTPUT ${${module}_generated_java_sources} "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp" + COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVA}" "${HDR_PARSER}" ${module} ${module_headers} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS "${GEN_JAVA}" "${HDR_PARSER}" ${module_headers}) - list(APPEND java_hdr_deps ${module_headers}) - list(APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp") - list(APPEND generated_java_sources ${${module}_generated_java_sources}) + list(APPEND java_hdr_deps ${module_headers}) + list(APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp") + list(APPEND generated_java_sources ${${module}_generated_java_sources}) + endif() endforeach() # get handwritten files used for wrappers generation diff --git a/modules/java/config/nonfree.filelist b/modules/java/config/nonfree.filelist new file mode 100644 index 0000000000..e69de29bb2 diff --git a/modules/java/src/cpp/jni_part.cpp b/modules/java/src/cpp/jni_part.cpp index 8273d94314..def3b3dc4b 100644 --- a/modules/java/src/cpp/jni_part.cpp +++ b/modules/java/src/cpp/jni_part.cpp @@ -21,4 +21,16 @@ JNI_OnUnload(JavaVM *vm, void *reserved) //do nothing } -} // extern "C" \ No newline at end of file +} // extern "C" + +#include "opencv2/opencv_modules.hpp" + +#if HAVE_OPENCV_MODULES_NONFREE +#include "opencv2/nonfree/nonfree.hpp" +static bool makeUseOfNonfree = initModule_nonfree(); +#endif + +#if HAVE_OPENCV_MODULES_FEATURES2D +#include "opencv2/features2d/features2d.hpp" +static bool makeUseOfNonfree = initModule_features2d(); +#endif \ No newline at end of file