From 1300d4bfe1d74e887ffaf5bdb7ed2e3c0e5fe201 Mon Sep 17 00:00:00 2001 From: kimit0310 Date: Thu, 3 Apr 2025 09:50:17 -0400 Subject: [PATCH] fix: Add Apple Silicon (M1/M2/M3) compatibility support for LabRecorder This commit enhances the macOS build process to properly support Apple Silicon processors by: 1. Detecting arm64 architecture during the build process 2. Fixing Qt plugin path references on Apple Silicon to use @executable_path instead of @rpath for proper library loading 3. Implementing a thorough code signing process that handles component level signing for Frameworks and PlugIns These changes address the reported issues with missing dependencies(libbrotlicommon.1.dylib) and code signing errors that prevented LabRecorder from running on Apple Silicon Macs. --- CMakeLists.txt | 54 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04bc856..71933ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,25 +166,45 @@ set(CPACK_DEBIAN_LABRECORDER_PACKAGE_SECTION "science" CACHE INTERNAL "") LSLGenerateCPackConfig() if(APPLE AND NOT DEFINED ENV{GITHUB_ACTIONS}) - # Qt6 QtNetwork depends on libbrotidec which depends on libbroticommon but whose search path uses @loader_path. - # Unfortunately, macdeployqt does not seem to traverse @loader_path dependencies. - # So we are forced to call `fixup_bundle`. For now, we only do this if homebrew is present - # because that seems to be where the bad dependency is coming from. - # Note that fixup_bundle also destroys the codesigning so we have to redo that. - # TODO: Checkout supercollider apple-specific stuff, e.g.: https://github.com/supercollider/supercollider/blob/develop/CMakeLists.txt#L260-L262 - execute_process( + # Qt6 QtNetwork depends on libbrotidec which depends on libbroticommon but whose search path uses @loader_path. + # Unfortunately, macdeployqt does not seem to traverse @loader_path dependencies. + # So we are forced to call `fixup_bundle`. For now, we only do this if homebrew is present + # because that seems to be where the bad dependency is coming from. + # Note that fixup_bundle also destroys the codesigning so we have to redo that. + # TODO: Checkout supercollider apple-specific stuff, e.g.: https://github.com/supercollider/supercollider/blob/develop/CMakeLists.txt#L260-L262 + + # Detect Apple Silicon + execute_process( + COMMAND uname -m + OUTPUT_VARIABLE ARCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Check for Homebrew + execute_process( COMMAND brew --prefix RESULT_VARIABLE BREW_LIB OUTPUT_VARIABLE BREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE ) - if (BREW_LIB EQUAL 0 AND EXISTS "${BREW_PREFIX}") - install(CODE - " - include(BundleUtilities) - fixup_bundle(\"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app\" \"\" \"${BREW_PREFIX}/lib\") - execute_process(COMMAND codesign --force --deep --sign - ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app) - " - ) - endif() -endif(APPLE AND NOT DEFINED ENV{GITHUB_ACTIONS}) + + if (BREW_LIB EQUAL 0 AND EXISTS "${BREW_PREFIX}") + install(CODE + " + include(BundleUtilities) + fixup_bundle(\"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app\" \"\" \"${BREW_PREFIX}/lib\") + + # Fix Qt plugin references specifically for Apple Silicon + if(\"${ARCH}\" STREQUAL \"arm64\") + execute_process(COMMAND install_name_tool -change @rpath/QtGui.framework/Versions/A/QtGui @executable_path/../Frameworks/QtGui + \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app/Contents/PlugIns/platforms/libqcocoa.dylib\") + endif() + + # Re-sign with the same approach the project already uses + execute_process(COMMAND codesign --remove-signature \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app\") + execute_process(COMMAND find \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app/Contents/Frameworks\" -type f -exec codesign --force --sign - {} \\; 2>/dev/null || true) + execute_process(COMMAND find \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app/Contents/PlugIns\" -type f -exec codesign --force --sign - {} \\; 2>/dev/null || true) + execute_process(COMMAND codesign --force --deep --sign - \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app\") " + ) + endif() +endif(APPLE AND NOT DEFINED ENV{GITHUB_ACTIONS}) \ No newline at end of file