Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't configure background image for DMG installation using CMake

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?

like image 817
Tron Thomas Avatar asked May 16 '13 20:05

Tron Thomas


2 Answers

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.

like image 91
Tron Thomas Avatar answered Nov 17 '22 05:11

Tron Thomas


@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.

  1. Set a background image with set(CPACK_DMG_BACKGROUND_IMAGE /path/to/image)
  2. Create the DMG file using the CPack generator DragNDrop
  3. Mount the image in read/write mode using a shadow file hdiutil attach mypackage.dmg -shadow junk.dmg
  4. At this point, we don't see a background image, but one exists in the folder .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.
  5. On the Finder menu, click View->Show View Options
  6. Under 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.
  7. In the file dialog, go back to the mounted DMG image. Then, press cmd-shift-. This should show the hidden folders. From here, go into the .background folder and select the background image.
  8. If everything has worked properly, the background image should now be visible.
  9. Adjust the windows size and view or hide toolbars as desired on the View menu. The exact settings will be replicated by the installer.
  10. Copy off the the hidden .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.
  11. Eject the DMG file from Finder. Delete junk.dmg or any shadow files remaining.
  12. Back in the 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.
  13. Rebuild the DMG file with 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.

like image 33
wyer33 Avatar answered Nov 17 '22 06:11

wyer33