2011-06-23 23:51:51 +08:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# CMake file for java support
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
project(opencv_java)
|
2011-07-25 04:44:20 +08:00
|
|
|
set(target opencv_java)
|
|
|
|
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp")
|
|
|
|
|
2011-06-23 23:51:51 +08:00
|
|
|
|
2011-07-11 16:33:12 +08:00
|
|
|
SET(OPENCV_JAVA_MODULES objdetect features2d imgproc video highgui ml core calib3d)
|
|
|
|
SET(OPENCV_EXTRA_JAVA_MODULES contrib legacy flann)
|
2011-07-04 19:41:39 +08:00
|
|
|
IF(WITH_ANDROID_CAMERA AND NOT BUILD_SHARED_LIBS)
|
2011-06-23 23:51:51 +08:00
|
|
|
LIST(APPEND OPENCV_EXTRA_JAVA_MODULES androidcamera)
|
|
|
|
ENDIF()
|
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
|
2011-06-23 23:51:51 +08:00
|
|
|
SET(GEN_JAVA "${CMAKE_CURRENT_SOURCE_DIR}/gen_java.py")
|
|
|
|
SET(HDR_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/../python/src2/hdr_parser.py")
|
2011-07-08 23:29:59 +08:00
|
|
|
SET(GEN_JAVADOC "${CMAKE_CURRENT_SOURCE_DIR}/gen_javadoc.py")
|
|
|
|
SET(RST_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/rst_parser.py")
|
2011-07-26 16:17:52 +08:00
|
|
|
SET(CHECK_TEST_COVERAGE "${CMAKE_CURRENT_SOURCE_DIR}/check-tests.py")
|
2011-06-23 23:51:51 +08:00
|
|
|
|
2011-07-22 21:10:50 +08:00
|
|
|
# setup raw java and cpp files generation (without javadoc and at temporary location)
|
2011-06-23 23:51:51 +08:00
|
|
|
foreach(module ${OPENCV_JAVA_MODULES})
|
2011-07-25 04:44:20 +08:00
|
|
|
# get list of module headers
|
2011-06-24 16:13:02 +08:00
|
|
|
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist")
|
|
|
|
FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist" headers_to_parse)
|
2011-06-23 23:51:51 +08:00
|
|
|
SET (module_cheaders "")
|
2011-06-24 16:13:02 +08:00
|
|
|
SET (module_cppheaders "")
|
|
|
|
foreach(header ${headers_to_parse})
|
|
|
|
list(APPEND module_cppheaders "${CMAKE_CURRENT_SOURCE_DIR}/../${module}/${header}")
|
|
|
|
endforeach()
|
2011-06-23 23:51:51 +08:00
|
|
|
ELSE()
|
|
|
|
FILE(GLOB module_cheaders "${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include/opencv2/${module}/*.h")
|
|
|
|
FILE(GLOB module_cppheaders "${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include/opencv2/${module}/*.hpp")
|
2011-06-24 16:13:02 +08:00
|
|
|
list(SORT module_cheaders)
|
|
|
|
list(SORT module_cppheaders)
|
2011-06-23 23:51:51 +08:00
|
|
|
ENDIF()
|
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
# add dependencies to cmake (we should rerun cmake if any of these headers are modified)
|
2011-07-22 21:10:50 +08:00
|
|
|
foreach(header ${module_cheaders} ${module_cppheaders})
|
|
|
|
get_filename_component(header_name "${header}" NAME_WE)
|
|
|
|
configure_file("${header}" "${CMAKE_BINARY_DIR}/junk/${header_name}.junk" COPYONLY)
|
|
|
|
endforeach()
|
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
# the same about gen_java.py and hdr_parser.py
|
|
|
|
configure_file("${GEN_JAVA}" "${CMAKE_BINARY_DIR}/junk/gen_java.junk" COPYONLY)
|
|
|
|
configure_file("${HDR_PARSER}" "${CMAKE_BINARY_DIR}/junk/hdr_parser.junk" COPYONLY)
|
|
|
|
|
|
|
|
|
|
|
|
# first run (to get list of generated files)
|
|
|
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out")
|
|
|
|
|
|
|
|
execute_process(COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVA}" "${HDR_PARSER}" ${module} ${module_cheaders} ${module_cppheaders}
|
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out"
|
|
|
|
OUTPUT_QUIET ERROR_QUIET)
|
|
|
|
|
|
|
|
# create list of generated files
|
|
|
|
file(GLOB_RECURSE generated_java_sources RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/" "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/*.java")
|
|
|
|
file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out/")
|
|
|
|
|
|
|
|
set(${module}_generated_java_sources)
|
|
|
|
foreach(f ${generated_java_sources})
|
|
|
|
list(APPEND ${module}_generated_java_sources "${CMAKE_CURRENT_BINARY_DIR}/${f}")
|
|
|
|
endforeach()
|
2011-07-19 23:37:17 +08:00
|
|
|
|
2011-07-22 21:10:50 +08:00
|
|
|
# second run
|
2011-06-23 23:51:51 +08:00
|
|
|
add_custom_command(
|
2011-07-19 23:37:17 +08:00
|
|
|
OUTPUT ${${module}_generated_java_sources}
|
2011-06-24 15:48:04 +08:00
|
|
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp"
|
2011-06-27 16:24:10 +08:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVA}" "${HDR_PARSER}" ${module} ${module_cheaders} ${module_cppheaders}
|
2011-06-23 23:51:51 +08:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
2011-06-24 15:48:04 +08:00
|
|
|
DEPENDS "${GEN_JAVA}"
|
|
|
|
DEPENDS "${HDR_PARSER}"
|
2011-07-25 04:44:20 +08:00
|
|
|
DEPENDS ${module_cheaders}
|
|
|
|
DEPENDS ${module_cppheaders}
|
2011-06-23 23:51:51 +08:00
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
FILE(GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp")
|
|
|
|
FILE(GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.h*")
|
|
|
|
FILE(GLOB handwrittren_java_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/java/*.java")
|
|
|
|
SET (generated_cpp_sources)
|
|
|
|
SET (generated_java_sources)
|
|
|
|
SET (documented_java_files)
|
|
|
|
SET (undocumented_java_files)
|
|
|
|
SET (dependent_libs)
|
|
|
|
SET (dependent_extra_libs)
|
2011-06-23 23:51:51 +08:00
|
|
|
|
|
|
|
foreach(module ${OPENCV_JAVA_MODULES})
|
|
|
|
LIST(APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp")
|
2011-07-19 23:37:17 +08:00
|
|
|
LIST(APPEND generated_java_sources ${${module}_generated_java_sources})
|
2011-06-23 23:51:51 +08:00
|
|
|
LIST(APPEND dependent_libs opencv_${module})
|
|
|
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include")
|
|
|
|
endforeach()
|
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
# extra includes and dependencies
|
2011-06-23 23:51:51 +08:00
|
|
|
foreach(module ${OPENCV_EXTRA_JAVA_MODULES})
|
|
|
|
LIST(APPEND dependent_extra_libs opencv_${module})
|
|
|
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include")
|
|
|
|
endforeach()
|
|
|
|
|
2011-07-22 21:10:50 +08:00
|
|
|
# created list of documented files targets
|
|
|
|
foreach(java_file ${handwrittren_java_sources} ${generated_java_sources})
|
|
|
|
get_filename_component(java_file_name "${java_file}" NAME_WE)
|
|
|
|
if (NOT java_file_name MATCHES ".*-jdoc$")
|
|
|
|
list(APPEND documented_java_files "${CMAKE_CURRENT_BINARY_DIR}/${java_file_name}-jdoc.java")
|
|
|
|
list(APPEND undocumented_java_files "${java_file}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# generate javadoc files
|
2011-07-25 04:44:20 +08:00
|
|
|
file(GLOB_RECURSE refman_rst_headers "${CMAKE_CURRENT_SOURCE_DIR}/../*.rst")
|
2011-07-22 21:10:50 +08:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${documented_java_files}
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVADOC}" "${CMAKE_CURRENT_SOURCE_DIR}/src/java" "${CMAKE_CURRENT_BINARY_DIR}" 2>"${CMAKE_CURRENT_BINARY_DIR}/get_javadoc_errors.log"
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
DEPENDS ${undocumented_java_files}
|
|
|
|
DEPENDS "${GEN_JAVADOC}"
|
|
|
|
DEPENDS "${RST_PARSER}"
|
2011-07-25 04:44:20 +08:00
|
|
|
DEPENDS ${refman_rst_headers}
|
2011-07-22 21:10:50 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
# copy generated java files to the final location
|
2011-07-25 04:44:20 +08:00
|
|
|
SET(JAVA_OUTPUT_DIR "src/org/opencv")
|
2011-07-22 21:10:50 +08:00
|
|
|
|
|
|
|
set(java_files)
|
|
|
|
foreach(java_file ${documented_java_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}")
|
2011-06-23 23:51:51 +08:00
|
|
|
|
2011-07-22 21:10:50 +08:00
|
|
|
add_custom_command(
|
2011-07-25 04:44:20 +08:00
|
|
|
OUTPUT "${CMAKE_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${java_file}" "${CMAKE_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}"
|
2011-07-22 21:10:50 +08:00
|
|
|
DEPENDS "${java_file}"
|
2011-07-25 04:44:20 +08:00
|
|
|
COMMENT "Generating ${JAVA_OUTPUT_DIR}/${java_file_name}"
|
2011-07-22 21:10:50 +08:00
|
|
|
)
|
2011-07-25 04:44:20 +08:00
|
|
|
list(APPEND java_files "${CMAKE_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}")
|
|
|
|
|
2011-07-22 21:10:50 +08:00
|
|
|
if(ANDROID)
|
2011-07-25 04:44:20 +08:00
|
|
|
get_filename_component(install_subdir "${java_file_name}" PATH)
|
|
|
|
install(FILES "${CMAKE_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}" DESTINATION ${JAVA_OUTPUT_DIR}/${install_subdir} COMPONENT main)
|
2011-07-22 21:10:50 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
# custom target for java API
|
|
|
|
set(api_target ${target}_api)
|
|
|
|
ADD_CUSTOM_TARGET(${api_target} DEPENDS ${java_files})
|
|
|
|
|
2011-07-22 21:10:50 +08:00
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
# add opencv_java library
|
|
|
|
add_library(${target} SHARED ${handwrittren_h_sources} ${handwrittren_cpp_sources} ${generated_cpp_sources})
|
2011-06-23 23:51:51 +08:00
|
|
|
target_link_libraries(${target} ${dependent_libs} ${dependent_extra_libs} ${OPENCV_LINKER_LIBS})
|
2011-07-25 04:44:20 +08:00
|
|
|
add_dependencies(${target} ${dependent_extra_libs} ${dependent_libs} ${api_target})
|
2011-07-04 16:18:02 +08:00
|
|
|
|
2011-07-22 21:10:50 +08:00
|
|
|
# Additional target properties
|
|
|
|
set_target_properties(${target} PROPERTIES
|
|
|
|
OUTPUT_NAME "${target}"
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
|
|
|
|
INSTALL_NAME_DIR ${OPENCV_LIB_INSTALL_PATH}
|
|
|
|
)
|
|
|
|
|
|
|
|
install(TARGETS ${target} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main)
|
|
|
|
|
2011-06-23 23:51:51 +08:00
|
|
|
if(ANDROID)
|
|
|
|
target_link_libraries(${target} jnigraphics)
|
2011-07-04 16:18:02 +08:00
|
|
|
|
2011-07-08 23:29:59 +08:00
|
|
|
# force strip library after build command
|
2011-07-04 16:18:02 +08:00
|
|
|
# because samples and tests will make a copy of library before install
|
|
|
|
ADD_CUSTOM_COMMAND(
|
|
|
|
TARGET ${target}
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${CMAKE_STRIP} "${LIBRARY_OUTPUT_PATH}/lib${target}.so"
|
|
|
|
)
|
2011-07-22 21:10:50 +08:00
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
set(lib_proj_files)
|
2011-07-22 21:10:50 +08:00
|
|
|
# library project blank
|
|
|
|
file(GLOB_RECURSE android_lib_project_files "${CMAKE_CURRENT_SOURCE_DIR}/android/*")
|
|
|
|
foreach(file ${android_lib_project_files})
|
|
|
|
if(NOT file MATCHES "\\.svn")
|
|
|
|
file(RELATIVE_PATH file_rel "${CMAKE_CURRENT_SOURCE_DIR}/android/" "${file}")
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${CMAKE_BINARY_DIR}/${file_rel}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${file}" "${CMAKE_BINARY_DIR}/${file_rel}"
|
|
|
|
DEPENDS "${file}"
|
|
|
|
COMMENT "Generating ${file_rel}"
|
|
|
|
)
|
2011-07-25 04:44:20 +08:00
|
|
|
|
|
|
|
list(APPEND lib_proj_files "${CMAKE_BINARY_DIR}/${file_rel}")
|
2011-07-22 22:11:16 +08:00
|
|
|
|
|
|
|
if(NOT file_rel MATCHES "jni/.+")
|
|
|
|
install(FILES "${CMAKE_BINARY_DIR}/${file_rel}" DESTINATION . COMPONENT main)
|
|
|
|
endif()
|
2011-07-22 21:10:50 +08:00
|
|
|
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 "${CMAKE_BINARY_DIR}/jni/${jni_file_name}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${jni_file}" "${CMAKE_BINARY_DIR}/jni/${jni_file_name}"
|
2011-07-22 21:34:25 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_BINARY_DIR}/jni/${jni_file_name}"
|
2011-07-22 21:10:50 +08:00
|
|
|
DEPENDS "${jni_file}"
|
|
|
|
COMMENT "Generating jni/${jni_file_name}"
|
|
|
|
)
|
2011-07-25 04:44:20 +08:00
|
|
|
list(APPEND lib_proj_files "${CMAKE_BINARY_DIR}/jni/${jni_file_name}")
|
|
|
|
endforeach()
|
2011-07-04 14:33:10 +08:00
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
# create Android library project in build folder
|
|
|
|
set(lib_target ${target}_android_library)
|
|
|
|
ADD_CUSTOM_TARGET(${lib_target}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/res"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/gen"
|
|
|
|
DEPENDS ${lib_proj_files}
|
2011-06-30 22:35:35 +08:00
|
|
|
)
|
2011-07-25 15:47:18 +08:00
|
|
|
add_dependencies(${lib_target} ${api_target})
|
2011-07-25 04:44:20 +08:00
|
|
|
add_dependencies(${target} ${lib_target})
|
2011-06-30 22:35:35 +08:00
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
endif(ANDROID)
|
2011-06-30 22:35:35 +08:00
|
|
|
|
2011-07-25 04:44:20 +08:00
|
|
|
#android test project
|
|
|
|
if(BUILD_TESTS)
|
|
|
|
add_android_project(opencv_test_java "${CMAKE_CURRENT_SOURCE_DIR}/android_test")
|
2011-07-26 16:17:52 +08:00
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
TARGET opencv_test_java_android_project POST_BUILD
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CHECK_TEST_COVERAGE} "${CMAKE_CURRENT_SOURCE_DIR}/android_test/src" "${CMAKE_BINARY_DIR}/src" > "${CMAKE_CURRENT_BINARY_DIR}/tests_coverage.log"
|
|
|
|
)
|
2011-07-25 04:44:20 +08:00
|
|
|
endif()
|