|
| 1 | +# SPDX-License-Identifier: GPL-3.0-only |
| 2 | +# MuseScore-Studio-CLA-applies |
| 3 | +# |
| 4 | +# MuseScore Studio |
| 5 | +# Music Composition & Notation |
| 6 | +# |
| 7 | +# Copyright (C) 2024 MuseScore Limited |
| 8 | +# |
| 9 | +# This program is free software: you can redistribute it and/or modify |
| 10 | +# it under the terms of the GNU General Public License version 3 as |
| 11 | +# published by the Free Software Foundation. |
| 12 | +# |
| 13 | +# This program is distributed in the hope that it will be useful, |
| 14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +# GNU General Public License for more details. |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU General Public License |
| 19 | +# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + |
| 21 | +if(NOT OS_IS_MAC) |
| 22 | + return() |
| 23 | +endif() |
| 24 | + |
| 25 | +set(SWIFT_BUILD_DIR "${CMAKE_BINARY_DIR}/swift_build") |
| 26 | +file(MAKE_DIRECTORY ${SWIFT_BUILD_DIR}) |
| 27 | + |
| 28 | +file(GLOB_RECURSE SWIFT_SOURCES |
| 29 | + "${CMAKE_CURRENT_SOURCE_DIR}/**/*.swift" |
| 30 | + "${CMAKE_CURRENT_SOURCE_DIR}/**/*.plist" |
| 31 | + "${CMAKE_CURRENT_SOURCE_DIR}/**/*.entitlements" |
| 32 | + "${CMAKE_CURRENT_SOURCE_DIR}/Package.swift" |
| 33 | +) |
| 34 | + |
| 35 | +set(SWIFT_BUILD_TYPE $<IF:$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>,debug,release>) |
| 36 | + |
| 37 | +add_custom_command( |
| 38 | + OUTPUT "${SWIFT_BUILD_DIR}/${SWIFT_BUILD_TYPE}/MuseScoreQLPreviewProvider" |
| 39 | + "${SWIFT_BUILD_DIR}/${SWIFT_BUILD_TYPE}/MuseScoreThumbnailProvider" |
| 40 | + COMMAND swift package resolve |
| 41 | + COMMAND swift build --build-path ${SWIFT_BUILD_DIR} -c ${SWIFT_BUILD_TYPE} |
| 42 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 43 | + DEPENDS ${SWIFT_SOURCES} |
| 44 | + COMMENT "Building swift code" |
| 45 | +) |
| 46 | + |
| 47 | +add_custom_target(swift_package_build ALL |
| 48 | + DEPENDS "${SWIFT_BUILD_DIR}/${SWIFT_BUILD_TYPE}/MuseScoreQLPreviewProvider" |
| 49 | + "${SWIFT_BUILD_DIR}/${SWIFT_BUILD_TYPE}/MuseScoreThumbnailProvider" |
| 50 | +) |
| 51 | + |
| 52 | +# Install targets |
| 53 | +install(CODE " |
| 54 | + # Create directory structure |
| 55 | + file(MAKE_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/mscore.app/Contents/PlugIns/MuseScoreQLPreviewProvider.appex/Contents/MacOS\") |
| 56 | + file(MAKE_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/mscore.app/Contents/PlugIns/MuseScoreThumbnailProvider.appex/Contents/MacOS\") |
| 57 | +
|
| 58 | + # Copy Info.plist files |
| 59 | + file(COPY \"${CMAKE_CURRENT_SOURCE_DIR}/Sources/MuseScoreQLPreviewProvider/Info.plist\" |
| 60 | + DESTINATION \"${CMAKE_INSTALL_PREFIX}/mscore.app/Contents/PlugIns/MuseScoreQLPreviewProvider.appex/Contents\") |
| 61 | + file(COPY \"${CMAKE_CURRENT_SOURCE_DIR}/Sources/MuseScoreThumbnailProvider/Info.plist\" |
| 62 | + DESTINATION \"${CMAKE_INSTALL_PREFIX}/mscore.app/Contents/PlugIns/MuseScoreThumbnailProvider.appex/Contents\") |
| 63 | +
|
| 64 | + # Copy executable to MacOS |
| 65 | + file(COPY \"${SWIFT_BUILD_DIR}/${SWIFT_BUILD_TYPE}/MuseScoreQLPreviewProvider\" |
| 66 | + DESTINATION \"${CMAKE_INSTALL_PREFIX}/mscore.app/Contents/PlugIns/MuseScoreQLPreviewProvider.appex/Contents/MacOS\") |
| 67 | + file(COPY \"${SWIFT_BUILD_DIR}/${SWIFT_BUILD_TYPE}/MuseScoreThumbnailProvider\" |
| 68 | + DESTINATION \"${CMAKE_INSTALL_PREFIX}/mscore.app/Contents/PlugIns/MuseScoreThumbnailProvider.appex/Contents/MacOS\") |
| 69 | +
|
| 70 | + # Ad-hoc code sign the QuickLook extension, for dev |
| 71 | + execute_process( |
| 72 | + COMMAND codesign --force --sign - --timestamp=none --entitlements \"${CMAKE_CURRENT_SOURCE_DIR}/plugin.entitlements\" |
| 73 | + \"${CMAKE_INSTALL_PREFIX}/mscore.app/Contents/PlugIns/MuseScoreQLPreviewProvider.appex\" |
| 74 | + RESULT_VARIABLE CODESIGN_RESULT |
| 75 | + ) |
| 76 | + if(NOT CODESIGN_RESULT EQUAL 0) |
| 77 | + message(FATAL_ERROR \"Failed to ad-hoc sign QuickLook extension\") |
| 78 | + endif() |
| 79 | +
|
| 80 | + # Ad-hoc code sign the Thumbnail Provider extension, for dev |
| 81 | + execute_process( |
| 82 | + COMMAND codesign --force --sign - --timestamp=none --entitlements \"${CMAKE_CURRENT_SOURCE_DIR}/plugin.entitlements\" |
| 83 | + \"${CMAKE_INSTALL_PREFIX}/mscore.app/Contents/PlugIns/MuseScoreThumbnailProvider.appex\" |
| 84 | + RESULT_VARIABLE CODESIGN_RESULT |
| 85 | + ) |
| 86 | + if(NOT CODESIGN_RESULT EQUAL 0) |
| 87 | + message(FATAL_ERROR \"Failed to ad-hoc sign Thumbnail Provider extension\") |
| 88 | + endif() |
| 89 | +
|
| 90 | + # Ad-hoc code sign the main app, for dev |
| 91 | + execute_process( |
| 92 | + COMMAND codesign --force --sign - --timestamp=none |
| 93 | + \"${CMAKE_INSTALL_PREFIX}/mscore.app\" |
| 94 | + RESULT_VARIABLE CODESIGN_RESULT |
| 95 | + ) |
| 96 | + if(NOT CODESIGN_RESULT EQUAL 0) |
| 97 | + message(FATAL_ERROR \"Failed to ad-hoc sign main app\") |
| 98 | + endif() |
| 99 | +") |
0 commit comments