Skip to content

Commit fa35a5c

Browse files
authored
Merge pull request #126 from kimit0310/fix/issue-125-apple-silicon-compatibility
fix(apple_silicon): Add Apple Silicon (M1/M2/M3) compatibility support
2 parents b4ccb2f + 1300d4b commit fa35a5c

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

CMakeLists.txt

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,45 @@ set(CPACK_DEBIAN_LABRECORDER_PACKAGE_SECTION "science" CACHE INTERNAL "")
166166
LSLGenerateCPackConfig()
167167

168168
if(APPLE AND NOT DEFINED ENV{GITHUB_ACTIONS})
169-
# Qt6 QtNetwork depends on libbrotidec which depends on libbroticommon but whose search path uses @loader_path.
170-
# Unfortunately, macdeployqt does not seem to traverse @loader_path dependencies.
171-
# So we are forced to call `fixup_bundle`. For now, we only do this if homebrew is present
172-
# because that seems to be where the bad dependency is coming from.
173-
# Note that fixup_bundle also destroys the codesigning so we have to redo that.
174-
# TODO: Checkout supercollider apple-specific stuff, e.g.: https://github.com/supercollider/supercollider/blob/develop/CMakeLists.txt#L260-L262
175-
execute_process(
169+
# Qt6 QtNetwork depends on libbrotidec which depends on libbroticommon but whose search path uses @loader_path.
170+
# Unfortunately, macdeployqt does not seem to traverse @loader_path dependencies.
171+
# So we are forced to call `fixup_bundle`. For now, we only do this if homebrew is present
172+
# because that seems to be where the bad dependency is coming from.
173+
# Note that fixup_bundle also destroys the codesigning so we have to redo that.
174+
# TODO: Checkout supercollider apple-specific stuff, e.g.: https://github.com/supercollider/supercollider/blob/develop/CMakeLists.txt#L260-L262
175+
176+
# Detect Apple Silicon
177+
execute_process(
178+
COMMAND uname -m
179+
OUTPUT_VARIABLE ARCH
180+
OUTPUT_STRIP_TRAILING_WHITESPACE
181+
)
182+
183+
# Check for Homebrew
184+
execute_process(
176185
COMMAND brew --prefix
177186
RESULT_VARIABLE BREW_LIB
178187
OUTPUT_VARIABLE BREW_PREFIX
179188
OUTPUT_STRIP_TRAILING_WHITESPACE
180189
)
181-
if (BREW_LIB EQUAL 0 AND EXISTS "${BREW_PREFIX}")
182-
install(CODE
183-
"
184-
include(BundleUtilities)
185-
fixup_bundle(\"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app\" \"\" \"${BREW_PREFIX}/lib\")
186-
execute_process(COMMAND codesign --force --deep --sign - ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app)
187-
"
188-
)
189-
endif()
190-
endif(APPLE AND NOT DEFINED ENV{GITHUB_ACTIONS})
190+
191+
if (BREW_LIB EQUAL 0 AND EXISTS "${BREW_PREFIX}")
192+
install(CODE
193+
"
194+
include(BundleUtilities)
195+
fixup_bundle(\"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app\" \"\" \"${BREW_PREFIX}/lib\")
196+
197+
# Fix Qt plugin references specifically for Apple Silicon
198+
if(\"${ARCH}\" STREQUAL \"arm64\")
199+
execute_process(COMMAND install_name_tool -change @rpath/QtGui.framework/Versions/A/QtGui @executable_path/../Frameworks/QtGui
200+
\"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app/Contents/PlugIns/platforms/libqcocoa.dylib\")
201+
endif()
202+
203+
# Re-sign with the same approach the project already uses
204+
execute_process(COMMAND codesign --remove-signature \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app\")
205+
execute_process(COMMAND find \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app/Contents/Frameworks\" -type f -exec codesign --force --sign - {} \\; 2>/dev/null || true)
206+
execute_process(COMMAND find \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app/Contents/PlugIns\" -type f -exec codesign --force --sign - {} \\; 2>/dev/null || true)
207+
execute_process(COMMAND codesign --force --deep --sign - \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/${PROJECT_NAME}.app\") "
208+
)
209+
endif()
210+
endif(APPLE AND NOT DEFINED ENV{GITHUB_ACTIONS})

0 commit comments

Comments
 (0)