# Building OVITO on MacOS

## Installing dependencies

See the list of requirements and install the required build tools and third-party libraries. OVITO should be compiled with Apple's Clang compiler that is shipped with Xcode. It's easiest to use MacPorts to install many of the required dependencies. After installing MacPorts, run

    sudo port install netcdf python35 py35-sphinx py35-numpy py35-sip zlib \
                      boost cmake docbook-xml doxygen libxslt yasm

Download and install Qt 5.x for Mac.

Download and install PyQt5. Adjust the path to Qt's `qmake` below as needed:

    /opt/local/bin/python3.5 configure.py \
    	--qmake $HOME/Qt/5.7/clang_64/bin/qmake \
    	--confirm-license \
    	--no-designer-plugin \
    	--no-qml-plugin \
    	--assume-shared \
    	--sip=/opt/local/bin/sip-3.5 \
    	--concatenate \
    	--enable QtCore \
    	--enable QtGui \
    	--enable QtWidgets \
    	--enable QtMacExtras
    make -j2
    sudo make install

Download and install QScintilla2. Adjust the path to `qmake` below as needed:

    cd QScintilla_gpl-2.9.3/Qt4Qt5/
    $HOME/Qt/5.7/clang_64/bin/qmake qscintilla.pro
    make -j2
    install_name_tool -id $PWD/libqscintilla2.dylib libqscintilla2.dylib

Download and build a static version of the Libav video encoding library:

    wget https://libav.org/releases/libav-11.1.tar.gz
    tar xzfv libav-11.1.tar.gz
    cd libav-11.1
    ./configure \
    	--disable-network \
    	--disable-programs \
    	--disable-debug \
    	--disable-doc \
    	--disable-filters \
    	--enable-gpl \
    	--prefix=$HOME/libavstatic
    make install

The compiled libraries will be installed under `$HOME/libavstatic/`.

## Downloading the source code

To download OVITO's source code into a new subdirectory named `ovito`, run:

    git clone https://gitlab.com/stuko/ovito.git ovito

## Compiling OVITO

Within that directory, create a build directory and let CMake generate the Makefile:

    cd ovito
    mkdir build
    cd build
    cmake -DOVITO_BUILD_DOCUMENTATION=ON \
          -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_INSTALL_PREFIX=../install \
          -DCMAKE_PREFIX_PATH=$HOME/Qt/5.7/clang_64/ \
          -DPYTHON_INCLUDE_DIR=/opt/local/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m \
          -DPYTHON_LIBRARY=/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5.dylib \
          -DLIBAV_INCLUDE_DIR=$HOME/libavstatic/include \
          -DLIBAV_LIBRARY_DIR=$HOME/libavstatic/lib \
          -DSPHINX_PROCESSOR=/opt/local/bin/sphinx-build-3.5 \
          -DQSCINTILLA_INCLUDE_DIR=$HOME/QScintilla_gpl-2.9.3/Qt4Qt5 \
          -DQSCINTILLA_LIBRARY=$HOME/QScintilla_gpl-2.9.3/Qt4Qt5/libqscintilla2.dylib \
          ..

Adjust the paths above as needed. If this step fails, or if you want to disable individual components of OVITO, you can now run "`ccmake .`" to open the CMake configuration program. Finally build OVITO by running

    make -j4

If this succeeds, you can run `make install` to create a distributable app bundle in `ovito/install/`, which contains all dependencies.