@ -5,38 +5,46 @@ if(NOT ANDROID OR NOT PYTHON_EXECUTABLE)
ocv_module_disable ( java )
endif ( )
set ( OPENCV_MODULES_EXPORTED_TO_JAVA opencv_objdetect opencv_features2d opencv_video opencv_highgui opencv_ml opencv_calib3d CACHE STRING "List of modules exported to Java API" )
mark_as_advanced ( OPENCV_MODULES_EXPORTED_TO_JAVA )
set ( the_description "The java bindings" )
ocv_add_module ( java BINDINGS opencv_objdetect opencv_features2d opencv_imgproc opencv_video opencv_highgui opencv_ml opencv_core opencv_calib3d )
ocv_add_module ( java BINDINGS opencv_core opencv_imgproc OPTIONAL ${ OPENCV_MODULES_EXPORTED_TO_JAVA } )
string ( REPLACE "opencv_" "" OPENCV_JAVA_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS}" )
string ( REPLACE "opencv_" "" OPENCV_JAVA_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS};${OPENCV_MODULE_${the_module}_OPT_DEPS}" )
foreach ( module ${ OPENCV_JAVA_MODULES } )
if ( NOT HAVE_opencv_ ${ module } )
list ( REMOVE_ITEM OPENCV_JAVA_MODULES ${ module } )
endif ( )
endforeach ( )
set ( target ${ the_module } )
include_directories ( "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp" )
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 ( CHECK_TEST_COVERAGE "${CMAKE_CURRENT_SOURCE_DIR}/check-tests.py" )
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 ( CHECK_TEST_COVERAGE "${CMAKE_CURRENT_SOURCE_DIR}/check-tests.py" )
# s e t u p r a w j a v a a n d c p p f i l e s generation ( without javadoc and at temporary location )
foreach ( module ${ OPENCV_JAVA_MODULES } )
# g e t l i s t o f m o d u l e h e a d e r s
IF ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist" )
FILE ( STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist" headers_to_parse )
SET ( module_cheaders "" )
SET ( module_cppheaders "" )
if ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist" )
file ( STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist" headers_to_parse )
set ( module_cheaders "" )
set ( module_cppheaders "" )
foreach ( header ${ headers_to_parse } )
list ( APPEND module_cppheaders "${CMAKE_CURRENT_SOURCE_DIR}/../${module}/${header}" )
endforeach ( )
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" )
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" )
list ( SORT module_cheaders )
list ( SORT module_cppheaders )
ENDIF ( )
endif ( )
# a d d d e p e n d e n c i e s t o cmake ( we should rerun cmake if any of these headers are modified )
# a d d d e p e n d e n c i e s t o cmake ( we should rerun cmake if any of these headers is 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 )
@ -46,10 +54,8 @@ foreach(module ${OPENCV_JAVA_MODULES})
configure_file ( "${GEN_JAVA}" "${CMAKE_BINARY_DIR}/junk/gen_java.junk" COPYONLY )
configure_file ( "${HDR_PARSER}" "${CMAKE_BINARY_DIR}/junk/hdr_parser.junk" COPYONLY )
# f i r s t 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 }
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 } / g e n _ j a v a _ o u t "
O U T P U T _ Q U I E T E R R O R _ Q U I E T )
@ -76,17 +82,24 @@ foreach(module ${OPENCV_JAVA_MODULES})
)
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" )
SET ( generated_cpp_sources )
SET ( generated_java_sources )
SET ( documented_java_files )
SET ( undocumented_java_files )
file ( GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp" )
file ( GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.hpp" )
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 )
foreach ( jfile ${ handwrittren_java_sources } )
string ( REGEX REPLACE "^.*/([^+]+)\\+.*\\.java$" "\\1" jmodname "${jfile}" )
if ( DEFINED HAVE_opencv_ ${ jmodname } AND NOT HAVE_opencv_ ${ jmodname } )
list ( REMOVE_ITEM handwrittren_java_sources "${jfile}" )
endif ( )
endforeach ( )
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} )
list ( APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp" )
list ( APPEND generated_java_sources ${ ${module } _generated_java_sources} )
endforeach ( )
# a l l n e e d e d i n c l u d e s
@ -117,7 +130,7 @@ add_custom_command(
)
# c o p y g e n e r a t e d j a v a f i l e s t o t h e f i n a l l o c a t i o n
SET ( JAVA_OUTPUT_DIR "src/org/opencv" )
set ( JAVA_OUTPUT_DIR "src/org/opencv" )
set ( java_files )
foreach ( java_file ${ documented_java_files } )
@ -139,9 +152,10 @@ foreach(java_file ${documented_java_files})
endif ( )
endforeach ( )
# c u s t o m t a r g e t f o r j a v a A P I
set ( api_target ${ target } _api )
ADD_CUSTOM_TARGET ( ${ api_target } DEPENDS ${ java_files } )
add_custom_target ( ${ api_target } DEPENDS ${ java_files } )
# a d d o p e n c v _ j a v a l i b r a r y
@ -164,13 +178,13 @@ if(ANDROID)
# f o r c e s t r i p l i b r a r y a f t e r b u i l d c o m m a n d
# b e c a u s e s a m p l e s a n d t e s t s w i l l m a k e a c o p y o f l i b r a r y b e f o r e i n s t a l l
ADD_CUSTOM_COMMAND (
add_custom_command (
T A R G E T $ { t a r g e t }
P O S T _ B U I L D
C O M M A N D $ { C M A K E _ S T R I P } " $ { L I B R A R Y _ O U T P U T _ P A T H } / l i b $ { t a r g e t } . s o "
)
set ( lib_proj_files )
set ( lib_proj_files "" )
# l i b r a r y p r o j e c t b l a n k
file ( GLOB_RECURSE android_lib_project_files "${CMAKE_CURRENT_SOURCE_DIR}/android/*" )
foreach ( file ${ android_lib_project_files } )
@ -206,14 +220,13 @@ if(ANDROID)
# c r e a t e A n d r o i d l i b r a r y p r o j e c t i n b u i l d f o l d e r
set ( lib_target ${ target } _android_library )
ADD_CUSTOM_TARGET ( ${ lib_target }
add_custom_target ( ${ lib_target }
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ { C M A K E _ B I N A R Y _ D I R } / r e s "
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ { C M A K E _ B I N A R Y _ D I R } / g e n "
D E P E N D S $ { l i b _ p r o j _ f i l e s }
)
if ( ANT_EXECUTABLE AND ANDROID_EXECUTABLE AND ANDROID_TOOLS_Pkg_Revision GREATER 13 )
add_custom_command (
T A R G E T $ { t a r g e t }
add_custom_command ( TARGET ${ target }
C O M M A N D $ { A N D R O I D _ E X E C U T A B L E } u p d a t e l i b - p r o j e c t - - t a r g e t " $ { A N D R O I D _ S D K _ T A R G E T } " - - p a t h " $ { C M A K E _ B I N A R Y _ D I R } "
C O M M A N D $ { A N T _ E X E C U T A B L E } d e b u g
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } "
@ -223,11 +236,11 @@ if(ANDROID)
add_dependencies ( ${ lib_target } ${ api_target } )
add_dependencies ( ${ target } ${ lib_target } )
endif ( ANDROID )
# a n d r o i d t e s t p r o j e c t
if ( BUILD_TESTS )
ocv_check_dependencies ( ${ OPENCV_MODULE_${the_module } _OPT_DEPS} )
if ( BUILD_TESTS AND OCV_DEPENDENCIES_FOUND )
add_android_project ( opencv_test_java "${CMAKE_CURRENT_SOURCE_DIR}/android_test" )
add_custom_command (
@ -235,3 +248,4 @@ if(BUILD_TESTS)
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C H E C K _ T E S T _ C O V E R A G E } " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a n d r o i d _ t e s t / s r c " " $ { C M A K E _ B I N A R Y _ D I R } / s r c " > " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / t e s t s _ c o v e r a g e . l o g "
)
endif ( )