diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake
index ee2f8bcbb..0e0240ca8 100644
--- a/cmake/OpenCVDetectAndroidSDK.cmake
+++ b/cmake/OpenCVDetectAndroidSDK.cmake
@@ -302,7 +302,7 @@ macro(add_android_project target path)
COMMAND ${CMAKE_COMMAND} -E touch "${android_proj_bin_dir}/bin/${target}-debug.apk" # needed because ant does not update the timestamp of updated apk
WORKING_DIRECTORY "${android_proj_bin_dir}"
MAIN_DEPENDENCY "${android_proj_bin_dir}/${ANDROID_MANIFEST_FILE}"
- DEPENDS "${OpenCV_BINARY_DIR}/bin/.classes.jar.dephelper" opencv_java # as we are part of OpenCV we can just force this dependency
+ DEPENDS "${OpenCV_BINARY_DIR}/bin/classes.jar.dephelper" opencv_java # as we are part of OpenCV we can just force this dependency
DEPENDS ${android_proj_file_deps} ${JNI_LIB_NAME})
endif()
diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake
index d47909386..b6d129a26 100644
--- a/cmake/OpenCVModule.cmake
+++ b/cmake/OpenCVModule.cmake
@@ -461,6 +461,7 @@ macro(ocv_create_module)
OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}"
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
+ LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
INSTALL_NAME_DIR lib
)
diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp
index b3a136b03..a891e94cc 100644
--- a/modules/core/src/system.cpp
+++ b/modules/core/src/system.cpp
@@ -439,7 +439,7 @@ void error( const Exception& exc )
exc.func.c_str() : "unknown function", exc.file.c_str(), exc.line );
fprintf( stderr, "%s\n", buf );
fflush( stderr );
-# ifdef ANDROID
+# ifdef __ANDROID__
__android_log_print(ANDROID_LOG_ERROR, "cv::error()", "%s", buf);
# endif
}
diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt
index aa7db6951..400668817 100644
--- a/modules/java/CMakeLists.txt
+++ b/modules/java/CMakeLists.txt
@@ -1,15 +1,10 @@
# ----------------------------------------------------------------------------
# CMake file for java support
# ----------------------------------------------------------------------------
-if(IOS OR NOT PYTHON_EXECUTABLE OR NOT (JNI_FOUND OR (ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7)))
+if(IOS OR NOT PYTHON_EXECUTABLE OR NOT ANT_EXECUTABLE OR NOT (JNI_FOUND OR (ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7)))
ocv_module_disable(java)
endif()
-if(NOT ANDROID)
- # disable java by default because java support on desktop is experimental
- set(BUILD_opencv_java_INIT OFF)
-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 opencv_nonfree opencv_contrib)
ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp")
@@ -18,6 +13,10 @@ if(NOT ANDROID)
include_directories(${JNI_INCLUDE_DIRS})
endif()
+# output locations
+set(JAVA_INSTALL_ROOT "sdk/java")
+set(JNI_INSTALL_ROOT "sdk/native")
+
# get list of modules to wrap
string(REPLACE "opencv_" "" OPENCV_JAVA_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS};${OPENCV_MODULE_${the_module}_OPT_DEPS}")
foreach(module ${OPENCV_JAVA_MODULES})
@@ -26,20 +25,29 @@ foreach(module ${OPENCV_JAVA_MODULES})
endif()
endforeach()
-set(GEN_JAVA "${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_java.py")
-set(HDR_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/../python/src2/hdr_parser.py")
-set(GEN_JAVADOC "${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_javadoc.py")
-set(RST_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/generator/rst_parser.py")
+######################################################################################################################################
-# add dependencies to cmake (we should rerun cmake if any of these scripts is modified)
-configure_file("${GEN_JAVA}" "${OpenCV_BINARY_DIR}/junk/gen_java.junk" COPYONLY)
-configure_file("${HDR_PARSER}" "${OpenCV_BINARY_DIR}/junk/hdr_parser.junk" COPYONLY)
+# scripts
+set(scripts_gen_java "${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_java.py")
+set(scripts_hdr_parser "${CMAKE_CURRENT_SOURCE_DIR}/../python/src2/hdr_parser.py")
+set(scripts_gen_javadoc "${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_javadoc.py")
+set(scripts_rst_parser "${CMAKE_CURRENT_SOURCE_DIR}/generator/rst_parser.py")
-set(java_hdr_deps "")
-set(generated_cpp_sources "")
-set(generated_java_sources "")
+# handwritten C/C++ and Java sources
+file(GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.hpp")
+file(GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.cpp")
+file(GLOB handwrittren_java_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java/*.java")
+file(GLOB handwrittren_aidl_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java/*.aidl")
+if(NOT ANDROID)
+ ocv_list_filterout(handwrittren_java_sources "/(engine|android)\\\\+")
+ ocv_list_filterout(handwrittren_aidl_sources "/(engine|android)\\\\+")
+else()
+ file(GLOB_RECURSE handwrittren_lib_project_files_rel RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/" "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/*")
+ list(REMOVE_ITEM handwrittren_lib_project_files_rel "${ANDROID_MANIFEST_FILE}")
+endif()
-# setup raw java and cpp files generation (without javadoc and at temporary location)
+# headers of OpenCV modules
+set(opencv_public_headers "")
foreach(module ${OPENCV_JAVA_MODULES})
# get list of module headers
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/generator/config/${module}.filelist")
@@ -48,121 +56,213 @@ foreach(module ${OPENCV_JAVA_MODULES})
else()
set(module_headers "${OPENCV_MODULE_opencv_${module}_HEADERS}")
endif()
-
- # C headers must go first
- set(module_headers_cpp ${module_headers})
- ocv_list_filterout(module_headers_cpp "\\\\.h$")
- if(module_headers_cpp)
- list(REMOVE_ITEM module_headers ${module_headers_cpp})
- list(APPEND module_headers ${module_headers_cpp})
- endif()
- unset(module_headers_cpp)
-
- # add dependencies to cmake (we should rerun cmake if any of these headers is modified)
- foreach(header ${module_headers})
- get_filename_component(header_name "${header}" NAME_WE)
- configure_file("${header}" "${OpenCV_BINARY_DIR}/junk/${header_name}.junk" COPYONLY)
- endforeach()
-
- # first run (to get list of generated files)
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}/")
+ # C headers must go first
+ set(module_headers_cpp ${module_headers})
+ ocv_list_filterout(module_headers_cpp "\\\\.h$")
+ if(module_headers_cpp)
+ list(REMOVE_ITEM module_headers ${module_headers_cpp})
+ list(APPEND module_headers ${module_headers_cpp})
+ endif()
+ unset(module_headers_cpp)
- # 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})
+ set(opencv_public_headers_${module} ${module_headers})
+ list(APPEND opencv_public_headers ${module_headers})
+ else()
+ list(REMOVE_ITEM OPENCV_JAVA_MODULES ${module})
endif()
endforeach()
-# get handwritten files used for wrappers generation
-file(GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.hpp")
-file(GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.cpp")
-file(GLOB handwrittren_java_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java/*.java")
-file(GLOB handwrittren_aidl_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java/*.aidl")
-
-# remove handwritten java files for disabled modules
-foreach(jfile ${handwrittren_java_sources})
- string(REGEX REPLACE "^.*/([^+]+)\\+.*\\.java$" "\\1" jmodname "${jfile}")
- if(DEFINED HAVE_opencv_${jmodname} AND NOT HAVE_opencv_${jmodname})
- list(REMOVE_ITEM handwrittren_java_sources "${jfile}")
- endif()
+# rst documentation used for javadoc generation
+set(javadoc_rst_sources "")
+foreach(module ${OPENCV_JAVA_MODULES})
+ file(GLOB_RECURSE refman_rst_headers "${OPENCV_MODULE_opencv_${module}_LOCATION}/*.rst")
+ list(APPEND javadoc_rst_sources ${refman_rst_headers})
endforeach()
-# remove VideoCapture wrapper if highgui is disabled
-if(NOT HAVE_opencv_highgui)
- list(REMOVE_ITEM handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/VideoCapture.cpp")
-endif()
+# generated cpp files
+set(generated_cpp_sources "")
+foreach(module ${OPENCV_JAVA_MODULES})
+ list(APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp")
+endforeach()
-# create list of javadoc documented files
-unset(documented_java_files)
-foreach(java_file ${handwrittren_java_sources} ${generated_java_sources})
+# IMPORTANT: add dependencies to cmake (we should rerun cmake if any of these files is modified)
+configure_file("${scripts_gen_java}" "${OpenCV_BINARY_DIR}/junk/gen_java.junk" COPYONLY)
+configure_file("${scripts_hdr_parser}" "${OpenCV_BINARY_DIR}/junk/hdr_parser.junk" COPYONLY)
+foreach(header ${opencv_public_headers})
+ get_filename_component(header_name "${header}" NAME)
+ configure_file("${header}" "${OpenCV_BINARY_DIR}/junk/${header_name}.junk" COPYONLY)
+endforeach()
+
+# generated java files
+set(generated_java_sources "")
+foreach(module ${OPENCV_JAVA_MODULES})
+ # first run of gen_java.py (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} "${scripts_gen_java}" "${scripts_hdr_parser}" ${module} ${opencv_public_headers_${module}}
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out"
+ OUTPUT_QUIET ERROR_QUIET)
+ unset(generated_java_sources_${module})
+ file(GLOB_RECURSE generated_java_sources_${module} RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/" "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/*.java")
+ ocv_list_add_prefix(generated_java_sources_${module} "${CMAKE_CURRENT_BINARY_DIR}/")
+
+ list(APPEND generated_java_sources ${generated_java_sources_${module}})
+endforeach()
+
+# generated java files with javadoc
+set(documented_java_files "")
+foreach(java_file ${generated_java_sources} ${handwrittren_java_sources})
get_filename_component(java_file_name "${java_file}" NAME_WE)
list(APPEND documented_java_files "${CMAKE_CURRENT_BINARY_DIR}/${java_file_name}-jdoc.java")
endforeach()
-# generate javadoc files
-file(GLOB_RECURSE refman_rst_headers "${CMAKE_CURRENT_SOURCE_DIR}/../*.rst")
-set(java_documented_headers_deps ${handwrittren_java_sources} ${generated_java_sources} ${java_hdr_deps} ${refman_rst_headers}
- "${GEN_JAVADOC}" "${RST_PARSER}" "${GEN_JAVA}" "${HDR_PARSER}")
+######################################################################################################################################
+# step 1: generate .cpp/.java from OpenCV headers
+set(step1_depends "${scripts_gen_java}" "${scripts_hdr_parser}" ${opencv_public_headers})
+foreach(module ${OPENCV_JAVA_MODULES})
+ # second run of gen_java.py (at build time)
+ add_custom_command(OUTPUT ${generated_java_sources_${module}} "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp"
+ COMMAND ${PYTHON_EXECUTABLE} "${scripts_gen_java}" "${scripts_hdr_parser}" ${module} ${opencv_public_headers_${module}}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ DEPENDS "${scripts_gen_java}" "${scripts_hdr_parser}" ${opencv_public_headers_${module}}
+ )
+endforeach()
+
+# step 2: generate javadoc comments
+set(step2_depends ${step1_depends} ${scripts_gen_javadoc} ${scripts_rst_parser} ${javadoc_rst_sources} ${generated_java_sources} ${handwrittren_java_sources})
string(REPLACE ";" "," OPENCV_JAVA_MODULES_STR "${OPENCV_JAVA_MODULES}")
-add_custom_command(
- OUTPUT ${documented_java_files}
- COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVADOC}" --modules ${OPENCV_JAVA_MODULES_STR} "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java" "${CMAKE_CURRENT_BINARY_DIR}" 2>"${CMAKE_CURRENT_BINARY_DIR}/get_javadoc_errors.log"
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- DEPENDS ${java_documented_headers_deps}
-)
+add_custom_command(OUTPUT ${documented_java_files}
+ COMMAND ${PYTHON_EXECUTABLE} "${scripts_gen_javadoc}" --modules ${OPENCV_JAVA_MODULES_STR} "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java" "${CMAKE_CURRENT_BINARY_DIR}" 2>"${CMAKE_CURRENT_BINARY_DIR}/get_javadoc_errors.log"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ DEPENDS ${step2_depends}
+ )
-# copy generated java files to the final location
-set(JAVA_OUTPUT_DIR "src/org/opencv")
-set(JAVA_INSTALL_ROOT "sdk/java")
-set(JNI_INSTALL_ROOT "sdk/native")
-
-# copy each documented header to the final destination
-set(java_files "")
-set(source_java_files ${documented_java_files} ${handwrittren_aidl_sources})
-if(NOT ANDROID)
- ocv_list_filterout(source_java_files "/(engine|android)\\\\+")
-endif()
-
-foreach(java_file ${source_java_files})
+# step 3: copy files to destination
+set(step3_input_files ${documented_java_files} ${handwrittren_aidl_sources})
+set(copied_files "")
+foreach(java_file ${step3_input_files})
get_filename_component(java_file_name "${java_file}" NAME)
string(REPLACE "-jdoc.java" ".java" java_file_name "${java_file_name}")
string(REPLACE "+" "/" java_file_name "${java_file_name}")
+ set(output_name "${OpenCV_BINARY_DIR}/src/org/opencv/${java_file_name}")
- add_custom_command(
- OUTPUT "${OpenCV_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}"
- COMMAND ${CMAKE_COMMAND} -E copy "${java_file}" "${OpenCV_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}"
- MAIN_DEPENDENCY "${java_file}"
- DEPENDS ${java_documented_headers_deps}
- COMMENT "Generating ${JAVA_OUTPUT_DIR}/${java_file_name}"
- )
- list(APPEND java_files "${OpenCV_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}")
+ add_custom_command(OUTPUT "${output_name}"
+ COMMAND ${CMAKE_COMMAND} -E copy "${java_file}" "${output_name}"
+ MAIN_DEPENDENCY "${java_file}"
+ DEPENDS ${step2_depends}
+ COMMENT "Generating src/org/opencv/${java_file_name}"
+ )
+ list(APPEND copied_files "${output_name}")
if(ANDROID)
get_filename_component(install_subdir "${java_file_name}" PATH)
- install(FILES "${OpenCV_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}" DESTINATION ${JAVA_INSTALL_ROOT}/${JAVA_OUTPUT_DIR}/${install_subdir} COMPONENT main)
+ install(FILES "${output_name}" DESTINATION "${JAVA_INSTALL_ROOT}/src/org/opencv/${install_subdir}" COMPONENT main)
endif()
endforeach()
-# custom target for java API
-set(api_target ${the_module}_api)
-add_custom_target(${api_target} DEPENDS ${java_files} ${documented_java_files} ${java_documented_headers_deps})
+if(ANDROID)
+ set(android_copied_files "")
+ set(android_step3_input_files "")
+ foreach(file ${handwrittren_lib_project_files_rel})
+ add_custom_command(OUTPUT "${OpenCV_BINARY_DIR}/${file}"
+ COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${file}" "${OpenCV_BINARY_DIR}/${file}"
+ MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${file}"
+ COMMENT "Generating ${file}"
+ )
+ list(APPEND android_copied_files "${OpenCV_BINARY_DIR}/${file}")
+ list(APPEND android_step3_input_files "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${file}")
-# add opencv_java library
-add_library(${the_module} SHARED ${handwrittren_h_sources} ${handwrittren_cpp_sources} ${generated_cpp_sources})
+ if(NOT file MATCHES "jni/.+")
+ get_filename_component(install_subdir "${file}" PATH)
+ install(FILES "${OpenCV_BINARY_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT main)
+ endif()
+ endforeach()
+
+ # library project jni sources (nothing really depends on them so we will not add them to step3_input_files)
+ foreach(jni_file ${handwrittren_cpp_sources} ${handwrittren_h_sources} ${generated_cpp_sources})
+ get_filename_component(jni_file_name "${jni_file}" NAME)
+ add_custom_command(OUTPUT "${OpenCV_BINARY_DIR}/jni/${jni_file_name}"
+ COMMAND ${CMAKE_COMMAND} -E copy "${jni_file}" "${OpenCV_BINARY_DIR}/jni/${jni_file_name}"
+ DEPENDS "${jni_file}" ${java_hdr_deps}
+ COMMENT "Generating jni/${jni_file_name}"
+ )
+ list(APPEND android_copied_files "${OpenCV_BINARY_DIR}/jni/${jni_file_name}")
+ endforeach()
+endif(ANDROID)
+
+# step 3.5: generate Android library project
+if(ANDROID AND ANDROID_EXECUTABLE)
+ set(lib_target_files ${ANDROID_LIB_PROJECT_FILES})
+ ocv_list_add_prefix(lib_target_files "${OpenCV_BINARY_DIR}/")
+
+ android_get_compatible_target(lib_target_sdk_target ${ANDROID_NATIVE_API_LEVEL} ${ANDROID_SDK_TARGET} 11)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${ANDROID_MANIFEST_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}")
+
+ add_custom_command(OUTPUT ${lib_target_files} "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
+ COMMAND ${CMAKE_COMMAND} -E remove ${lib_target_files}
+ COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
+ COMMAND ${ANDROID_EXECUTABLE} --silent create lib-project --path \"${OpenCV_BINARY_DIR}\" --target \"${lib_target_sdk_target}\" --name OpenCV --package org.opencv 2>\"${CMAKE_CURRENT_BINARY_DIR}/create_lib_project.log\"
+ COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
+ MAIN_DEPENDENCY "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
+ DEPENDS ${android_step3_input_files} ${android_copied_files}
+ COMMENT "Generating OpenCV Android library project. SDK target: ${lib_target_sdk_target}"
+ )
+ list(APPEND copied_files ${lib_target_files} "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}")
+ list(APPEND step3_input_files "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}")
+
+ install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_PROJECT_PROPERTIES_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT main)
+ install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT main)
+ # creating empty 'gen' and 'res' folders
+ install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/gen\")" COMPONENT main)
+ install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/res\")" COMPONENT main)
+endif(ANDROID AND ANDROID_EXECUTABLE)
+
+set(step3_depends ${step2_depends} ${step3_input_files} ${copied_files})
+
+# step 4: build jar
+if(ANDROID)
+ set(JAR_FILE "${OpenCV_BINARY_DIR}/bin/classes.jar")
+ if(ANDROID_TOOLS_Pkg_Revision GREATER 13)
+ # build the library project
+ # normally we should do this after a native part, but for a library project we can build the java part first
+ add_custom_command(OUTPUT "${JAR_FILE}" "${JAR_FILE}.dephelper"
+ COMMAND ${ANT_EXECUTABLE} -q -noinput -k debug
+ COMMAND ${CMAKE_COMMAND} -E touch "${JAR_FILE}.dephelper" # can not rely on classes.jar because different versions of SDK update timestamp at different times
+ WORKING_DIRECTORY "${OpenCV_BINARY_DIR}"
+ DEPENDS ${step3_depends}
+ COMMENT "Building OpenCV Android library project"
+ )
+ else()
+ # ditto
+ add_custom_command(OUTPUT "${JAR_FILE}" "${JAR_FILE}.dephelper"
+ COMMAND ${CMAKE_COMMAND} -E touch "${JAR_FILE}"
+ COMMAND ${CMAKE_COMMAND} -E touch "${JAR_FILE}.dephelper"
+ WORKING_DIRECTORY "${OpenCV_BINARY_DIR}"
+ DEPENDS ${step3_depends}
+ COMMENT ""
+ )
+ endif()
+else(ANDROID)
+ set(JAR_NAME opencv-${OPENCV_VERSION}.jar)
+ set(JAR_FILE "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}")
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.xml.in" "${OpenCV_BINARY_DIR}/build.xml" IMMEDIATE @ONLY)
+ list(APPEND step3_depends "${OpenCV_BINARY_DIR}/build.xml")
+
+ add_custom_command(OUTPUT "${JAR_FILE}" "${JAR_FILE}.dephelper"
+ COMMAND ${ANT_EXECUTABLE} -q -noinput -k jar
+ COMMAND ${CMAKE_COMMAND} -E touch "${JAR_FILE}.dephelper"
+ WORKING_DIRECTORY "${OpenCV_BINARY_DIR}"
+ DEPENDS ${step3_depends}
+ COMMENT "Generating ${JAR_NAME}"
+ )
+endif(ANDROID)
+
+# step 5: build native part
+add_library(${the_module} SHARED ${handwrittren_h_sources} ${handwrittren_cpp_sources} ${generated_cpp_sources}
+ ${copied_files}
+ "${JAR_FILE}" "${JAR_FILE}.dephelper")
if(BUILD_FAT_JAVA_LIB)
set(__deps ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULES_BUILD})
list(REMOVE_ITEM __deps ${the_module} opencv_ts)
@@ -176,22 +276,7 @@ if(BUILD_FAT_JAVA_LIB)
else()
target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
endif()
-add_dependencies(${the_module} ${api_target})
-# Additional target properties
-set_target_properties(${the_module} PROPERTIES
- OUTPUT_NAME "${the_module}"
- ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
- RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
- INSTALL_NAME_DIR ${OPENCV_LIB_INSTALL_PATH}
- LINK_INTERFACE_LIBRARIES ""
- )
-
-install(TARGETS ${the_module}
- LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
- ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main)
-
-set(lib_target ${the_module}_library)
if(ANDROID)
target_link_libraries(${the_module} jnigraphics) # for Mat <=> Bitmap converters
@@ -202,105 +287,37 @@ if(ANDROID)
if ( NOT (CMAKE_BUILD_TYPE MATCHES "Debug"))
add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${__opencv_java_location}")
endif()
+endif()
- set(lib_proj_files "")
-
- # manifest, jni, Eclipse project
- file(GLOB_RECURSE android_lib_project_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/" "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/*")
- list(REMOVE_ITEM android_lib_project_files "${ANDROID_MANIFEST_FILE}")
- foreach(f ${android_lib_project_files})
- if(NOT f MATCHES "\\.svn")
- configure_file("${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${f}" "${OpenCV_BINARY_DIR}/${f}")
- list(APPEND lib_proj_files "${OpenCV_BINARY_DIR}/${f}")
-
- if(NOT f MATCHES "jni/.+")
- get_filename_component(install_subdir "${f}" PATH)
- install(FILES "${OpenCV_BINARY_DIR}/${f}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT main)
- endif()
- endif()
- endforeach()
-
- # library project jni sources
- foreach(jni_file ${handwrittren_cpp_sources} ${handwrittren_h_sources} ${generated_cpp_sources})
- get_filename_component(jni_file_name "${jni_file}" NAME)
- add_custom_command(
- OUTPUT "${OpenCV_BINARY_DIR}/jni/${jni_file_name}"
- COMMAND ${CMAKE_COMMAND} -E copy "${jni_file}" "${OpenCV_BINARY_DIR}/jni/${jni_file_name}"
- DEPENDS "${jni_file}" ${java_hdr_deps}
- COMMENT "Generating jni/${jni_file_name}"
- )
- list(APPEND lib_proj_files "${OpenCV_BINARY_DIR}/jni/${jni_file_name}")
- endforeach()
-
- # create Android library project in build folder
- if(ANDROID_EXECUTABLE)
- set(lib_target_files ${ANDROID_LIB_PROJECT_FILES})
- ocv_list_add_prefix(lib_target_files "${OpenCV_BINARY_DIR}/")
-
- android_get_compatible_target(lib_target_sdk_target ${ANDROID_NATIVE_API_LEVEL} ${ANDROID_SDK_TARGET} 11)
-
- configure_file("${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${ANDROID_MANIFEST_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}")
-
- add_custom_command(
- OUTPUT ${lib_target_files} "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
- COMMAND ${CMAKE_COMMAND} -E remove ${lib_target_files}
- COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
- COMMAND ${ANDROID_EXECUTABLE} --silent create lib-project --path \"${OpenCV_BINARY_DIR}\" --target \"${lib_target_sdk_target}\" --name OpenCV --package org.opencv 2>\"${CMAKE_CURRENT_BINARY_DIR}/create_lib_project.log\"
- COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
- MAIN_DEPENDENCY "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
- DEPENDS ${lib_proj_files}
- COMMENT "Generating OpenCV Android library project. SDK target: ${lib_target_sdk_target}"
- )
-
- install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_PROJECT_PROPERTIES_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT main)
- install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT main)
- # creating empty 'gen' and 'res' folders
- install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/sdk/java/gen\")" COMPONENT main)
- install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/sdk/java/res\")" COMPONENT main)
-
- if(ANT_EXECUTABLE AND ANDROID_TOOLS_Pkg_Revision GREATER 13)
- # build the library project
- # normally we should do this after a native part, but for a library project we can build the java part first
- add_custom_command(
- OUTPUT "${OpenCV_BINARY_DIR}/bin/classes.jar" "${OpenCV_BINARY_DIR}/bin/.classes.jar.dephelper"
- COMMAND ${ANT_EXECUTABLE} -q -noinput -k debug
- COMMAND ${CMAKE_COMMAND} -E touch "${OpenCV_BINARY_DIR}/bin/.classes.jar.dephelper" # can not rely on classes.jar because different versions of SDK update timestamp at different times
- WORKING_DIRECTORY "${OpenCV_BINARY_DIR}"
- DEPENDS ${lib_proj_files} ${lib_target_files} ${java_files}
- COMMENT "Building OpenCV Android library project"
- )
- #install(FILES "${OpenCV_BINARY_DIR}/bin/classes.jar" "${OpenCV_BINARY_DIR}/bin/jarlist.cache" "${OpenCV_BINARY_DIR}/bin/build.prop" DESTINATION bin COMPONENT main)
- #install(DIRECTORY "${OpenCV_BINARY_DIR}/bin/res" "${OpenCV_BINARY_DIR}/bin/classes" DESTINATION bin COMPONENT main)
- list(APPEND lib_target_files "${OpenCV_BINARY_DIR}/bin/classes.jar")
- endif()
-
- add_custom_target(${lib_target} SOURCES ${lib_proj_files} ${lib_target_files} "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}")
- endif()
-else(ANDROID)
- configure_file("${CMAKE_CURRENT_SOURCE_DIR}/jar/build.xml" "${OpenCV_BINARY_DIR}/build.xml" IMMEDIATE @ONLY)
- set(JAR_NAME opencv-${OPENCV_VERSION}.jar)
-
- add_custom_command(
- OUTPUT "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}" "${OpenCV_BINARY_DIR}/bin/.${JAR_NAME}.dephelper"
- COMMAND ${ANT_EXECUTABLE} -q -noinput -k jar
- COMMAND ${CMAKE_COMMAND} -E touch "${OpenCV_BINARY_DIR}/bin/.${JAR_NAME}.dephelper"
- WORKING_DIRECTORY "${OpenCV_BINARY_DIR}"
- DEPENDS "${OpenCV_BINARY_DIR}/build.xml" ${java_files}
- COMMENT "Generating ${JAR_NAME}"
+# Additional target properties
+set_target_properties(${the_module} PROPERTIES
+ OUTPUT_NAME "${the_module}"
+ ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
+ RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
+ INSTALL_NAME_DIR ${OPENCV_LIB_INSTALL_PATH}
+ LINK_INTERFACE_LIBRARIES ""
)
- add_custom_target(${lib_target} SOURCES "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}")
-endif(ANDROID)
-
-add_dependencies(${lib_target} ${api_target})
-add_dependencies(${the_module} ${lib_target})
-
-# android test project
-if(ANDROID AND BUILD_TESTS)
- add_subdirectory(android_test)
+if(ANDROID)
+ set_target_properties(${the_module} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH})
+else()
+ set_target_properties(${the_module} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
endif()
-# Desktop Java test project.
-if((NOT ANDROID) AND BUILD_TESTS)
- add_subdirectory(java_test)
+if(ENABLE_SOLUTION_FOLDERS)
+ set_target_properties(${the_module} PROPERTIES FOLDER "bindings")
+endif()
+
+install(TARGETS ${the_module}
+ LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
+ ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main)
+
+######################################################################################################################################
+
+if(BUILD_TESTS)
+ if(ANDROID)
+ add_subdirectory(android_test)
+ else()
+ add_subdirectory(test)
+ endif()
endif()
diff --git a/modules/java/android_test/CMakeLists.txt b/modules/java/android_test/CMakeLists.txt
index f6e5a7be9..06ebf4aa1 100644
--- a/modules/java/android_test/CMakeLists.txt
+++ b/modules/java/android_test/CMakeLists.txt
@@ -47,7 +47,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E touch "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" # needed because ant does not update the timestamp of updated apk
WORKING_DIRECTORY "${opencv_test_java_bin_dir}"
MAIN_DEPENDENCY "${opencv_test_java_bin_dir}/${ANDROID_MANIFEST_FILE}"
- DEPENDS "${OpenCV_BINARY_DIR}/bin/.classes.jar.dephelper" opencv_java
+ DEPENDS "${JAR_FILE}.dephelper" opencv_java
DEPENDS ${opencv_test_java_file_deps})
add_custom_target(${PROJECT_NAME} ALL SOURCES "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" )
diff --git a/modules/java/jar/build.xml b/modules/java/build.xml.in
similarity index 90%
rename from modules/java/jar/build.xml
rename to modules/java/build.xml.in
index 07705b2f0..98ba2e36b 100644
--- a/modules/java/jar/build.xml
+++ b/modules/java/build.xml.in
@@ -10,6 +10,6 @@
-
+
\ No newline at end of file
diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py
index 429360cd2..0f3ba1d33 100755
--- a/modules/java/generator/gen_java.py
+++ b/modules/java/generator/gen_java.py
@@ -871,22 +871,9 @@ public class %(jc)s {
// This file is auto-generated, please don't edit!
//
-#include
-
-#include "converters.h"
-
-#if defined DEBUG && defined ANDROID
-# include
-# define MODULE_LOG_TAG "OpenCV.%(m)s"
-# define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
-#else //DEBUG
-# define LOGD(...)
-#endif //DEBUG
-
-#ifdef _MSC_VER
-# pragma warning(disable:4800 4244)
-#endif
+#define LOG_TAG "org.opencv.%(m)s"
+#include "common.h"
#include "opencv2/%(m)s/%(m)s.hpp"
using namespace cv;
diff --git a/modules/java/generator/src/cpp/Mat.cpp b/modules/java/generator/src/cpp/Mat.cpp
index 3831e188a..726dcaf5f 100644
--- a/modules/java/generator/src/cpp/Mat.cpp
+++ b/modules/java/generator/src/cpp/Mat.cpp
@@ -1,27 +1,6 @@
-#include
-
-#include "converters.h"
-
-#ifdef ANDROID
-
-#include
#define LOG_TAG "org.opencv.core.Mat"
-#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#ifdef DEBUG
-#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#else //!DEBUG
-#define LOGD(...)
-#endif //DEBUG
-
-#else
-#define LOGE(...)
-#define LOGD(...)
-#endif
-
-#ifdef _MSC_VER
-# pragma warning(disable:4800)
-#endif
+#include "common.h"
#include "opencv2/core/core.hpp"
using namespace cv;
diff --git a/modules/java/generator/src/cpp/VideoCapture.cpp b/modules/java/generator/src/cpp/VideoCapture.cpp
index 48dc151b0..5b9266660 100644
--- a/modules/java/generator/src/cpp/VideoCapture.cpp
+++ b/modules/java/generator/src/cpp/VideoCapture.cpp
@@ -1,12 +1,5 @@
-#include
-
-#if defined DEBUG && defined ANDROID
-#include
-#define MODULE_LOG_TAG "OpenCV.highgui"
-#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
-#else
-#define LOGD(...)
-#endif
+#define LOG_TAG "org.opencv.highgui.VideoCapture"
+#include "common.h"
#include "opencv2/opencv_modules.hpp"
#ifdef HAVE_OPENCV_HIGHGUI
diff --git a/modules/java/generator/src/cpp/common.h b/modules/java/generator/src/cpp/common.h
new file mode 100644
index 000000000..b67f633f7
--- /dev/null
+++ b/modules/java/generator/src/cpp/common.h
@@ -0,0 +1,33 @@
+#ifndef __JAVA_COMMON_H__
+#define __JAVA_COMMON_H__
+
+#if !defined(__ppc__)
+// to suppress warning from jni.h on OS X
+# define TARGET_RT_MAC_CFM 0
+#endif
+#include
+
+#ifdef __ANDROID__
+# include
+# define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
+# ifdef DEBUG
+# define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
+# else
+# define LOGD(...)
+# endif
+#else
+# define LOGE(...)
+# define LOGD(...)
+#endif
+
+#include "converters.h"
+
+#include "core_manual.hpp"
+#include "features2d_manual.hpp"
+
+
+#ifdef _MSC_VER
+# pragma warning(disable:4800 4244)
+#endif
+
+#endif //__JAVA_COMMON_H__
\ No newline at end of file
diff --git a/modules/java/generator/src/cpp/converters.cpp b/modules/java/generator/src/cpp/converters.cpp
index 6bf52c00e..860f0bc0e 100644
--- a/modules/java/generator/src/cpp/converters.cpp
+++ b/modules/java/generator/src/cpp/converters.cpp
@@ -1,12 +1,4 @@
-#include "converters.h"
-
-#if defined DEBUG && defined ANDROID
-#include
-#define MODULE_LOG_TAG "OpenCV.converters"
-#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
-#else //DEBUG
-#define LOGD(...)
-#endif //DEBUG
+#include "common.h"
using namespace cv;
diff --git a/modules/java/generator/src/cpp/converters.h b/modules/java/generator/src/cpp/converters.h
index dde73bc6a..bdffe9269 100644
--- a/modules/java/generator/src/cpp/converters.h
+++ b/modules/java/generator/src/cpp/converters.h
@@ -1,5 +1,3 @@
-#include
-
#include "opencv2/opencv_modules.hpp"
#include "opencv2/core/core.hpp"
#include "features2d_manual.hpp"
diff --git a/modules/java/generator/src/cpp/core_manual.cpp b/modules/java/generator/src/cpp/core_manual.cpp
new file mode 100644
index 000000000..d7ba5b994
--- /dev/null
+++ b/modules/java/generator/src/cpp/core_manual.cpp
@@ -0,0 +1,15 @@
+#define LOG_TAG "org.opencv.core.Core"
+#include "common.h"
+
+static int quietCallback( int, const char*, const char*, const char*, int, void* )
+{
+ return 0;
+}
+
+void cv::setErrorVerbosity(bool verbose)
+{
+ if(verbose)
+ cv::redirectError(0);
+ else
+ cv::redirectError((cv::ErrorCallback)quietCallback);
+}
\ No newline at end of file
diff --git a/modules/java/generator/src/cpp/core_manual.hpp b/modules/java/generator/src/cpp/core_manual.hpp
index 28d29e0a1..a2fc62782 100644
--- a/modules/java/generator/src/cpp/core_manual.hpp
+++ b/modules/java/generator/src/cpp/core_manual.hpp
@@ -2,6 +2,13 @@
#include "opencv2/core/core.hpp"
+namespace cv
+{
+
+CV_EXPORTS_W void setErrorVerbosity(bool verbose);
+
+}
+
#if 0
namespace cv
diff --git a/modules/java/generator/src/cpp/jni_part.cpp b/modules/java/generator/src/cpp/jni_part.cpp
index b0315a287..df1bd142c 100644
--- a/modules/java/generator/src/cpp/jni_part.cpp
+++ b/modules/java/generator/src/cpp/jni_part.cpp
@@ -1,4 +1,4 @@
-#include
+#include "common.h"
#include "opencv2/opencv_modules.hpp"
diff --git a/modules/java/generator/src/cpp/utils.cpp b/modules/java/generator/src/cpp/utils.cpp
index 03a2bbdc2..9f6b1bfcf 100644
--- a/modules/java/generator/src/cpp/utils.cpp
+++ b/modules/java/generator/src/cpp/utils.cpp
@@ -1,24 +1,14 @@
-#include
+#define LOG_TAG "org.opencv.android.Utils"
+#include "common.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
-#ifdef ANDROID
-
+#ifdef __ANDROID__
#include
-#include
-#define LOG_TAG "org.opencv.android.Utils"
-#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#ifdef DEBUG
-#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#else //!DEBUG
-#define LOGD(...)
-#endif //DEBUG
-
using namespace cv;
-
extern "C" {
/*
@@ -168,4 +158,4 @@ JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nMatToBitmap
} // extern "C"
-#endif //ANDROID
\ No newline at end of file
+#endif //__ANDROID__
\ No newline at end of file
diff --git a/modules/java/java_test/CMakeLists.txt b/modules/java/java_test/CMakeLists.txt
deleted file mode 100644
index b2c8d10ae..000000000
--- a/modules/java/java_test/CMakeLists.txt
+++ /dev/null
@@ -1,80 +0,0 @@
-ocv_check_dependencies(opencv_java ${OPENCV_MODULE_opencv_java_OPT_DEPS} ${OPENCV_MODULE_opencv_java_REQ_DEPS})
-
-if(NOT OCV_DEPENDENCIES_FOUND OR NOT ANT_EXECUTABLE)
- return()
-endif()
-
-# TODO: This has the same name as the Android test project. That project should
-# probably be renamed.
-project(opencv_test_java)
-
-set(opencv_test_java_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/.build")
-
-set(android_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../android_test")
-
-set(java_source_dir ${CMAKE_CURRENT_SOURCE_DIR})
-
-# get project sources
-file(GLOB_RECURSE opencv_test_java_files RELATIVE "${android_source_dir}" "${android_source_dir}/res/*" "${android_source_dir}/src/*")
-ocv_list_filterout(opencv_test_java_files ".svn")
-ocv_list_filterout(opencv_test_java_files ".*#.*")
-# These are the files that need to be updated for pure Java.
-ocv_list_filterout(opencv_test_java_files ".*OpenCVTestCase.*")
-ocv_list_filterout(opencv_test_java_files ".*OpenCVTestRunner.*")
-# These files aren't for desktop Java.
-ocv_list_filterout(opencv_test_java_files ".*android.*")
-
-# These are files updated for pure Java.
-file(GLOB_RECURSE modified_files RELATIVE "${java_source_dir}" "${java_source_dir}/src/*")
-ocv_list_filterout(modified_files ".svn")
-ocv_list_filterout(modified_files ".*#.*")
-
-# These are extra jars needed to run the tests.
-file(GLOB_RECURSE lib_files RELATIVE "${java_source_dir}" "${java_source_dir}/lib/*")
-ocv_list_filterout(lib_files ".svn")
-ocv_list_filterout(lib_files ".*#.*")
-
-# copy sources out from the build tree
-set(opencv_test_java_file_deps "")
-foreach(f ${opencv_test_java_files})
- add_custom_command(
- OUTPUT "${opencv_test_java_bin_dir}/${f}"
- COMMAND ${CMAKE_COMMAND} -E copy "${android_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}"
- MAIN_DEPENDENCY "${android_source_dir}/${f}"
- COMMENT "Copying ${f}")
- list(APPEND opencv_test_java_file_deps "${android_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}")
-endforeach()
-
-# Overwrite select Android sources with Java-specific sources.
-# Also, copy over the libs we'll need for testing.
-foreach(f ${modified_files} ${lib_files})
- add_custom_command(
- OUTPUT "${opencv_test_java_bin_dir}/${f}"
- COMMAND ${CMAKE_COMMAND} -E copy "${java_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}"
- MAIN_DEPENDENCY "${java_source_dir}/${f}"
- COMMENT "Copying ${f}")
- list(APPEND opencv_test_java_file_deps "${java_source_dir}/${f}")
-endforeach()
-
-# Copy the OpenCV jar after it has been generated.
-add_custom_command(
- OUTPUT "${opencv_test_java_bin_dir}/bin/${JAR_NAME}"
- COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/bin/${JAR_NAME}" "${opencv_test_java_bin_dir}/bin/${JAR_NAME}"
- COMMENT "Copying the OpenCV jar")
-add_custom_target(copy_opencv_jar ALL SOURCES "${opencv_test_java_bin_dir}/bin/${JAR_NAME}")
-# ${the_module} is the target for the Java jar.
-add_dependencies(copy_opencv_jar ${the_module})
-
-# Copy the ant build file.
-file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/build.xml" DESTINATION "${opencv_test_java_bin_dir}")
-
-# Create a script for running the Java tests and place it in build/bin.
-if(WIN32)
- file(WRITE "${CMAKE_BINARY_DIR}/bin/opencv_test_java.cmd" "cd ${opencv_test_java_bin_dir}\nset PATH=${EXECUTABLE_OUTPUT_PATH}/Release;%PATH%\nant -DjavaLibraryPath=${EXECUTABLE_OUTPUT_PATH}/Release buildAndTest")
- file(WRITE "${CMAKE_BINARY_DIR}/bin/opencv_test_java_D.cmd" "cd ${opencv_test_java_bin_dir}\nset PATH=${EXECUTABLE_OUTPUT_PATH}/Debug;%PATH%\nant -DjavaLibraryPath=${EXECUTABLE_OUTPUT_PATH}/Debug buildAndTest")
-else()
- file(WRITE "${CMAKE_BINARY_DIR}/bin/opencv_test_java.sh" "cd ${opencv_test_java_bin_dir};\nant -DjavaLibraryPath=${LIBRARY_OUTPUT_PATH} buildAndTest;\ncd -")
-endif()
-
-add_custom_target(${PROJECT_NAME} ALL SOURCES ${opencv_test_java_file_deps})
-add_dependencies(opencv_tests ${PROJECT_NAME})
diff --git a/modules/java/test/CMakeLists.txt b/modules/java/test/CMakeLists.txt
new file mode 100644
index 000000000..8f3021991
--- /dev/null
+++ b/modules/java/test/CMakeLists.txt
@@ -0,0 +1,77 @@
+ocv_check_dependencies(opencv_java ${OPENCV_MODULE_opencv_java_OPT_DEPS} ${OPENCV_MODULE_opencv_java_REQ_DEPS})
+
+if(NOT OCV_DEPENDENCIES_FOUND)
+ return()
+endif()
+
+project(opencv_test_java)
+
+set(opencv_test_java_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/.build")
+set(android_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../android_test")
+set(java_source_dir ${CMAKE_CURRENT_SOURCE_DIR})
+
+# get project sources
+file(GLOB_RECURSE opencv_test_java_files RELATIVE "${android_source_dir}" "${android_source_dir}/res/*" "${android_source_dir}/src/*.java")
+# These are the files that need to be updated for pure Java.
+ocv_list_filterout(opencv_test_java_files "OpenCVTest(Case|Runner).java")
+# These files aren't for desktop Java.
+ocv_list_filterout(opencv_test_java_files "/android/")
+
+# These are files updated for pure Java.
+file(GLOB_RECURSE modified_files RELATIVE "${java_source_dir}" "${java_source_dir}/src/*")
+
+# These are extra jars needed to run the tests.
+file(GLOB_RECURSE lib_files RELATIVE "${java_source_dir}" "${java_source_dir}/lib/*.jar")
+
+# copy sources out from the build tree
+set(opencv_test_java_file_deps "")
+foreach(f ${opencv_test_java_files})
+ add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/${f}"
+ COMMAND ${CMAKE_COMMAND} -E copy "${android_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}"
+ DEPENDS "${android_source_dir}/${f}"
+ COMMENT "Copying ${f}"
+ )
+ list(APPEND opencv_test_java_file_deps "${android_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}")
+endforeach()
+
+# Overwrite select Android sources with Java-specific sources.
+# Also, copy over the libs we'll need for testing.
+foreach(f ${modified_files} ${lib_files})
+ add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/${f}"
+ COMMAND ${CMAKE_COMMAND} -E copy "${java_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}"
+ DEPENDS "${java_source_dir}/${f}"
+ COMMENT "Copying ${f}"
+ )
+ list(APPEND opencv_test_java_file_deps "${java_source_dir}/${f}" "${opencv_test_java_bin_dir}/${f}")
+endforeach()
+
+# Copy the OpenCV jar after it has been generated.
+add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/bin/${JAR_NAME}"
+ COMMAND ${CMAKE_COMMAND} -E copy "${JAR_FILE}" "${opencv_test_java_bin_dir}/bin/${JAR_NAME}"
+ DEPENDS "${JAR_FILE}"
+ COMMENT "Copying the OpenCV jar"
+ )
+
+add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/build.xml"
+ COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/build.xml" "${opencv_test_java_bin_dir}/build.xml"
+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build.xml"
+ COMMENT "Copying build.xml"
+ )
+
+# Create a script for running the Java tests and place it in build/bin.
+#if(WIN32)
+ #file(WRITE "${CMAKE_BINARY_DIR}/bin/opencv_test_java.cmd" "cd ${opencv_test_java_bin_dir}\nset PATH=${EXECUTABLE_OUTPUT_PATH}/Release;%PATH%\nant -DjavaLibraryPath=${EXECUTABLE_OUTPUT_PATH}/Release buildAndTest")
+ #file(WRITE "${CMAKE_BINARY_DIR}/bin/opencv_test_java_D.cmd" "cd ${opencv_test_java_bin_dir}\nset PATH=${EXECUTABLE_OUTPUT_PATH}/Debug;%PATH%\nant -DjavaLibraryPath=${EXECUTABLE_OUTPUT_PATH}/Debug buildAndTest")
+#else()
+ #file(WRITE "${CMAKE_BINARY_DIR}/bin/opencv_test_java.sh" "cd ${opencv_test_java_bin_dir};\nant -DjavaLibraryPath=${LIBRARY_OUTPUT_PATH} buildAndTest;\ncd -")
+#endif()
+
+add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar"
+ COMMAND "${ANT_EXECUTABLE}" build
+ WORKING_DIRECTORY "${opencv_test_java_bin_dir}"
+ 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}"
+ COMMENT "Build Java tests"
+ )
+
+add_custom_target(${PROJECT_NAME} ALL SOURCES "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar")
+add_dependencies(${PROJECT_NAME} ${the_module})
diff --git a/modules/java/java_test/build.xml b/modules/java/test/build.xml
similarity index 62%
rename from modules/java/java_test/build.xml
rename to modules/java/test/build.xml
index 49d2bf11a..d91118f0a 100644
--- a/modules/java/java_test/build.xml
+++ b/modules/java/test/build.xml
@@ -16,7 +16,7 @@
-
+
@@ -26,30 +26,36 @@
-
+
-
+
+
-
+
-
-
-
+
+
+
+
+
+
+
+
diff --git a/modules/java/java_test/lib/junit-4.11.jar b/modules/java/test/lib/junit-4.11.jar
similarity index 100%
rename from modules/java/java_test/lib/junit-4.11.jar
rename to modules/java/test/lib/junit-4.11.jar
diff --git a/modules/java/java_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/test/src/org/opencv/test/OpenCVTestCase.java
similarity index 94%
rename from modules/java/java_test/src/org/opencv/test/OpenCVTestCase.java
rename to modules/java/test/src/org/opencv/test/OpenCVTestCase.java
index 15ff735f8..ac1bf863c 100644
--- a/modules/java/java_test/src/org/opencv/test/OpenCVTestCase.java
+++ b/modules/java/test/src/org/opencv/test/OpenCVTestCase.java
@@ -96,31 +96,33 @@ public class OpenCVTestCase extends TestCase {
protected void setUp() throws Exception {
super.setUp();
- try {
- System.loadLibrary("opencv_java");
- } catch (SecurityException e) {
- System.out.println(e.toString());
- System.exit(-1);
- } catch (UnsatisfiedLinkError e) {
- System.out.println(e.toString());
- System.exit(-1);
- }
+ try {
+ System.loadLibrary("opencv_java");
+ } catch (SecurityException e) {
+ System.out.println(e.toString());
+ System.exit(-1);
+ } catch (UnsatisfiedLinkError e) {
+ System.out.println(e.toString());
+ System.exit(-1);
+ }
- String pwd;
- try {
- pwd = new File(".").getCanonicalPath() + File.separator;
- } catch (IOException e) {
- System.out.println(e);
- return;
- }
+ Core.setErrorVerbosity(false);
- OpenCVTestRunner.LENA_PATH = pwd + "res/drawable/lena.jpg";
- OpenCVTestRunner.CHESS_PATH = pwd + "res/drawable/chessboard.jpg";
- OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH = pwd + "res/raw/lbpcascade_frontalface.xml";
+ String pwd;
+ try {
+ pwd = new File(".").getCanonicalPath() + File.separator;
+ } catch (IOException e) {
+ System.out.println(e);
+ return;
+ }
- assert(new File(OpenCVTestRunner.LENA_PATH).exists());
- assert(new File(OpenCVTestRunner.CHESS_PATH).exists());
- assert(new File(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH).exists());
+ OpenCVTestRunner.LENA_PATH = pwd + "res/drawable/lena.jpg";
+ OpenCVTestRunner.CHESS_PATH = pwd + "res/drawable/chessboard.jpg";
+ OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH = pwd + "res/raw/lbpcascade_frontalface.xml";
+
+ assert(new File(OpenCVTestRunner.LENA_PATH).exists());
+ assert(new File(OpenCVTestRunner.CHESS_PATH).exists());
+ assert(new File(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH).exists());
dst = new Mat();
assertTrue(dst.empty());
diff --git a/modules/java/java_test/src/org/opencv/test/OpenCVTestRunner.java b/modules/java/test/src/org/opencv/test/OpenCVTestRunner.java
similarity index 96%
rename from modules/java/java_test/src/org/opencv/test/OpenCVTestRunner.java
rename to modules/java/test/src/org/opencv/test/OpenCVTestRunner.java
index 4d05304a1..455f9533e 100644
--- a/modules/java/java_test/src/org/opencv/test/OpenCVTestRunner.java
+++ b/modules/java/test/src/org/opencv/test/OpenCVTestRunner.java
@@ -39,6 +39,6 @@ public class OpenCVTestRunner {
public static String getOutputFileName(String name)
{
- return getTempFileName(name);
+ return getTempFileName(name);
}
}
diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt
index 8d4a0ca1a..9db2c8aae 100644
--- a/modules/python/CMakeLists.txt
+++ b/modules/python/CMakeLists.txt
@@ -80,6 +80,10 @@ set_target_properties(${the_module} PROPERTIES
OUTPUT_NAME cv2
SUFFIX ${CVPY_SUFFIX})
+if(ENABLE_SOLUTION_FOLDERS)
+ set_target_properties(${the_module} PROPERTIES FOLDER "bindings")
+endif()
+
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
endif()
diff --git a/modules/ts/misc/run.py b/modules/ts/misc/run.py
index d6e61d327..435171371 100755
--- a/modules/ts/misc/run.py
+++ b/modules/ts/misc/run.py
@@ -69,6 +69,8 @@ parse_patterns = (
{'name': "ndk_path", 'default': None, 'pattern': re.compile("^(?:ANDROID_NDK|ANDROID_STANDALONE_TOOLCHAIN)?:PATH=(.*)$")},
{'name': "android_abi", 'default': None, 'pattern': re.compile("^ANDROID_ABI:STRING=(.*)$")},
{'name': "android_executable", 'default': None, 'pattern': re.compile("^ANDROID_EXECUTABLE:FILEPATH=(.*android.*)$")},
+ {'name': "ant_executable", 'default': None, 'pattern': re.compile("^ANT_EXECUTABLE:FILEPATH=(.*ant.*)$")},
+ {'name': "java_test_binary_dir", 'default': None, 'pattern': re.compile("^opencv_test_java_BINARY_DIR:STATIC=(.*)$")},
{'name': "is_x64", 'default': "OFF", 'pattern': re.compile("^CUDA_64_BIT_DEVICE_CODE:BOOL=(ON)$")},#ugly(
{'name': "cmake_generator", 'default': None, 'pattern': re.compile("^CMAKE_GENERATOR:INTERNAL=(.+)$")},
{'name': "cxx_compiler", 'default': None, 'pattern': re.compile("^CMAKE_CXX_COMPILER:FILEPATH=(.+)$")},
@@ -431,6 +433,8 @@ class TestSuite(object):
if self.tests_dir and os.path.isdir(self.tests_dir):
files = glob.glob(os.path.join(self.tests_dir, self.nameprefix + "*"))
files = [f for f in files if self.isTest(f)]
+ if self.ant_executable and self.java_test_binary_dir:
+ files.append("java")
return files
return []
@@ -740,6 +744,16 @@ class TestSuite(object):
if os.path.isfile(hostlogpath):
return hostlogpath
return None
+ elif path == "java":
+ cmd = [self.ant_executable, "-DjavaLibraryPath=" + self.tests_dir, "buildAndTest"]
+
+ print >> _stderr, "Run command:", " ".join(cmd)
+ try:
+ Popen(cmd, stdout=_stdout, stderr=_stderr, cwd = self.java_test_binary_dir + "/.build").wait()
+ except OSError:
+ pass
+
+ return None
else:
cmd = [exe]
if self.options.help: