if ( NOT ANDROID_EXECUTABLE )
message ( WARNING "'android' tool required to build Android SDK" )
return ( )
endif ( )
ocv_assert ( ANDROID_TOOLS_Pkg_Revision GREATER 13 )
project ( ${ the_module } _android )
set ( OPENCV_JAVA_DIR "${OpenCV_BINARY_DIR}/android_sdk" CACHE INTERNAL "" )
set ( OPENCV_ANDROID_LIB_DIR "${OPENCV_JAVA_DIR}" CACHE INTERNAL "" ) # for OpenCV samples
file ( REMOVE_RECURSE "${OPENCV_JAVA_DIR}" )
file ( MAKE_DIRECTORY "${OPENCV_JAVA_DIR}/bin" )
set ( java_src_dir "${OPENCV_JAVA_DIR}/src" )
file ( MAKE_DIRECTORY "${java_src_dir}" )
ocv_copyfiles_append_dir ( JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/java" "${java_src_dir}" )
ocv_copyfiles_append_dir ( JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android/java" "${java_src_dir}" )
# calc default SDK Target
android_get_compatible_target ( ANDROID_SDK_COMPATIBLE_TARGET ${ ANDROID_NATIVE_API_LEVEL } ${ ANDROID_SDK_TARGET } 14 )
if ( ANDROID_SDK_COMPATIBLE_TARGET )
set ( ANDROID_SDK_COMPATIBLE_TARGET "${ANDROID_SDK_COMPATIBLE_TARGET}" CACHE INTERNAL "" )
endif ( )
string ( REGEX REPLACE "android-" "" android_sdk_target_num ${ ANDROID_SDK_COMPATIBLE_TARGET } )
if ( ( ANDROID_SDK_TARGET AND ANDROID_SDK_TARGET LESS 21 ) OR ( android_sdk_target_num LESS 21 ) )
message ( STATUS "[OpenCV for Android SDK]: A new OpenGL Camera Bridge (CameraGLSurfaceView, CameraGLRendererBase, CameraRenderer, Camera2Renderer) is disabled, because ANDROID_SDK_TARGET (${android_sdk_target_num}) < 21" )
else ( )
ocv_copyfiles_append_dir ( JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android-21/java" "${java_src_dir}" )
endif ( )
# copy boilerplate
file ( GLOB_RECURSE seed_project_files_rel RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/" "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/*" )
list ( REMOVE_ITEM seed_project_files_rel "${ANDROID_MANIFEST_FILE}" )
foreach ( file ${ seed_project_files_rel } )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${file}" "${OPENCV_JAVA_DIR}/${file}" @ONLY )
list ( APPEND depends "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${file}" )
get_filename_component ( install_subdir "${file}" PATH )
install ( FILES "${OPENCV_JAVA_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT java )
endforeach ( )
list ( APPEND depends gen_opencv_java_source "${OPENCV_DEPHELPER}/gen_opencv_java_source" )
ocv_copyfiles_add_target ( ${ the_module } _android_source_copy JAVA_SRC_COPY "Copy Java(Android SDK) source files" ${ depends } )
file ( REMOVE "${OPENCV_DEPHELPER}/${the_module}_android_source_copy" ) # force rebuild after CMake run
set ( depends ${ the_module } _android_source_copy "${OPENCV_DEPHELPER}/${the_module}_android_source_copy" )
# generate Android library project
set ( android_sdk_project_files ${ ANDROID_LIB_PROJECT_FILES } ) # build.xml;local.properties;proguard-project.txt;project.properties
ocv_list_add_prefix ( android_sdk_project_files "${OPENCV_JAVA_DIR}/" )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${ANDROID_MANIFEST_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" @ONLY )
add_custom_command (
O U T P U T $ { a n d r o i d _ s d k _ p r o j e c t _ f i l e s } " $ { O P E N C V _ J A V A _ D I R } / $ { A N D R O I D _ M A N I F E S T _ F I L E } "
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e $ { a n d r o i d _ s d k _ p r o j e c t _ f i l e s }
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { A N D R O I D _ M A N I F E S T _ F I L E } " " $ { O P E N C V _ J A V A _ D I R } / $ { A N D R O I D _ M A N I F E S T _ F I L E } "
C O M M A N D $ { A N D R O I D _ E X E C U T A B L E } - - s i l e n t c r e a t e l i b - p r o j e c t - - p a t h \ " $ { O P E N C V _ J A V A _ D I R } \ " - - t a r g e t \ " $ { A N D R O I D _ S D K _ C O M P A T I B L E _ T A R G E T } \ " - - n a m e O p e n C V - - p a c k a g e o r g . o p e n c v 2 > \ " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c r e a t e _ l i b _ p r o j e c t . l o g \ "
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { A N D R O I D _ M A N I F E S T _ F I L E } " " $ { O P E N C V _ J A V A _ D I R } / $ { A N D R O I D _ M A N I F E S T _ F I L E } "
W O R K I N G _ D I R E C T O R Y " $ { O P E N C V _ J A V A _ D I R } "
M A I N _ D E P E N D E N C Y " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { A N D R O I D _ M A N I F E S T _ F I L E } "
D E P E N D S $ { d e p e n d s }
C O M M E N T " G e n e r a t i n g O p e n C V A n d r o i d l i b r a r y p r o j e c t . S D K t a r g e t : $ { l i b _ t a r g e t _ s d k _ t a r g e t } "
)
list ( APPEND depends ${ android_sdk_project_files } "${OPENCV_JAVA_DIR}/${ANDROID_MANIFEST_FILE}" )
install ( DIRECTORY "${OPENCV_JAVA_DIR}/src" DESTINATION "${JAVA_INSTALL_ROOT}" COMPONENT java )
install ( FILES "${OPENCV_JAVA_DIR}/${ANDROID_PROJECT_PROPERTIES_FILE}" DESTINATION ${ JAVA_INSTALL_ROOT } COMPONENT java )
install ( FILES "${OPENCV_JAVA_DIR}/${ANDROID_MANIFEST_FILE}" DESTINATION ${ JAVA_INSTALL_ROOT } COMPONENT java )
# build jar
set ( JAR_FILE "${OpenCV_BINARY_DIR}/bin/classes.jar" )
# 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 (
O U T P U T " $ { J A R _ F I L E } " " $ { O P E N C V _ D E P H E L P E R } / $ { t h e _ m o d u l e } _ a n d r o i d "
C O M M A N D $ { A N T _ E X E C U T A B L E } - q - n o i n p u t - k d e b u g - D j a v a . t a r g e t = 1 . 6 - D j a v a . s o u r c e = 1 . 6
C O M M A N D $ { C M A K E _ C O M M A N D } - E t o u c h " $ { O P E N C V _ D E P H E L P E R } / $ { t h e _ m o d u l e } _ a n d r o i d "
W O R K I N G _ D I R E C T O R Y " $ { O P E N C V _ J A V A _ D I R } "
D E P E N D S $ { d e p e n d s }
C O M M E N T " B u i l d i n g O p e n C V A n d r o i d l i b r a r y p r o j e c t "
)
add_custom_target ( ${ the_module } _android DEPENDS "${OPENCV_DEPHELPER}/${the_module}_android" SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${ANDROID_MANIFEST_FILE}" )
add_dependencies ( ${ the_module } ${ the_module } _android )
# empty 'gen' and 'res' folders
install ( CODE "
FILE ( MAKE_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/gen\")
FILE ( MAKE_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/res\")
" C O M P O N E N T j a v a )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${CMAKE_CURRENT_BINARY_DIR}/build.gradle" @ONLY )
install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/build.gradle" DESTINATION ${ JAVA_INSTALL_ROOT } /.. COMPONENT java )