Friday, July 28, 2017

Setting up a Mac OSX Development Environment for VTK, ITK, Qt 4 and SMILI

I recently got access to a Mac and decided to improve support for SMILI on Mac OSX. This required setting up the Mac OSX development environment and so I log my experiences/steps in this post.

Firstly some notes. This is to setup VTK 5 and/or 6, ITK 4.10+ and Qt 4 with the current version of Mac OSX at the time - Sierra (10.12).

The first steps involved setting up Homebrew. This allows one to install Git and CMake for the command-line.
brew install make

Next we installed Xcode from the AppStore. You should not run CMake on libraries until Xcode has been installed.

Then (or during the XCode install) we download the required libraries for your environment:

  • Insight Toolkit (ITK) - I used version 4.10.1, but newer versions of ITK 4 should be OK.
  • Visualisation Toolkit (VTK) - I used version 6.3.0, but also a modified version of 5.8.0 (for MSVC 2013) that I made available here. Versions newer than 6.3.0 had visualisation bugs introduced into SMILI.
  • Qt 4.8.x - Just use the home-brew version described here. I tried using version 4.8.6 that you can find here. Download the .tar.gz version for Mac OSX. But it had issues, see below. So the HomeBrew version as described here.

Qt 4

I Failed: After Xcode was installed, I began compiling Qt. Turns out that using the zip version messes up the line endings and breaks the configure script. So make sure to download the TAR version. When compiling, There was a compile error for the 'qpaintengine_mac.cpp' file. The fix for Qt 4.8.6 is here. There are issues with 10.9 and libstd++ which I haven't figured out yet. I will update this side of the post once I have. I will leave the configure command I tried using here for future reference:
./configure -fast -release -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -DMACOSX_DEPLOYMENT_TARGET=10.9 -arch x86_64
You could also try 4.8.7 from here. It required the same fix as 4.8.6 from here.

I Succeeded: by using the HomeBrew Qt4 version as described here. I just did step 2 as I had a fresh install. No compilation, just downloaded and installed. This will become outdated at some point unless maintained, so you may need to search for other recipes. This link might help in that case.


ITK

No issues. Just build fine from source. I usually enable review to get access to less known ITK classes. I used the following CMake command to generate the project for Sublime Text:
ccmake -G "Sublime Text 2 - Unix Makefiles" -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.6 ..

VTK

I Failed: Once Qt 4 is built and installed, I enabled VTK_USE_QT to ON. I had two major issues. The first issue I had was with the duplicate symbols error with TIFF. Installing lib tiff with HomeBrew solved the problem, but could potentially caused crashes in certain versions of Mac OSX, so will post a better solution later. The second was a garbage collection compilation error that I have yet to find solution for.

I succeeded: Compiling VTK 6.3 had no issues at all. I used the same CMake command as for ITK. I used deployment target of 10.6 to ensure support for Mac OSX 10.6.

EDIT: I succeeded: Compiling VTK 5.8 by ensuring that the VTK_REQUIRED_OBJCXX_FLAGS was empty. This was because of a 'garbage collection not found' error. This is because GC memory management model has been deprecated and removed. See the COCOA VTK page for more details.

SMILI

Once the above dependencies are built, SMILI v1.01 had no issues. I reused the CMake command for ITK above. I built both 10.6 and 10.9 deployment targets for ITK, VTK and SMILI for testing.

More will be added as I encounter/fix issues.

Cheers Shakes - L3mming