Skip to content

Commit

Permalink
Merge pull request #52 from kambala-decapitator/macos-dmg
Browse files Browse the repository at this point in the history
[macOS] produce dmg with CPack
  • Loading branch information
CvH authored Feb 21, 2024
2 parents 10c26e4 + bab3248 commit ccace84
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 205 deletions.
57 changes: 53 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ cmake_minimum_required(VERSION 3.19)
project(LibreELEC.USB-SD.Creator
VERSION 1.5
LANGUAGES CXX
HOMEPAGE_URL "https://libreelec.tv/"
)

set(projectDisplayName "LibreELEC USB-SD Creator")

# LINUX is available only since CMake 3.25
if (NOT LINUX AND UNIX AND NOT APPLE)
set(LINUX 1)
Expand Down Expand Up @@ -36,12 +39,16 @@ qt_add_executable(LibreELEC.USB-SD.Creator WIN32 MACOSX_BUNDLE
resources.qrc
translator.cpp translator.h
)
# TODO: use Qt's template <QTDIR>/lib/cmake/Qt6/macos/Info.plist.app.in

string(TIMESTAMP currentYear "%Y")
set_target_properties(LibreELEC.USB-SD.Creator PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "dmg_osx/template.app/Contents/Info.plist"
MACOSX_BUNDLE_BUNDLE_NAME "LibreELEC USB-SD Creator"
# TODO: use Qt's template (<QTDIR>/lib/cmake/Qt6/macos/Info.plist.app.in) once we support dark mode properly
MACOSX_BUNDLE_INFO_PLIST "dmg_osx/Info.plist.in"
MACOSX_BUNDLE_BUNDLE_NAME "${projectDisplayName}"
MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "LibreELEC © ${currentYear}"
MACOSX_BUNDLE_GUI_IDENTIFIER "tv.libreelec.usb-sd-creator"
MACOSX_BUNDLE_ICON_FILE "icon.icns"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
)

Expand Down Expand Up @@ -102,11 +109,37 @@ if(WIN32)
winapp.rc
)
elseif(APPLE)
set_target_properties(LibreELEC.USB-SD.Creator PROPERTIES
OUTPUT_NAME "${projectDisplayName}"
)

target_sources(LibreELEC.USB-SD.Creator PUBLIC
deviceenumerator_unix.cpp deviceenumerator_unix.h
diskwriter_unix.cpp diskwriter_unix.h
privileges_unix.cpp privileges_unix.h
)

set(bundleContentsDir "$<TARGET_BUNDLE_CONTENT_DIR:LibreELEC.USB-SD.Creator>")
install(FILES "dmg_osx/icon.icns"
DESTINATION "${bundleContentsDir}/Resources"
)

qt_generate_deploy_script(
TARGET LibreELEC.USB-SD.Creator
OUTPUT_SCRIPT qtDeployScript
CONTENT "
qt_deploy_runtime_dependencies(
EXECUTABLE \"$<TARGET_BUNDLE_DIR:LibreELEC.USB-SD.Creator>\"
GENERATE_QT_CONF
NO_APP_STORE_COMPLIANCE
VERBOSE
)
# macdeployqt also packages extra frameworks that aren't needed
foreach(qtModule in Pdf Svg)
file(REMOVE_RECURSE \"${bundleContentsDir}/Frameworks/Qt\\\${qtModule}.framework\")
endforeach()
")
install(SCRIPT ${qtDeployScript})
elseif(LINUX)
set_target_properties(LibreELEC.USB-SD.Creator PROPERTIES SUFFIX .Linux.bin)

Expand All @@ -122,5 +155,21 @@ elseif(LINUX)
endif()

install(TARGETS LibreELEC.USB-SD.Creator
BUNDLE DESTINATION .
BUNDLE
DESTINATION .
)

# cpack
set(CPACK_PACKAGE_NAME "${projectDisplayName}")
set(CPACK_PACKAGE_VENDOR "LibreELEC")
if(APPLE)
set(CPACK_PACKAGE_FILE_NAME "LibreELEC.USB-SD.Creator.macOS")

set(CPACK_GENERATOR DragNDrop)
set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_SOURCE_DIR}/dmg_osx/background.png")
set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "DS_Store_Setup.scpt")
set(CPACK_DMG_VOLUME_NAME "${projectDisplayName}")

configure_file("dmg_osx/DS_Store_Setup.scpt.in" "${CPACK_DMG_DS_STORE_SETUP_SCRIPT}" @ONLY)
endif()
include(CPack)
47 changes: 47 additions & 0 deletions dmg_osx/DS_Store_Setup.scpt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on run argv
set image_name to item 1 of argv

tell application "Finder"
tell disk image_name
set dmg_topleft_x to 100
set dmg_topleft_y to 100
set dmg_width to 480
set dmg_height to 320
set dmg_bottomright_x to (dmg_topleft_x + dmg_width)
set dmg_bottomright_y to (dmg_topleft_y + dmg_height)

set le_icon_x to 130
set app_icon_x to 360
set both_icon_y to 180

open
set viewOptions to the icon view options of container window
set arrangement of viewOptions to not arranged
set icon size of viewOptions to 72
set background picture of viewOptions to file ".background:background.png"
close

open
update without registering applications
tell container window
set current view to icon view
set sidebar width to 0
set pathbar visible to false
set statusbar visible to false
set toolbar visible to false
set the bounds to { dmg_topleft_x, dmg_topleft_y, dmg_bottomright_x, dmg_bottomright_y }
set position of item "@[email protected]" to { le_icon_x, both_icon_y }
set position of item "Applications" to { app_icon_x, both_icon_y }

-- set volume icon
-- another possible solution (if SetFile disappears at some point): NSWorkspace.shared.setIcon from AppKit
do shell script "cd '/Volumes/" & image_name & "' \\
&& ln -s '@[email protected]/Contents/Resources/icon.icns' .VolumeIcon.icns \\
&& SetFile -a C .
"
end tell
delay 2
close
end tell
end tell
end run
16 changes: 14 additions & 2 deletions dmg_osx/template.app/Contents/Info.plist → dmg_osx/Info.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<key>CFBundleAllowMixedLocalizations</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>applet</string>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand All @@ -18,9 +18,21 @@
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>LSMinimumSystemVersion</key>
<string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSRequiresAquaSystemAppearance</key>
<true/>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
</dict>
</plist>
File renamed without changes.
1 change: 0 additions & 1 deletion dmg_osx/template.app/Contents/PkgInfo

This file was deleted.

Binary file removed dmg_osx/template.app/Contents/Resources/applet.rsrc
Binary file not shown.

This file was deleted.

2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char *argv[])
if (getuid() != 0 && cmdArgs.contains("--elevated") == false)
{
const auto sudoPrompt = QLatin1String{"%1 requires admin permissions."}.arg(app.applicationDisplayName());
const QLatin1String appleScript{"do shell script \"sudo %1\" with prompt \"%2\" with administrator privileges"};
const QLatin1String appleScript{R"(do shell script "sudo '%1'" with prompt "%2" with administrator privileges)"};

QProcess myProcess;
myProcess.setProgram(QLatin1String{"osascript"});
Expand Down
193 changes: 0 additions & 193 deletions osx_make_dmg.sh

This file was deleted.

0 comments on commit ccace84

Please sign in to comment.