2011-06-23 17:51:51 +02:00
# ----------------------------------------------------------------------------
# CMake file for java support
# ----------------------------------------------------------------------------
2012-02-06 13:45:11 +01:00
if ( NOT ANDROID OR NOT PYTHON_EXECUTABLE )
2012-02-03 12:26:49 +01:00
ocv_module_disable ( java )
endif ( )
2011-07-24 22:44:20 +02:00
2012-03-16 16:11:56 +01:00
set ( OPENCV_MODULES_EXPORTED_TO_JAVA opencv_objdetect opencv_features2d opencv_video opencv_highgui opencv_ml opencv_calib3d opencv_photo CACHE STRING "List of modules exported to Java API" )
2012-02-20 12:50:43 +01:00
mark_as_advanced ( OPENCV_MODULES_EXPORTED_TO_JAVA )
2012-02-03 12:26:49 +01:00
set ( the_description "The java bindings" )
2012-02-20 12:50:43 +01:00
ocv_add_module ( java BINDINGS opencv_core opencv_imgproc OPTIONAL ${ OPENCV_MODULES_EXPORTED_TO_JAVA } )
2011-06-23 17:51:51 +02:00
2012-02-20 12:50:43 +01:00
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 ( )
2011-06-23 17:51:51 +02:00
2012-02-03 12:26:49 +01:00
set ( target ${ the_module } )
2012-03-03 16:49:23 +01:00
ocv_include_directories ( "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp" )
2011-07-24 22:44:20 +02:00
2012-02-20 12:50:43 +01:00
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" )
2011-06-23 17:51:51 +02:00
2011-07-22 15:10:50 +02:00
# setup raw java and cpp files generation (without javadoc and at temporary location)
2011-06-23 17:51:51 +02:00
foreach ( module ${ OPENCV_JAVA_MODULES } )
2012-02-20 12:50:43 +01:00
# 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 "" )
set ( module_cppheaders "" )
foreach ( header ${ headers_to_parse } )
list ( APPEND module_cppheaders "${CMAKE_CURRENT_SOURCE_DIR}/../${module}/${header}" )
2011-07-22 15:10:50 +02:00
endforeach ( )
2012-02-20 12:50:43 +01: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" )
list ( SORT module_cheaders )
list ( SORT module_cppheaders )
endif ( )
# add dependencies to 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 )
endforeach ( )
# 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 }
2011-07-24 22:44:20 +02: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 } / 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 )
2012-02-20 12:50:43 +01:00
# 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/" )
2011-07-24 22:44:20 +02:00
2012-02-20 12:50:43 +01:00
set ( ${ module } _generated_java_sources )
foreach ( f ${ generated_java_sources } )
list ( APPEND ${ module } _generated_java_sources "${CMAKE_CURRENT_BINARY_DIR}/${f}" )
endforeach ( )
2011-07-19 17:37:17 +02:00
2012-02-20 12:50:43 +01:00
# second run
add_custom_command (
2011-07-19 17:37:17 +02:00
O U T P U T $ { $ { m o d u l e } _ g e n e r a t e d _ j a v a _ s o u r c e s }
2011-06-24 09:48:04 +02:00
O U T P U T " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { m o d u l e } . c p p "
2011-06-27 10:24:10 +02:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } " $ { G E N _ J A V A } " " $ { H D R _ P A R S E R } " $ { m o d u l e } $ { m o d u l e _ c h e a d e r s } $ { m o d u l e _ c p p h e a d e r s }
2011-06-23 17:51:51 +02: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 }
2011-06-24 09:48:04 +02:00
D E P E N D S " $ { G E N _ J A V A } "
D E P E N D S " $ { H D R _ P A R S E R } "
2011-07-24 22:44:20 +02:00
D E P E N D S $ { m o d u l e _ c h e a d e r s }
D E P E N D S $ { m o d u l e _ c p p h e a d e r s }
2011-06-23 17:51:51 +02:00
)
endforeach ( )
2012-02-20 12:50:43 +01:00
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 ( )
2011-06-23 17:51:51 +02:00
foreach ( module ${ OPENCV_JAVA_MODULES } )
2012-02-20 12:50:43 +01:00
list ( APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp" )
list ( APPEND generated_java_sources ${ ${module } _generated_java_sources} )
2011-06-23 17:51:51 +02:00
endforeach ( )
2012-02-03 12:26:49 +01:00
# all needed includes
foreach ( module ${ OPENCV_MODULE_${the_module } _DEPS} )
2012-02-20 12:50:43 +01:00
string ( REPLACE "opencv_" "" module "${module}" )
2012-03-03 16:49:23 +01:00
ocv_include_directories ( "${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include" )
2011-06-23 17:51:51 +02:00
endforeach ( )
2011-07-22 15:10:50 +02:00
# created list of documented files targets
foreach ( java_file ${ handwrittren_java_sources } ${ generated_java_sources } )
2012-02-20 12:50:43 +01:00
get_filename_component ( java_file_name "${java_file}" NAME_WE )
if ( NOT java_file_name MATCHES ".*-jdoc$" )
list ( APPEND documented_java_files "${CMAKE_CURRENT_BINARY_DIR}/${java_file_name}-jdoc.java" )
list ( APPEND undocumented_java_files "${java_file}" )
endif ( )
2011-07-22 15:10:50 +02:00
endforeach ( )
# generate javadoc files
2011-07-24 22:44:20 +02:00
file ( GLOB_RECURSE refman_rst_headers "${CMAKE_CURRENT_SOURCE_DIR}/../*.rst" )
2011-07-22 15:10:50 +02:00
add_custom_command (
O U T P U T $ { d o c u m e n t e d _ j a v a _ f i l e s }
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } " $ { G E N _ J A V A D O C } " " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / j a v a " " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } " 2 > " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / g e t _ j a v a d o c _ e r r o r s . l o g "
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 $ { u n d o c u m e n t e d _ j a v a _ f i l e s }
D E P E N D S " $ { G E N _ J A V A D O C } "
D E P E N D S " $ { R S T _ P A R S E R } "
2011-07-24 22:44:20 +02:00
D E P E N D S $ { r e f m a n _ r s t _ h e a d e r s }
2011-07-22 15:10:50 +02:00
)
# copy generated java files to the final location
2012-02-20 12:50:43 +01:00
set ( JAVA_OUTPUT_DIR "src/org/opencv" )
2011-07-22 15:10:50 +02:00
set ( java_files )
foreach ( java_file ${ documented_java_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}" )
2011-06-23 17:51:51 +02:00
2012-02-20 12:50:43 +01:00
add_custom_command (
2011-07-24 22:44:20 +02:00
O U T P U T " $ { C M A K E _ B I N A R Y _ D I R } / $ { J A V A _ O U T P U T _ D I R } / $ { j a v a _ f i l e _ n a m e } "
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y " $ { j a v a _ f i l e } " " $ { C M A K E _ B I N A R Y _ D I R } / $ { J A V A _ O U T P U T _ D I R } / $ { j a v a _ f i l e _ n a m e } "
2011-07-22 15:10:50 +02:00
D E P E N D S " $ { j a v a _ f i l e } "
2011-07-24 22:44:20 +02:00
C O M M E N T " G e n e r a t i n g $ { J A V A _ O U T P U T _ D I R } / $ { j a v a _ f i l e _ n a m e } "
2011-07-22 15:10:50 +02:00
)
2012-02-20 12:50:43 +01:00
list ( APPEND java_files "${CMAKE_BINARY_DIR}/${JAVA_OUTPUT_DIR}/${java_file_name}" )
2011-07-24 22:44:20 +02:00
2012-02-20 12:50:43 +01:00
if ( ANDROID )
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 ( )
2011-07-22 15:10:50 +02:00
endforeach ( )
2012-02-20 12:50:43 +01:00
2011-07-24 22:44:20 +02:00
# custom target for java API
set ( api_target ${ target } _api )
2012-02-20 12:50:43 +01:00
add_custom_target ( ${ api_target } DEPENDS ${ java_files } )
2011-07-24 22:44:20 +02:00
2011-07-22 15:10:50 +02:00
2011-07-24 22:44:20 +02:00
# add opencv_java library
add_library ( ${ target } SHARED ${ handwrittren_h_sources } ${ handwrittren_cpp_sources } ${ generated_cpp_sources } )
2012-03-23 18:03:05 +01:00
if ( BUILD_FAT_JAVA_LIB )
set ( __deps ${ OPENCV_MODULE_${the_module } _DEPS} ${ OPENCV_MODULES_BUILD } )
list ( REMOVE_ITEM __deps ${ the_module } )
ocv_list_unique ( __deps )
set ( __extradeps ${ __deps } )
ocv_list_filterout ( __extradeps "^opencv_" )
if ( __extradeps )
list ( REMOVE_ITEM __deps ${ __extradeps } )
endif ( )
target_link_libraries ( ${ target } -Wl,-whole-archive ${ __deps } -Wl,-no-whole-archive ${ __extradeps } ${ OPENCV_LINKER_LIBS } )
else ( )
target_link_libraries ( ${ target } ${ OPENCV_MODULE_${the_module } _DEPS} ${ OPENCV_LINKER_LIBS } )
endif ( )
2012-02-03 12:26:49 +01:00
add_dependencies ( ${ target } ${ api_target } )
2011-07-04 10:18:02 +02:00
2011-07-22 15:10:50 +02:00
# Additional target properties
set_target_properties ( ${ target } PROPERTIES
O U T P U T _ N A M E " $ { t a r g e t } "
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 }
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 }
2012-03-23 18:03:05 +01:00
L I N K _ I N T E R F A C E _ L I B R A R I E S " "
2011-07-22 15:10:50 +02:00
)
install ( TARGETS ${ target } LIBRARY DESTINATION ${ OPENCV_LIB_INSTALL_PATH } COMPONENT main )
2011-06-23 17:51:51 +02:00
if ( ANDROID )
2012-02-20 12:50:43 +01:00
target_link_libraries ( ${ target } jnigraphics )
2011-07-04 10:18:02 +02:00
2012-02-20 12:50:43 +01:00
# force strip library after build command
# because samples and tests will make a copy of library before install
add_custom_command (
2011-07-04 10:18:02 +02:00
T A R G E T $ { t a r g e t }
P O S T _ B U I L D
2012-03-23 18:03:05 +01:00
C O M M A N D $ { C M A K E _ S T R I P } - - s t r i p - u n n e e d e d " $ { 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 "
2011-07-04 10:18:02 +02:00
)
2011-07-22 15:10:50 +02:00
2012-02-20 12:50:43 +01:00
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 } )
if ( NOT file MATCHES "\\.svn" )
file ( RELATIVE_PATH file_rel "${CMAKE_CURRENT_SOURCE_DIR}/android/" "${file}" )
add_custom_command (
2011-07-22 15:10:50 +02:00
O U T P U T " $ { C M A K E _ B I N A R Y _ D I R } / $ { f i l e _ r e l } "
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y " $ { f i l e } " " $ { C M A K E _ B I N A R Y _ D I R } / $ { f i l e _ r e l } "
D E P E N D S " $ { f i l e } "
C O M M E N T " G e n e r a t i n g $ { f i l e _ r e l } "
)
2011-07-24 22:44:20 +02:00
2012-02-20 12:50:43 +01:00
list ( APPEND lib_proj_files "${CMAKE_BINARY_DIR}/${file_rel}" )
2011-07-22 16:11:16 +02:00
2012-02-20 12:50:43 +01:00
if ( NOT file_rel MATCHES "jni/.+" )
install ( FILES "${CMAKE_BINARY_DIR}/${file_rel}" DESTINATION . COMPONENT main )
endif ( )
endif ( )
endforeach ( )
2011-07-22 15:10:50 +02:00
2012-02-20 12:50:43 +01:00
# library project jni sources
foreach ( jni_file ${ handwrittren_cpp_sources } ${ handwrittren_h_sources } ${ generated_cpp_sources } )
get_filename_component ( jni_file_name "${jni_file}" NAME )
add_custom_command (
2011-07-22 15:10:50 +02:00
O U T P U T " $ { C M A K E _ B I N A R Y _ D I R } / j n i / $ { j n i _ f i l e _ n a m e } "
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y " $ { j n i _ f i l e } " " $ { C M A K E _ B I N A R Y _ D I R } / j n i / $ { j n i _ f i l e _ n a m e } "
2011-07-22 15:34:25 +02:00
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 " $ { C M A K E _ B I N A R Y _ D I R } / j n i / $ { j n i _ f i l e _ n a m e } "
2011-07-22 15:10:50 +02:00
D E P E N D S " $ { j n i _ f i l e } "
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 } "
2012-02-20 12:50:43 +01:00
)
list ( APPEND lib_proj_files "${CMAKE_BINARY_DIR}/jni/${jni_file_name}" )
endforeach ( )
2011-07-04 08:33:10 +02:00
2012-02-20 12:50:43 +01:00
# create Android library project in build folder
set ( lib_target ${ target } _android_library )
add_custom_target ( ${ lib_target }
2011-07-24 22:44:20 +02:00
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 }
2012-02-20 12:50:43 +01:00
)
if ( ANT_EXECUTABLE AND ANDROID_EXECUTABLE AND ANDROID_TOOLS_Pkg_Revision GREATER 13 )
add_custom_command ( TARGET ${ target }
2011-12-01 13:27:03 +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 } 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 } "
2011-10-21 10:35:34 +02:00
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 } "
D E P E N D S $ { l i b _ t a r g e t }
)
2012-02-20 12:50:43 +01:00
endif ( )
2011-06-30 16:35:35 +02:00
2012-02-20 12:50:43 +01:00
add_dependencies ( ${ lib_target } ${ api_target } )
add_dependencies ( ${ target } ${ lib_target } )
2011-07-24 22:44:20 +02:00
endif ( ANDROID )
2011-06-30 16:35:35 +02:00
2011-07-24 22:44:20 +02:00
#android test project
2012-02-20 12:50:43 +01:00
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" )
2011-07-26 10:17:52 +02:00
2012-02-20 12:50:43 +01:00
add_custom_command (
2011-07-26 10:17:52 +02:00
T A R G E T o p e n c v _ t e s t _ j a v a _ a n d r o i d _ p r o j e c t P O S T _ B U I L D
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 "
)
2011-07-24 22:44:20 +02:00
endif ( )
2012-02-20 12:50:43 +01:00