cmake(android): fix non-idempotent INSTALL scripts

pull/10490/head
Alexander Alekhin 7 years ago
parent f5862dacb6
commit 9966903ae1
  1. 27
      cmake/OpenCVDetectAndroidSDK.cmake

@ -348,9 +348,18 @@ macro(add_android_project target path)
# put the final .apk to the OpenCV's bin folder
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${android_proj_bin_dir}/bin/${target}-debug.apk" "${OpenCV_BINARY_DIR}/bin/${target}.apk")
if(INSTALL_ANDROID_EXAMPLES AND "${target}" MATCHES "^example-")
#apk
install(FILES "${OpenCV_BINARY_DIR}/bin/${target}.apk" DESTINATION "samples" COMPONENT samples)
get_filename_component(sample_dir "${path}" NAME)
# apk
install(FILES "${OpenCV_BINARY_DIR}/bin/${target}.apk" DESTINATION "samples" COMPONENT samples)
# clear "external" project files (need to remove files generated by 'android' tool)
set(external_target_files ${ANDROID_PROJECT_FILES})
ocv_list_add_prefix(external_target_files "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/")
install(CODE "
MESSAGE(STATUS \"Cleaning generated project files from Android sample install directory: ${sample_dir}\")
FOREACH(f ${ANDROID_PROJECT_FILES})
FILE(REMOVE \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/\${f}\")
ENDFOREACH()
" COMPONENT samples)
#java part
list(REMOVE_ITEM android_proj_files ${ANDROID_MANIFEST_FILE})
foreach(f ${android_proj_files} ${ANDROID_MANIFEST_FILE})
@ -368,11 +377,15 @@ macro(add_android_project target path)
if(android_proj_lib_deps_commands)
set(inst_lib_opt " --library ../../sdk/java")
endif()
install(CODE "EXECUTE_PROCESS(COMMAND ${ANDROID_EXECUTABLE} --silent update project --path . --target \"${android_proj_sdk_target}\" --name \"${target}\" ${inst_lib_opt}
WORKING_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}\"
)" COMPONENT samples)
#empty 'gen'
install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/gen\")" COMPONENT samples)
install(CODE "
MESSAGE(STATUS \"Fixing Android library reference for sample: ${sample_dir}\")
EXECUTE_PROCESS(
COMMAND ${ANDROID_EXECUTABLE} --silent update project --path . --target \"${android_proj_sdk_target}\" --name \"${target}\" ${inst_lib_opt}
WORKING_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}\"
)
" COMPONENT samples)
# empty 'gen'
install(CODE "FILE(MAKE_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/gen\")" COMPONENT samples)
endif()
endif()
endmacro()

Loading…
Cancel
Save