InstallUtils_mac.cmake.in 8.4 KB

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