123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- #
- # Copyright (c) Contributors to the Open 3D Engine Project.
- # For complete copyright and license terms please see the LICENSE at the root of this distribution.
- #
- # SPDX-License-Identifier: Apache-2.0 OR MIT
- #
- #
- # Values configured for the output locations of the target
- # Gathered from the generator expression for TARGET_FILE_DIR, TARGET_BUNDLE_DIR
- # and TARGET_BUNDLE_CONTENT_DIR
- cmake_path(SET target_file_dir "@target_file_dir@")
- cmake_path(SET target_bundle_dir "@target_bundle_dir@")
- cmake_path(SET target_bundle_content_dir "@target_bundle_content_dir@")
- function(fixup_qt_framework lib_name framework_path)
- file(REMOVE_RECURSE
- ${framework_path}/Headers
- ${framework_path}/Resources
- ${framework_path}/${lib_name}
- ${framework_path}/Versions/Current
- ${framework_path}/Versions/5/Headers
- )
- execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink 5 Current
- WORKING_DIRECTORY ${framework_path}/Versions
- )
- execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/${lib_name} ${lib_name}
- WORKING_DIRECTORY ${framework_path}
- )
- execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Resources Resources
- WORKING_DIRECTORY ${framework_path}
- )
- endfunction()
- function(fixup_python_framework framework_path)
- file(REMOVE_RECURSE
- "${framework_path}/Versions/Current"
- "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/Headers"
- "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/lib/Python"
- "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/lib/python@LY_PYTHON_VERSION_MAJOR_MINOR@/test"
- "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/lib/python@LY_PYTHON_VERSION_MAJOR_MINOR@/site-packages/scipy/io/tests"
- "${framework_path}/Python"
- "${framework_path}/Resources"
- "${framework_path}/Headers"
- )
- file(GLOB_RECURSE exe_file_list "${framework_path}/**/*.exe")
- if(exe_file_list)
- file(REMOVE_RECURSE ${exe_file_list})
- endif()
- execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink include/python@LY_PYTHON_VERSION_MAJOR_MINOR@m Headers
- WORKING_DIRECTORY "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@"
- )
- execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink @LY_PYTHON_VERSION_MAJOR_MINOR@ Current
- WORKING_DIRECTORY "${framework_path}/Versions/"
- )
- execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink Versions/Current/Python Python
- WORKING_DIRECTORY "${framework_path}"
- )
- execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink Versions/Current/Headers Headers
- WORKING_DIRECTORY "${framework_path}"
- )
- execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink Versions/Current/Resources Resources
- WORKING_DIRECTORY "${framework_path}"
- )
- file(CHMOD "${framework_path}/Versions/Current/Python"
- PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
- )
- endfunction()
- function(codesign_file file entitlement_file)
- if (NOT @LY_ENABLE_HARDENED_RUNTIME@)
- return()
- endif()
- if(EXISTS "${entitlement_file}")
- execute_process(COMMAND "/usr/bin/codesign" "--force" "--sign" "@LY_CODE_SIGN_IDENTITY@" "--deep" "-o" "runtime" "--timestamp" "--entitlements" "${entitlement_file}" "${file}"
- TIMEOUT 300
- OUTPUT_VARIABLE codesign_out
- RESULT_VARIABLE codesign_ret
- )
- else()
- execute_process(COMMAND "/usr/bin/codesign" "--force" "--sign" "@LY_CODE_SIGN_IDENTITY@" "--deep" "-o" "runtime" "--timestamp" "${file}"
- TIMEOUT 300
- OUTPUT_VARIABLE codesign_out
- RESULT_VARIABLE codesign_ret
- )
- endif()
- if(NOT ${codesign_ret} EQUAL "0")
- message(FATAL_ERROR "Codesign operation for ${file_path} returned ${codesign_ret} with message ${codesign_out}")
- endif()
- endfunction()
- function(codesign_python_framework_binaries framework_path)
- if (NOT @LY_ENABLE_HARDENED_RUNTIME@)
- return()
- endif()
- # The codesign "--deep" flag will only codesign binaries in folders with specific names.
- # We need to codesign all the binaries that the "--deep" flag will miss.
- file(GLOB_RECURSE files
- LIST_DIRECTORIES false
- "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/bin/**"
- "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/lib/**"
- "${framework_path}/Versions/@LY_PYTHON_VERSION_MAJOR_MINOR@/Resources/**")
- foreach(file ${files})
- if(NOT EXISTS "${file}")
- file(REMOVE "${file}")
- continue()
- endif()
- cmake_path(SET path_var "${file}")
- cmake_path(GET path_var EXTENSION LAST_ONLY extension)
- set(should_codesign FALSE)
- set(extension_skip_list ".dylib" ".so" ".7m")
- if (NOT extension)
- set(should_codesign TRUE)
- elseif(extension IN_LIST extension_skip_list)
- set(should_codesign TRUE)
- endif()
- if(${should_codesign})
- codesign_file("${file}" "@LY_ROOT_FOLDER@/python/Platform/Mac/PythonEntitlements.plist")
- endif()
- endforeach()
- endfunction()
- function(ly_copy source_files relative_target_directory)
- set(options)
- set(oneValueArgs TARGET_FILE_DIR SOURCE_TYPE SOURCE_GEM_MODULE)
- set(multiValueArgs)
- cmake_parse_arguments("${CMAKE_CURRENT_FUNCTION}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
- set(target_file_dir "${${CMAKE_CURRENT_FUNCTION}_TARGET_FILE_DIR}")
- set(source_type "${${CMAKE_CURRENT_FUNCTION}_SOURCE_TYPE}")
- set(source_is_gem "${${CMAKE_CURRENT_FUNCTION}_SOURCE_GEM_MODULE}")
- # Create the full path to the target directory
- cmake_path(APPEND target_directory "${target_file_dir}" "${relative_target_directory}")
- foreach(source_file IN LISTS source_files)
- if("${source_file}" MATCHES "\\.[Ff]ramework")
- # fixup origin to copy the whole Framework folder
- string(REGEX REPLACE "(.*\\.[Ff]ramework).*" "\\1" source_file "${source_file}")
- endif()
- cmake_path(GET source_file FILENAME target_filename)
- cmake_path(APPEND full_target_directory "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}" "${target_directory}")
- cmake_path(APPEND target_file "${full_target_directory}" "${target_filename}")
- if("${source_file}" IS_NEWER_THAN "${target_file}")
- message(STATUS "Copying ${source_file} to ${full_target_directory}...")
- file(MAKE_DIRECTORY "${full_target_directory}")
- file(COPY "${source_file}" DESTINATION "${full_target_directory}" FILE_PERMISSIONS @LY_COPY_PERMISSIONS@ FOLLOW_SYMLINK_CHAIN)
- file(TOUCH_NOCREATE "${target_file}")
- # Our Qt and Python frameworks aren't in the correct bundle format to be codesigned.
- if("${target_filename}" MATCHES "(Qt[^.]+)\\.[Ff]ramework")
- fixup_qt_framework(${CMAKE_MATCH_1} "${target_file}")
- # For some Qt frameworks(QtCore), signing the bundle doesn't work because of bundle
- # format issues(despite the fixes above). But once we've patched the framework above, there's
- # only one executable that we need to sign so we can do it directly.
- set(target_filename "${target_filename}/Versions/5/${CMAKE_MATCH_1}")
- elseif("${target_filename}" MATCHES "Python.framework")
- fixup_python_framework("${target_file}")
- codesign_python_framework_binaries("${target_file}")
- endif()
- codesign_file("${target_file}" "none")
- endif()
- endforeach()
- endfunction()
- function(ly_download_and_codesign_sdk_python)
- execute_process(COMMAND "${CMAKE_COMMAND}" -DPAL_PLATFORM_NAME=Mac "-DLY_3RDPARTY_PATH=${CMAKE_INSTALL_PREFIX}/python" -P "${CMAKE_INSTALL_PREFIX}/python/get_python.cmake"
- WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}"
- )
- fixup_python_framework("${CMAKE_INSTALL_PREFIX}/python/runtime/@LY_PYTHON_PACKAGE_NAME@/Python.framework")
- codesign_python_framework_binaries("${CMAKE_INSTALL_PREFIX}/python/runtime/@LY_PYTHON_PACKAGE_NAME@/Python.framework")
- codesign_file("${CMAKE_INSTALL_PREFIX}/python/runtime/@LY_PYTHON_PACKAGE_NAME@/Python.framework" "@LY_ROOT_FOLDER@/python/Platform/Mac/PythonEntitlements.plist")
- endfunction()
- function(ly_codesign_sdk)
- codesign_file("${LY_INSTALL_PATH_ORIGINAL}/O3DE_SDK.app" "none")
- endfunction()
|