CMake:Android: copy templates, bindings and gradle files pre_build

At the moment when doing a non-prefix build and changing some of those
files, CMake will not update the changes to the build folder unless
done manually or a re-configure is done manually.

qt_copy_or_install() only does copy those files at configure time once,
and using CMAKE_CONFIGURE_DEPENDS would be an overkill here and even
a bit of an extra annoyance, so in this case having a custom command
seem to be suitable.

Done-with: Alexey Edelev <alexey.edelev@qt.io>
Change-Id: I55aa9e9d3eea32a4bb54c64abd4cbdcb891c44b6
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Assam Boudjelthia 2022-11-25 16:48:26 +02:00
parent fd6b136337
commit 633ab16bc8
4 changed files with 88 additions and 0 deletions

View File

@ -183,3 +183,67 @@ function(_qt_internal_create_versioned_link_or_copy install_dir base_name suffix
list(JOIN code "\n" code) list(JOIN code "\n" code)
install(CODE "${code}") install(CODE "${code}")
endfunction() endfunction()
# Use case is copying files or directories in a non-prefix build with each build, so that changes
# are available each time, this is useful for some Android templates that are needed for building,
# apks and need to sync changes each time a build is started
function(qt_internal_copy_at_build_time)
set(flags)
set(options TARGET DESTINATION)
set(multiopts FILES DIRECTORIES)
cmake_parse_arguments(arg "${flags}" "${options}" "${multiopts}" ${ARGN})
file(MAKE_DIRECTORY "${arg_DESTINATION}")
unset(outputs)
foreach(dir_to_copy IN LISTS arg_DIRECTORIES)
get_filename_component(file_name "${dir_to_copy}" NAME)
set(destination_file_name "${arg_DESTINATION}/${file_name}")
file(GLOB_RECURSE all_files_in_dir RELATIVE "${dir_to_copy}" "${dir_to_copy}/*")
set(dir_outputs ${all_files_in_dir})
set(dir_deps ${all_files_in_dir})
list(TRANSFORM dir_outputs PREPEND "${destination_file_name}/")
list(TRANSFORM dir_deps PREPEND "${dir_to_copy}/")
add_custom_command(OUTPUT ${dir_outputs}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${dir_to_copy} "${destination_file_name}"
DEPENDS ${dir_deps}
COMMENT "Copying directory ${dir_to_copy} to ${arg_DESTINATION}."
)
list(APPEND outputs ${dir_outputs})
endforeach()
unset(file_outputs)
unset(files_to_copy)
foreach(path_to_copy IN LISTS arg_FILES)
get_filename_component(file_name "${path_to_copy}" NAME)
set(destination_file_name "${arg_DESTINATION}/${file_name}")
list(APPEND file_outputs "${destination_file_name}")
list(APPEND files_to_copy "${path_to_copy}")
endforeach()
if(files_to_copy)
add_custom_command(OUTPUT ${file_outputs}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${files_to_copy} ${arg_DESTINATION}
DEPENDS ${files_to_copy}
COMMENT "Copying files ${files_to_copy} to ${arg_DESTINATION}."
)
list(APPEND outputs ${file_outputs})
endif()
get_property(count GLOBAL PROPERTY _qt_internal_copy_at_build_time_count)
if(NOT count)
set(count 0)
endif()
add_custom_target(qt_internal_copy_at_build_time_${count} DEPENDS ${outputs})
if(arg_TARGET)
add_dependencies(${arg_TARGET} qt_internal_copy_at_build_time_${count})
endif()
math(EXPR count "${count} + 1")
set_property(GLOBAL PROPERTY _qt_internal_copy_at_build_time_count ${count})
endfunction()

View File

@ -42,3 +42,11 @@ qt_copy_or_install(
DESTINATION DESTINATION
"${destination}" "${destination}"
) )
if(NOT QT_WILL_INSTALL)
qt_internal_copy_at_build_time(TARGET Qt${QtBase_VERSION_MAJOR}GradleScripts
FILES ${gradle_programs} ${gradle_files}
DIRECTORIES ${gradle_wrapper}
DESTINATION ${destination}
)
endif()

View File

@ -53,4 +53,11 @@ qt_path_join(destination ${QT_INSTALL_DIR} "src/android/java")
qt_copy_or_install(DIRECTORY ${resource_directories} qt_copy_or_install(DIRECTORY ${resource_directories}
DESTINATION "${destination}" DESTINATION "${destination}"
) )
if(NOT QT_WILL_INSTALL)
qt_internal_copy_at_build_time(TARGET Qt${QtBase_VERSION_MAJOR}AndroidBindings
DIRECTORIES ${resource_directories}
DESTINATION ${destination})
endif()
# special case end # special case end

View File

@ -25,4 +25,13 @@ qt_copy_or_install(FILES ${template_files}
qt_copy_or_install(DIRECTORY ${template_directories} qt_copy_or_install(DIRECTORY ${template_directories}
DESTINATION "${destination}") DESTINATION "${destination}")
if(NOT QT_WILL_INSTALL)
qt_internal_copy_at_build_time(TARGET Qt${QtBase_VERSION_MAJOR}AndroidTemplates
FILES ${template_files}
DIRECTORIES ${template_directories}
DESTINATION ${destination}
)
endif()
# special case end # special case end