3
0

runtime_dependencies_linux.cmake.in 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. cmake_minimum_required(VERSION 3.22)
  9. cmake_policy(SET CMP0012 NEW) # new policy for the if that evaluates a boolean out of "if(NOT ${same_location})"
  10. cmake_path(SET target_file_dir "@target_file_dir@")
  11. set(target_copy_files $<FILTER:$<REMOVE_DUPLICATES:"@target_copy_files@">,EXCLUDE,"^$">)
  12. set(target_target_files $<FILTER:$<REMOVE_DUPLICATES:"@target_target_files@">,EXCLUDE,"^$">)
  13. set(target_link_files $<FILTER:$<REMOVE_DUPLICATES:"@target_link_files@">,EXCLUDE,"^$">)
  14. set(target_imported_files $<FILTER:$<REMOVE_DUPLICATES:"@target_imported_files@">,EXCLUDE,"^$">)
  15. function(ly_copy source_files relative_target_directory)
  16. set(options)
  17. set(oneValueArgs TARGET_FILE_DIR SOURCE_TYPE SOURCE_GEM_MODULE)
  18. set(multiValueArgs)
  19. cmake_parse_arguments("${CMAKE_CURRENT_FUNCTION}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  20. set(target_file_dir "${${CMAKE_CURRENT_FUNCTION}_TARGET_FILE_DIR}")
  21. set(source_type "${${CMAKE_CURRENT_FUNCTION}_SOURCE_TYPE}")
  22. set(source_is_gem "${${CMAKE_CURRENT_FUNCTION}_SOURCE_GEM_MODULE}")
  23. # Create the full path to the target directory
  24. cmake_path(APPEND target_directory "${target_file_dir}" "${relative_target_directory}")
  25. foreach(source_file IN LISTS source_files)
  26. cmake_path(GET source_file FILENAME target_filename)
  27. cmake_PATH(GET source_file EXTENSION target_filename_ext)
  28. cmake_path(APPEND target_file "${target_directory}" "${target_filename}")
  29. cmake_path(COMPARE "${source_file}" EQUAL "${target_file}" same_location)
  30. if(NOT ${same_location})
  31. file(LOCK "${target_file}.lock" GUARD FUNCTION TIMEOUT 300)
  32. file(SIZE "${source_file}" source_file_size)
  33. if(EXISTS "${target_file}")
  34. file(SIZE "${target_file}" target_file_size)
  35. else()
  36. set(target_file_size 0)
  37. endif()
  38. if((NOT source_file_size EQUAL target_file_size) OR "${source_file}" IS_NEWER_THAN "${target_file}")
  39. message(STATUS "Copying \"${source_file}\" to \"${target_directory}\"...")
  40. file(MAKE_DIRECTORY "${full_target_directory}")
  41. file(COPY "${source_file}" DESTINATION "${target_directory}" FILE_PERMISSIONS @LY_COPY_PERMISSIONS@ FOLLOW_SYMLINK_CHAIN)
  42. file(TOUCH_NOCREATE "${target_file}")
  43. # Special case, shared libraries that are copied from qt/plugins have their RPATH set to \$ORIGIN/../../lib
  44. # which is the correct relative path based on the source location. But when we copy it to their subfolder,
  45. # the rpath needs to be adjusted to the parent ($ORIGIN/..)
  46. if("${source_file}" MATCHES "qt/plugins" AND "${target_filename_ext}" STREQUAL ".so")
  47. file(RPATH_CHANGE FILE "${target_file}" OLD_RPATH "\$ORIGIN/../../lib" NEW_RPATH "\$ORIGIN/..")
  48. endif()
  49. endif()
  50. endif()
  51. endforeach()
  52. endfunction()
  53. @LY_COPY_COMMANDS@
  54. file(TOUCH "@STAMP_OUTPUT_FILE@")