Skip to content

Commit f68d175

Browse files
committed
OSX: create dmg script
1 parent 3ff64b5 commit f68d175

10 files changed

+149
-9
lines changed

cmake/MacOSXBundleInfo.plist.template

-5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,5 @@
3232
<true/>
3333
<key>NSHumanReadableCopyright</key>
3434
<string>@MACOSX_BUNDLE_COPYRIGHT@</string>
35-
<key>LSEnvironment</key>
36-
<dict>
37-
<key>PREFIX_PATH</key>
38-
<string>../Resources</string>
39-
</dict>
4035
</dict>
4136
</plist>

cmake/macros.cmake

+3-4
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ macro(cp_osx_add_target_properties TARGET VERSION VERSION_CODE)
730730
cp_set_properties(${TARGET} MACOSX_BUNDLE_COPYRIGHT "CaveProductions")
731731
cp_set_properties(${TARGET} MACOSX_BUNDLE_INFO_STRING "")
732732
cp_set_properties(${TARGET} MACOSX_BUNDLE_GUI_IDENTIFIER "org.${TARGET}")
733-
cp_set_properties(${TARGET} MACOSX_BUNDLE_ICON_FILE "${TARGET}-icon.png")
733+
cp_set_properties(${TARGET} MACOSX_BUNDLE_ICON_FILE "${TARGET}.icns")
734734
cp_set_properties(${TARGET} PROPERTIES XCODE_ATTRIBUTE_INSTALL_PATH "/Applications")
735735
if (IOS)
736736
if (RELEASE)
@@ -931,9 +931,8 @@ macro(cp_add_executable)
931931
set(BIN_DIR "${_EXE_TARGET}.app/Contents/MacOS")
932932
install(FILES ${PROJECT_BINARY_DIR}/Info.plist DESTINATION ${SHARE_DIR} COMPONENT ${_EXE_TARGET})
933933
install(FILES ${ROOT_DIR}/cmake/PKgInfo DESTINATION ${SHARE_DIR} COMPONENT ${_EXE_TARGET})
934-
endif()
935-
936-
if (NOT TESTS)
934+
install(FILES ${ROOT_DIR}/contrib/${_EXE_TARGET}.icns DESTINATION ${ICON_DIR} COMPONENT ${_EXE_TARGET})
935+
elseif (NOT TESTS)
937936
set(ICON "${_EXE_TARGET}-icon.png")
938937
if (EXISTS ${ROOT_DIR}/contrib/${ICON})
939938
install(FILES ${ROOT_DIR}/contrib/${ICON} DESTINATION ${ICON_DIR} COMPONENT ${_EXE_TARGET})
Binary file not shown.

contrib/caveexpress.icns

176 KB
Binary file not shown.

contrib/caveexpresshd.icns

261 KB
Binary file not shown.

contrib/cavepacker.icns

328 KB
Binary file not shown.

contrib/icon.icns

176 KB
Binary file not shown.

contrib/installer/osx/background.png

104 KB
Loading

contrib/scripts/create_dmg.sh

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
3+
# by Andy Maloney
4+
# http://asmaloney.com/2013/07/howto/packaging-a-mac-os-x-application-using-a-dmg/
5+
6+
dir=${0%/*}
7+
if [ -d "$dir" ]; then
8+
pushd "$dir"
9+
fi
10+
11+
pushd ../../../cp-build-osx
12+
13+
# ./contrib/scripts/create_dmg.sh caveexpress 2.4
14+
15+
# set up your app name, version number, and background image file name
16+
APP_NAME="$1"
17+
VERSION="$2"
18+
DMG_BACKGROUND_IMG="Background.png"
19+
cp "../caveexpress/contrib/installer/osx/background.png" ${DMG_BACKGROUND_IMG}
20+
21+
# you should not need to change these
22+
APP_EXE="${APP_NAME}.app/Contents/MacOS/${APP_NAME}"
23+
24+
VOL_NAME="${APP_NAME} ${VERSION}" # volume name will be "SuperCoolApp 1.0.0"
25+
DMG_TMP="${VOL_NAME}-temp.dmg"
26+
DMG_FINAL="${VOL_NAME}.dmg" # final DMG name will be "SuperCoolApp 1.0.0.dmg"
27+
STAGING_DIR="./Install" # we copy all our stuff into this dir
28+
29+
# clear out any old data
30+
rm -rf "${STAGING_DIR}" "${DMG_TMP}" "${DMG_FINAL}"
31+
32+
# copy over the stuff we want in the final disk image to our staging dir
33+
mkdir -p "${STAGING_DIR}"
34+
cp -rpf "${APP_NAME}.app" "${STAGING_DIR}"
35+
# ... cp anything else you want in the DMG - documentation, etc.
36+
37+
pushd "${STAGING_DIR}"
38+
39+
# strip the executable
40+
echo "Stripping ${APP_EXE}..."
41+
strip -u -r "${APP_EXE}"
42+
43+
# compress the executable if we have upx in PATH
44+
# UPX: http://upx.sourceforge.net/
45+
if hash upx 2>/dev/null; then
46+
echo "Compressing (UPX) ${APP_EXE}..."
47+
upx -9 "${APP_EXE}"
48+
fi
49+
50+
# ... perform any other stripping/compressing of libs and executables
51+
52+
popd
53+
54+
# figure out how big our DMG needs to be
55+
# assumes our contents are at least 1M!
56+
SIZE=`du -sh "${STAGING_DIR}" | sed 's/\([0-9\.]*\)M\(.*\)/\1/'`
57+
SIZE=`echo "${SIZE} + 1.0" | bc | awk '{print int($1+0.5)}'`
58+
59+
if [ $? -ne 0 ]; then
60+
echo "Error: Cannot compute size of staging dir"
61+
exit
62+
fi
63+
64+
# create the temp DMG file
65+
hdiutil create -srcfolder "${STAGING_DIR}" -volname "${VOL_NAME}" -fs HFS+ \
66+
-fsargs "-c c=64,a=16,e=16" -format UDRW -size ${SIZE}M "${DMG_TMP}"
67+
68+
echo "Created DMG: ${DMG_TMP} with size ${SIZE}"
69+
70+
# mount it and save the device
71+
DEVICE=$(hdiutil attach -readwrite -noverify "${DMG_TMP}" | \
72+
egrep '^/dev/' | sed 1q | awk '{print $1}')
73+
74+
sleep 2
75+
76+
# add a link to the Applications dir
77+
echo "Add link to /Applications"
78+
pushd /Volumes/"${VOL_NAME}"
79+
ln -s /Applications
80+
popd
81+
82+
# add a background image
83+
mkdir /Volumes/"${VOL_NAME}"/.background
84+
cp "${DMG_BACKGROUND_IMG}" /Volumes/"${VOL_NAME}"/.background/
85+
86+
# tell the Finder to resize the window, set the background,
87+
# change the icon size, place the icons in the right position, etc.
88+
echo '
89+
tell application "Finder"
90+
tell disk "'${VOL_NAME}'"
91+
open
92+
set current view of container window to icon view
93+
set toolbar visible of container window to false
94+
set statusbar visible of container window to false
95+
set the bounds of container window to {400, 100, 920, 440}
96+
set viewOptions to the icon view options of container window
97+
set arrangement of viewOptions to not arranged
98+
set icon size of viewOptions to 72
99+
set background picture of viewOptions to file ".background:'${DMG_BACKGROUND_IMG}'"
100+
set position of item "'${APP_NAME}'.app" of container window to {160, 205}
101+
set position of item "Applications" of container window to {360, 205}
102+
close
103+
open
104+
update without registering applications
105+
delay 2
106+
end tell
107+
end tell
108+
' | osascript
109+
110+
sync
111+
112+
# unmount it
113+
hdiutil detach "${DEVICE}"
114+
115+
# now make the final image a compressed disk image
116+
echo "Creating compressed image"
117+
hdiutil convert "${DMG_TMP}" -format UDZO -imagekey zlib-level=9 -o "${DMG_FINAL}"
118+
119+
# clean up
120+
rm -rf "${DMG_TMP}"
121+
rm -rf "${STAGING_DIR}"
122+
123+
echo 'Done.'
124+
125+
exit

contrib/scripts/create_icns.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
export PROJECT=caveexpress
4+
export ICONDIR=$PROJECT.app/Contents/Resources/$PROJECT.iconset
5+
export ORIGICON=../caveexpress/contrib/icon-512x512.png
6+
7+
mkdir $ICONDIR
8+
9+
# Normal screen icons
10+
for SIZE in 16 32 64 128 256 512; do
11+
sips -z $SIZE $SIZE $ORIGICON --out $ICONDIR/icon_${SIZE}x${SIZE}.png ;
12+
done
13+
14+
# Retina display icons
15+
for SIZE in 16 32 64 128 256 512; do
16+
sips -z $SIZE $SIZE $ORIGICON --out $ICONDIR/icon_$(expr $SIZE / 2)x$(expr $SIZE / 2)x2.png ;
17+
done
18+
19+
# Make a multi-resolution Icon
20+
iconutil -c icns -o $PROJECT.app/Contents/Resources/$PROJECT.icns $ICONDIR
21+
rm -rf $ICONDIR #it is useless now

0 commit comments

Comments
 (0)