RuntimeDependencies_ios.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. ly_set(IOS_FRAMEWORK_TARGET_TYPES MODULE_LIBRARY SHARED_LIBRARY)
  9. ly_set(LY_TARGET_TYPES_WITH_RUNTIME_OUTPUTS MODULE_LIBRARY SHARED_LIBRARY EXECUTABLE)
  10. include(cmake/Platform/Common/RuntimeDependencies_common.cmake)
  11. function(o3de_get_filtered_dependencies_for_target dependencies target)
  12. unset(filtered_dependencies)
  13. unset(target_copy_dependencies)
  14. unset(target_target_dependencies)
  15. unset(target_link_dependencies)
  16. unset(target_imported_dependencies)
  17. o3de_get_dependencies_for_target(
  18. TARGET "${target}"
  19. COPY_DEPENDENCIES_VAR target_copy_dependencies
  20. TARGET_DEPENDENCIES_VAR target_target_dependencies
  21. LINK_DEPENDENCIES_VAR target_link_dependencies
  22. IMPORTED_DEPENDENCIES_VAR target_imported_dependencies
  23. )
  24. # o3de_get_dependencies_for_target also returns asset files that are
  25. # associated with a target. However, we only want frameworks(runtime
  26. # libraries) here which Xcode will embed in the app bundle
  27. # Those dependenices come from the LINK_DEPENDENCIES for the target
  28. foreach(dependency IN LISTS target_link_dependencies)
  29. if (TARGET ${dependency})
  30. # Imported libraries are used as alias to other targets, so
  31. # only non imported dependencies will be appended.
  32. get_property(dependency_is_imported TARGET ${dependency} PROPERTY IMPORTED)
  33. if (NOT dependency_is_imported)
  34. list(APPEND filtered_dependencies ${dependency})
  35. endif()
  36. # Recursively resolve alias' dependencies.
  37. # Retrieve the de-aliased targets using the target dependency as key into the O3DE_ALIASED_TARGETS_* "dict"
  38. get_property(dealiased_targets GLOBAL PROPERTY O3DE_ALIASED_TARGETS_${dependency})
  39. if (dealiased_targets)
  40. foreach(dealiased_target ${dealiased_targets})
  41. unset(dealiased_dependencies)
  42. ly_get_filtered_runtime_dependencies(dealiased_dependencies ${dealiased_target})
  43. list(APPEND filtered_dependencies ${dealiased_dependencies})
  44. endforeach()
  45. endif()
  46. endif()
  47. endforeach()
  48. list(REMOVE_DUPLICATES filtered_dependencies)
  49. set(${dependencies} ${filtered_dependencies} PARENT_SCOPE)
  50. endfunction()
  51. function(ly_delayed_generate_runtime_dependencies)
  52. # For each (non-monolithic) game project, find runtime dependencies and tell XCode to embed/sign them
  53. if(NOT LY_MONOLITHIC_GAME)
  54. get_property(project_names GLOBAL PROPERTY O3DE_PROJECTS_NAME)
  55. foreach(project_name IN LISTS project_names)
  56. # Recursively get all dependent frameworks for the game project.
  57. unset(dependencies)
  58. o3de_get_filtered_dependencies_for_target(dependencies ${project_name}.GameLauncher)
  59. if(dependencies)
  60. set_target_properties(${project_name}.GameLauncher
  61. PROPERTIES
  62. XCODE_EMBED_FRAMEWORKS "${dependencies}"
  63. XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY TRUE
  64. XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks"
  65. )
  66. endif()
  67. endforeach()
  68. endif()
  69. get_property(all_targets GLOBAL PROPERTY LY_ALL_TARGETS)
  70. unset(test_runner_dependencies)
  71. foreach(aliased_target IN LISTS all_targets)
  72. unset(target)
  73. ly_de_alias_target(${aliased_target} target)
  74. # Exclude targets that dont produce runtime outputs
  75. get_target_property(target_type ${target} TYPE)
  76. if(NOT target_type IN_LIST LY_TARGET_TYPES_WITH_RUNTIME_OUTPUTS)
  77. continue()
  78. endif()
  79. file(GENERATE
  80. OUTPUT ${CMAKE_BINARY_DIR}/runtime_dependencies/$<CONFIG>/${target}.cmake
  81. CONTENT ""
  82. )
  83. if(target_type IN_LIST IOS_FRAMEWORK_TARGET_TYPES)
  84. list(APPEND test_runner_dependencies ${target})
  85. endif()
  86. endforeach()
  87. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  88. add_dependencies("AzTestRunner" ${test_runner_dependencies})
  89. # We still need to add indirect dependencies(eg. 3rdParty)
  90. unset(dependencies)
  91. o3de_get_filtered_dependencies_for_target(dependencies AzTestRunner)
  92. if(dependencies)
  93. set_target_properties("AzTestRunner"
  94. PROPERTIES
  95. XCODE_EMBED_FRAMEWORKS "${dependencies}"
  96. XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY TRUE
  97. XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks"
  98. )
  99. endif()
  100. endif()
  101. endfunction()