CMake: Speed up configuration of qml modules with newer CMake

When using CMake 3.21 use the new builtin command for copying files if
they are different.

On my macbook pro 2019, according to cmake's 3.25 profiling,
qt6_target_qml_sources execution speed goes down from 1072ms to 122ms
when processing the imagine style qml module.

Pick-to: 6.5
Change-Id: I46c51d03bc16cadacb64c011fdf9899a88332052
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2023-02-06 17:28:19 +01:00
parent 6ab7e33b05
commit 1f207f4a97
1 changed files with 9 additions and 3 deletions

View File

@ -2049,9 +2049,15 @@ function(qt6_target_qml_sources target)
get_filename_component(file_out_dir ${file_out} DIRECTORY)
file(MAKE_DIRECTORY ${file_out_dir})
execute_process(COMMAND
${CMAKE_COMMAND} -E copy_if_different ${file_absolute} ${file_out}
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.21")
# Significantly increases copying speed according to profiling, presumably
# because we bypass process creation.
file(COPY_FILE "${file_absolute}" "${file_out}" ONLY_IF_DIFFERENT)
else()
execute_process(COMMAND
${CMAKE_COMMAND} -E copy_if_different ${file_absolute} ${file_out}
)
endif()
add_custom_command(OUTPUT ${file_out}
COMMAND ${CMAKE_COMMAND} -E copy ${file_absolute} ${file_out}