How to install ITK on a Mac: CMake >> MacPorts

Installing Insight Toolkit (ITK) shouldn’t be that hard to do, but I wasted a lot of time trying to figure this out, so I’ll share what I’ve learned. If you’re in a hurry, here’s the gist: go with CMake, it took about half an hour on my 2-gb, 2.13-ghz MacBook Air.

Since I have a Mac, specifically OS X 10.6 (Snow Leopard), I reduced my installation options to two routes: CMake and MacPorts. Both are free and run from the command line; CMake also has a GUI. Initially I tried MacPorts, since it seemed the easier of the two with a one-liner:

sudo port -d install InsightToolkit

For reference, here’s the wiki guide on ITK with MacPorts.

However, the process seemed to stall after several minutes, attempting to download something at ever decreasing speeds. I let it run all night and it still didn’t finish. The longer it went, the more the download rate slowed, like an annoying instance of Zeno’s paradox. So finally I ^C’ed outta there. I did try initiating the build again and it seemed to bypass the steps it had already taken but again stalled at a similar downloading step.

After that failure, I set about learning some of this CMake compiling business. I should have known to start there from the beginning, since CMake is from Kitware, the open-source software group responsible for ITK as well. Here’s what would have made my life easier if it had been spelled out for me:

  1. Download and install CMake using the familiar and friendly .dmg format meant for simple folks like me.
  2. Download ITK and unarchive the compressed file. This folder is the ITK source folder, which CMake will need.
  3. CMake can be run from the command line or from a GUI. Since I’m feeling particularly noob, I went with the GUI. It looks something like this, once it is running (note the output in the bottom window):
    CMake GUI
    Set your Source (the ITK source folder that you downloaded) and the Build folder, which should be an empty new folder where you will build ITK. I called mine “ITK_bin.”
  4. Click “Configure.” A window will pop up, asking you to “specify the generator for this project.” I went with the defaults on this and it worked. After you click “Done,” CMake will write files to the build directory. At some point it should have a red screen and ask you to choose from a set of options such as the one below:

    I unchecked “Build Examples” and “Build Testing” since I don’t need them. When you have set the options as you like, click “Configure” again. Repeat this until no new options are available, at which point the screen is no longer red.
  5. At this point, you will need the command line, but this last step is very easy. Go to your ITK build directory and enter “make.” E.g., if I am in the parent folder of my ITK build directory,
    $ cd ITK_bin
    $ make

    ITK should start building, with progress displayed as [4%], [11%], and so forth.

2 thoughts on “How to install ITK on a Mac: CMake >> MacPorts

  1. Pingback: MacPorts “build.cmd” error fixed with Xcode « worldwide penguin

  2. Thanks, I made it. The question is how do I write a simple a simple ITK program with XCOde now?

    I tried this one, but all I get are errors.

    #include
    int main()
    {
    typedef itk::Image ImageType;
    ImageType::Pointer image = ImageType::New();
    std::cout << "ITK Hello World !" << std::endl;
    return 0;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>