Install_mac.cmake 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. install(SCRIPT ${CMAKE_BINARY_DIR}/runtime_install/PreInstallSteps_mac.cmake COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
  39. #! ly_install_target_override: Mac specific target installation
  40. function(ly_install_target_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. # For bundles on Mac, we set the icons by passing in a path to the Images.xcassets directory.
  46. # However, the CMake install command expects paths to files for the the RESOURCE property.
  47. # More details can be found in the CMake issue: https://gitlab.kitware.com/cmake/cmake/-/issues/22409
  48. get_target_property(is_bundle ${ly_platform_install_target_TARGET} MACOSX_BUNDLE)
  49. if (${is_bundle})
  50. get_target_property(cached_resources_dir ${ly_platform_install_target_TARGET} RESOURCE)
  51. set_property(TARGET ${ly_platform_install_target_TARGET} PROPERTY RESOURCE "")
  52. endif()
  53. install(
  54. TARGETS ${ly_platform_install_target_TARGET}
  55. ARCHIVE
  56. DESTINATION ${ly_platform_install_target_ARCHIVE_DIR}
  57. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  58. LIBRARY
  59. DESTINATION ${ly_platform_install_target_LIBRARY_DIR}/${ly_platform_install_target_LIBRARY_SUBDIR}
  60. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  61. RUNTIME
  62. DESTINATION ${ly_platform_install_target_RUNTIME_DIR}/${ly_platform_install_target_RUNTIME_SUBDIR}
  63. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  64. BUNDLE
  65. DESTINATION ${ly_platform_install_target_RUNTIME_DIR}/${ly_platform_install_target_RUNTIME_SUBDIR}
  66. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  67. RESOURCE
  68. DESTINATION ${ly_platform_install_target_RUNTIME_DIR}/${ly_platform_install_target_RUNTIME_SUBDIR}
  69. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  70. )
  71. set(install_relative_binaries_path "${ly_platform_install_target_RUNTIME_DIR}/${ly_platform_install_target_RUNTIME_SUBDIR}")
  72. if (${is_bundle})
  73. set_property(TARGET ${ly_platform_install_target_TARGET} PROPERTY RESOURCE ${cached_resources_dir})
  74. set(runtime_output_filename "$<TARGET_FILE_NAME:${ly_platform_install_target_TARGET}>.app")
  75. else()
  76. set(runtime_output_filename "$<TARGET_FILE_NAME:${ly_platform_install_target_TARGET}>")
  77. endif()
  78. get_target_property(target_type ${ly_platform_install_target_TARGET} TYPE)
  79. if(target_type IN_LIST LY_TARGET_TYPES_WITH_RUNTIME_OUTPUTS)
  80. get_target_property(entitlement_file ${ly_platform_install_target_TARGET} ENTITLEMENT_FILE_PATH)
  81. if (NOT entitlement_file)
  82. set(entitlement_file "none")
  83. endif()
  84. ly_file_read(${LY_ROOT_FOLDER}/cmake/Platform/Mac/runtime_install_mac.cmake.in template_file)
  85. string(CONFIGURE "${template_file}" configured_template_file @ONLY)
  86. file(GENERATE
  87. OUTPUT ${CMAKE_BINARY_DIR}/runtime_install/$<CONFIG>/${ly_platform_install_target_TARGET}.cmake
  88. CONTENT "${configured_template_file}"
  89. )
  90. endif()
  91. endfunction()
  92. #! ly_install_code_function_override: Mac specific copy function to handle frameworks
  93. function(ly_install_code_function_override)
  94. configure_file(${LY_ROOT_FOLDER}/cmake/Platform/Mac/InstallUtils_mac.cmake.in ${CMAKE_BINARY_DIR}/runtime_install/InstallUtils_mac.cmake @ONLY)
  95. ly_install_run_script(${CMAKE_BINARY_DIR}/runtime_install/InstallUtils_mac.cmake)
  96. endfunction()
  97. #! ly_post_install_steps: Any additional platform specific post install steps
  98. function(ly_post_install_steps)
  99. # On Mac, after CMake is done installing, the code signatures on all our built binaries will be invalid.
  100. # We need to now codesign each dynamic library, executable, and app bundle. It's specific to each target
  101. # because there could potentially be different entitlements for different targets.
  102. get_property(all_targets GLOBAL PROPERTY LY_ALL_TARGETS)
  103. foreach(alias_target IN LISTS all_targets)
  104. ly_de_alias_target(${alias_target} target)
  105. # Exclude targets that dont produce runtime outputs
  106. get_target_property(target_type ${target} TYPE)
  107. if(NOT target_type IN_LIST LY_TARGET_TYPES_WITH_RUNTIME_OUTPUTS)
  108. continue()
  109. endif()
  110. ly_install_run_script(${CMAKE_BINARY_DIR}/runtime_install/$<CONFIG>/${target}.cmake)
  111. endforeach()
  112. ly_install_run_code("
  113. ly_download_and_codesign_sdk_python()
  114. ly_codesign_sdk()
  115. set(CMAKE_INSTALL_PREFIX ${LY_INSTALL_PATH_ORIGINAL})
  116. ")
  117. endfunction()