mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 14:13:15 +08:00
Hardly refactored CMake script for Java wrappers
This commit is contained in:
parent
c92743d124
commit
46c4390a2e
@ -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
|
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}"
|
WORKING_DIRECTORY "${android_proj_bin_dir}"
|
||||||
MAIN_DEPENDENCY "${android_proj_bin_dir}/${ANDROID_MANIFEST_FILE}"
|
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})
|
DEPENDS ${android_proj_file_deps} ${JNI_LIB_NAME})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# CMake file for java support
|
# 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)
|
ocv_module_disable(java)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -18,6 +18,10 @@ if(NOT ANDROID)
|
|||||||
include_directories(${JNI_INCLUDE_DIRS})
|
include_directories(${JNI_INCLUDE_DIRS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# output locations
|
||||||
|
set(JAVA_INSTALL_ROOT "sdk/java")
|
||||||
|
set(JNI_INSTALL_ROOT "sdk/native")
|
||||||
|
|
||||||
# get list of modules to wrap
|
# get list of modules to wrap
|
||||||
string(REPLACE "opencv_" "" OPENCV_JAVA_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS};${OPENCV_MODULE_${the_module}_OPT_DEPS}")
|
string(REPLACE "opencv_" "" OPENCV_JAVA_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS};${OPENCV_MODULE_${the_module}_OPT_DEPS}")
|
||||||
foreach(module ${OPENCV_JAVA_MODULES})
|
foreach(module ${OPENCV_JAVA_MODULES})
|
||||||
@ -26,20 +30,29 @@ foreach(module ${OPENCV_JAVA_MODULES})
|
|||||||
endif()
|
endif()
|
||||||
endforeach()
|
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)
|
# scripts
|
||||||
configure_file("${GEN_JAVA}" "${OpenCV_BINARY_DIR}/junk/gen_java.junk" COPYONLY)
|
set(scripts_gen_java "${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_java.py")
|
||||||
configure_file("${HDR_PARSER}" "${OpenCV_BINARY_DIR}/junk/hdr_parser.junk" COPYONLY)
|
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 "")
|
# handwritten C/C++ and Java sources
|
||||||
set(generated_cpp_sources "")
|
file(GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.hpp")
|
||||||
set(generated_java_sources "")
|
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})
|
foreach(module ${OPENCV_JAVA_MODULES})
|
||||||
# get list of module headers
|
# get list of module headers
|
||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/generator/config/${module}.filelist")
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/generator/config/${module}.filelist")
|
||||||
@ -48,7 +61,7 @@ foreach(module ${OPENCV_JAVA_MODULES})
|
|||||||
else()
|
else()
|
||||||
set(module_headers "${OPENCV_MODULE_opencv_${module}_HEADERS}")
|
set(module_headers "${OPENCV_MODULE_opencv_${module}_HEADERS}")
|
||||||
endif()
|
endif()
|
||||||
|
if(module_headers)
|
||||||
# C headers must go first
|
# C headers must go first
|
||||||
set(module_headers_cpp ${module_headers})
|
set(module_headers_cpp ${module_headers})
|
||||||
ocv_list_filterout(module_headers_cpp "\\\\.h$")
|
ocv_list_filterout(module_headers_cpp "\\\\.h$")
|
||||||
@ -58,103 +71,203 @@ foreach(module ${OPENCV_JAVA_MODULES})
|
|||||||
endif()
|
endif()
|
||||||
unset(module_headers_cpp)
|
unset(module_headers_cpp)
|
||||||
|
|
||||||
# add dependencies to cmake (we should rerun cmake if any of these headers is modified)
|
set(opencv_public_headers_${module} ${module_headers})
|
||||||
foreach(header ${module_headers})
|
list(APPEND opencv_public_headers ${module_headers})
|
||||||
get_filename_component(header_name "${header}" NAME_WE)
|
else()
|
||||||
|
list(REMOVE_ITEM OPENCV_JAVA_MODULES ${module})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
# generated cpp files
|
||||||
|
set(generated_cpp_sources "")
|
||||||
|
foreach(module ${OPENCV_JAVA_MODULES})
|
||||||
|
list(APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# 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)
|
configure_file("${header}" "${OpenCV_BINARY_DIR}/junk/${header_name}.junk" COPYONLY)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# first run (to get list of generated files)
|
# generated java files
|
||||||
if(module_headers)
|
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(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/")
|
||||||
file(MAKE_DIRECTORY "${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}
|
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"
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out"
|
||||||
OUTPUT_QUIET ERROR_QUIET)
|
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")
|
unset(generated_java_sources_${module})
|
||||||
ocv_list_add_prefix(${module}_generated_java_sources "${CMAKE_CURRENT_BINARY_DIR}/")
|
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}/")
|
||||||
|
|
||||||
# second run (at build time)
|
list(APPEND generated_java_sources ${generated_java_sources_${module}})
|
||||||
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})
|
|
||||||
endif()
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# get handwritten files used for wrappers generation
|
# generated java files with javadoc
|
||||||
file(GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.hpp")
|
set(documented_java_files "")
|
||||||
file(GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.cpp")
|
foreach(java_file ${generated_java_sources} ${handwrittren_java_sources})
|
||||||
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()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# create list of javadoc documented files
|
|
||||||
unset(documented_java_files)
|
|
||||||
foreach(java_file ${handwrittren_java_sources} ${generated_java_sources})
|
|
||||||
get_filename_component(java_file_name "${java_file}" NAME_WE)
|
get_filename_component(java_file_name "${java_file}" NAME_WE)
|
||||||
list(APPEND documented_java_files "${CMAKE_CURRENT_BINARY_DIR}/${java_file_name}-jdoc.java")
|
list(APPEND documented_java_files "${CMAKE_CURRENT_BINARY_DIR}/${java_file_name}-jdoc.java")
|
||||||
endforeach()
|
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}")
|
|
||||||
|
|
||||||
string(REPLACE ";" "," OPENCV_JAVA_MODULES_STR "${OPENCV_JAVA_MODULES}")
|
# step 1: generate .cpp/.java from OpenCV headers
|
||||||
add_custom_command(
|
set(step1_depends "${scripts_gen_java}" "${scripts_hdr_parser}" ${opencv_public_headers})
|
||||||
OUTPUT ${documented_java_files}
|
foreach(module ${OPENCV_JAVA_MODULES})
|
||||||
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"
|
# 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}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
DEPENDS ${java_documented_headers_deps}
|
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} "${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
|
# step 3: copy files to destination
|
||||||
set(JAVA_OUTPUT_DIR "src/org/opencv")
|
set(step3_input_files ${documented_java_files} ${handwrittren_aidl_sources})
|
||||||
set(JAVA_INSTALL_ROOT "sdk/java")
|
set(copied_files "")
|
||||||
set(JNI_INSTALL_ROOT "sdk/native")
|
foreach(java_file ${step3_input_files})
|
||||||
|
|
||||||
# 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})
|
|
||||||
get_filename_component(java_file_name "${java_file}" NAME)
|
get_filename_component(java_file_name "${java_file}" NAME)
|
||||||
string(REPLACE "-jdoc.java" ".java" 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}")
|
string(REPLACE "+" "/" java_file_name "${java_file_name}")
|
||||||
|
set(output_name "${OpenCV_BINARY_DIR}/src/org/opencv/${java_file_name}")
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(OUTPUT "${output_name}"
|
||||||
OUTPUT "${OpenCV_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}"
|
COMMAND ${CMAKE_COMMAND} -E copy "${java_file}" "${output_name}"
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy "${java_file}" "${OpenCV_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}"
|
|
||||||
MAIN_DEPENDENCY "${java_file}"
|
MAIN_DEPENDENCY "${java_file}"
|
||||||
DEPENDS ${java_documented_headers_deps}
|
DEPENDS ${step2_depends}
|
||||||
COMMENT "Generating ${JAVA_OUTPUT_DIR}/${java_file_name}"
|
COMMENT "Generating src/org/opencv/${java_file_name}"
|
||||||
)
|
)
|
||||||
list(APPEND java_files "${OpenCV_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}")
|
list(APPEND copied_files "${output_name}")
|
||||||
|
|
||||||
if(ANDROID)
|
if(ANDROID)
|
||||||
get_filename_component(install_subdir "${java_file_name}" PATH)
|
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()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# add opencv_java library
|
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}")
|
||||||
|
|
||||||
|
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}
|
add_library(${the_module} SHARED ${handwrittren_h_sources} ${handwrittren_cpp_sources} ${generated_cpp_sources}
|
||||||
${java_files} ${documented_java_files} ${java_documented_headers_deps})
|
${copied_files}
|
||||||
|
"${JAR_FILE}" "${JAR_FILE}.dephelper")
|
||||||
if(BUILD_FAT_JAVA_LIB)
|
if(BUILD_FAT_JAVA_LIB)
|
||||||
set(__deps ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULES_BUILD})
|
set(__deps ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULES_BUILD})
|
||||||
list(REMOVE_ITEM __deps ${the_module} opencv_ts)
|
list(REMOVE_ITEM __deps ${the_module} opencv_ts)
|
||||||
@ -169,20 +282,6 @@ else()
|
|||||||
target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
|
target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# 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)
|
if(ANDROID)
|
||||||
target_link_libraries(${the_module} jnigraphics) # for Mat <=> Bitmap converters
|
target_link_libraries(${the_module} jnigraphics) # for Mat <=> Bitmap converters
|
||||||
|
|
||||||
@ -193,104 +292,31 @@ if(ANDROID)
|
|||||||
if ( NOT (CMAKE_BUILD_TYPE MATCHES "Debug"))
|
if ( NOT (CMAKE_BUILD_TYPE MATCHES "Debug"))
|
||||||
add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${__opencv_java_location}")
|
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()
|
endif()
|
||||||
|
|
||||||
add_custom_target(${lib_target} SOURCES ${lib_proj_files} ${lib_target_files} "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}")
|
# Additional target properties
|
||||||
endif()
|
set_target_properties(${the_module} PROPERTIES
|
||||||
else(ANDROID)
|
OUTPUT_NAME "${the_module}"
|
||||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/jar/build.xml" "${OpenCV_BINARY_DIR}/build.xml" IMMEDIATE @ONLY)
|
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
|
||||||
set(JAR_NAME opencv-${OPENCV_VERSION}.jar)
|
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
|
||||||
|
INSTALL_NAME_DIR ${OPENCV_LIB_INSTALL_PATH}
|
||||||
add_custom_command(
|
LINK_INTERFACE_LIBRARIES ""
|
||||||
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} ${documented_java_files} ${java_documented_headers_deps}
|
|
||||||
COMMENT "Generating ${JAR_NAME}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(${lib_target} SOURCES "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}")
|
if(ENABLE_SOLUTION_FOLDERS)
|
||||||
endif(ANDROID)
|
set_target_properties(${the_module} PROPERTIES FOLDER "bindings")
|
||||||
|
endif()
|
||||||
|
|
||||||
add_dependencies(${the_module} ${lib_target})
|
install(TARGETS ${the_module}
|
||||||
|
LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
|
||||||
|
ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main)
|
||||||
|
|
||||||
# android test project
|
######################################################################################################################################
|
||||||
if(ANDROID AND BUILD_TESTS)
|
|
||||||
|
if(BUILD_TESTS)
|
||||||
|
if(ANDROID)
|
||||||
add_subdirectory(android_test)
|
add_subdirectory(android_test)
|
||||||
|
else()
|
||||||
|
add_subdirectory(test)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Desktop Java test project.
|
|
||||||
if((NOT ANDROID) AND BUILD_TESTS)
|
|
||||||
add_subdirectory(java_test)
|
|
||||||
endif()
|
endif()
|
||||||
|
@ -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
|
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}"
|
WORKING_DIRECTORY "${opencv_test_java_bin_dir}"
|
||||||
MAIN_DEPENDENCY "${opencv_test_java_bin_dir}/${ANDROID_MANIFEST_FILE}"
|
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})
|
DEPENDS ${opencv_test_java_file_deps})
|
||||||
|
|
||||||
add_custom_target(${PROJECT_NAME} ALL SOURCES "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" )
|
add_custom_target(${PROJECT_NAME} ALL SOURCES "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" )
|
||||||
|
@ -10,6 +10,6 @@
|
|||||||
<include name="**/*.java"/>
|
<include name="**/*.java"/>
|
||||||
</javac>
|
</javac>
|
||||||
|
|
||||||
<jar basedir="src" destfile="bin/opencv-@OPENCV_VERSION@.jar"/>
|
<jar basedir="src" destfile="bin/@JAR_NAME@"/>
|
||||||
</target>
|
</target>
|
||||||
</project>
|
</project>
|
@ -80,6 +80,10 @@ set_target_properties(${the_module} PROPERTIES
|
|||||||
OUTPUT_NAME cv2
|
OUTPUT_NAME cv2
|
||||||
SUFFIX ${CVPY_SUFFIX})
|
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)
|
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
|
||||||
endif()
|
endif()
|
||||||
|
Loading…
Reference in New Issue
Block a user