Cocoa VTK: Difference between revisions
Line 105: | Line 105: | ||
Now build. | Now build. | ||
Fingers crossed, you should see the app build with no errors and begin to run. | Fingers crossed, you should see the app build with no errors and begin to run. For more questions go [http://www.mac-how.net/ mac how to] | ||
Note that the 'Debug' configuration is built using the 'native architecture' (ppc on ppc, intel on intel), and that the 'Release' configuration is built for both ppc and i386. If you did not build VTK itself as Universal, the 'Release' configuration will not link. | Note that the 'Debug' configuration is built using the 'native architecture' (ppc on ppc, intel on intel), and that the 'Release' configuration is built for both ppc and i386. If you did not build VTK itself as Universal, the 'Release' configuration will not link. | ||
{{VTK/Template/Footer}} | {{VTK/Template/Footer}} |
Revision as of 08:48, 28 July 2010
Installing VTK on Mac OS X 10.4.x for the purposes of Cocoa
This document outlines how to build and install VTK 5 on Mac OS X 10.4.x with Xcode 2.2 or later.
Additionally, it discusses SimpleCocoaVTK, a sample Cocoa application written by Sean McBride and Mike Jackson that uses VTK. It can be downloaded from http://www.rogue-research.com/vtk/SimpleCocoaVTK.html. This document explains how to get VTK installed so that the SimpleCocoaVTK Xcode project will function. SimpleCocoaVTK is an example, it is not required to use VTK.
Installing VTK on Mac OS X 10.5.x (Leopard)
Follow the instructions for 10.4.x but change the version from 10.4 to 10.5 in the appropriate places.
For Leopard, you should use VTK version 5.4.2 or later.
Installing VTK on Mac OS X 10.6.x (Snow Leopard)
It is possible to use VTK 5.4 on Snow Leopard but some things, specifically support for Tk, will not compile. For best result, you should either get the latest VTK from the cvs repository, or use VTK 5.6 when it is released.
CMake
The first step is to install CMake. CMake is a cross platform make and is required to build VTK. You can download the most recent stable build from http://www.cmake.org/HTML/Download.html. As of this writing I used version 2.4.6. Mount the downloaded dmg file as you would for any other install. Run the installer from the disk image and when it is done CMake will be installed in /usr/bin/. This step has been greatly simplified thanks to the installer.
VTK
Now secure a copy of VTK. You can download the most recent stable build from http://www.vtk.org/get-software.php#latest. As of this writing I used version 5.0.2. Double click the downloaded file and expand the folder on your desktop. Rename the folder just ‘VTK’.
We will need a folder to put the VTK build in, I use a folder in my home directory name Development. Create a folder where you want VTK to reside.
cd ~/Development
Now drag the VTK folder into Development.
In ~/Development create a new directory. I named mine VTKBuild.
mkdir VTKBuild
Move into that folder.
cd VTKBuild
Issue the cmake command.
cmake ../VTK
A lot of code will scroll by. When it is done you will find a file named CMakeCache.txt in your VTKBuild folder. Edit that file in your favorite text editor. You need to edit it to make VTK build for Cocoa instead of Carbon. Find the following lines in the text file and change them to look like the following. (You're turning OFFs to ONs and vice versa.)
VTK_USE_CARBON:BOOL=OFF VTK_USE_COCOA:BOOL=ON
Next, you want to set two more variables. (They may or may not already be present in the file. If they are not, just add them after the above two.) CMAKE_OSX_ARCHITECTURES decides which CPU architectures you want to build VTK for. Possible values are: ppc, ppc64, i386, and x86_64. Typically, you would set this to "ppc;i386" to create a Universal Binary. (Warning: VTK 5.0.2 will build as Universal, but there are bugs in the object code for the opposite CPU. That is, if you build VTK on a ppc, the i386 code will be buggy, and vice versa.) CMAKE_OSX_SYSROOT decides which Mac OS SDK to use; you specify the full path. The Mac OS SDK determines the Mac OS APIs available to VTK, for example, if you use the 10.3.9 SDK, then no APIs introduced in 10.4 will be available. VTK requires the 10.2.8 SDK or later.
I recommend you set these variables like so:
CMAKE_OSX_ARCHITECTURES:STRING=ppc;i386 CMAKE_OSX_SYSROOT:STRING=/Developer/SDKs/MacOSX10.4u.sdk/
Finally, change the flag CMAKE_INSTALL_PREFIX from
CMAKE_INSTALL_PREFIX=/usr/local
to
CMAKE_INSTALL_PREFIX=~/Development/VTKBuild
Save the file.
Make sure you are in ~/Development/VTKBuild and issue the command
cmake ../VTK
again. When it is complete, do another one for good measure since Drew McCormick seems to think it's good practice (and it only takes a second).
The next step is to actually compile VTK.
First, we must set the MACOSX_DEPLOYMENT_TARGET environment variable. Possible values are 10.2, 10.3, or 10.4. This determines the oldest version of Mac OS you wish to support. If you use bash (the default shell in Mac OS X 10.4) issue the command
export MACOSX_DEPLOYMENT_TARGET=10.4
Finally, make sure you are still in ~/Development/VTKBuild then issue the make command.
make
VTK is now being built and a lot of material will scroll by the screen. Hopefully there will be no errors. On my virgin MacBook Pro with Xcode 2.4 installed it all worked the first time.
Note that if you are building with Java Wrappings ON you might get an error during compilation. This is due to a bug in CMake 2.4.7 and earlier. The best solution is to use CMake from CVS. Alternatively, you could edit the file Rendering/CMakeFiles/vtkRenderingJava.dir/link.txt and add at the end of the line "-framework JavaVM" (without the quotes).
Now issue the following command:
make install
The make install command will copy all the .h header files for VTK into a single directory, the ~/Development/VTKBuild/include/vtk-5.1 directory, the one defined by CMAKE_INSTALL_PREFIX. We do this because the SimpleCocoaVTK Xcode project needs to have all the headers in one folder and installing VTK spreads the headers in a number of different directories. This make install gathers them all up and puts them into one folder. (Just copies though, the originals are still in the right place).
SimpleCocoaVTK
To make Xcode aware of VTK we need to add two source trees, as outlined in the SimpleCocoaVTK documentation. Open the SimpleCocoaVTK project in Xcode. Then go to Xcode -> Preferences and look for the source tree icon along the top bar. In my Xcode it is the third icon from the right and looks like a traffic sign. Click the icon and a table display will come up. Click the + icon twice and add two rows to the table.
For the first row, set the setting name and display name to 'vtk-lib' (without the single quotes) and set the path to '/Users/rglover/Development/VTKBuild/bin' (without the single quotes). Notice I have my username in there (rglover), replace it with your own.
For the second row, set the setting name and display name to 'vtk-include' (without the single quotes) and set the path to '/Users/rglover/Development/VTKBuild/include/VTK-5.1' (without the single quotes).
Case is important here so make sure it is correct.
With the SimpleCocoaVTK Xcode project open go to the 'Build' menu and choose 'Clean All Targets'.
A final point, make sure ZeroLink is off. To check this click the targets icon (looks like a bulls eye) in the left hand menu. Drop down the bulls eye until you see the SimpleCocoaVTK target (the standard A icon made of pencil/pen/ruler). Click SimpleCocoaVTK to select it and hit the info button (blue i icon in the top menu). Click the Build tab and make sure that the configuration drop down says 'All Configurations' and the collection drop down says 'All Settings'.
In the search box type 'zerolink'. The list will shorten to a manageable size and you will see ZeroLink there. Click the checkbox button until it is empty (not a checkmark or a negative sign, just empty).
Close information and 'Clean All Targets' again.
Now build.
Fingers crossed, you should see the app build with no errors and begin to run. For more questions go mac how to
Note that the 'Debug' configuration is built using the 'native architecture' (ppc on ppc, intel on intel), and that the 'Release' configuration is built for both ppc and i386. If you did not build VTK itself as Universal, the 'Release' configuration will not link.