How to install VTK 6.1 for OSX 10.8 with Cocoa/XCode support?

风流意气都作罢 提交于 2019-11-28 07:03:26
Angus Forbes

* 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.

I also had to set

VTK_WRAP_PYTHON:BOOL=ON

in CMakeCache.txt

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!

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!