mirror of
https://github.com/opencv/opencv.git
synced 2025-01-19 23:19:23 +08:00
Fixed build of Android samples and tests
This commit is contained in:
parent
3aea74d408
commit
a17b693aa9
@ -339,6 +339,9 @@ endif()
|
||||
|
||||
include(OpenCVPCHSupport.cmake REQUIRED)
|
||||
include(OpenCVModule.cmake REQUIRED)
|
||||
if(ANDROID)
|
||||
include(OpenCVAndroidProject.cmake REQUIRED)
|
||||
endif()
|
||||
|
||||
if(PCHSupport_FOUND)
|
||||
SET(USE_PRECOMPILED_HEADERS ON CACHE BOOL "Use precompiled headers")
|
||||
|
136
OpenCVAndroidProject.cmake
Normal file
136
OpenCVAndroidProject.cmake
Normal file
@ -0,0 +1,136 @@
|
||||
# creates target "${_target}_android_project" for building standard Android project
|
||||
macro(add_android_project _target _path)
|
||||
SET (android_dependencies opencv_contrib opencv_legacy opencv_objdetect opencv_calib3d opencv_features2d opencv_video opencv_highgui opencv_ml opencv_imgproc opencv_flann opencv_core)
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
LIST(APPEND android_dependencies opencv_androidcamera)
|
||||
endif()
|
||||
|
||||
if (ANDROID AND CAN_BUILD_ANDROID_PROJECTS)
|
||||
file(GLOB_RECURSE res_files_all RELATIVE "${_path}" "${_path}/res/*")
|
||||
file(GLOB_RECURSE jni_files_all RELATIVE "${_path}" "${_path}/jni/*.c*" "${_path}/jni/*.h*")
|
||||
file(GLOB_RECURSE src_files_all RELATIVE "${_path}" "${_path}/src/*.java")
|
||||
|
||||
#remove .svn
|
||||
set(res_files)
|
||||
foreach(f ${res_files_all})
|
||||
if(NOT f MATCHES "\\.svn")
|
||||
list(APPEND res_files "${f}")
|
||||
endif()
|
||||
endforeach()
|
||||
set(jni_files)
|
||||
foreach(f ${jni_files_all})
|
||||
if(NOT f MATCHES "\\.svn")
|
||||
list(APPEND jni_files "${f}")
|
||||
endif()
|
||||
endforeach()
|
||||
set(src_files)
|
||||
foreach(f ${src_files_all})
|
||||
if(NOT f MATCHES "\\.svn")
|
||||
list(APPEND src_files "${f}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# get temporary location for the project
|
||||
file(RELATIVE_PATH build_path "${OpenCV_SOURCE_DIR}" "${_path}")
|
||||
SET(build_path "${CMAKE_BINARY_DIR}/${build_path}")
|
||||
|
||||
# copy project to temporary location
|
||||
SET(${_target}_project_files)
|
||||
foreach(f ${res_files} ${src_files} "AndroidManifest.xml")
|
||||
if(NOT "${build_path}" STREQUAL "${_path}")
|
||||
#this is not needed in case of in-source build
|
||||
add_custom_command(
|
||||
OUTPUT "${build_path}/${f}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${_path}/${f}" "${build_path}/${f}"
|
||||
DEPENDS "${_path}/${f}"
|
||||
COMMENT ""
|
||||
)
|
||||
endif()
|
||||
list(APPEND ${_target}_project_files "${build_path}/${f}")
|
||||
endforeach()
|
||||
|
||||
# process default.properties
|
||||
file(STRINGS "${_path}/default.properties" default_properties REGEX "^android\\.library\\.reference\\.1=.+$")
|
||||
if (default_properties)
|
||||
# has opencv dependency
|
||||
file(RELATIVE_PATH OPENCV_REFERENCE_PATH "${build_path}" "${CMAKE_BINARY_DIR}")
|
||||
add_custom_command(
|
||||
OUTPUT "${build_path}/default.properties"
|
||||
OUTPUT "${build_path}/build.xml"
|
||||
OUTPUT "${build_path}/local.properties"
|
||||
OUTPUT "${build_path}/proguard.cfg"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#do not edit; this file is generated automatically" > "default.properties"
|
||||
COMMAND ${ANDROID_EXECUTABLE} update project --name "${_target}" --target "${ANDROID_SDK_TARGET}" --library "${OPENCV_REFERENCE_PATH}" --path .
|
||||
WORKING_DIRECTORY ${build_path}
|
||||
DEPENDS ${${_target}_project_files}
|
||||
DEPENDS opencv_java_android_library
|
||||
COMMENT "Updating android project - ${_target}"
|
||||
)
|
||||
else()
|
||||
# has no opencv dependency
|
||||
add_custom_command(
|
||||
OUTPUT "${build_path}/default.properties"
|
||||
OUTPUT "${build_path}/build.xml"
|
||||
OUTPUT "${build_path}/local.properties"
|
||||
OUTPUT "${build_path}/proguard.cfg"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#do not edit; this file is generated automatically" > "default.properties"
|
||||
COMMAND ${ANDROID_EXECUTABLE} update project --name "${_target}" --target "${ANDROID_SDK_TARGET}" --path .
|
||||
WORKING_DIRECTORY ${build_path}
|
||||
DEPENDS ${${_target}_project_files}
|
||||
COMMENT "Updating android project - ${_target}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if("${build_path}" STREQUAL "${_path}")
|
||||
#in case of in-source build default.properties file is not generated (it is just overwritten :)
|
||||
SET_SOURCE_FILES_PROPERTIES("${build_path}/default.properties" PROPERTIES GENERATED FALSE)
|
||||
endif()
|
||||
|
||||
list(APPEND ${_target}_project_files "${build_path}/default.properties" "${build_path}/build.xml" "${build_path}/local.properties" "${build_path}/proguard.cfg")
|
||||
|
||||
# build native part of android project
|
||||
if(jni_files)
|
||||
INCLUDE_DIRECTORIES("${_path}/jni")
|
||||
|
||||
FILE(STRINGS "${_path}/jni/Android.mk" JNI_LIB_NAME REGEX "LOCAL_MODULE[ ]*:=[ ]*.*" )
|
||||
string(REGEX REPLACE "LOCAL_MODULE[ ]*:=[ ]*([a-zA-Z_][a-zA-Z_0-9]*)[ ]*" "\\1" JNI_LIB_NAME "${JNI_LIB_NAME}")
|
||||
|
||||
SET(jni_sources)
|
||||
foreach(src ${jni_files})
|
||||
list(APPEND jni_sources "${_path}/${src}")
|
||||
endforeach()
|
||||
|
||||
ADD_LIBRARY(${JNI_LIB_NAME} MODULE ${jni_sources})
|
||||
TARGET_LINK_LIBRARIES(${JNI_LIB_NAME} ${OPENCV_LINKER_LIBS} ${android_dependencies})
|
||||
|
||||
set_target_properties(${JNI_LIB_NAME} PROPERTIES
|
||||
OUTPUT_NAME "${JNI_LIB_NAME}"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${build_path}/libs/${ARMEABI_NDK_NAME}"
|
||||
)
|
||||
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET ${JNI_LIB_NAME}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_STRIP} "${build_path}/libs/${ARMEABI_NDK_NAME}/*.so"
|
||||
)
|
||||
else()
|
||||
SET(JNI_LIB_NAME)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${build_path}/bin/${_target}-debug.apk"
|
||||
OUTPUT "${CMAKE_BINARY_DIR}/bin/${_target}.apk"
|
||||
COMMAND ${ANT_EXECUTABLE} debug
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${build_path}/bin/${_target}-debug.apk" "${CMAKE_BINARY_DIR}/bin/${_target}.apk"
|
||||
WORKING_DIRECTORY ${build_path}
|
||||
DEPENDS ${${_target}_project_files}
|
||||
DEPENDS ${JNI_LIB_NAME} opencv_java
|
||||
COMMENT "Generating bin/${_target}.apk"
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(${_target}_android_project ALL
|
||||
DEPENDS "${build_path}/bin/${_target}-debug.apk"
|
||||
DEPENDS "${CMAKE_BINARY_DIR}/bin/${_target}.apk"
|
||||
)
|
||||
endif()
|
||||
endmacro()
|
@ -2,6 +2,9 @@
|
||||
# CMake file for java support
|
||||
# ----------------------------------------------------------------------------
|
||||
project(opencv_java)
|
||||
set(target opencv_java)
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp")
|
||||
|
||||
|
||||
SET(OPENCV_JAVA_MODULES objdetect features2d imgproc video highgui ml core calib3d)
|
||||
SET(OPENCV_EXTRA_JAVA_MODULES contrib legacy flann)
|
||||
@ -9,32 +12,15 @@ IF(WITH_ANDROID_CAMERA AND NOT BUILD_SHARED_LIBS)
|
||||
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")
|
||||
SET(GEN_JAVADOC "${CMAKE_CURRENT_SOURCE_DIR}/gen_javadoc.py")
|
||||
SET(RST_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/rst_parser.py")
|
||||
|
||||
SET(additional_clean_files "")
|
||||
|
||||
macro(cleanup)
|
||||
file(GLOB files_to_clean "${CMAKE_CURRENT_BINARY_DIR}/*.java" "${CMAKE_CURRENT_BINARY_DIR}/*.cpp" "${CMAKE_CURRENT_BINARY_DIR}/*.h" "${CMAKE_CURRENT_BINARY_DIR}/*.txt" "${CMAKE_CURRENT_BINARY_DIR}/*.log")
|
||||
if(files_to_clean)
|
||||
file(REMOVE ${files_to_clean})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(capitalize name outputvar)
|
||||
string(SUBSTRING "${name}" 0 1 first_letter)
|
||||
string(SUBSTRING "${name}" 1 -1 tail_letters)
|
||||
string(TOUPPER "${first_letter}" first_letter)
|
||||
SET(${outputvar} "${first_letter}${tail_letters}")
|
||||
endmacro()
|
||||
|
||||
# cleanup required to correct process situations when some class is removed from exports
|
||||
cleanup()
|
||||
|
||||
# setup raw java and cpp files generation (without javadoc and at temporary location)
|
||||
foreach(module ${OPENCV_JAVA_MODULES})
|
||||
# get list of module headers
|
||||
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist")
|
||||
FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist" headers_to_parse)
|
||||
SET (module_cheaders "")
|
||||
@ -49,18 +35,32 @@ foreach(module ${OPENCV_JAVA_MODULES})
|
||||
list(SORT module_cppheaders)
|
||||
ENDIF()
|
||||
|
||||
# first run
|
||||
execute_process(COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVA}" "${HDR_PARSER}" ${module} ${module_cheaders} ${module_cppheaders}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
OUTPUT_QUIET ERROR_QUIET)
|
||||
|
||||
# add dependencies to cmake
|
||||
# add dependencies to cmake (we should rerun cmake if any of these headers are modified)
|
||||
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()
|
||||
|
||||
FILE(GLOB ${module}_generated_java_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}+*.java")
|
||||
# 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()
|
||||
|
||||
# second run
|
||||
add_custom_command(
|
||||
@ -70,20 +70,21 @@ foreach(module ${OPENCV_JAVA_MODULES})
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS "${GEN_JAVA}"
|
||||
DEPENDS "${HDR_PARSER}"
|
||||
DEPENDS ${module_cheaders}
|
||||
DEPENDS ${module_cppheaders}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
cleanup()
|
||||
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)
|
||||
|
||||
set(target opencv_java)
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp")
|
||||
|
||||
SET (generated_cpp_sources "")
|
||||
SET (generated_java_sources "")
|
||||
SET (dependent_libs "")
|
||||
SET (dependent_extra_libs "")
|
||||
|
||||
# summarize all sources for Java API
|
||||
foreach(module ${OPENCV_JAVA_MODULES})
|
||||
LIST(APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp")
|
||||
LIST(APPEND generated_java_sources ${${module}_generated_java_sources})
|
||||
@ -91,19 +92,13 @@ foreach(module ${OPENCV_JAVA_MODULES})
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include")
|
||||
endforeach()
|
||||
|
||||
# set libopencv_java.so shared library includes and dependencies
|
||||
# extra includes and dependencies
|
||||
foreach(module ${OPENCV_EXTRA_JAVA_MODULES})
|
||||
LIST(APPEND dependent_extra_libs opencv_${module})
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include")
|
||||
endforeach()
|
||||
|
||||
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")
|
||||
|
||||
# created list of documented files targets
|
||||
SET(documented_java_files)
|
||||
SET(undocumented_java_files)
|
||||
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$")
|
||||
@ -113,18 +108,19 @@ foreach(java_file ${handwrittren_java_sources} ${generated_java_sources})
|
||||
endforeach()
|
||||
|
||||
# generate javadoc files
|
||||
file(GLOB_RECURSE refman_rst_headers "${CMAKE_CURRENT_SOURCE_DIR}/../*.rst")
|
||||
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 ${handwrittren_java_sources}
|
||||
DEPENDS ${undocumented_java_files}
|
||||
DEPENDS "${GEN_JAVADOC}"
|
||||
DEPENDS "${RST_PARSER}"
|
||||
DEPENDS ${refman_rst_headers}
|
||||
)
|
||||
|
||||
# copy generated java files to the final location
|
||||
SET(JAVA_OUTPUT_DIR "${CMAKE_BINARY_DIR}/src/org/opencv")
|
||||
SET(JAVA_OUTPUT_DIR "src/org/opencv")
|
||||
|
||||
set(java_files)
|
||||
foreach(java_file ${documented_java_files})
|
||||
@ -133,32 +129,28 @@ foreach(java_file ${documented_java_files})
|
||||
string(REPLACE "+" "/" java_file_name "${java_file_name}")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${JAVA_OUTPUT_DIR}/${java_file_name}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${java_file}" "${JAVA_OUTPUT_DIR}/${java_file_name}"
|
||||
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}"
|
||||
DEPENDS "${java_file}"
|
||||
COMMENT "Generating src/org/opencv/${java_file_name}"
|
||||
COMMENT "Generating ${JAVA_OUTPUT_DIR}/${java_file_name}"
|
||||
)
|
||||
list(APPEND java_files "${JAVA_OUTPUT_DIR}/${java_file_name}")
|
||||
list(APPEND java_files "${CMAKE_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}")
|
||||
|
||||
if(ANDROID)
|
||||
get_filename_component(install_dir "${java_file_name}" PATH)
|
||||
install(FILES "${JAVA_OUTPUT_DIR}/${java_file_name}" DESTINATION src/org/opencv/${install_dir} COMPONENT main)
|
||||
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)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# setup dependencies
|
||||
SET(dependency_file "${CMAKE_CURRENT_BINARY_DIR}/dependencies.cpp")
|
||||
add_custom_command(
|
||||
OUTPUT "${dependency_file}"
|
||||
COMMAND ${CMAKE_COMMAND} -E touch "${dependency_file}"
|
||||
)
|
||||
SET_SOURCE_FILES_PROPERTIES(${java_files} PROPERTIES HEADER_FILE_ONLY TRUE)
|
||||
SET(opencv_java_dependency_files "${java_files}")
|
||||
# custom target for java API
|
||||
set(api_target ${target}_api)
|
||||
ADD_CUSTOM_TARGET(${api_target} DEPENDS ${java_files})
|
||||
|
||||
# add opencv_java project
|
||||
add_library(${target} SHARED ${handwrittren_h_sources} ${handwrittren_cpp_sources} ${generated_cpp_sources} ${dependency_file})
|
||||
|
||||
# add opencv_java library
|
||||
add_library(${target} SHARED ${handwrittren_h_sources} ${handwrittren_cpp_sources} ${generated_cpp_sources})
|
||||
target_link_libraries(${target} ${dependent_libs} ${dependent_extra_libs} ${OPENCV_LINKER_LIBS})
|
||||
add_dependencies(${target} "${GEN_JAVA}" "${HDR_PARSER}")
|
||||
add_dependencies(${target} ${dependent_extra_libs} ${dependent_libs})
|
||||
add_dependencies(${target} ${dependent_extra_libs} ${dependent_libs} ${api_target})
|
||||
|
||||
# Additional target properties
|
||||
set_target_properties(${target} PROPERTIES
|
||||
@ -170,7 +162,6 @@ set_target_properties(${target} PROPERTIES
|
||||
|
||||
install(TARGETS ${target} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main)
|
||||
|
||||
|
||||
if(ANDROID)
|
||||
target_link_libraries(${target} jnigraphics)
|
||||
|
||||
@ -182,13 +173,7 @@ if(ANDROID)
|
||||
COMMAND ${CMAKE_STRIP} "${LIBRARY_OUTPUT_PATH}/lib${target}.so"
|
||||
)
|
||||
|
||||
# create Android library project in build folder
|
||||
add_custom_command(
|
||||
TARGET ${target} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/res"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/gen"
|
||||
)
|
||||
|
||||
set(lib_proj_files)
|
||||
# library project blank
|
||||
file(GLOB_RECURSE android_lib_project_files "${CMAKE_CURRENT_SOURCE_DIR}/android/*")
|
||||
foreach(file ${android_lib_project_files})
|
||||
@ -200,8 +185,8 @@ if(ANDROID)
|
||||
DEPENDS "${file}"
|
||||
COMMENT "Generating ${file_rel}"
|
||||
)
|
||||
SET_SOURCE_FILES_PROPERTIES("${CMAKE_BINARY_DIR}/${file_rel}" PROPERTIES HEADER_FILE_ONLY TRUE)
|
||||
list(APPEND opencv_java_dependency_files "${CMAKE_BINARY_DIR}/${file_rel}")
|
||||
|
||||
list(APPEND lib_proj_files "${CMAKE_BINARY_DIR}/${file_rel}")
|
||||
|
||||
if(NOT file_rel MATCHES "jni/.+")
|
||||
install(FILES "${CMAKE_BINARY_DIR}/${file_rel}" DESTINATION . COMPONENT main)
|
||||
@ -219,42 +204,22 @@ if(ANDROID)
|
||||
DEPENDS "${jni_file}"
|
||||
COMMENT "Generating jni/${jni_file_name}"
|
||||
)
|
||||
SET_SOURCE_FILES_PROPERTIES("${CMAKE_BINARY_DIR}/jni/${jni_file_name}" PROPERTIES HEADER_FILE_ONLY TRUE)
|
||||
list(APPEND opencv_java_dependency_files "${CMAKE_BINARY_DIR}/jni/${jni_file_name}")
|
||||
endforeach()
|
||||
endif()
|
||||
list(APPEND lib_proj_files "${CMAKE_BINARY_DIR}/jni/${jni_file_name}")
|
||||
endforeach()
|
||||
|
||||
# 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}
|
||||
DEPENDS ${api_target}
|
||||
)
|
||||
add_dependencies(${target} ${lib_target})
|
||||
|
||||
# apply dependencies
|
||||
SET_SOURCE_FILES_PROPERTIES("${dependency_file}" PROPERTIES OBJECT_DEPENDS "${opencv_java_dependency_files}")
|
||||
endif(ANDROID)
|
||||
|
||||
#android test project
|
||||
if(ANDROID AND BUILD_TESTS AND CAN_BUILD_ANDROID_PROJECTS)
|
||||
file(COPY android_test DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
PATTERN ".svn" EXCLUDE
|
||||
PATTERN "gen" EXCLUDE
|
||||
PATTERN "bin" EXCLUDE
|
||||
)
|
||||
SET(test_dir "${CMAKE_CURRENT_BINARY_DIR}/android_test")
|
||||
|
||||
SET(test_name opencv_test_java)
|
||||
SET(test_target ${test_name}_android)
|
||||
|
||||
add_custom_target(${test_target} ALL)
|
||||
add_dependencies(${test_target} opencv_java)
|
||||
|
||||
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"
|
||||
COMMAND ${ANDROID_EXECUTABLE} update project --name "${test_name}" --target "${ANDROID_SDK_TARGET}" --library "${OPENCV_REFERENCE_PATH}" --path .
|
||||
COMMAND ${ANT_EXECUTABLE} debug
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${test_dir}/bin/${test_name}-debug.apk" "${CMAKE_BINARY_DIR}/bin/${test_name}.apk"
|
||||
)
|
||||
|
||||
LIST(APPEND additional_clean_files "${CMAKE_BINARY_DIR}/bin/${test_name}.apk" "${test_dir}/build.xml" "${test_dir}/local.properties" "${test_dir}/proguard.cfg")
|
||||
if(BUILD_TESTS)
|
||||
add_android_project(opencv_test_java "${CMAKE_CURRENT_SOURCE_DIR}/android_test")
|
||||
endif()
|
||||
|
||||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${additional_clean_files}")
|
||||
|
@ -1,5 +1,4 @@
|
||||
import sys, re, os.path
|
||||
|
||||
from string import Template
|
||||
|
||||
try:
|
||||
|
@ -25,83 +25,13 @@ if (BUILD_ANDROID_EXAMPLES)
|
||||
LIST(APPEND sample_dependencies opencv_androidcamera)
|
||||
endif()
|
||||
|
||||
SET(additional_clean_files "")
|
||||
|
||||
macro(ADD_ANDROID_SAMPLE sample_name)
|
||||
#message(STATUS "Build android sample: '${sample_name}'")
|
||||
#SET(sample_dir "${CMAKE_CURRENT_SOURCE_DIR}/${sample}")
|
||||
SET(sample_dir "${CMAKE_CURRENT_BINARY_DIR}/${sample}")
|
||||
|
||||
add_custom_target(${sample} ALL)
|
||||
add_dependencies(${sample} opencv_java)
|
||||
|
||||
set_target_properties(${sample} PROPERTIES
|
||||
PROJECT_LABEL "(ANDROID EXAMPLE) ${sample}")
|
||||
|
||||
file(RELATIVE_PATH OPENCV_REFERENCE_PATH "${sample_dir}" "${CMAKE_BINARY_DIR}")
|
||||
|
||||
if(NOT ("${sample}" MATCHES "tutorial-[03].*"))
|
||||
SET(opencv_reference --library \"${OPENCV_REFERENCE_PATH}\")
|
||||
else()
|
||||
SET(opencv_reference)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
TARGET ${sample}
|
||||
WORKING_DIRECTORY ${sample_dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E remove -f "${sample_dir}/default.properties"
|
||||
COMMAND ${CMAKE_COMMAND} -E touch "${sample_dir}/default.properties"
|
||||
COMMAND ${ANDROID_EXECUTABLE} update project --name "${sample}" --target "${ANDROID_SDK_TARGET}" ${opencv_reference} --path .
|
||||
COMMAND ${ANT_EXECUTABLE} debug
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${sample_dir}/bin/${sample}-debug.apk" "${CMAKE_BINARY_DIR}/bin/${sample}.apk"
|
||||
)
|
||||
|
||||
LIST(APPEND additional_clean_files "${CMAKE_BINARY_DIR}/bin/${sample}.apk" "${sample_dir}/build.xml" "${sample_dir}/local.properties" "${sample_dir}/proguard.cfg")
|
||||
|
||||
if(IS_DIRECTORY "${sample_dir}/jni")
|
||||
INCLUDE_DIRECTORIES("${sample_dir}/jni")
|
||||
FILE( GLOB srcs "${sample_dir}/jni/*.cpp" )
|
||||
|
||||
FILE(STRINGS "${sample_dir}/jni/Android.mk" JNI_LIB_NAME REGEX "LOCAL_MODULE[ ]*:=[ ]*.*" )
|
||||
string(REGEX REPLACE "LOCAL_MODULE[ ]*:=[ ]*([a-zA-Z_][a-zA-Z_0-9]*)[ ]*" "\\1" JNI_LIB_NAME "${JNI_LIB_NAME}")
|
||||
|
||||
ADD_LIBRARY( ${JNI_LIB_NAME} MODULE ${srcs} )
|
||||
|
||||
ADD_DEPENDENCIES(${JNI_LIB_NAME} ${sample_dependencies})
|
||||
TARGET_LINK_LIBRARIES(${JNI_LIB_NAME} ${OPENCV_LINKER_LIBS} ${sample_dependencies})
|
||||
|
||||
set_target_properties(${JNI_LIB_NAME} PROPERTIES
|
||||
OUTPUT_NAME "${JNI_LIB_NAME}"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${sample_dir}/libs/${ARMEABI_NDK_NAME}"
|
||||
)
|
||||
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET ${JNI_LIB_NAME}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_STRIP} "${sample_dir}/libs/${ARMEABI_NDK_NAME}/*.so"
|
||||
)
|
||||
|
||||
add_dependencies(${sample} ${JNI_LIB_NAME})
|
||||
endif()
|
||||
|
||||
if(INSTALL_ANDROID_EXAMPLES)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/bin/${sample}.apk" DESTINATION bin COMPONENT main)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
file(GLOB android_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
|
||||
list(REMOVE_ITEM android_samples hello-android)
|
||||
list(SORT android_samples)
|
||||
|
||||
file(COPY ${android_samples} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
PATTERN ".svn" EXCLUDE
|
||||
PATTERN "gen" EXCLUDE
|
||||
PATTERN "bin" EXCLUDE
|
||||
)
|
||||
|
||||
foreach(sample ${android_samples})
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${sample}/AndroidManifest.xml)
|
||||
ADD_ANDROID_SAMPLE(${sample})
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${sample}/AndroidManifest.xml")
|
||||
add_android_project("${sample}" "${CMAKE_CURRENT_SOURCE_DIR}/${sample}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
@ -114,5 +44,4 @@ if (BUILD_ANDROID_EXAMPLES)
|
||||
install(TARGETS hello-android DESTINATION bin COMPONENT main)
|
||||
endif()
|
||||
|
||||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${additional_clean_files}")
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user