From 7eeaf7dad5d1c28b0e817cb26bad88df58d0c914 Mon Sep 17 00:00:00 2001 From: SJ Date: Wed, 14 Jul 2021 17:32:07 -0700 Subject: [PATCH] Generate install layout for Mac (#2144) * 1. Move call to install(TARGETS...) to its own function to create a platform specific implementation for Mac. 2. Add linker-signed flag to work around cmake install issue. Signed-off-by: amzn-sj * Add newline Signed-off-by: amzn-sj * 1. Rename function to ly_install_target_override and only call it if it has been implemented. 2. Pass in runtime, archive, and library directory paths as params to clean it up a bit. Signed-off-by: amzn-sj --- cmake/Platform/Common/Install_common.cmake | 45 ++++++++++++++------ cmake/Platform/Mac/Configurations_mac.cmake | 4 +- cmake/Platform/Mac/Install_mac.cmake | 46 +++++++++++++++++++-- 3 files changed, 78 insertions(+), 17 deletions(-) diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index 7ab6006220..20b7a7c81d 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -100,18 +100,29 @@ function(ly_setup_target OUTPUT_CONFIGURED_TARGET ALIAS_TARGET_NAME absolute_tar cmake_path(RELATIVE_PATH target_library_output_directory BASE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} OUTPUT_VARIABLE target_library_output_subdirectory) endif() - install( - TARGETS ${TARGET_NAME} - ARCHIVE - DESTINATION ${archive_output_directory}/${PAL_PLATFORM_NAME}/$ - COMPONENT ${install_component} - LIBRARY - DESTINATION ${library_output_directory}/${PAL_PLATFORM_NAME}/$/${target_library_output_subdirectory} - COMPONENT ${install_component} - RUNTIME - DESTINATION ${runtime_output_directory}/${PAL_PLATFORM_NAME}/$/${target_runtime_output_subdirectory} - COMPONENT ${install_component} - ) + if(COMMAND ly_install_target_override) + # Mac needs special handling because of a cmake issue + ly_install_target_override(TARGET ${TARGET_NAME} + ARCHIVE_DIR ${archive_output_directory} + LIBRARY_DIR ${library_output_directory} + RUNTIME_DIR ${runtime_output_directory} + LIBRARY_SUBDIR ${target_library_output_subdirectory} + RUNTIME_SUBDIR ${target_runtime_output_subdirectory} + ) + else() + install( + TARGETS ${TARGET_NAME} + ARCHIVE + DESTINATION ${archive_output_directory}/${PAL_PLATFORM_NAME}/$ + COMPONENT ${install_component} + LIBRARY + DESTINATION ${library_output_directory}/${PAL_PLATFORM_NAME}/$/${target_library_output_subdirectory} + COMPONENT ${install_component} + RUNTIME + DESTINATION ${runtime_output_directory}/${PAL_PLATFORM_NAME}/$/${target_runtime_output_subdirectory} + COMPONENT ${install_component} + ) + endif() # CMakeLists.txt file string(REGEX MATCH "(.*)::(.*)$" match ${ALIAS_TARGET_NAME}) @@ -487,7 +498,7 @@ function(ly_setup_others) # Scripts file(GLOB o3de_scripts "${LY_ROOT_FOLDER}/scripts/o3de.*") - install(FILES + install(PROGRAMS ${o3de_scripts} DESTINATION ./scripts ) @@ -505,6 +516,14 @@ function(ly_setup_others) DESTINATION . REGEX "downloaded_packages" EXCLUDE REGEX "runtime" EXCLUDE + REGEX ".*$\.sh" EXCLUDE + ) + + # For Mac/Linux shell scripts need to be installed as PROGRAMS to have execute permission + file(GLOB python_scripts "${LY_ROOT_FOLDER}/python/*.sh") + install(PROGRAMS + ${python_scripts} + DESTINATION ./python ) # Registry diff --git a/cmake/Platform/Mac/Configurations_mac.cmake b/cmake/Platform/Mac/Configurations_mac.cmake index a3551be3b9..bdb358e9d2 100644 --- a/cmake/Platform/Mac/Configurations_mac.cmake +++ b/cmake/Platform/Mac/Configurations_mac.cmake @@ -28,7 +28,9 @@ else() endif() # Signing -ly_set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS --deep) +# The "-o linker-signed" flag is required as a work-around for the following CMake issue: +# https://gitlab.kitware.com/cmake/cmake/-/issues/21854 +ly_set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "--deep -o linker-signed") # Generate scheme files for Xcode ly_set(CMAKE_XCODE_GENERATE_SCHEME TRUE) diff --git a/cmake/Platform/Mac/Install_mac.cmake b/cmake/Platform/Mac/Install_mac.cmake index 74ebd293ae..40f09a16b0 100644 --- a/cmake/Platform/Mac/Install_mac.cmake +++ b/cmake/Platform/Mac/Install_mac.cmake @@ -5,7 +5,47 @@ # # -# Empty implementations for untested platforms to fix build errors. +#! ly_install_target_override: Mac specific target installation +function(ly_install_target_override) -function(ly_setup_o3de_install) -endfunction() \ No newline at end of file + set(options) + set(oneValueArgs TARGET ARCHIVE_DIR LIBRARY_DIR RUNTIME_DIR LIBRARY_SUBDIR RUNTIME_SUBDIR) + set(multiValueArgs) + cmake_parse_arguments(ly_platform_install_target "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + get_property(install_component TARGET ${ly_platform_install_target_TARGET} PROPERTY INSTALL_COMPONENT) + + # For bundles on Mac, we set the icons by passing in a path to the Images.xcassets directory. + # However, the CMake install command expects paths to files for the the RESOURCE property. + # More details can be found in the CMake issue: https://gitlab.kitware.com/cmake/cmake/-/issues/22409 + get_target_property(is_bundle ${ly_platform_install_target_TARGET} MACOSX_BUNDLE) + if (${is_bundle}) + get_target_property(cached_resources_dir ${ly_platform_install_target_TARGET} RESOURCE) + set_property(TARGET ${ly_platform_install_target_TARGET} PROPERTY RESOURCE "") + endif() + + install( + TARGETS ${ly_platform_install_target_TARGET} + ARCHIVE + DESTINATION ${ly_platform_install_target_ARCHIVE_DIR}/${PAL_PLATFORM_NAME}/$ + COMPONENT ${install_component} + LIBRARY + DESTINATION ${ly_platform_install_target_LIBRARY_DIR}/${PAL_PLATFORM_NAME}/$/${ly_platform_install_target_LIBRARY_SUBDIR} + COMPONENT ${install_component} + RUNTIME + DESTINATION ${ly_platform_install_target_RUNTIME_DIR}/${PAL_PLATFORM_NAME}/$/${ly_platform_install_target_RUNTIME_SUBDIR} + COMPONENT ${install_component} + BUNDLE + DESTINATION ${ly_platform_install_target_RUNTIME_DIR}/${PAL_PLATFORM_NAME}/$/${ly_platform_install_target_RUNTIME_SUBDIR} + COMPONENT ${install_component} + RESOURCE + DESTINATION ${ly_platform_install_target_RUNTIME_DIR}/${PAL_PLATFORM_NAME}/$/${ly_platform_install_target_RUNTIME_SUBDIR}/ + COMPONENT ${install_component} + ) + + if (${is_bundle}) + set_property(TARGET ${ly_platform_install_target_TARGET} PROPERTY RESOURCE ${cached_resources_dir}) + endif() +endfunction() + +include(cmake/Platform/Common/Install_common.cmake)