I am working with CMake 2.8.10.2 on Mac OS X 10.7.5.
I've configured CMake to build a simple application with Xcode that creates an empty window. I then tried to configure CMake to build a DMG installation of the program specifying a background image using:
set(CPACK_DMG_BACKGROUND_IMAGE /path/to/image)
and custom .DS_Store to set windows size and icon placement using:
set(CPACK_DMG_DS_STORE /path/to/DS_Store file)
Xcode will successfully build the application and create the disk image. When I mount the image it comes up with the correct size and icon placement, however the background is always set to white instead of specified background image.
What is needed to get the background to display properly in the disk image?
Unfortunately no one has responded this question. This has been a frustrating experience, however, it looks like I finally solved it so I'm posting a description here to save someone else the grief if they ever have to deal with this.
In order for a background to work on an installation image, basically two things must happen; the background file must exist within the installation image, and the .DS_Store at the root of the image must be configured to use that background.
The .DS_Store file can be configured by mounting the install image in a writable state and then selecting Show View Options from the Finder's View menu. From there someone will select the Picture option for the Background and drag the background file to the placeholder in the Show View Options panel.
When working with CPack, the trick is to be able to drag the image. When someone sets the background for the installation, builds, and mounts the image it will not look like there is any background to drag to the Show View Options panel. If someone goes into the Terminal and does
ls -a
on the root of the mounted install, that command will list, among other things, a file called background.png. This file does not display in the Finder.
The reason this file displays in the Terminal and not the Finder is because it has an extended attributes that makes it hidden for the Finder. Since the file is hidden from the Finder it is not possible to drag the file to the Show View Options panel. Doing
ls -l@
will reveal what extended attributes are applied to the file. There should be only one called com.apple.FinderInfo. Removing this attribute should make the file visible in the Finder. The attribute can be removed using this command from the Terminal
xattr -d com.apple.FinderInfo background.png
After removing the attribute the background file still will not show up in the Finder right away. Someone will have to eject and remount the install image. Once this has happened, the background file should appear in the Finder and someone can drag it to the Show View Options panel, which will cause the background image to display in the Finder window for the install image. After that, someone can copy the .DS_Store file from the root of the install image and apply it to the CPACK_DMG_DS_STORE attribute, and the background image should appear whenever an install image is built.
@TronThomas response helped me out dramatically. Not to supplant his answer, here's some additional information about the process that I just worked through. For reference, this is with MacOS Sierra and CMake 3.6.2.
set(CPACK_DMG_BACKGROUND_IMAGE /path/to/image)
DragNDrop
hdiutil attach mypackage.dmg -shadow junk.dmg
.background
in the DMG file. Our strategy will be to use Finder to make the window exactly how we want, then copy out the .DS_Store
file.View->Show View Options
Background:
, click the Picture
radio button. Then, click the image above the text Drag Image Here
. Note, the current view must be as Icons
otherwise this dialog will not be there.cmd-shift-.
This should show the hidden folders. From here, go into the .background
folder and select the background image.View
menu. The exact settings will be replicated by the installer..DS_Store
file in the root directory of the volume to another location. The cmd-shift-.
trick can be used view the file or just use the Terminal at this point to copy everything. Note, we can change the name of this file to DS_Store
, so that it's not hidden when we store it.junk.dmg
or any shadow files remaining.CMakeLists.txt
, set the variable set(CPACK_DMG_DS_STORE /path/to/DS_Store)
This is the file that we just created and moved off of the volume.CPack
. Everything should be as viewed before.As a warning, there's a lot of information that gets stored in the .DS_Store
file such as file locations, user names, and the like. At the moment, I don't know how to control this information, so be a little careful when distributing the final DMG file. If you're curious as to what's in there, use a hex editor like xxd
.
As a brief comment, this process is very obtuse. That said, I don't think it's Kitware's fault. Though, they could document the process better. From what I can tell, the .DS_Store
file format is not well documented or disclosed, so we're basically forced to use Finder to make one for us. This is a MacOS issue that probably should be fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With