From 1e808a495d855624b6d1e54c26541146fe665e3f Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 15 Mar 2018 14:17:02 +0300 Subject: [PATCH] cmake: fix android examples dependencies add_dependencies(${target}) doesn't control regeneration of .apk file, because "${target}" is dummy target. --- cmake/OpenCVDetectAndroidSDK.cmake | 41 +++++++++++++++--------------- cmake/copy_files.cmake | 2 +- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake index e0bbd2860a..fb11714733 100644 --- a/cmake/OpenCVDetectAndroidSDK.cmake +++ b/cmake/OpenCVDetectAndroidSDK.cmake @@ -302,6 +302,27 @@ macro(add_android_project target path) else() list(APPEND android_proj_extra_deps opencv_java_android) endif() + + set(_native_deps "") + if(NOT android_proj_IGNORE_JAVA) + set(_native_deps opencv_java) + endif() + if(android_proj_native_deps) + list(APPEND _native_deps ${android_proj_native_deps}) + endif() + if(_native_deps) + list(APPEND android_proj_extra_deps ${_native_deps}) + endif() + + if((android_proj_COPY_LIBS OR ANDROID_EXAMPLES_WITH_LIBS) AND _native_deps) + message(STATUS "Android project with native libs: " ${target} " (" ${_native_deps} ")") + + ocv_copyfiles_append_dir(NATIVE_COPY "${OpenCV_BINARY_DIR}/lib" "${android_proj_bin_dir}/libs" "${OpenCV_BINARY_DIR}/lib/*.so") + ocv_copyfiles_add_target(${target}_copy_libs NATIVE_COPY "Copy native libs for project: ${target}" ${_native_deps}) + + list(APPEND android_proj_extra_deps ${target}_copy_libs) + endif() + add_custom_command( OUTPUT "${android_proj_bin_dir}/bin/${target}-debug.apk" COMMAND ${ANT_EXECUTABLE} -q -noinput -k debug -Djava.target=1.6 -Djava.source=1.6 @@ -315,26 +336,6 @@ macro(add_android_project target path) add_custom_target(${target} ALL SOURCES "${android_proj_bin_dir}/bin/${target}-debug.apk" ) - set(_native_deps "") - if(NOT android_proj_IGNORE_JAVA) - set(_native_deps opencv_java) - endif() - if(android_proj_native_deps) - list(APPEND _native_deps ${android_proj_native_deps}) - endif() - if(_native_deps) - add_dependencies(${target} ${_native_deps}) - endif() - - if((android_proj_COPY_LIBS OR ANDROID_EXAMPLES_WITH_LIBS) AND _native_deps) - message(STATUS "Android project with native libs: " ${target} " (" ${_native_deps} ")") - - ocv_copyfiles_append_dir(NATIVE_COPY "${OpenCV_BINARY_DIR}/lib" "${android_proj_bin_dir}/libs" "${OpenCV_BINARY_DIR}/lib/*.so") - ocv_copyfiles_add_target(${target}_copy_libs NATIVE_COPY "Copy native libs for project: ${target}" ${_native_deps}) - - add_dependencies(${target} ${target}_copy_libs) - endif() - # There is some strange problem with concurrent Android .APK builds: # /tools/ant/build.xml:781: Problem reading /bin/classes.jar' if(__android_project_chain) diff --git a/cmake/copy_files.cmake b/cmake/copy_files.cmake index 2613eee99b..423f7fff9c 100644 --- a/cmake/copy_files.cmake +++ b/cmake/copy_files.cmake @@ -25,7 +25,7 @@ macro(copy_file_ src dst prefix) endif() get_filename_component(target_path "${dst}" PATH) file(MAKE_DIRECTORY "${target_path}") - execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${src} ${dst} + execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${src}" "${dst}" RESULT_VARIABLE SYMLINK_RESULT) if(NOT SYMLINK_RESULT EQUAL 0) #message("Symlink failed, fallback to 'copy'")