OOF: Finite Element Analysis of Microstructures

Installing vtk 5.10.1 on OS X El Capitan with MacPorts

oof3d logo

vtk 5.10.1 is nominally available from MacPorts, but as of now (July 2016) doesn't build properly on OS X 10.11 (El Capitan). There is a bug report at https://trac.macports.org/ticket/49418.

These are instructions for building vtk 5.10.1 on Macintosh OS X 10.11. They will build a version of vtk suitable for using with OOF3D, and install it in /usr/local. These instructions may not be suitable for other operating systems, other versions of OS X, or other applications using vtk.

All lines beginning with % are meant to be typed in a terminal window. Don't type the %. Lines containing sudo do things that you need administrator privileges for. If you're not an administrator and can't use sudo, find an administrator and ask for help.

  1. Install the vtk dependencies using MacPorts:

      % sudo port install cmake mesa libGLU Xft2 xorg-libXScrnSaver xorg-libXt tcl tk
    
  2. Download and unpack the vtk 5.10.1 source code. It's no longer available from www.vtk.org, but fortunately we kept a copy here:

    Unpacking it will create a directory called VTK5.10.1.

  3. Make some modifications to the source code. Using a text editor (not a word processor)

    • Uncomment the line //#define GLX_GLXEXT_LEGACY in VTK5.10.1/Rendering/vtkXOpenGLRenderWindow.cxx. (Ie, remove the // at the beginning of the line.)

    • In VTK5.10.1/Utilities/vtktiff/tif_config.h.in, remove or comment out the line #define inline. (See http://review.source.kitware.com/#/c/12924/.)

  4. Make a directory build-vtk in the same directory as VTK5.10.1:

      % mkdir build-vtk
    
  5. Run ccmake in the build directory.

      % cd build-vtk
      % ccmake -Wno-dev -D CMAKE_INSTALL_NAME_DIR:PATH=/usr/local/lib/vtk-5.10 ../VTK5.10.1
    

    (If for some reason you need to run ccmake a second time in the same build-vtk directory, you can omit the -D CMAKE_INSTALL_NAME_DIR:PATH=... argument.)

  6. Within ccmake:

    1. Type h if you need help using ccmake.
    2. Type c.
    3. Wait a bit.
    4. Type t to get into advanced mode.
    5. Set these variables to these values:
          BUILD_SHARED_LIBS         ON
          CMAKE_BUILD_TYPE          Release
          CMAKE_CXX_FLAGS           -I/opt/local/include
          CMAKE_C_FLAGS             -I/opt/local/include
          OPENGL_INCLUDE_DIR        /opt/local/include
          OPENGL_gl_LIBRARY         /opt/local/lib/libGL.dylib
          OPENGL_glu_LIBRARY        /opt/local/lib/libGLU.dylib
          VTK_USE_COCOA             OFF
          VTK_USE_X                 ON
      
    6. Type c to configure again, and repeat until
        Press [g] to generate and exit
      
      appears at the bottom of the screen.
    7. Type g to generate the build scripts and to exit ccmake.
  7. Build vtk. This takes a while.

      % make
    
  8. Install vtk in /usr/local.

      % sudo make install
    

Comments

The MacPorts distribution of vtk5 includes the output from ccmake, so its build process is basically just the "make" and "make install" steps above. Somehow it invokes a subshell that isn't getting the correct environment variables, and the build fails. (In El Capitan, DYLD_LIBRARY_PATH isn't exported to subshells.) I don't know why the steps outlined above don't have this problem.

ccmake caches its settings in CMakeCache.txt. That file is included in the vtk5 port, and I compared it with the file I generated with ccmake to see which default values might need to be changed. The set listed above appears to be minimal. I can't promise that it's sufficient.

MacPorts' vtk5 port changes

  SET(VTK_OBJCXX_FLAGS_DEFAULT "-fobjc-gc")
to
  SET(VTK_OBJCXX_FLAGS_DEFAULT "")
at line 24 in CMakeLists.txt in the top vtk directory. This appears to be unnecessary when VTK_USE_COCOA is OFF. If VTK_USE_COCOA is ON and this change is not made, compilation will fail with an error message about unsupported garbage collection.

The following variables are set in the MacPorts' CMakeCache.txt but don't seem to be required (or don't require the values that macports uses):

CMAKE_CXX_COMPILER         /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
CMAKE_CXX_FLAGS            -pipe -DUSE_INTERP_ERRORLINE -stdlib=libc++ -I/opt/local/include
CMAKE_C_COMPILER           /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
CMAKE_C_FLAGS              -pipe -I/opt/local/include
CMAKE_EXE_LINKER_FLAGS     -L/opt/local/lib -Wl,-headerpad_max_install_names
CMAKE_MODULE_LINKER_FLAGS  -L/opt/local/lib -Wl,-headerpad_max_install_names
CMAKE_OSX_ARCHITECTURES    x86_64
CMAKE_OSX_DEPLOYMENT_TARGET 10.11
CMAKE_OSX_SYSROOT          /
CMAKE_SHARED_LINKER_FLAGS  -L/opt/local/lib -L/usr/local/lib -Wl,-headerpad_max_install_names
CMAKE_VERBOSE_MAKEFILE     ON
VTK_DATA_ROOT     /opt/local/share/VTKData (git clone git://vtk.org/VTKData.git)
VTK_USE_GL2PS              ON
VTK_WRAP_TCL               ON

The MacPorts' CMakeCache.txt says that these variables were set on the command line (with ccmake -D..., I assume), but I didn't set them and it didn't seem to cause a problem:

CMAKE_FIND_FRAMEWORK = LAST
CMAKE_INSTALL_NAME_DIR = /opt/local/lib/vtk-5.10
CMAKE_INSTALL_RPATH = /opt/local/lib/vtk-5.10
CMAKE_INSTALL_RPATH_USE_LINK_PATH = ON
CMAKE_MODULE_PATH = /opt/local/share/cmake/Modules
CMAKE_SYSTEM_PREFIX_PATH = /opt/local;/usr
TCL_INCLUDE_PATH = /opt/local/include
TCL_LIBRARY = /opt/local/lib/libtcl.dylib
TK_INCLUDE_PATH = /opt/local/include
TK_INTERNAL_PATH = something long
TK_LIBARY = /opt/local/lib/libtk.dylib
VTK_INSTALL_PREFIX = /opt/local
VTK_USE_RPATH = ON

These entries in MacPorts' CMakeCache.txt aren't available in ccmake when I run it with the files downloaded from www.vtk.org, but CMakeCache.txt doesn't say that they were set on the command line. I didn't set them:

CPACK_BINARY_BUNDLE and other CPACK options
VTK_TCL_TK_STATIC = OFF
VTK_USE_SYSTEM_GL2PS = OFF
VTK_USE_TK = ON
X11_fontconfig_LIB = /opt/local/lib/libfontconfig.dylib