# Building_Qt5_From_Source_with_QtWebkit_Added_Back_on_MacOSX

# We highly recommend you use the same Qt versions as official Sigil builds on Mac OS X.
# which is now Qt 5.11.2

# As of Qt 5.6, QtWebkit was removed from the stock Qt releases.  Sigil depends on this 
# module for both its BookView and Preview windows.  We are following the examples of
# the Linux Distributions and Adding back the latest QtWebKit to build our own

# FIRST:  make sure you have XCode 8, 9 or 10 or later installed and the Command Line Tools

# We will need to build Qt5 from source first.  
# These instructions will lead you through building from source

# set the delpoyment target
export MACOSX_DEPLOYMENT_TARGET=10.9

# cd to a location to store your src tree then do
export MYQTSRC=`pwd`


# Build Prerequisites
# -------------------
# First build and install the following prerequisites for the build: 
#      cmake, libpng, ligjpeg 
# and install into /usr/local so that they can be found during qtwebkit's build
# Note: older versions of these prerequisites may work but have not been tested


# cmake 3.12.0 or later from https://cmake.org/download
tar -zxvf cmake-3.12.0.tar.gz
cd cmake-3.12.0
./bootstrap --prefix=/usr/local -- -DCMAKE_BUILD_TYPE:STRING=Release
make
sudo make install

# libpng 1.6.35 or later from png's sourcefore site: http://www.libpng.org/pub/png/libpng.html
tar -zxvf libpng-1.6.35.tar.gz
cd libpng-1.6.35
./configure --enable-static=yes --enable-shared=no --prefix=/usr/local
make
sudo make install

#libjpeg from the Independent JPEG Group -  https://http://www.ijg.org
tar -zxvf jpegsrc.v9c.tar.gz
cd jpeg-9c
./configure --enable-static=yes --enable-shared=no --prefix=/usr/local
make
sudo make install


# Building Qt5.11.2 from source
# -----------------------------

# download qt-everywhere-src-5.11.2.tar.gz directly from Qt
# From:  http://download.qt.io/archive/qt/5.11/5.11.2/single/

# and then unpack it
tar -zxvf qt-everywhere-src-5.11.2.tar.gz

# then apply the font weight fix patch if you are on Mojave or later  
cd qt-everywhere-src-5.11.2
patch -p0 < ../qt_mojave_fontweight_fix.patch

# then apply build fixes for qtwebengine when built with 10.14 SDK (XCode 10)
patch -p0 < ../qt511.2_fixes1.patch

# Create a destination directory to house your complete Qt binary in your home directory
# to be similar to how stock Qt does it
cd ~/
mkdir Qt511

# Now return and create a shadow build inside a new directory to keep your Qt 5.11.2 sources clean
cd ${MYQTSRC}
mkdir buildqt
cd buildqt

../qt-everywhere-src-5.11.2/configure --prefix=/Users/${USER}/Qt511 -opensource -nomake examples -nomake tests

# note the build itself can take a couple of hours depending on memory available, disk and cpus used
make -j4
make install

# After the install phase completes your newly built Qt should exist in ~/Qt511 ready to be
# Used to build QtWebKit


# Building The Latest QtWebKit for Qt5.11.2
# -----------------------------------------

# Detailed QtWebKit build instructions can be found here:
# https://github.com/annulen/webkit/wiki/Building-QtWebKit-on-OS-X

cd ${MYQTSRC}

# clone qtwebkit from git::/code.qt.io/qt/qtwebkit.git and get the QtWebKit 5.212 Branch
git clone git://code.qt.io/qt.qtwebkit.git

cd qtwebkit

./Tools/Scripts/build-webkit --qt --cmakeargs="-Wno-dev -DQt5_DIR=$HOME/Qt511/lib/cmake/Qt5 -DCMAKE_PREFIX_PATH=/usr/local"

make -C WebKitBuild/Release install

# QtWebKit will be installed into your Qt directory, side by side with other Qt modules, 
# and will be available for building your projects.

