Skip to content

Building Mantid on OS X 10.10 & 10.11 using clang and Xcode

Steven Hahn edited this page Aug 1, 2016 · 30 revisions

These instructions are from the assumptions of a blank newly installed Mac and want to use the system python. Other python distributions may work but have not been tested.

  1. First install Xcode and then clone the mantid git repository.
  • The last version to support OS X Mavericks is Xcode 6.2
  • The last version to support OS X Yosemite is Xcode 7.2.1
  • Our OS X El Capitan build server is currently running Xcode 7.3.1
  1. Install Apple's Command Line tools (without this then /usr/include will not exist)

      xcode-select --install
    
  2. Install Homebrew. If you already have Homebrew and are upgrading the OS follow the instructions here:

      ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  3. Add the necessary 'taps'

     brew tap homebrew/science
     brew tap homebrew/python
     brew tap mantidproject/mantid
     brew tap caskroom/cask
    
  4. Install required dependencies (will make a mantid-developer formula soon) If you plan on distributing your application bundle, change brew install to brew install --build-bottle

     brew cask install xquartz
     # mactex is optional, needed for parsing equations in qthelp documentation.
     brew cask install mactex
     brew install openssl
     brew install qt --with-qt3support --build-bottle
     brew install cmake
     # sip,pyqt and qscintilla2 bring in homebrew's python if
     # installed with --build-bottle. And add --build-from-source.
     brew install sip --build-from-source
     brew install pyqt --build-from-source
     brew install qscintilla2 --build-from-source
     # unit tests fail with 1.6.0.
     brew install poco --c++11
     brew install boost --c++11 
     # boost-python brings in homebrew's python if installed with --build-bottle.
     brew install boost-python --c++11 --build-from-source
     brew install gsl
     brew install hdf5 --c++11
     brew install libmxml
     brew install muparser
     brew install nexusformat --c++11
     brew install jsoncpp
     #removing tbb simplifies packaging
     brew install opencascade7 --without-tbb --build-bottle
     brew install qwt5
     brew install qwtplot3d
     brew install google-perftools
    
  5. Uninstall homebrew Python that some of the dependencies insist on installing

     brew uninstall python
    
  6. Optional: for cmake-gui

     brew cask install cmake
    
  7. Now to install the ipython stuff for the terminal in MantidPlot.

     sudo easy_install pip
     sudo -H pip install sphinx
     # https://github.com/mantidproject/mantid/issues/13481
     sudo -H pip install "ipython[notebook]==3.2.1"
     sudo -H pip install qtconsole
     sudo -H pip install pygments
     sudo -H pip install pyzmq
    
  8. Install the theme for sphinx

     sudo pip install sphinx_bootstrap_theme
    
  9. Install other python dependencies

     sudo pip install psutil
     brew install h5py
    
  10. Add Homebrew’s site-packages to your python path.

     mkdir -p ~/Library/Python/2.7/lib/python/site-packages
     echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
    
  11. Now you need to patch a header in your python!

a. If building on the command line with make or ninja.

    cd /usr/include/python2.7

or

    cd /System/Library/Frameworks/Python.framework/Headers 

then

    sudo cp pyport.h pyport.h.original
    sudo patch pyport.h $MANTIDCHECKOUTROOT/buildconfig/pyport.patch

b. If building with Xcode on OS X Yosemite

    cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7

then

    sudo cp pyport.h pyport.h.original
    sudo patch pyport.h $MANTIDCHECKOUTROOT/buildconfig/pyport.patch

Note: If Xcode updates for any reason, the patch will be lost.

  1. Now run CMake and select the Xcode generator with the default native compilers.

  2. Now open the project in Xcode (doing this from the command line to ensure the PYTHONPATH is correctly picked up by Xcode).

    cd /path/to/my/build/dir
    open Mantid.xcodeproj
    

Troubleshooting

  1. The main problem that can arise is due to python path issues. This usually either arises at the CMake or Run from Xcode steps. It is because the PYTHONPATH is not being picked up.
  2. If you have upgraded to Mavericks (OS X 10.9) from a previous version of OS X with homebrew already installed then you may encounter some issues related to the fact that the default std lib has changed. The easiest way to avoid this is to remove and then re-install all your formulas.
  3. You may find that if you build the MantidPlot target then you will get errors when you run, such as Can't start python and Cannot load Curve Fitting Plugins, this is due to the fact that the MantidPlot target does not contain all the dependencies. You are best, if you are unsure of the hierarchy, to just use the ALL_BUILD target and then just switch to the MantidPlot target in order to run.
  4. NOTE that you might need to run ./MantidPlot.app/Contents/MacOS/MantidPlot from the BUILD-DIR/bin (instead of open MantidPlot.app OR ./MantidPlot from BUILD-DIR/bin/MantidPlot.app/Contents/MacOS/) to get the library paths correct. Otherwise the issues above might show up (at least on OS X 10.11 El Capitan).