2011-06-23 17:51:51 +02:00
# ----------------------------------------------------------------------------
# CMake file for java support
# ----------------------------------------------------------------------------
2015-02-20 17:47:45 +01:00
if ( IOS OR WINRT OR NOT PYTHON_DEFAULT_AVAILABLE OR NOT ANT_EXECUTABLE OR NOT ( JNI_FOUND OR ( ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7 ) )
2014-08-01 16:11:20 +02:00
O R B U I L D _ o p e n c v _ w o r l d
)
2012-02-03 12:26:49 +01:00
ocv_module_disable ( java )
endif ( )
2011-07-24 22:44:20 +02:00
2012-02-03 12:26:49 +01:00
set ( the_description "The java bindings" )
2015-02-19 14:17:19 +01:00
ocv_add_module ( java BINDINGS opencv_core opencv_imgproc )
2012-06-21 13:44:31 +02:00
ocv_module_include_directories ( "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp" )
2015-03-26 13:25:42 +01:00
ocv_module_include_directories ( "${OpenCV_SOURCE_DIR}/include" )
2011-06-23 17:51:51 +02:00
2012-09-15 13:46:34 +02:00
if ( NOT ANDROID )
include_directories ( ${ JNI_INCLUDE_DIRS } )
endif ( )
2013-01-22 14:56:04 +01:00
# output locations
set ( JAVA_INSTALL_ROOT "sdk/java" )
set ( JNI_INSTALL_ROOT "sdk/native" )
2012-03-25 21:57:58 +02:00
# get list of modules to wrap
2015-02-24 16:38:12 +01:00
# message(STATUS "Wrapped in java:")
2015-02-19 14:17:19 +01:00
set ( OPENCV_JAVA_MODULES )
foreach ( m ${ OPENCV_MODULES_BUILD } )
if ( ";${OPENCV_MODULE_${m}_WRAPPERS};" MATCHES ";java;" AND HAVE_ ${ m } )
string ( REPLACE "opencv_" "" m ${ m } )
list ( APPEND OPENCV_JAVA_MODULES ${ m } )
2015-02-24 16:38:12 +01:00
# message(STATUS "\topencv_${m}")
2012-02-20 12:50:43 +01:00
endif ( )
endforeach ( )
2011-06-23 17:51:51 +02:00
2013-01-22 14:56:04 +01:00
######################################################################################################################################
2011-06-23 17:51:51 +02:00
2015-02-19 14:17:19 +01:00
# UTILITY: make C headers go first
macro ( sort_headers_c_cpp __lst )
set ( __cpp ${ ${__lst } } )
ocv_list_filterout ( __cpp "\\\\.h$" )
if ( __cpp )
list ( REMOVE_ITEM ${ __lst } ${ __cpp } )
list ( APPEND ${ __lst } ${ __cpp } )
endif ( )
unset ( __cpp )
endmacro ( )
# UTILITY: force cmake to rerun when files from list have changed
macro ( add_cmake_dependencies )
foreach ( f ${ ARGN } )
get_filename_component ( f_name "${f}" NAME )
configure_file ( ${ f } ${ OpenCV_BINARY_DIR } /junk/ ${ f_name } .junk COPYONLY )
endforeach ( )
endmacro ( )
# UTILITY: glob specific sources and append them to list (type is in H, CPP, JAVA, AIDL)
macro ( glob_more_specific_sources _type _root _output )
unset ( _masks )
if ( ${ _type } STREQUAL "H" )
set ( _masks "${_root}/src/cpp/*.h" "${root}/src/cpp/*.hpp" )
elseif ( ${ _type } STREQUAL "CPP" )
set ( _masks "${_root}/src/cpp/*.cpp" )
elseif ( ${ _type } STREQUAL "JAVA" )
set ( _masks "${_root}/src/java/*.java" )
elseif ( ${ _type } STREQUAL "AIDL" )
set ( _masks "${_root}/src/java/*.aidl" )
endif ( )
if ( _masks )
file ( GLOB _result ${ _masks } )
list ( APPEND ${ _output } ${ _result } )
else ( )
message ( WARNING "Bad argument passed to macro: skipped" )
endif ( )
endmacro ( )
# UTILITY: copy common java test files and add them to _deps
# copy_common_tests(<source-folder> <destination-folder> <variable-to-store-deps>)
macro ( copy_common_tests _src_location _dst_location _deps )
set ( _src ${ ${_src_location } } )
set ( _dst ${ ${_dst_location } } )
file ( GLOB_RECURSE _files RELATIVE "${_src}" "${_src}/res/*" "${_src}/src/*" )
foreach ( f ${ _files } )
add_custom_command (
O U T P U T " $ { _ d s t } / $ { f } "
2015-09-08 21:42:05 +02:00
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 " $ { _ s r c } / $ { f } " " $ { _ d s t } / $ { f } "
2015-02-19 14:17:19 +01:00
M A I N _ D E P E N D E N C Y " $ { _ s r c } / $ { f } "
C O M M E N T " C o p y i n g $ { f } " )
list ( APPEND ${ _deps } "${_src}/${f}" "${_dst}/${f}" )
endforeach ( )
unset ( _files )
unset ( _src )
unset ( _dst )
endmacro ( )
# UTILITY: copy all java tests for specific module and add them to _deps
# copy_modules_tests(<modules-list> <destination-folder> <variable-to-store-deps>)
macro ( copy_modules_tests _modules _dst_location _deps )
set ( _dst ${ ${_dst_location } } )
foreach ( module ${ ${_modules } } )
set ( _src "${OPENCV_MODULE_opencv_${module}_LOCATION}/misc/java/test" )
set ( _tree "src/org/opencv/test/${module}" )
file ( GLOB _files RELATIVE "${_src}" "${_src}/*.java" )
foreach ( f ${ _files } )
add_custom_command (
O U T P U T " $ { _ d s t } / $ { _ t r e e } / $ { f } "
2015-09-08 21:42:05 +02:00
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 " $ { _ s r c } / $ { f } " " $ { _ d s t } / $ { _ t r e e } / $ { f } "
2015-02-19 14:17:19 +01:00
M A I N _ D E P E N D E N C Y " $ { _ s r c } / $ { f } "
C O M M E N T " C o p y i n g $ { f } " )
list ( APPEND ${ _deps } "${_src}/${f}" "${_dst}/${_tree}/${f}" )
endforeach ( )
unset ( _files )
unset ( _src )
unset ( _tree )
endforeach ( )
unset ( _dst )
endmacro ( )
######################################################################################################################################
2013-01-22 14:56:04 +01:00
# scripts
set ( scripts_gen_java "${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_java.py" )
set ( scripts_hdr_parser "${CMAKE_CURRENT_SOURCE_DIR}/../python/src2/hdr_parser.py" )
2012-03-25 21:57:58 +02:00
2015-02-19 14:17:19 +01:00
# directory to store temporary files generated on first gen_java.py run
set ( probe_dir "${CMAKE_CURRENT_BINARY_DIR}/gen_java_out" )
2013-01-22 14:56:04 +01:00
# handwritten C/C++ and Java sources
2015-02-19 14:17:19 +01:00
glob_more_specific_sources ( H "${CMAKE_CURRENT_SOURCE_DIR}/generator" handwritten_h_sources )
glob_more_specific_sources ( CPP "${CMAKE_CURRENT_SOURCE_DIR}/generator" handwritten_cpp_sources )
glob_more_specific_sources ( JAVA "${CMAKE_CURRENT_SOURCE_DIR}/generator" handwritten_java_sources )
glob_more_specific_sources ( AIDL "${CMAKE_CURRENT_SOURCE_DIR}/generator" handwritten_aidl_sources )
2012-03-25 21:57:58 +02:00
2013-01-22 14:56:04 +01:00
# headers of OpenCV modules
set ( opencv_public_headers "" )
2015-02-19 14:17:19 +01:00
set ( generated_cpp_sources "" )
set ( generated_java_sources "" )
2011-06-23 17:51:51 +02:00
foreach ( module ${ OPENCV_JAVA_MODULES } )
2015-02-19 14:17:19 +01:00
set ( module_java_dir "${OPENCV_MODULE_opencv_${module}_LOCATION}/misc/java" )
set ( custom_header_list "${module_java_dir}/filelist" )
if ( EXISTS "${custom_header_list}" )
file ( STRINGS "${custom_header_list}" module_headers )
2012-03-25 21:57:58 +02:00
ocv_list_add_prefix ( module_headers "${OPENCV_MODULE_opencv_${module}_LOCATION}/" )
2012-02-20 12:50:43 +01:00
else ( )
2012-03-25 21:57:58 +02:00
set ( module_headers "${OPENCV_MODULE_opencv_${module}_HEADERS}" )
2012-02-20 12:50:43 +01:00
endif ( )
2015-02-19 14:17:19 +01:00
if ( NOT module_headers )
message ( WARNING "Module ${module} does not have headers to wrap for java" )
2012-03-25 21:57:58 +02:00
endif ( )
2015-02-19 14:17:19 +01:00
sort_headers_c_cpp ( module_headers )
set ( opencv_public_headers_ ${ module } ${ module_headers } )
list ( APPEND opencv_public_headers ${ module_headers } )
2013-01-22 14:56:04 +01:00
list ( APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp" )
2011-06-23 17:51:51 +02:00
2015-02-19 14:17:19 +01:00
include_directories ( "${module_java_dir}/src/cpp" )
glob_more_specific_sources ( H "${module_java_dir}" handwritten_h_sources )
glob_more_specific_sources ( CPP "${module_java_dir}" handwritten_cpp_sources )
glob_more_specific_sources ( JAVA "${module_java_dir}" handwritten_java_sources )
glob_more_specific_sources ( AIDL "${module_java_dir}" handwritten_aidl_sources )
2012-02-20 12:50:43 +01:00
2013-01-22 14:56:04 +01:00
# first run of gen_java.py (to get list of generated files)
2015-02-19 14:17:19 +01:00
file ( REMOVE_RECURSE "${probe_dir}" )
file ( MAKE_DIRECTORY "${probe_dir}" )
2014-06-29 22:45:24 +02:00
execute_process ( COMMAND ${ PYTHON_DEFAULT_EXECUTABLE } "${scripts_gen_java}" "${scripts_hdr_parser}" ${ module } ${ opencv_public_headers_${module } }
2015-02-19 14:17:19 +01:00
W O R K I N G _ D I R E C T O R Y " $ { p r o b e _ d i r } "
2013-01-22 14:56:04 +01:00
O U T P U T _ Q U I E T E R R O R _ Q U I E T )
2015-02-19 14:17:19 +01:00
file ( GLOB_RECURSE generated_java_sources_ ${ module } RELATIVE "${probe_dir}" "${probe_dir}/*.java" )
2013-01-22 14:56:04 +01:00
ocv_list_add_prefix ( generated_java_sources_ ${ module } "${CMAKE_CURRENT_BINARY_DIR}/" )
list ( APPEND generated_java_sources ${ generated_java_sources_${module } } )
2012-02-20 12:50:43 +01:00
endforeach ( )
2011-06-23 17:51:51 +02:00
2015-02-19 14:17:19 +01:00
file ( REMOVE_RECURSE "${probe_dir}" )
if ( NOT ANDROID )
2015-05-20 16:59:42 +02:00
ocv_list_filterout ( handwritten_java_sources "/(engine|android)\\\\+" )
ocv_list_filterout ( handwritten_aidl_sources "/(engine|android)\\\\+" )
2015-02-19 14:17:19 +01:00
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 ( )
2015-10-07 10:28:57 +02:00
# Calc default SDK Target
android_get_compatible_target ( android_sdk_target ${ ANDROID_NATIVE_API_LEVEL } ${ ANDROID_SDK_TARGET } 11 )
string ( REGEX REPLACE "android-" "" android_sdk_target_num ${ android_sdk_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" )
ocv_list_filterout ( handwritten_java_sources "android\\\\+CameraGL" )
ocv_list_filterout ( handwritten_java_sources "android\\\\+Camera.?Renderer" )
endif ( )
2015-02-19 14:17:19 +01:00
# IMPORTANT: add dependencies to cmake (we should rerun cmake if any of these files is modified)
add_cmake_dependencies ( ${ scripts_gen_java } ${ scripts_hdr_parser } ${ opencv_public_headers } )
2013-01-22 14:56:04 +01:00
######################################################################################################################################
2012-03-25 21:57:58 +02:00
2013-01-22 14:56:04 +01:00
# step 1: generate .cpp/.java from OpenCV headers
set ( step1_depends "${scripts_gen_java}" "${scripts_hdr_parser}" ${ opencv_public_headers } )
foreach ( module ${ OPENCV_JAVA_MODULES } )
# second run of gen_java.py (at build time)
add_custom_command ( OUTPUT ${ generated_java_sources_${module } } "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp"
2014-06-29 22:45:24 +02:00
C O M M A N D $ { P Y T H O N _ D E F A U L T _ E X E C U T A B L E } " $ { s c r i p t s _ g e n _ j a v a } " " $ { s c r i p t s _ h d r _ p a r s e r } " $ { m o d u l e } $ { o p e n c v _ p u b l i c _ h e a d e r s _ $ { m o d u l e } }
2013-01-22 14:56:04 +01:00
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
D E P E N D S " $ { s c r i p t s _ g e n _ j a v a } " " $ { s c r i p t s _ h d r _ p a r s e r } " $ { o p e n c v _ p u b l i c _ h e a d e r s _ $ { m o d u l e } }
)
endforeach ( )
2012-09-15 13:46:34 +02:00
2015-02-19 14:17:19 +01:00
# step 2: TODO: generate documentation somewhere
2013-01-22 14:56:04 +01:00
# step 3: copy files to destination
2015-02-19 14:17:19 +01:00
set ( step3_input_files ${ generated_java_sources } ${ handwritten_java_sources } ${ handwritten_aidl_sources } )
2013-01-22 14:56:04 +01:00
set ( copied_files "" )
foreach ( java_file ${ step3_input_files } )
2012-02-20 12:50:43 +01:00
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}" )
2013-01-22 14:56:04 +01:00
set ( output_name "${OpenCV_BINARY_DIR}/src/org/opencv/${java_file_name}" )
add_custom_command ( OUTPUT "${output_name}"
2015-09-08 21:42:05 +02:00
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 " $ { j a v a _ f i l e } " " $ { o u t p u t _ n a m e } "
2013-01-22 14:56:04 +01:00
M A I N _ D E P E N D E N C Y " $ { j a v a _ f i l e } "
2015-02-19 14:17:19 +01:00
D E P E N D S $ { s t e p 1 _ d e p e n d s } $ { g e n e r a t e d _ j a v a _ s o u r c e s } $ { h a n d w r i t t e n _ j a v a _ s o u r c e s }
2013-01-22 14:56:04 +01:00
C O M M E N T " G e n e r a t i n g s r c / o r g / o p e n c v / $ { j a v a _ f i l e _ n a m e } "
)
list ( APPEND copied_files "${output_name}" )
2012-03-25 21:57:58 +02:00
2012-02-20 12:50:43 +01:00
if ( ANDROID )
get_filename_component ( install_subdir "${java_file_name}" PATH )
2014-01-17 13:30:31 +01:00
install ( FILES "${output_name}" DESTINATION "${JAVA_INSTALL_ROOT}/src/org/opencv/${install_subdir}" COMPONENT java )
2012-02-20 12:50:43 +01:00
endif ( )
2011-07-22 15:10:50 +02:00
endforeach ( )
2013-01-22 14:56:04 +01:00
if ( ANDROID )
set ( android_copied_files "" )
set ( android_step3_input_files "" )
foreach ( file ${ handwrittren_lib_project_files_rel } )
2013-02-08 15:21:49 +01:00
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${file}" "${OpenCV_BINARY_DIR}/${file}" @ONLY )
2013-01-22 14:56:04 +01:00
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 )
2014-01-17 13:30:31 +01:00
install ( FILES "${OpenCV_BINARY_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT java )
2013-01-22 14:56:04 +01:00
endif ( )
endforeach ( )
# library project jni sources (nothing really depends on them so we will not add them to step3_input_files)
2015-02-19 14:17:19 +01:00
foreach ( jni_file ${ handwritten_cpp_sources } ${ handwritten_h_sources } ${ generated_cpp_sources } )
2013-01-22 14:56:04 +01:00
get_filename_component ( jni_file_name "${jni_file}" NAME )
add_custom_command ( OUTPUT "${OpenCV_BINARY_DIR}/jni/${jni_file_name}"
2015-09-08 21:42:05 +02:00
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 " $ { j n i _ f i l e } " " $ { O p e n C V _ B I N A R Y _ D I R } / j n i / $ { j n i _ f i l e _ n a m e } "
2013-01-22 14:56:04 +01:00
D E P E N D S " $ { j n i _ f i l e } " $ { j a v a _ h d r _ d e p s }
C O M M E N T " G e n e r a t i n g j n i / $ { j n i _ f i l e _ n a m e } "
)
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}/" )
2013-09-10 16:05:45 +02:00
android_get_compatible_target ( lib_target_sdk_target ${ ANDROID_NATIVE_API_LEVEL } ${ ANDROID_SDK_TARGET } 14 )
2013-02-08 15:21:49 +01:00
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${ANDROID_MANIFEST_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" @ONLY )
2013-01-22 14:56:04 +01:00
add_custom_command ( OUTPUT ${ lib_target_files } "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
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 $ { l i b _ t a r g e t _ f i l e s }
2015-09-08 21:42:05 +02:00
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 _ 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 } "
2013-01-22 14:56:04 +01:00
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 _ B I N A R Y _ D I R } \ " - - t a r g e t \ " $ { l i b _ t a r g e t _ s d k _ 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 \ "
2015-09-08 21:42:05 +02:00
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 _ 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 } "
2013-01-22 14:56:04 +01:00
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 $ { a n d r o i d _ s t e p 3 _ i n p u t _ f i l e s } $ { a n d r o i d _ c o p i e d _ f i l e 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 copied_files ${ lib_target_files } "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" )
list ( APPEND step3_input_files "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" )
2014-01-17 13:30:31 +01:00
install ( FILES "${OpenCV_BINARY_DIR}/${ANDROID_PROJECT_PROPERTIES_FILE}" DESTINATION ${ JAVA_INSTALL_ROOT } COMPONENT java )
install ( FILES "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" DESTINATION ${ JAVA_INSTALL_ROOT } COMPONENT java )
2013-01-22 14:56:04 +01:00
# creating empty 'gen' and 'res' folders
2014-01-17 13:30:31 +01:00
install ( CODE "MAKE_DIRECTORY(\" \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/gen\")" COMPONENT java )
install ( CODE "MAKE_DIRECTORY(\" \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/res\")" COMPONENT java )
2013-01-22 14:56:04 +01:00
endif ( ANDROID AND ANDROID_EXECUTABLE )
set ( step3_depends ${ step2_depends } ${ step3_input_files } ${ copied_files } )
2013-02-18 08:23:44 +01:00
if ( ANDROID )
2015-05-20 16:59:42 +02:00
set ( LIB_NAME_SUFIX "${OPENCV_VERSION_MAJOR}" )
2013-02-18 08:23:44 +01:00
else ( )
set ( LIB_NAME_SUFIX "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}" )
endif ( )
2015-06-17 12:11:11 +02:00
file ( MAKE_DIRECTORY "${OpenCV_BINARY_DIR}/bin" )
2013-01-22 14:56:04 +01:00
# 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"
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
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 " $ { J A R _ F I L E } . d e p h e l p e r " # can not rely on classes.jar because different versions of SDK update timestamp at different times
W O R K I N G _ D I R E C T O R Y " $ { O p e n C V _ B I N A R Y _ D I R } "
D E P E N D S $ { s t e p 3 _ 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 "
)
else ( )
# ditto
add_custom_command ( OUTPUT "${JAR_FILE}" "${JAR_FILE}.dephelper"
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 " $ { J A R _ F I L E } "
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 " $ { J A R _ F I L E } . d e p h e l p e r "
W O R K I N G _ D I R E C T O R Y " $ { O p e n C V _ B I N A R Y _ D I R } "
D E P E N D S $ { s t e p 3 _ d e p e n d s }
C O M M E N T " "
)
endif ( )
else ( ANDROID )
2013-02-18 08:23:44 +01:00
set ( JAR_NAME opencv- ${ LIB_NAME_SUFIX } .jar )
2013-01-22 14:56:04 +01:00
set ( JAR_FILE "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}" )
2014-01-29 16:34:02 +01:00
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/build.xml.in" "${OpenCV_BINARY_DIR}/build.xml" @ONLY )
2013-01-22 14:56:04 +01:00
list ( APPEND step3_depends "${OpenCV_BINARY_DIR}/build.xml" )
add_custom_command ( OUTPUT "${JAR_FILE}" "${JAR_FILE}.dephelper"
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 j a r
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 " $ { J A R _ F I L E } . d e p h e l p e r "
W O R K I N G _ D I R E C T O R Y " $ { O p e n C V _ B I N A R Y _ D I R } "
D E P E N D S $ { s t e p 3 _ d e p e n d s }
C O M M E N T " G e n e r a t i n g $ { J A R _ N A M E } "
)
2013-02-11 13:28:19 +01:00
2015-03-12 17:14:14 +01:00
install ( FILES ${ JAR_FILE } OPTIONAL DESTINATION ${ OPENCV_JAR_INSTALL_PATH } COMPONENT java )
2013-01-22 14:56:04 +01:00
endif ( ANDROID )
# step 5: build native part
2013-06-14 18:25:23 +02:00
# workarounding lack of `__attribute__ ((visibility("default")))` in jni_md.h/JNIEXPORT
string ( REPLACE "-fvisibility=hidden" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
2015-02-19 14:17:19 +01:00
ocv_add_library ( ${ the_module } SHARED ${ handwritten_h_sources } ${ handwritten_cpp_sources } ${ generated_cpp_sources }
2013-01-22 14:56:04 +01:00
$ { c o p i e d _ f i l e s }
" $ { J A R _ F I L E } " " $ { J A R _ F I L E } . d e p h e l p e r " )
2013-03-20 17:46:22 +01:00
2012-03-23 18:03:05 +01:00
if ( BUILD_FAT_JAVA_LIB )
set ( __deps ${ OPENCV_MODULE_${the_module } _DEPS} ${ OPENCV_MODULES_BUILD } )
2013-10-24 17:04:41 +02:00
foreach ( m ${ OPENCV_MODULES_BUILD } ) # filterout INTERNAL (like opencv_ts) and BINDINGS (like opencv_python) modules
ocv_assert ( DEFINED OPENCV_MODULE_ ${ m } _CLASS )
if ( NOT OPENCV_MODULE_ ${ m } _CLASS STREQUAL "PUBLIC" )
list ( REMOVE_ITEM __deps ${ m } )
endif ( )
endforeach ( )
2012-03-23 18:03:05 +01:00
ocv_list_unique ( __deps )
set ( __extradeps ${ __deps } )
ocv_list_filterout ( __extradeps "^opencv_" )
if ( __extradeps )
list ( REMOVE_ITEM __deps ${ __extradeps } )
endif ( )
2013-04-03 18:02:13 +02:00
if ( APPLE )
foreach ( _dep ${ __deps } )
2014-08-01 16:11:20 +02:00
ocv_target_link_libraries ( ${ the_module } -Wl,-force_load "${_dep}" )
2013-04-03 18:02:13 +02:00
endforeach ( )
else ( )
2014-08-01 16:11:20 +02:00
ocv_target_link_libraries ( ${ the_module } -Wl,-whole-archive ${ __deps } -Wl,-no-whole-archive )
2013-04-03 18:02:13 +02:00
endif ( )
2014-08-01 16:11:20 +02:00
ocv_target_link_libraries ( ${ the_module } ${ __extradeps } ${ OPENCV_LINKER_LIBS } )
2012-03-23 18:03:05 +01:00
else ( )
2014-08-01 16:11:20 +02:00
ocv_target_link_libraries ( ${ the_module } ${ OPENCV_MODULE_${the_module } _DEPS} ${ OPENCV_LINKER_LIBS } )
2012-03-23 18:03:05 +01:00
endif ( )
2011-07-04 10:18:02 +02:00
2015-05-20 16:59:42 +02:00
# Additional target properties
set_target_properties ( ${ the_module } PROPERTIES
O U T P U T _ N A M E " $ { t h e _ m o d u l e } $ { L I B _ N A M E _ S U F I X } "
A R C H I V E _ O U T P U T _ D I R E C T O R Y $ { L I B R A R Y _ O U T P U T _ P A T H }
L I B R A R Y _ O U T P U T _ D I R E C T O R Y $ { L I B R A R Y _ O U T P U T _ P A T H }
R U N T I M E _ O U T P U T _ D I R E C T O R Y $ { E X E C U T A B L E _ O U T P U T _ P A T H }
I N S T A L L _ N A M E _ D I R $ { O P E N C V _ L I B _ I N S T A L L _ P A T H }
L I N K _ I N T E R F A C E _ L I B R A R I E S " "
)
2011-06-23 17:51:51 +02:00
if ( ANDROID )
2014-08-01 16:11:20 +02:00
ocv_target_link_libraries ( ${ the_module } jnigraphics ) # for Mat <=> Bitmap converters
2015-06-16 15:40:18 +02:00
ocv_target_link_libraries ( ${ the_module } LINK_INTERFACE_LIBRARIES ${ OPENCV_LINKER_LIBS } jnigraphics )
2011-07-04 10:18:02 +02:00
2012-03-25 21:57:58 +02:00
# force strip library after the build command
# because samples and tests will make a copy of the library before install
get_target_property ( __opencv_java_location ${ the_module } LOCATION )
2012-08-14 10:03:05 +02:00
# Turn off stripping in debug build
2012-09-04 11:26:08 +02:00
if ( NOT ( CMAKE_BUILD_TYPE MATCHES "Debug" ) )
2012-08-14 10:03:05 +02:00
add_custom_command ( TARGET ${ the_module } POST_BUILD COMMAND ${ CMAKE_STRIP } --strip-unneeded "${__opencv_java_location}" )
endif ( )
2013-01-22 14:56:04 +01:00
endif ( )
2011-07-22 15:10:50 +02:00
2013-03-05 15:41:44 +01:00
if ( WIN32 )
2013-01-22 16:43:54 +01:00
set_target_properties ( ${ the_module } PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${ EXECUTABLE_OUTPUT_PATH } )
endif ( )
2013-01-22 14:56:04 +01:00
if ( ENABLE_SOLUTION_FOLDERS )
set_target_properties ( ${ the_module } PROPERTIES FOLDER "bindings" )
endif ( )
2011-06-30 16:35:35 +02:00
2013-02-11 13:28:19 +01:00
if ( ANDROID )
2015-01-19 16:03:29 +01:00
ocv_install_target ( ${ the_module } OPTIONAL EXPORT OpenCVModules
2014-01-17 13:30:31 +01:00
L I B R A R Y D E S T I N A T I O N $ { O P E N C V _ L I B _ I N S T A L L _ P A T H } C O M P O N E N T j a v a
A R C H I V E D E S T I N A T I O N $ { O P E N C V _ L I B _ I N S T A L L _ P A T H } C O M P O N E N T j a v a )
2013-02-11 13:28:19 +01:00
else ( )
2013-10-04 15:48:43 +02:00
if ( NOT INSTALL_CREATE_DISTRIB )
2015-01-19 16:03:29 +01:00
ocv_install_target ( ${ the_module } OPTIONAL EXPORT OpenCVModules
2015-03-12 17:14:14 +01:00
R U N T I M E D E S T I N A T I O N $ { O P E N C V _ J A R _ I N S T A L L _ P A T H } C O M P O N E N T j a v a
L I B R A R Y D E S T I N A T I O N $ { O P E N C V _ J A R _ I N S T A L L _ P A T H } C O M P O N E N T j a v a )
2013-10-04 15:48:43 +02:00
else ( )
2015-01-19 16:03:29 +01:00
ocv_install_target ( ${ the_module } OPTIONAL EXPORT OpenCVModules
2015-03-12 17:14:14 +01:00
R U N T I M E D E S T I N A T I O N $ { O P E N C V _ J A R _ I N S T A L L _ P A T H } / $ { O p e n C V _ A R C H } C O M P O N E N T j a v a
L I B R A R Y D E S T I N A T I O N $ { O P E N C V _ J A R _ I N S T A L L _ P A T H } / $ { O p e n C V _ A R C H } C O M P O N E N T j a v a )
2013-10-04 15:48:43 +02:00
endif ( )
2013-02-11 13:28:19 +01:00
endif ( )
2012-09-15 13:46:34 +02:00
2013-01-22 14:56:04 +01:00
######################################################################################################################################
2012-12-19 23:28:59 +01:00
2013-01-22 14:56:04 +01:00
if ( BUILD_TESTS )
if ( ANDROID )
add_subdirectory ( android_test )
else ( )
2015-02-19 14:17:19 +01:00
add_subdirectory ( pure_test )
2013-01-22 14:56:04 +01:00
endif ( )
2012-12-19 23:28:59 +01:00
endif ( )