Compiling ITK, VTK, FLTK, & InsightApplications for X11 on Mac OS X
Methods In Medical Image Analysis (BioE 2630 : 16-725 : 42-735) - Spring 2008
John Galeotti

Acknowledgement: This is partially based on the work of others from previous sessions of this class. However, I am the author of all the X11 specific stuff.

  1. Installing CMake
  2. Compiling & Testing FLTK
  3. Compiling & Testing ITK
  4. Compiling & Testing VTK
  5. Compiling & Testing Insight Applications

For further guidance on these procedures and how to test your build environment, you may wish to consult the slides from Lecture 3.

1. Installing CMake

CMake can be downloaded from http://www.cmake.org/. The most recent version is 2.4.8. Binary installers are provided in the Download section of the CMake web site. Installing CMake is relatively painless and you probably won't run into any problems here.

2. Compiling & Installing FLTK

FLTK can be found at http://www.fltk.org/. The latest stable release - and the one we recommend you download - is v1.1.7.

Download fltk-1.1.7-source.zip and extract its contents somewhere appropriate (e.g., I use ~/MIIA). You will probably find it convenient to keep all of your downloaded libraries (i.e., ITK, VTK, etc.) in this same root directory. After extraction you will have the FLTK source tree residing at either ~/MIIA/fltk-1.1.7. Create a new directory to build FLTK in (e.g. ~\MIIA\FLTKBin).

Now run the CMake GUI. You will first need to tell CMake what compiler system you are using. For the input (CMakeLists.txt) file, point to the directory where fltk has been extracted (e.g. ~\MIIA\fltk-1.1.7). In order to compile FLTK to use X11 instead of native OS X graphics, use the command-line tool ccmake by issuing exactly the following command within your FLTKBin directory (with or without the "-G Xcode"):

for X11 on Mac, use the following (all on one line):
ccmake (-G Xcode) -D FLTK_APPLE_X11:BOOL=1 -D CMAKE_CXX_FLAGS:STRING=-U__APPLE__ -D OPENGL_gl_LIBRARY:STRING=-lGL -D OPENGL_glu_LIBRARY:STRING=-lGLU -D OPENGL_INCLUDE_DIR:STRING=/usr/X11R6/include ../fltk-1.1.7

IMPORTANT: Note that "../fltk-1.1.7" should be the path to the directory where you extracted FLTK. Change this if necessary.

Once ccmake is running, you want to "configure" the system. This will cause cmake to establish environment settings for the build process. Once finished, you will be presented with a list of optional or unknown values for you to change as needed. You should turn on BUILD_EXAMPLES and BUILD_TESTING and turn off BUILD_SHARED_LIBS.

Once these variables have been set, Configure again. Finally, you should be able to "Generate" the build environment. This should generate either an Xcode project or a Makefile. To use a Makefile, simply issue the make command from within the FLTKBin directory. After the build completes, your FLTKBin/bin/(Debug/) (or similar) directory will contain the compiled binaries necessary for linking to FLTK. This directory will also conain several example programs, one of which is checkers. Run the checkers program to test things out.

3. Compiling & Installing ITK

The ITK source code is at http://www.itk.org/, on the Download page. You'll have to fill out a small form before continuing with the download, and once you reach the actual download page you want to grab both InsightToolkit-3.4.0.zip and InsightApplications-3.4.0.zip.

Extract both archives. Create a new directory to build ITK in (e.g. C:\MIIA\InsightBin).

Now run the CMake GUI, as you did for FLTK but without all the -D options and using your newly created InsightBin and InsightToolkit-3.4.0 directories. Turn off BUILD_SHARED_LIBS, BUILD_EXAMPLES, and BUILD_TESTS. You may wish to enable advanced options and then turn on ITK_USE_PATENTED in case you have interest in using any of the patented algorithms in ITK (e.g. fuzzy connectedness).

Once these variables have been set, Configure again. Finally, you should be able to "Generate" the build environment. Build ITK (just like you built FLTK); this will take a considerable amount of time. Follow the instructions in Lecture03 to perform the ITK installation test.

4. Compiling & Installing VTK

The VTK source code can be downloaded from http://www.vtk.org/ (under Download). You want the latest official source release (vtk-5.0.4.zip). You also need the vtkdata-5.0.4.zip file. Regarding the windows installer listed on the VTK website, we have no experience with it, and recommend that for consistency across platforms you use the source release instead.

Create new directories for both of these files (in the same place you extracted FLTK, e.g. ~\MIIA\VTK-5.0.4 and ~\MIIA\VTKData-5.0.4), and extract both of these archives into them. Create a new directory in which to build VTK (e.g. ~\MIIA\VTKBin).

Now run the CMake GUI, similar to how you did for FLTK, but using your newly created VTK source and build directories:

for X11 on Mac, only run ccmake for VTK as follows (all on one line):
ccmake (-G Xcode) -D VTK_USE_X:BOOL=1 -D VTK_USE_CARBON:BOOL=0 -D VTK_USE_COCOA:BOOL=0 -D OPENGL_gl_LIBRARY:STRING=-lGL -D OPENGL_glu_LIBRARY:STRING=-lGLU -D OPENGL_INCLUDE_DIR:STRING=/usr/X11R6/include ../VTK-5.0.4

You should turn on VTK_USE_PARALLEL and VTK_USE_RENDERING. Make sure that BUILD_SHARED_LIBS and BUILD_EXAMPLES are turned off. Also set VTK_DATA_ROOT to the directory where the VTKData archive has been extracted (e.g., ~\MIIA\VTKData-5.0.4). You should also turn on VTK_USE_X and turn off VTK_USE_CARBON and VTK_USE_COCOA. Once these variables have been set, Configure again. Finally, you should be able to "Generate" the build environment. Build VTK (just like you built FLTK); this will take a considerable amount of time.

VTK-5.0.4 contains an Examples directory, similar to the one in ITK. As you did with ITK, copy the Examples/Tutorial/Step6/Cxx directory out of VTK (e.g., to a new directory ~\MIIA\VTKTest-5.0.4). Now you need to fix a "bug" in the CMakeLists.txt file by changing the ADD_EXECUTABLE line to read as follows "ADD_EXECUTABLE(Cone6 MACOSX_BUNDLE Cone6.cxx)". Creat a build directory (e.g. ~\MIIA\VTKTestBin). Run the CMake GUI with the newly created source and build directories. Build it. Inside your build directory there will now be an executable program named Cone6. Run the Cone6 program by double-clicking on the application bundle icon or by typing "open Cone6.app" from the command line in the same directory as the newly built app. If all you see is white then press the "r" key on your keyboard.

5. Insight Applications

Create a new directory to build InsightApplications in (e.g. ~\MIIA\ITKAppsBin).

Now run ccmake using your newly created ITKAppsBin and the InsightApplications-3.4.0 directories, and with a command-line argument telling it the full path to your FLTK installation. (This is to work around a bug in the included CMakeLists.txt file) Do it like this:

for X11 on Mac, you should run ccmake as follows from within your ITKAppsBin folder (all on one line):
ccmake (-G Xcode) -D USE_FLTK:BOOL=1 -D FLTK_USE_X:BOOL=1 -D FLTK_DIR:STRING=/Users/galeotti/MIIA/FLTKBin -D USE_VTK:BOOL=1 -D VTK_DIR:STRING=/Users/galeotti/MIIA/VTKBin ../InsightApplications-3.4.0/

Turn off BUILD_SHARED_LIBS and turn on USE_FLTK, USE_VTK,and BUILD_TESTING. You may have to repeatedly configure several times to get all these options turned on. Eventually, you should be able to turn on USE_SNAP.

Once all the variables have been set, Configure again. Finally, you should be able to "Generate" the build environment. Build InsightApplications (just like you built FLTK); this will take a really long time and a lot of disk space.

Test things by running the SNAP program (InsightSNAP).

6. Rejoice...

...Or not. One thing you may try before contacting anyone is to ensure that your compiler system is up-to-date with the latest patches.

Microsoft publishes service packs for the Visual Studio suite that can be found at http://msdn.microsoft.com/.

Apple makes available the latest version of the Xcode Tools for download at http://developer.apple.com (may require setting up an account on the site - it's free).