Improve post steps on macOS

This commit is contained in:
David Chavez 2024-11-04 13:55:26 +01:00
parent 79d7503704
commit ac7ee4f13e

View File

@ -342,46 +342,40 @@ if (APPLE)
# Copy required frameworks to bundle # Copy required frameworks to bundle
target_link_libraries(Zelda64Recompiled PRIVATE ${MOLTENVK_PATH} ${VULKAN_LOADER_PATH}) target_link_libraries(Zelda64Recompiled PRIVATE ${MOLTENVK_PATH} ${VULKAN_LOADER_PATH})
add_custom_command(TARGET Zelda64Recompiled POST_BUILD
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/.github/macos/fixup_bundle.cmake
)
# Copy assets folder to the MacOS folder of the app bundle # Post-build steps for macOS bundle
set(TEMP_ASSETS_DIR "${CMAKE_BINARY_DIR}/temp_assets")
add_custom_command(TARGET Zelda64Recompiled POST_BUILD add_custom_command(TARGET Zelda64Recompiled POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/assets ${TEMP_ASSETS_DIR} # 1. Copy and fix frameworks first
COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEMP_ASSETS_DIR}/scss COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/.github/macos/fixup_bundle.cmake
COMMAND ${CMAKE_COMMAND} -E copy_directory ${TEMP_ASSETS_DIR} $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/Resources/assets
COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEMP_ASSETS_DIR}
)
# Copy ICD files to macOS Resources folder # 2. Copy all resources
add_custom_command(TARGET Zelda64Recompiled POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/assets ${CMAKE_BINARY_DIR}/temp_assets
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/Resources/vulkan/icd.d COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/temp_assets/scss
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/.github/macOS/MoltenVK_icd.json $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/Resources/vulkan/icd.d/ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/temp_assets $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/Resources/assets
) COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/temp_assets
# Copy controller db file to macOS Resources folder # 3. Copy Vulkan ICD files
add_custom_command(TARGET Zelda64Recompiled POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/Resources/vulkan/icd.d
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/Resources/ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/.github/macOS/MoltenVK_icd.json $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/Resources/vulkan/icd.d/
)
# Use install_name_tool to set the RPATH after the build # 4. Copy controller database
add_custom_command(TARGET Zelda64Recompiled POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/Resources/
COMMAND install_name_tool -add_rpath "@executable_path/../Frameworks/" $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/MacOS/Zelda64Recompiled
)
# Apply JIT compilation workaround # 5. Set RPATH
add_custom_command(TARGET Zelda64Recompiled POST_BUILD COMMAND install_name_tool -add_rpath "@executable_path/../Frameworks/" $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/MacOS/Zelda64Recompiled
# 6. Apply JIT workaround
COMMAND ${CMAKE_COMMAND} -E echo "Applying JIT compilation workaround" COMMAND ${CMAKE_COMMAND} -E echo "Applying JIT compilation workaround"
COMMAND /bin/bash -c "printf '\\x07' | dd of=$<TARGET_FILE:Zelda64Recompiled> bs=1 seek=160 count=1 conv=notrunc" COMMAND /bin/bash -c "printf '\\x07' | dd of=$<TARGET_FILE:Zelda64Recompiled> bs=1 seek=160 count=1 conv=notrunc"
VERBATIM
)
# Code sign the app bundle with ad-hoc identity # 7. Sign frameworks first
add_custom_command(TARGET Zelda64Recompiled POST_BUILD COMMAND codesign --force --sign - $<TARGET_BUNDLE_DIR:Zelda64Recompiled>/Contents/Frameworks/*
COMMAND codesign --deep --force --sign - $<TARGET_BUNDLE_DIR:Zelda64Recompiled>
COMMENT "Code signing the app bundle with ad-hoc identity" # 8. Finally sign the whole bundle with runtime option
COMMAND codesign --deep --force --sign - --options runtime $<TARGET_BUNDLE_DIR:Zelda64Recompiled>
COMMENT "Performing post-build steps for macOS bundle"
VERBATIM
) )
endif() endif()
@ -428,7 +422,7 @@ endif()
target_link_libraries(Zelda64Recompiled PRIVATE target_link_libraries(Zelda64Recompiled PRIVATE
PatchesLib PatchesLib
RecompiledFuncs RecompiledFuncs
SDL2 SDL2::SDL2
librecomp librecomp
ultramodern ultramodern
rt64 rt64