InstallUtils_mac.cmake.in 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. function(fixup_qt_framework lib_name framework_path)
  9. file(REMOVE_RECURSE
  10. ${framework_path}/Headers
  11. ${framework_path}/Resources
  12. ${framework_path}/${lib_name}
  13. ${framework_path}/Versions/Current
  14. ${framework_path}/Versions/5/Headers
  15. )
  16. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink 5 Current
  17. WORKING_DIRECTORY ${framework_path}/Versions
  18. )
  19. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/${lib_name} ${lib_name}
  20. WORKING_DIRECTORY ${framework_path}
  21. )
  22. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Resources Resources
  23. WORKING_DIRECTORY ${framework_path}
  24. )
  25. endfunction()
  26. function(fixup_python_framework framework_path)
  27. file(REMOVE_RECURSE
  28. ${framework_path}/Versions/Current
  29. ${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/Headers
  30. ${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/lib/Python
  31. ${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/lib/python@LY_PYTHON_VERSION_MAJOR_MINOR@/test
  32. ${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/lib/python@LY_PYTHON_VERSION_MAJOR_MINOR@/site-packages/scipy/io/tests
  33. ${framework_path}/Python
  34. ${framework_path}/Resources
  35. ${framework_path}/Headers
  36. )
  37. file(GLOB_RECURSE exe_file_list "${framework_path}/**/*.exe")
  38. if(exe_file_list)
  39. file(REMOVE_RECURSE ${exe_file_list})
  40. endif()
  41. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink include/python@LY_PYTHON_VERSION_MAJOR_MINOR@m Headers
  42. WORKING_DIRECTORY ${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@
  43. )
  44. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink @LY_PYTHON_VERSION_MAJOR_MINOR@ Current
  45. WORKING_DIRECTORY ${framework_path}/Versions/
  46. )
  47. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Python Python
  48. WORKING_DIRECTORY ${framework_path}
  49. )
  50. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Headers Headers
  51. WORKING_DIRECTORY ${framework_path}
  52. )
  53. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Resources Resources
  54. WORKING_DIRECTORY ${framework_path}
  55. )
  56. file(CHMOD ${framework_path}/Versions/Current/Python
  57. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
  58. )
  59. endfunction()
  60. function(codesign_file file entitlement_file)
  61. if (NOT @LY_ENABLE_HARDENED_RUNTIME@)
  62. return()
  63. endif()
  64. if(EXISTS ${entitlement_file})
  65. execute_process(COMMAND "/usr/bin/codesign" "--force" "--sign" "@LY_CODE_SIGN_IDENTITY@" "--deep" "-o" "runtime" "--timestamp" "--entitlements" "${entitlement_file}" "${file}"
  66. TIMEOUT 300
  67. OUTPUT_VARIABLE codesign_out
  68. RESULT_VARIABLE codesign_ret
  69. )
  70. else()
  71. execute_process(COMMAND "/usr/bin/codesign" "--force" "--sign" "@LY_CODE_SIGN_IDENTITY@" "--deep" "-o" "runtime" "--timestamp" "${file}"
  72. TIMEOUT 300
  73. OUTPUT_VARIABLE codesign_out
  74. RESULT_VARIABLE codesign_ret
  75. )
  76. endif()
  77. if(NOT ${codesign_ret} EQUAL "0")
  78. message(FATAL_ERROR "Codesign operation for ${file_path} returned ${codesign_ret} with message ${codesign_out}")
  79. endif()
  80. endfunction()
  81. function(codesign_python_framework_binaries framework_path)
  82. if (NOT @LY_ENABLE_HARDENED_RUNTIME@)
  83. return()
  84. endif()
  85. # The codesign "--deep" flag will only codesign binaries in folders with specific names.
  86. # We need to codesign all the binaries that the "--deep" flag will miss.
  87. file(GLOB_RECURSE files
  88. LIST_DIRECTORIES false
  89. "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/bin/**"
  90. "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/lib/**"
  91. "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/Resources/**")
  92. foreach(file ${files})
  93. if(NOT EXISTS ${file})
  94. file(REMOVE ${file})
  95. continue()
  96. endif()
  97. cmake_path(SET path_var "${file}")
  98. cmake_path(GET path_var EXTENSION LAST_ONLY extension)
  99. set(should_codesign FALSE)
  100. set(extension_skip_list ".dylib" ".so" ".7m")
  101. if (NOT extension)
  102. set(should_codesign TRUE)
  103. elseif(extension IN_LIST extension_skip_list)
  104. set(should_codesign TRUE)
  105. endif()
  106. if(${should_codesign})
  107. codesign_file("${file}" "@LY_ROOT_FOLDER@/python/Platform/Mac/PythonEntitlements.plist")
  108. endif()
  109. endforeach()
  110. endfunction()
  111. function(ly_copy source_file target_directory)
  112. if("${source_file}" MATCHES "\\.[Ff]ramework[^\\.]")
  113. # fixup origin to copy the whole Framework folder
  114. string(REGEX REPLACE "(.*\\.[Ff]ramework).*" "\\1" source_file "${source_file}")
  115. endif()
  116. get_filename_component(target_filename "${source_file}" NAME)
  117. file(COPY "${source_file}" DESTINATION "${target_directory}" FILE_PERMISSIONS @LY_COPY_PERMISSIONS@ FOLLOW_SYMLINK_CHAIN)
  118. # Our Qt and Python frameworks aren't in the correct bundle format to be codesigned.
  119. if("${target_filename}" MATCHES "(Qt[^.]+)\\.[Ff]ramework")
  120. fixup_qt_framework(${CMAKE_MATCH_1} "${target_directory}/${target_filename}")
  121. # For some Qt frameworks(QtCore), signing the bundle doesn't work because of bundle
  122. # format issues(despite the fixes above). But once we've patched the framework above, there's
  123. # only one executable that we need to sign so we can do it directly.
  124. set(target_filename "${target_filename}/Versions/5/${CMAKE_MATCH_1}")
  125. elseif("${target_filename}" MATCHES "Python.framework")
  126. fixup_python_framework("${target_directory}/${target_filename}")
  127. codesign_python_framework_binaries("${target_directory}/${target_filename}")
  128. endif()
  129. codesign_file("${target_directory}/${target_filename}" "none")
  130. endfunction()
  131. function(ly_download_and_codesign_sdk_python)
  132. execute_process(COMMAND ${CMAKE_COMMAND} -DPAL_PLATFORM_NAME=Mac -DLY_3RDPARTY_PATH=${CMAKE_INSTALL_PREFIX}/python -P ${CMAKE_INSTALL_PREFIX}/python/get_python.cmake)
  133. fixup_python_framework(${CMAKE_INSTALL_PREFIX}/python/runtime/@LY_PYTHON_PACKAGE_NAME@/Python.framework)
  134. codesign_python_framework_binaries(${CMAKE_INSTALL_PREFIX}/python/runtime/@LY_PYTHON_PACKAGE_NAME@/Python.framework)
  135. codesign_file(${CMAKE_INSTALL_PREFIX}/python/runtime/@LY_PYTHON_PACKAGE_NAME@/Python.framework @LY_ROOT_FOLDER@/python/Platform/Mac/PythonEntitlements.plist)
  136. endfunction()
  137. function(ly_codesign_sdk)
  138. codesign_file(${LY_INSTALL_PATH_ORIGINAL}/O3DE_SDK.app "none")
  139. endfunction()