Packaging in macOS

My previous blog post was about porting a piece of software from Qt4 to Qt5. Now I get to the packaging part.

As we do not really have any optional components, or programmatic stuff in the installation, we can make do with a an App.app bundle, as described in the Bundle Programming Guide. If some heavy lifting with scripts were needed, an App.pkg installer package would be prudent.

Handling dynamic library dependencies

One requirement in the packaging was to add couple of open source libraries in to the package, as the customer did not want a separate install for those. Otherwise this would be fine from packaging point of view, but the dynamic library naturally depends on other libraries, so the search order needs to be changed somehow. Enter install_name_tool.

This lovely program can be used to change how the dyld, the dynamic linker in macOS, searches for the dependancies of an executable or a dynamic library.

In the post, the author uses @executable_path, but I think the current recommendation is to use @loader_path. This I did, and it worked beautifully.

An example to change a dll to use the ICU copied to the package:

% install_name_tool -change /usr/local/opt/icu4c/lib/libicuuc.58.dylib \
     @loader_path/libicuuc.58.dylib mydll.so

Icon for the package

The icon needs to be in special icon format. Digging the internets, the command to do that on macOS:

% sips -s format icns foo.png --out bar.icns

I had already a suitable PNG icon file available, with dimensions of 256x256 pixels.

Creating the Disk Image

Disk images can be created on the command-line with hdiutil.

% hdiutil create -srcfolder imagedir -f HFS+ -volname Application \
  Application.dmg

This creates a disk image from the contents of imagedir.

links

social