As VTK is cross-platform, building on Mac OS X is much the same as on any other supported platform. This page only discusses some OS X-specific topics related to VTK 5.10 and later. For information on antique versions of VTK, refer to the version of this page in the history from 2013-07-21 or earlier.
VTK 6.x supports Intel and PowerPC, 32 and 64 bit, and requires OS X 10.5 or later.
VTK 5.x supports Intel and PowerPC, 32 and 64 bit, and requires OS X 10.4 or later.
On OS X 10.5, you should use at least VTK 5.4.2. On OS X 10.6, at least VTK 5.6. On OS X 10.7 and later, VTK 6.x is recommended.
On OS X, there are two windowing APIs: Carbon and Cocoa. Older versions of VTK defaulted to Carbon, but newer versions default to Cocoa. Carbon support is deprecated by both Apple and VTK, and should not be used for new development. To choose, set one of the following to ON:
Deployment Target and SDK
The 'deployment target' and 'SDK' are concepts that should be familiar to OS X developers. In brief, the 'deployment target' specifies the oldest version of OS X that you which to support at runtime; it should always be set. Ex:
The 'SDK' specifies which version of OS headers and libraries you want to build against. Usually, you want to built against the newest SDK, which is what CMake defaults to. But you can override it:
VTK can be built as a universal binary, that is, as libraries that have executable code for several CPU types. Even if you want to build for only one CPU type, you should always specify them explicitly, ex:
Possible values are: ppc, ppc64, i386, and x86_64.
Cocoa Memory Management Models
Cocoa has three memory management models, chronologically by date of introduction:
- manual reference counting (MRC)
- garbage collection (GC)
- automatic reference counting (ARC)
VTK supports MRC and GC. MRC is the default. GC was deprecated by Apple in OS X 10.8, but to use it set:
ARC support will eventually be available, but if your host application is ARC you can build VTK as MRC and still link to it.
VTK has several VTK_USE_SYSTEM_* options, allowing you to link against the OS's built-in versions of popular third party libraries. The advantage of doing so is that it reduces your compile time and binary size. Only a few are built-in to OS X, which you can make VTK use by setting:
VTK_USE_SYSTEM_ZLIB:BOOL=ON VTK_USE_SYSTEM_EXPAT=ON VTK_USE_SYSTEM_LIBXML2=ON
Use Application Bundles
On OS X, there are (at least) two kinds of executables:
- Application Bundles
- plain UNIX executables
To be able to display a graphical interface (that is, display windows that allow mouse and keyboard interaction), OS X requires you to use an application bundle. If a plain UNIX executable tries, it will mostly work, but there will be various bugs, such as keyboard and mouse events not working properly. Many, but not all, of the VTK examples are built as plain UNIX executables, and thus have these problems. This is bug 2025. When you build your own VTK application, it is best to make it in the form of an application bundle. Simply add the following to your CMakeLists.txt file:
IF(APPLE) SET(EXECUTABLE_FLAG MACOSX_BUNDLE) ENDIF(APPLE)
If for some reason you cannot build as an application bundle, see bug 2025 for possible workarounds.
SimpleCocoaVTK is a sample Cocoa application written by Sean McBride and Mike Jackson that uses VTK. It illustrates how to use the VTK libraries within an Xcode-based OS X application. SimpleCocoaVTK is an example, it is not required to use VTK.
Originally standalone, SimpleCocoaVTK is now part of VTK itself in the Examples/GUI/Cocoa folder. See the documentation there for how to use it.