Install_mac.cmake 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. include(cmake/Platform/Common/Install_common.cmake)
  9. # This is used to generate a setreg file which will be placed inside the bundle
  10. # for targets that request it(eg. AssetProcessor/Editor). This is the relative path
  11. # to the bundle from the installed engine's root. This will be used to compute the
  12. # absolute path to bundle which may contain dependent dylibs(eg. Gems) used by a project.
  13. set(installed_binaries_path_template [[
  14. {
  15. "Amazon": {
  16. "AzCore": {
  17. "Runtime": {
  18. "FilePaths": {
  19. "InstalledBinariesFolder": "@runtime_output_directory@"
  20. }
  21. }
  22. }
  23. }
  24. }]]
  25. )
  26. # This setreg file will be used by all of our installed app bundles to locate installed
  27. # runtime dependencies. It contains the path to binary install directory relative to
  28. # the installed engine root.
  29. string(CONFIGURE "${installed_binaries_path_template}" configured_setreg_file)
  30. file(GENERATE
  31. OUTPUT ${CMAKE_BINARY_DIR}/runtime_install/$<CONFIG>/BinariesInstallPath.setreg
  32. CONTENT "${configured_setreg_file}"
  33. )
  34. # ly_install_run_script isn't defined yet so we use install(SCRIPT) directly.
  35. # This needs to be done here because it needs to update the install prefix
  36. # before cmake does anything else in the install process.
  37. configure_file(${LY_ROOT_FOLDER}/cmake/Platform/Mac/PreInstallSteps_mac.cmake.in ${CMAKE_BINARY_DIR}/runtime_install/PreInstallSteps_mac.cmake @ONLY)
  38. ly_install(SCRIPT ${CMAKE_BINARY_DIR}/runtime_install/PreInstallSteps_mac.cmake COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
  39. #! ly_setup_target_install_targets_override: Mac specific target installation
  40. function(ly_setup_target_install_targets_override)
  41. set(options)
  42. set(oneValueArgs TARGET ARCHIVE_DIR LIBRARY_DIR RUNTIME_DIR LIBRARY_SUBDIR RUNTIME_SUBDIR)
  43. set(multiValueArgs)
  44. cmake_parse_arguments(ly_platform_install_target "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  45. set(target_name "${ly_platform_install_target_TARGET}")
  46. # For bundles on Mac, we set the icons by passing in a path to the Images.xcassets directory.
  47. # However, the CMake install command expects paths to files for the RESOURCE property.
  48. # More details can be found in the CMake issue: https://gitlab.kitware.com/cmake/cmake/-/issues/22409
  49. get_property(is_bundle TARGET ${target_name} PROPERTY MACOSX_BUNDLE)
  50. if (is_bundle)
  51. get_target_property(cached_resources_dir ${target_name} RESOURCE)
  52. set_property(TARGET ${target_name} PROPERTY RESOURCE "")
  53. # Set the target_bundle_dir and target_bundle_content_dir variables to CONFIGURE into
  54. # the InstallUtils_mac.cmake.in template file
  55. set(target_bundle_dir "$<TARGET_BUNDLE_DIR:${target_name}>")
  56. set(target_bundle_content_dir "$<TARGET_BUNDLE_CONTENT_DIR:${target_name}>")
  57. endif()
  58. # Set the target_file_dir variables to CONFIGURE into
  59. # the InstallUtils_mac.cmake.in template file
  60. set(target_file_dir "$<TARGET_FILE_DIR:${target_name}>")
  61. foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
  62. string(TOUPPER ${conf} UCONF)
  63. ly_install(TARGETS ${target_name}
  64. ARCHIVE
  65. DESTINATION ${ly_platform_install_target_ARCHIVE_DIR}
  66. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  67. CONFIGURATIONS ${conf}
  68. LIBRARY
  69. DESTINATION ${ly_platform_install_target_LIBRARY_DIR}/${ly_platform_install_target_LIBRARY_SUBDIR}
  70. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  71. CONFIGURATIONS ${conf}
  72. RUNTIME
  73. DESTINATION ${ly_platform_install_target_RUNTIME_DIR}/${ly_platform_install_target_RUNTIME_SUBDIR}
  74. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  75. CONFIGURATIONS ${conf}
  76. BUNDLE
  77. DESTINATION ${ly_platform_install_target_RUNTIME_DIR}/${ly_platform_install_target_RUNTIME_SUBDIR}
  78. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  79. CONFIGURATIONS ${conf}
  80. RESOURCE
  81. DESTINATION ${ly_platform_install_target_RUNTIME_DIR}/${ly_platform_install_target_RUNTIME_SUBDIR}
  82. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  83. CONFIGURATIONS ${conf}
  84. )
  85. endforeach()
  86. set(install_relative_binaries_path "${ly_platform_install_target_RUNTIME_DIR}/${ly_platform_install_target_RUNTIME_SUBDIR}")
  87. if (is_bundle)
  88. set_property(TARGET ${target_name} PROPERTY RESOURCE ${cached_resources_dir})
  89. set(runtime_output_filename "$<TARGET_FILE_NAME:${target_name}>.app")
  90. else()
  91. set(runtime_output_filename "$<TARGET_FILE_NAME:${target_name}>")
  92. endif()
  93. get_target_property(target_type ${target_name} TYPE)
  94. if(target_type IN_LIST LY_TARGET_TYPES_WITH_RUNTIME_OUTPUTS)
  95. get_target_property(entitlement_file ${target_name} ENTITLEMENT_FILE_PATH)
  96. if (NOT entitlement_file)
  97. set(entitlement_file "none")
  98. endif()
  99. ly_file_read(${LY_ROOT_FOLDER}/cmake/Platform/Mac/runtime_install_mac.cmake.in template_file)
  100. string(CONFIGURE "${template_file}" configured_template_file @ONLY)
  101. file(GENERATE
  102. OUTPUT ${CMAKE_BINARY_DIR}/runtime_install/$<CONFIG>/${target_name}.cmake
  103. CONTENT "${configured_template_file}"
  104. )
  105. endif()
  106. endfunction()
  107. #! ly_setup_runtime_dependencies_copy_function_override: Mac specific copy function to handle frameworks
  108. function(ly_setup_runtime_dependencies_copy_function_override)
  109. configure_file(${LY_ROOT_FOLDER}/cmake/Platform/Mac/InstallUtils_mac.cmake.in ${CMAKE_BINARY_DIR}/runtime_install/InstallUtils_mac.cmake @ONLY)
  110. foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
  111. string(TOUPPER ${conf} UCONF)
  112. ly_install(SCRIPT "${CMAKE_BINARY_DIR}/runtime_install/InstallUtils_mac.cmake"
  113. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  114. )
  115. endforeach()
  116. endfunction()
  117. #! ly_post_install_steps: Any additional platform specific post install steps
  118. function(ly_post_install_steps)
  119. # On Mac, after CMake is done installing, the code signatures on all our built binaries will be invalid.
  120. # We need to now codesign each dynamic library, executable, and app bundle. It's specific to each target
  121. # because there could potentially be different entitlements for different targets.
  122. get_property(all_targets GLOBAL PROPERTY LY_ALL_TARGETS)
  123. foreach(alias_target IN LISTS all_targets)
  124. ly_de_alias_target(${alias_target} target)
  125. # Exclude targets that dont produce runtime outputs
  126. get_target_property(target_type ${target} TYPE)
  127. if(NOT target_type IN_LIST LY_TARGET_TYPES_WITH_RUNTIME_OUTPUTS)
  128. continue()
  129. endif()
  130. ly_install_run_script(${CMAKE_BINARY_DIR}/runtime_install/$<CONFIG>/${target}.cmake)
  131. endforeach()
  132. ly_install_run_code("
  133. ly_download_and_codesign_sdk_python()
  134. ly_codesign_sdk()
  135. set(CMAKE_INSTALL_PREFIX ${LY_INSTALL_PATH_ORIGINAL})
  136. ")
  137. endfunction()