runtime_dependencies_linux.cmake.in 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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("${source_file}" MATCHES "@LY_PYTHON_SHARED_LIB@")
  31. # Special case: Since the shared python library is loaded dynamically, it has the potential of being loaded from multiple
  32. # sources. To make sure that duplicate loads to the shared python library load to the same handle, create a soft-symlink
  33. # instead so that the dlopen call can resolve the library properly
  34. # Use the relative path to the package source for the link
  35. set(source_python_package_abs @LY_CURRENT_PYTHON_PACKAGE_PATH@/python/lib/@LY_PYTHON_SHARED_LIB@)
  36. execute_process(COMMAND ln -s -f "${source_python_package_abs}" @LY_PYTHON_SHARED_LIB@
  37. WORKING_DIRECTORY "${target_directory}")
  38. elseif(NOT ${same_location})
  39. file(LOCK "${target_file}.lock" GUARD FUNCTION TIMEOUT 300)
  40. file(SIZE "${source_file}" source_file_size)
  41. if(EXISTS "${target_file}")
  42. file(SIZE "${target_file}" target_file_size)
  43. else()
  44. set(target_file_size 0)
  45. endif()
  46. if((NOT source_file_size EQUAL target_file_size) OR "${source_file}" IS_NEWER_THAN "${target_file}")
  47. message(STATUS "Copying \"${source_file}\" to \"${target_directory}\"...")
  48. file(MAKE_DIRECTORY "${full_target_directory}")
  49. file(COPY "${source_file}" DESTINATION "${target_directory}" USE_SOURCE_PERMISSIONS FOLLOW_SYMLINK_CHAIN)
  50. file(TOUCH_NOCREATE "${target_file}")
  51. # Special case, shared libraries that are copied from qt/plugins have their RPATH set to \$ORIGIN/../../lib
  52. # which is the correct relative path based on the source location. But when we copy it to their subfolder,
  53. # the rpath needs to be adjusted to the parent ($ORIGIN/..)
  54. if("${source_file}" MATCHES "qt/plugins" AND "${target_filename_ext}" STREQUAL ".so")
  55. file(RPATH_CHANGE FILE "${target_file}" OLD_RPATH "\$ORIGIN/../../lib" NEW_RPATH "\$ORIGIN/..")
  56. endif()
  57. endif()
  58. endif()
  59. endforeach()
  60. endfunction()
  61. @LY_COPY_COMMANDS@
  62. file(TOUCH "@STAMP_OUTPUT_FILE@")