Creating Mac OS X Packages with CMake

One of the newer features that we have added to CMake is the ability to generate visually appealing DragNDrop packages for Mac OS X. In doing so, we have refined our layout script and now wish to share our work so that other projects can easily generate DragNDrop packages.

Creating Mac OS X Packages with CMake

ParaView displays an example DragNDrop package generated with CMake.

Generating these packages entails specifying a custom background image and AppleScript to CPack. While the new ability allows each project to have nearly full control over the process and the layout of a package, it does require knowledge of AppleScript and the techniques used to create a package.
Below, you can find the AppleScript that CMake uses to package itself. This AppleScript is also available on GitLab, as is the background image.


on run argv
set image_name to item 1 of argv

tell application "Finder"
tell disk image_name

  -- wait for the image to finish mounting
  set open_attempts to 0
  repeat while open_attempts < 4
    try
      open
        delay 1
        set open_attempts to 5
      close
      on error errStr number errorNumber
        set open_attempts to open_attempts + 1
        delay 10
    end try
  end repeat
  delay 5

  -- open the image the first time and save a DS_Store with just
  -- background and icon setup
  open
    set current view of container window to icon view
    set theViewOptions to the icon view options of container window
    set background picture of theViewOptions to file ".background:background.tif"
    set arrangement of theViewOptions to not arranged
    set icon size of theViewOptions to 128
    delay 5
  close

  -- next setup the position of the app and Applications symlink
  -- plus hide all the window decoration
  open
    update without registering applications
    tell container window
      set sidebar width to 0
      set statusbar visible to false
      set toolbar visible to false
      set the bounds to { 400, 100, 900, 465 }
      set position of item "CMake.app" to { 133, 200 }
      set position of item "Applications" to { 378, 200 }
    end tell
    update without registering applications
    delay 5
  close
  
  -- one last open and close so you can see everything looks correct
  open
    delay 5
  close

end tell
delay 1
end tell
end run

The AppleScript can easily be modified and integrated by other projects. The only major change required is to edit line 42, which explicitly specifies the name of the package.

In preparation for the 5.2 release, the ParaView team integrated the above background image and AppleScript into the ParaView Superbuild to automatically create more visually appealing Mac packages. Special thanks goes to Sandia National Laboratories, which funded this effort.

We would also like to acknowledge Adam Strzelecki, who made the addition of the ability to CMake possible, as he designed the background image and the initial implementation.

CMake at SC16

In November, I will attend The International Conference for High Performance Computing, Networking, Storage and Analysis (SC16) along with other members of the CMake development team. I hope you will stop by the Kitware booth (#3437) to learn more about creating Mac OS X packages with CMake. Be sure to also ask us about the many open-source solutions we offer that leverage CMake, such as ParaView Catalyst, which ran on over one million cores earlier this year. We have posted our conference activities on our event listing, so take advantage of the opportunity to talk to us!

One Response to Creating Mac OS X Packages with CMake

  1. Marcus D. Hanwell says:

    This looks great, I hope we can start using this for more projects soon!

Questions or comments are always welcome!