Detects changes in size of the copied runtime dependency (#5711)

* Detects changes in size of the copied runtime dependency, this enables a 3rdparty to switch which runtime dependencies to use and get the new ones copied

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>

* simplifies some parameters, (addresses PR comments)

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
Esteban Papp
2021-11-17 12:43:07 -08:00
committed by GitHub
parent aaafb3ee34
commit 6d8ca966f3
5 changed files with 49 additions and 25 deletions
+2 -2
View File
@@ -354,7 +354,7 @@ function(ly_add_target)
# of running the copy of runtime dependencies, the stamp file is touched so the timestamp is updated.
# Adding a config as part of the name since the stamp file is added to the VS project.
# Note the STAMP_OUTPUT_FILE need to match with the one used in runtime dependencies (e.g. RuntimeDependencies_common.cmake)
set(STAMP_OUTPUT_FILE ${CMAKE_BINARY_DIR}/runtime_dependencies/$<CONFIG>/${ly_add_target_NAME}_$<CONFIG>.stamp)
set(STAMP_OUTPUT_FILE ${CMAKE_BINARY_DIR}/runtime_dependencies/$<CONFIG>/${ly_add_target_NAME}.stamp)
add_custom_command(
OUTPUT ${STAMP_OUTPUT_FILE}
DEPENDS "$<GENEX_EVAL:$<TARGET_PROPERTY:${ly_add_target_NAME},RUNTIME_DEPENDENCIES_DEPENDS>>"
@@ -367,7 +367,7 @@ function(ly_add_target)
# stamp file on each configuration so it gets properly excluded by the generator
unset(stamp_files_per_config)
foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
set(stamp_file_conf ${CMAKE_BINARY_DIR}/runtime_dependencies/${conf}/${ly_add_target_NAME}_${conf}.stamp)
set(stamp_file_conf ${CMAKE_BINARY_DIR}/runtime_dependencies/${conf}/${ly_add_target_NAME}.stamp)
set_source_files_properties(${stamp_file_conf} PROPERTIES GENERATED TRUE SKIP_AUTOGEN TRUE)
list(APPEND stamp_files_per_config $<$<CONFIG:${conf}>:${stamp_file_conf}>)
endforeach()
@@ -272,7 +272,7 @@ function(ly_delayed_generate_runtime_dependencies)
endforeach()
# Generate the output file, note the STAMP_OUTPUT_FILE need to match with the one defined in LYWrappers.cmake
set(STAMP_OUTPUT_FILE ${CMAKE_BINARY_DIR}/runtime_dependencies/$<CONFIG>/${target}_$<CONFIG>.stamp)
set(STAMP_OUTPUT_FILE ${CMAKE_BINARY_DIR}/runtime_dependencies/$<CONFIG>/${target}.stamp)
set(target_file_dir "$<TARGET_FILE_DIR:${target}>")
set(target_file "$<TARGET_FILE:${target}>")
ly_file_read(${LY_RUNTIME_DEPENDENCIES_TEMPLATE} template_file)
@@ -9,14 +9,21 @@
cmake_policy(SET CMP0012 NEW) # new policy for the if that evaluates a boolean out of "if(NOT ${same_location})"
function(ly_copy source_file target_directory)
get_filename_component(target_filename "${source_file}" NAME)
cmake_path(COMPARE "${source_file}" EQUAL "${target_directory}/${target_filename}" same_location)
cmake_path(GET source_file FILENAME target_filename)
cmake_path(APPEND target_file "${target_directory}" "${target_filename}")
cmake_path(COMPARE "${source_file}" EQUAL "${target_file}" same_location)
if(NOT ${same_location})
file(LOCK ${target_directory}/${target_filename}.lock GUARD FUNCTION TIMEOUT 300)
if("${source_file}" IS_NEWER_THAN "${target_directory}/${target_filename}")
file(LOCK ${target_file}.lock GUARD FUNCTION TIMEOUT 300)
file(SIZE "${source_file}" source_file_size)
if(EXISTS "${target_file}")
file(SIZE "${target_file}" target_file_size)
else()
set(target_file_size 0)
endif()
if((NOT source_file_size EQUAL target_file_size) OR "${source_file}" IS_NEWER_THAN "${target_file}")
message(STATUS "Copying \"${source_file}\" to \"${target_directory}\"...")
file(COPY "${source_file}" DESTINATION "${target_directory}" FILE_PERMISSIONS @LY_COPY_PERMISSIONS@ FOLLOW_SYMLINK_CHAIN)
file(TOUCH_NOCREATE ${target_directory}/${target_filename})
file(TOUCH_NOCREATE ${target_file})
endif()
endif()
endfunction()
@@ -9,23 +9,32 @@
cmake_policy(SET CMP0012 NEW) # new policy for the if that evaluates a boolean out of "if(NOT ${same_location})"
function(ly_copy source_file target_directory)
get_filename_component(target_filename "${source_file}" NAME)
get_filename_component(target_filename_ext "${source_file}" LAST_EXT)
cmake_path(COMPARE "${source_file}" EQUAL "${target_directory}/${target_filename}" same_location)
cmake_path(GET source_file FILENAME target_filename)
cmake_path(APPEND target_file "${target_directory}" "${target_filename}")
cmake_path(COMPARE "${source_file}" EQUAL "${target_file}" same_location)
if(NOT ${same_location})
file(LOCK ${target_directory}/${target_filename}.lock GUARD FUNCTION TIMEOUT 300)
if("${source_file}" IS_NEWER_THAN "${target_directory}/${target_filename}")
file(LOCK ${target_file}.lock GUARD FUNCTION TIMEOUT 300)
file(SIZE "${source_file}" source_file_size)
if(EXISTS "${target_file}")
file(SIZE "${target_file}" target_file_size)
else()
set(target_file_size 0)
endif()
if((NOT source_file_size EQUAL target_file_size) OR "${source_file}" IS_NEWER_THAN "${target_file}")
message(STATUS "Copying \"${source_file}\" to \"${target_directory}\"...")
file(COPY "${source_file}" DESTINATION "${target_directory}" FILE_PERMISSIONS @LY_COPY_PERMISSIONS@ FOLLOW_SYMLINK_CHAIN)
file(TOUCH_NOCREATE "${target_file}")
# Special case, shared libraries that are copied from qt/plugins have their RPATH set to \$ORIGIN/../../lib
# which is the correct relative path based on the source location. But when we copy it to their subfolder,
# the rpath needs to be adjusted to the parent ($ORIGIN/..)
if("${source_file}" MATCHES "qt/plugins" AND "${target_filename_ext}" STREQUAL ".so")
file(RPATH_CHANGE FILE "${target_directory}/${target_filename}" OLD_RPATH "\$ORIGIN/../../lib" NEW_RPATH "\$ORIGIN/..")
file(RPATH_CHANGE FILE "${target_file}" OLD_RPATH "\$ORIGIN/../../lib" NEW_RPATH "\$ORIGIN/..")
endif()
endif()
endif()
endfunction()
@LY_COPY_COMMANDS@
file(TOUCH @STAMP_OUTPUT_FILE@)
@@ -34,7 +34,7 @@ endif()
function(ly_copy source_file target_directory)
get_filename_component(target_filename "${source_file}" NAME)
cmake_path(GET source_file FILENAME target_filename)
# If target_directory is a bundle
if("${target_directory}" MATCHES "\\.app/Contents/MacOS")
@@ -113,20 +113,28 @@ function(ly_copy source_file target_directory)
endif()
cmake_path(COMPARE "${source_file}" EQUAL "${target_directory}/${target_filename}" same_location)
cmake_path(APPEND target_file "${target_directory}" "${target_filename}")
cmake_path(COMPARE "${source_file}" EQUAL "${target_file}" same_location)
if(NOT ${same_location})
if(NOT EXISTS "${target_directory}")
file(MAKE_DIRECTORY "${target_directory}")
endif()
if(NOT EXISTS "${target_directory}/${target_filename}" OR "${source_file}" IS_NEWER_THAN "${target_directory}/${target_filename}")
if(NOT target_is_bundle)
# if it is a bundle, there is no contention about the files in the destination, each bundle target will copy everything
# we dont want these files to invalidate the bundle and cause a new signature
file(LOCK ${target_file}.lock GUARD FUNCTION TIMEOUT 300)
endif()
file(SIZE "${source_file}" source_file_size)
if(EXISTS "${target_file}")
file(SIZE "${target_file}" target_file_size)
else()
set(target_file_size 0)
endif()
if((NOT source_file_size EQUAL target_file_size) OR "${source_file}" IS_NEWER_THAN "${target_file}")
message(STATUS "Copying \"${source_file}\" to \"${target_directory}\"...")
if(NOT target_is_bundle)
# if it is a bundle, there is no contention about the files in the destination, each bundle target will copy everything
# we dont want these files to invalidate the bundle and cause a new signature
file(LOCK ${target_directory}/${target_filename}.lock GUARD FUNCTION TIMEOUT 300)
endif()
file(COPY "${source_file}" DESTINATION "${target_directory}" FILE_PERMISSIONS @LY_COPY_PERMISSIONS@ FOLLOW_SYMLINK_CHAIN)
file(TOUCH_NOCREATE ${target_directory}/${target_filename})
file(TOUCH_NOCREATE "${target_file}")
set(anything_new TRUE PARENT_SCOPE)
endif()
endif()