2011-06-23 23:51:51 +08:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# CMake file for java support
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
project(opencv_java)
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
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-06-23 23:51:51 +08:00
|
|
|
|
2011-06-30 21:37:56 +08:00
|
|
|
SET(additional_clean_files "")
|
|
|
|
|
2011-06-23 23:51:51 +08:00
|
|
|
foreach(module ${OPENCV_JAVA_MODULES})
|
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()
|
|
|
|
|
|
|
|
add_custom_command(
|
2011-06-24 15:48:04 +08:00
|
|
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${module}.java"
|
|
|
|
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-06-23 23:51:51 +08:00
|
|
|
DEPENDS ${module_headers}
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
2011-06-24 23:40:27 +08:00
|
|
|
set(target opencv_java)
|
2011-06-23 23:51:51 +08:00
|
|
|
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
|
|
|
|
SET (generated_cpp_sources "")
|
|
|
|
SET (generated_java_sources "")
|
|
|
|
SET (dependent_libs "")
|
|
|
|
SET (dependent_extra_libs "")
|
|
|
|
|
|
|
|
foreach(module ${OPENCV_JAVA_MODULES})
|
|
|
|
LIST(APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp")
|
|
|
|
LIST(APPEND generated_java_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.java")
|
|
|
|
LIST(APPEND dependent_libs opencv_${module})
|
|
|
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
foreach(module ${OPENCV_EXTRA_JAVA_MODULES})
|
|
|
|
LIST(APPEND dependent_extra_libs opencv_${module})
|
|
|
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include")
|
|
|
|
endforeach()
|
|
|
|
|
2011-06-24 23:40:27 +08:00
|
|
|
FILE(GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp")
|
2011-06-23 23:51:51 +08:00
|
|
|
|
|
|
|
add_library(${target} SHARED ${handwrittren_cpp_sources} ${generated_cpp_sources})
|
|
|
|
target_link_libraries(${target} ${dependent_libs} ${dependent_extra_libs} ${OPENCV_LINKER_LIBS})
|
2011-07-08 23:29:59 +08:00
|
|
|
add_dependencies(${target} "${GEN_JAVA}" "${HDR_PARSER}")
|
|
|
|
add_dependencies(${target} ${dependent_extra_libs} ${dependent_libs})
|
2011-07-04 16:18:02 +08:00
|
|
|
|
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-06-23 23:51:51 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Additional target properties
|
|
|
|
set_target_properties(${target} PROPERTIES
|
|
|
|
OUTPUT_NAME "${target}"
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
|
2011-06-27 21:59:03 +08:00
|
|
|
INSTALL_NAME_DIR ${OPENCV_LIB_INSTALL_PATH}
|
2011-06-23 23:51:51 +08:00
|
|
|
)
|
|
|
|
|
2011-06-24 23:40:27 +08:00
|
|
|
install(TARGETS ${target} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main)
|
|
|
|
|
2011-06-24 15:48:04 +08:00
|
|
|
set(api_target opencv_java_api)
|
|
|
|
add_custom_target(${api_target} ALL DEPENDS ${target})
|
2011-06-23 23:51:51 +08:00
|
|
|
|
|
|
|
IF(ANDROID)
|
|
|
|
# create Android library project in build folder
|
2011-06-24 15:48:04 +08:00
|
|
|
add_custom_command(
|
|
|
|
TARGET ${api_target}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/res"
|
|
|
|
COMMENT "Creating res directory"
|
|
|
|
)
|
2011-06-23 23:51:51 +08:00
|
|
|
|
|
|
|
FILE(GLOB android_lib_project_files "${CMAKE_CURRENT_SOURCE_DIR}/android/*")
|
|
|
|
foreach(lib_file ${android_lib_project_files})
|
|
|
|
if(NOT IS_DIRECTORY ${lib_file})
|
2011-06-24 15:48:04 +08:00
|
|
|
get_filename_component(lib_file_name "${lib_file}" NAME)
|
|
|
|
add_custom_command(
|
|
|
|
TARGET ${api_target}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${lib_file}" "${CMAKE_BINARY_DIR}"
|
|
|
|
DEPENDS "${lib_file}"
|
|
|
|
COMMENT "Generating ${lib_file_name}"
|
|
|
|
)
|
2011-06-24 23:40:27 +08:00
|
|
|
install(FILES "${CMAKE_BINARY_DIR}/${lib_file_name}" DESTINATION . COMPONENT main)
|
2011-06-30 21:37:56 +08:00
|
|
|
LIST(APPEND additional_clean_files "${CMAKE_BINARY_DIR}/${lib_file_name}")
|
2011-06-23 23:51:51 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2011-06-27 16:24:10 +08:00
|
|
|
|
|
|
|
foreach(jni_file ${handwrittren_cpp_sources} ${generated_cpp_sources})
|
|
|
|
get_filename_component(jni_file_name "${jni_file}" NAME)
|
|
|
|
add_custom_command(
|
|
|
|
TARGET ${api_target}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${jni_file}" "${CMAKE_BINARY_DIR}/jni/${jni_file_name}"
|
|
|
|
DEPENDS "${jni_file}"
|
|
|
|
COMMENT "Generating jni/${jni_file_name}"
|
|
|
|
)
|
2011-06-30 21:37:56 +08:00
|
|
|
LIST(APPEND additional_clean_files "${CMAKE_BINARY_DIR}/jni/${jni_file_name}")
|
2011-06-27 16:24:10 +08:00
|
|
|
endforeach()
|
2011-06-23 23:51:51 +08:00
|
|
|
ENDIF()
|
|
|
|
|
2011-07-08 23:29:59 +08:00
|
|
|
# generate javadoc comments
|
2011-06-24 15:48:04 +08:00
|
|
|
FILE(GLOB java_project_files "${CMAKE_CURRENT_SOURCE_DIR}/src/java/*.java")
|
2011-06-23 23:51:51 +08:00
|
|
|
|
2011-07-08 23:29:59 +08:00
|
|
|
SET(documented_java_files)
|
2011-06-23 23:51:51 +08:00
|
|
|
foreach(java_file ${java_project_files} ${generated_java_sources})
|
2011-07-08 23:29:59 +08:00
|
|
|
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()
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
TARGET ${api_target} PRE_BUILD
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVADOC}" "${CMAKE_CURRENT_SOURCE_DIR}/src/java" "${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
DEPENDS ${java_project_files}
|
|
|
|
DEPENDS ${generated_java_sources}
|
|
|
|
DEPENDS "${GEN_JAVA}"
|
|
|
|
DEPENDS "${HDR_PARSER}"
|
|
|
|
DEPENDS "${GEN_JAVADOC}"
|
|
|
|
DEPENDS "${RST_PARSER}"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
SET(JAVA_OUTPUT_DIR "${CMAKE_BINARY_DIR}/src/org/opencv")
|
|
|
|
|
|
|
|
foreach(java_file ${documented_java_files})
|
2011-06-24 15:48:04 +08:00
|
|
|
get_filename_component(java_file_name "${java_file}" NAME)
|
2011-07-08 23:29:59 +08:00
|
|
|
string(REPLACE "-jdoc.java" ".java" java_file_name "${java_file_name}")
|
2011-06-24 15:48:04 +08:00
|
|
|
add_custom_command(
|
|
|
|
TARGET ${api_target}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${java_file}" "${JAVA_OUTPUT_DIR}/${java_file_name}"
|
|
|
|
DEPENDS "${java_file}"
|
|
|
|
DEPENDS "${JAVA_OUTPUT_DIR}"
|
|
|
|
COMMENT "Generating src/org/opencv/${java_file_name}"
|
|
|
|
)
|
2011-06-30 21:37:56 +08:00
|
|
|
LIST(APPEND additional_clean_files "${JAVA_OUTPUT_DIR}/${java_file_name}")
|
2011-06-24 23:40:27 +08:00
|
|
|
if(ANDROID)
|
|
|
|
install(FILES "${JAVA_OUTPUT_DIR}/${java_file_name}" DESTINATION src/org/opencv COMPONENT main)
|
|
|
|
endif()
|
2011-06-23 23:51:51 +08:00
|
|
|
endforeach()
|
|
|
|
|
2011-06-30 22:35:35 +08:00
|
|
|
#android test project
|
|
|
|
if(ANDROID AND BUILD_TESTS AND CAN_BUILD_ANDROID_PROJECTS)
|
2011-07-04 14:33:10 +08:00
|
|
|
file(COPY android_test DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" PATTERN ".svn" EXCLUDE)
|
|
|
|
SET(test_dir "${CMAKE_CURRENT_BINARY_DIR}/android_test")
|
|
|
|
|
|
|
|
SET(test_name opencv_test_java)
|
|
|
|
SET(test_target ${test_name}_android)
|
2011-06-30 22:35:35 +08:00
|
|
|
|
|
|
|
add_custom_target(${test_target} ALL)
|
|
|
|
add_dependencies(${test_target} opencv_java opencv_java_api)
|
|
|
|
|
|
|
|
file(RELATIVE_PATH OPENCV_REFERENCE_PATH "${test_dir}" "${CMAKE_BINARY_DIR}")
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
TARGET ${test_target}
|
|
|
|
WORKING_DIRECTORY ${test_dir}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove -f "${test_dir}/default.properties"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch "${test_dir}/default.properties"
|
2011-07-12 23:59:31 +08:00
|
|
|
COMMAND ${ANDROID_EXECUTABLE} update project --name "${test_name}" --target "${ANDROID_SDK_TARGET}" --library "${OPENCV_REFERENCE_PATH}" --path .
|
2011-06-30 22:35:35 +08:00
|
|
|
COMMAND ${ANT_EXECUTABLE} debug
|
2011-07-04 14:33:10 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${test_dir}/bin/${test_name}-debug.apk" "${CMAKE_BINARY_DIR}/bin/${test_name}.apk"
|
2011-06-30 22:35:35 +08:00
|
|
|
)
|
|
|
|
|
2011-07-04 14:33:10 +08:00
|
|
|
LIST(APPEND additional_clean_files "${CMAKE_BINARY_DIR}/bin/${test_name}.apk" "${test_dir}/build.xml" "${test_dir}/local.properties" "${test_dir}/proguard.cfg")
|
2011-06-30 22:35:35 +08:00
|
|
|
endif()
|
|
|
|
|
2011-06-30 21:37:56 +08:00
|
|
|
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${additional_clean_files}")
|