8

The extremely helpful guidelines posted at http://www.vtk.org/Wiki/Cocoa_VTK and via the readme file by Sean McBride and Mike Jackson inside the VTK repo were slightly out of date for VTK 6.1. So in case this helps anybody, I'm posting instructions for installing VTK 6.1 on OSX 10.8 with support for the SimpleCocoaVTK Xcode project.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Angus Forbes
  • 982
  • 1
  • 9
  • 21

4 Answers4

13

* Installing VTK 6.1 for OSX 10.8 with Cocoa support *

These instructions slightly modify Ryan Glover's instructions at http://www.vtk.org/Wiki/Cocoa_VTK and the README.rtf in the VTK/Examples/GUI/Cocoa/Documentation folder by Sean McBride and Mike Jackson.

  1. Clone the VTK git repo into a directory of your choice:

    cd /Users/you/

    git clone https://github.com/Kitware/VTK.git

    cd VTK

    git checkout tags/v6.1.0

  2. make a build directory

    mkdir VTKBuild

    cd VTKBuild

  3. Run the VTK cmake script

    • You will now be inside /Users/you/VTK/VTKBuild, run cmake from here (using the parent directory's CMake files):

    cmake ..

  4. Edit lots of lines in the newly generated CMakeCache.txt (in the current VTKBuild directory). One issue I had was that there were error if I didn't use a full path for the CMAKE_INSTALL_PREFIX. So make sure to use "/Users/you/" instead of "~":

    CMAKE_INSTALL_PREFIX:PATH=/Users/you/VTK/VTKBuild

    BUILD_SHARED_LIBS:BOOL=OFF

    CMAKE_BUILD_TYPE:STRING=Debug

    VTK_USE_SYSTEM_ZLIB:BOOL=ON

    CMAKE_OSX_ARCHITECTURES:STRING=i386;x86_64

    CMAKE_OSX_SYSROOT:STRING=/Applications/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk

  5. Compile the VTK project (this might take over an hour to run!):

    make

  6. Copy headers to an include directory:

    make install

  7. VTK should now be completely installed in the VTKBuild directory and ready to use in an XCode project!

  8. Go to your finder, navigate to Users/you/VTK/Examples/GUI/Cocoa/ and double click to open SimpleCocoaVTK.xcodeproj in XCode.

  9. In the XCode menubar (at the top of the screen) Go to Preferences->Locations->Source Trees and use the + button to add in two source trees:

    vtk-debug-include vtk-debug-include Users/you/VTK/VTKBuild/include/vtk-6.1

    vtk-debug-lib vtk-debug-lib Users/you/VTK/VTKBuild/lib

  10. Click on the XCode project and delete all the references to vtk 6.0:

    • In the project view, select Targets->SimpleCocoaVTK and then press "Build Phases" and then open the "Link Binary With Libraries". Delete all the files that begin with "libvtk" and end with "6.0.a"

    • In the file view of the SimpleCocoaVTK project, hightlight and delete all the files in the vtk-libraries folder.

  11. Make sure the XCode file view is active. Then in the finder, navigate to /Users/you/VTK/VTKBuild/lib, and select all the files that begin with "libvtk" and end with "6.1.a". Drag these files into the folder "vtk-libraries" in the XCode file view.

  12. In XCode, do a Product->Clean

  13. You can now build and run the sample SimpleCocoaVTK project.

Translunar
  • 3,739
  • 33
  • 55
Angus Forbes
  • 982
  • 1
  • 9
  • 21
  • Contrary to some other instructions found elsewhere, don't use the system libtiff option. (In other words, these instructions here are correct.) – Translunar Jun 04 '14 at 00:40
  • In step 1 had to use `git clone git://github.com/Kitware/VTK.git` to get the download to work. –  Apr 12 '14 at 05:44
  • @Angus Forbes thank you for this info. I hope I can ask for help though I am 1 year late. My University course requires VTK 5.0.4. I seem to be stuck at your step 3. I tried running `cmake` inside the `/VTK/VTKBuild` , `/VTK/CMake/` , and in `/VTK` directories but nothing happens. I even get a message: `command not found: cmake` . Any ideas are appreciated. – Beast_Code Aug 22 '14 at 00:58
  • 1
    for those having HDF5 error at `make`: use `CMAKE_OSX_ARCHITECTURES:STRING=x86_64` – Oneiros Nov 17 '15 at 17:45
1

I also had to set

VTK_WRAP_PYTHON:BOOL=ON

in CMakeCache.txt

Tom Ryan
  • 11
  • 1
1

It depends on what user you are too on your machine (computer) and the permissions relevant to that user. I did a find and replace on the CMakeCache.txt file and changed all /usr/local references to /Users/myusername/Develop/VTKInstall. That way everything's at your fingertips and you don't have to change permissions on things.

When you open up the Cocoa example make sure to set in you preferences these paths (e.g. Preferences->Locations->Source Trees). Also you'll need to re-import your vtk-libraries into the project.

I'm running Yosemite with XCode 6.1.1. I hope this helps someone!

scarer
  • 101
  • 9
0

If you get error messages likes this, when trying to build VTK:

@error: garbage collection is no longer supported

make[2]: *** Rendering/OpenGL/CMakeFiles/vtkRenderingOpenGL.dir/vtkCocoaRenderWindowInteractor.mm.o] Error 1

make1: *** [[Rendering/OpenGL/CMakeFiles/vtkRenderingOpenGL.dir/all] Error 2

You need to remove a flag in the source CMakeLists.txt:

@IF(APPLE)
 SET(VTK_OBJCXX_FLAGS_DEFAULT "-fobjc-gc")
 SET(VTK_REQUIRED_OBJCXX_FLAGS ${VTK_OBJCXX_FLAGS_DEFAULT} CACHE STRING "Extra flags for Objective-C++ compilation")
MARK_AS_ADVANCED(VTK_REQUIRED_OBJCXX_FLAGS)
ENDIF(APPLE)@

Either outcomment or delete it all together. Then run cmake again in an empty build directory. Check in the generated CMakeCache.txt in your build directory if it contains a key like VTK_REQUIRED_OBJCXX_FLAGS, it shouldn´t, try running cmake in an empty build directory again.

This 'bug' maybe fixed in future VTK versions.

Source: [Solved] Build Qt 5.2.1 + VTK 6.1.0 + CMake 2.8.12.2

Scarysize
  • 4,131
  • 25
  • 37