From 00717ec936aa406695e69b11afc9db26bc0bf661 Mon Sep 17 00:00:00 2001
From: Dirk Hohndel <dirk@hohndel.org>
Date: Sun, 20 Dec 2015 15:27:26 -0800
Subject: [PATCH 1/2] Don't quite like to do squash commits but since there was
 quite a bit of trial and error on experimentations for the iOS stuff I needed
 a clean way to clean things up. This squashed path series gives us a working
 (in the sense that it starts) binary for the iOS simulator.

to use:
cd packaging/ios
sh build.sh

this will build the prerequisites, not Subsurface

open QtCreator and load the subsurface-ios in
packaging/ios/subsurface-ios/subsurface-ios.pro

configure for ios simulator

compile & run, things should work.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
---
 CMakeLists.txt                                   |  25 ++-
 packaging/ios/build.sh                           | 243 +++++++++++------------
 packaging/ios/configure-for-ios.sh               | 106 ----------
 packaging/ios/deployment.pri                     |  13 ++
 packaging/ios/iPhoneDeviceCMakeToolchain         |  29 +++
 packaging/ios/iPhoneSimulatorCMakeToolchain      |  22 ++
 packaging/ios/subsurface-ios/MainForm.ui.qml     |  25 +++
 packaging/ios/subsurface-ios/deployment.pri      |  13 ++
 packaging/ios/subsurface-ios/main.qml            |  40 ++++
 packaging/ios/subsurface-ios/qml.qrc             |   6 +
 packaging/ios/subsurface-ios/subsurface-ios.pro  | 221 +++++++++++++++++++++
 profile-widget/divepixmapitem.cpp                |   2 +-
 profile-widget/diveprofileitem.cpp               |   2 +-
 profile-widget/profilewidget2.cpp                |  12 +-
 qt-models/divelocationmodel.h                    |   2 +-
 subsurface-core/CMakeLists.txt                   |  23 ++-
 subsurface-core/configuredivecomputerthreads.cpp |   1 +
 subsurface-core/file.c                           |   5 +-
 subsurface-core/libdivecomputer.c                |   2 +-
 subsurface-core/libdivecomputer.h                |   2 +
 subsurface-core/macos.c                          |   2 +
 subsurface-core/profile.c                        |   2 +
 subsurface-core/qt-gui.h                         |   2 -
 subsurface-core/subsurfacestartup.c              |   2 +
 24 files changed, 547 insertions(+), 255 deletions(-)
 delete mode 100755 packaging/ios/configure-for-ios.sh
 create mode 100644 packaging/ios/deployment.pri
 create mode 100644 packaging/ios/iPhoneDeviceCMakeToolchain
 create mode 100644 packaging/ios/iPhoneSimulatorCMakeToolchain
 create mode 100644 packaging/ios/subsurface-ios/MainForm.ui.qml
 create mode 100644 packaging/ios/subsurface-ios/deployment.pri
 create mode 100644 packaging/ios/subsurface-ios/main.qml
 create mode 100644 packaging/ios/subsurface-ios/qml.qrc
 create mode 100644 packaging/ios/subsurface-ios/subsurface-ios.pro

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 13f34fd..309a335 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -87,11 +87,18 @@ include(cmake/Modules/pkgconfig_helper.cmake)
 # if you think a module miss anything, take a look on the specific
 # module file.
 include(cmake/Modules/HandleFindGit2.cmake)
-include(cmake/Modules/HandleFindLibDiveComputer.cmake)
-if(${SUBSURFACE_TARGET_EXECUTABLE} MATCHES "DesktopExecutable")
-	include(cmake/Modules/HandleFindMarble.cmake)
-	include(cmake/Modules/HandleFindGrantlee.cmake)
-	include(cmake/Modules/HandleUserManual.cmake)
+
+if(NOT IOS_PLATFORM)
+	include(cmake/Modules/HandleFindLibDiveComputer.cmake)
+    if(${SUBSURFACE_TARGET_EXECUTABLE} MATCHES "DesktopExecutable")
+    	include(cmake/Modules/HandleFindMarble.cmake)
+    	include(cmake/Modules/HandleFindGrantlee.cmake)
+    	include(cmake/Modules/HandleUserManual.cmake)
+    endif()
+else()
+	if(LIBDC_HEADERSONLY)
+		include_directories(${CMAKE_SOURCE_DIR}/../libdivecomputer/include)
+	endif()
 endif()
 include(cmake/Modules/HandleFtdiSupport.cmake)
 include(cmake/Modules/HandleVersionGeneration.cmake)
@@ -101,7 +108,9 @@ pkg_config_library(LIBXML libxml-2.0 REQUIRED)
 pkg_config_library(LIBSQLITE3 sqlite3 REQUIRED)
 pkg_config_library(LIBXSLT libxslt REQUIRED)
 pkg_config_library(LIBZIP libzip REQUIRED)
-pkg_config_library(LIBUSB libusb-1.0 QUIET)
+if(NOT IOS_PLATFORM)
+	pkg_config_library(LIBUSB libusb-1.0 QUIET)
+endif()
 
 if(SMARTTRAK_IMPORT)
 	pkg_config_library(GLIB2 glib-2.0 REQUIRED)
@@ -158,7 +167,9 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
                 OUTPUT_STRIP_TRAILING_WHITESPACE
         )
         find_library(APP_SERVICES_LIBRARY ApplicationServices)
-        find_library(HID_LIB HidApi)
+	if(NOT IOS_PLATFORM)
+		find_library(HID_LIB HidApi)
+	endif()
         set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} ${HID_LIB})
         set(EXTRA_LIBS ${APP_SERVICES_LIBRARY})
         set(ICON_FILE ${CMAKE_SOURCE_DIR}/packaging/macosx/Subsurface.icns)
diff --git a/packaging/ios/build.sh b/packaging/ios/build.sh
index e8f8069..92b1bd6 100644
--- a/packaging/ios/build.sh
+++ b/packaging/ios/build.sh
@@ -1,46 +1,56 @@
 #!/bin/bash
-set -e
+set -x
 
 TOP=$(pwd)
 
-SUBSURFACE_SOURCE=${TOP}/../subsurface
+SUBSURFACE_SOURCE=${TOP}/../../../subsurface
 IOS_QT=${TOP}/Qt
 
+# Build Subsurface-mobile by default
+SUBSURFACE_MOBILE=1
+
 mkdir -p $TOP/install-root/lib $TOP/install-root/bin $TOP/install-root/include
 PKG_CONFIG_LIBDIR=$TOP/install-root/lib/pkgconfig
 
+export PKG_CONFIG_PATH=$PKG_CONFIG_LIBDIR
+
+declare TOOLCHAIN_FILE="iPhoneSimulatorCMakeToolchain"
+declare -x PREFIX=$TOP/install-root
+declare -x SDK_NAME="iphonesimulator"
 # Build architecture,  [armv7|armv7s|arm64|i386|x86_64]
-export ARCH=i386
+declare -x ARCH_NAME="x86_64"
+declare -x ARCH=$ARCH_NAME
+declare -x SDK_DIR=`xcrun --sdk $SDK_NAME --show-sdk-path`
+declare -x PLATFORM_DIR=`xcrun --sdk $SDK_NAME --show-sdk-platform-path`
 
-#arm-apple-darwin, arch64-apple-darwin, i386-apple-darwin*, x86_64-apple-darwin*
-export BUILDCHAIN=i386-apple-darwin*
+declare -x CC=`xcrun -sdk $SDK_NAME -find clang`
+declare -x CXX=`xcrun -sdk $SDK_NAME -find clang++`
+declare -x LD=`xcrun -sdk $SDK_NAME -find ld`
+declare -x CFLAGS="-arch $ARCH_NAME -isysroot $SDK_DIR -miphoneos-version-min=6.0 -I$SDK_DIR/usr/include"
+declare -x CXXFLAGS="$CFLAGS"
+declare -x LDFLAGS="$CFLAGS  -lpthread -lc++ -L$SDK_DIR/usr/lib"
+export BUILDCHAIN=${ARCH_NAME}-apple-darwin
 
 #iphonesimulator or iphoneos  // SIMULATOR or OS
 export SDK=iphonesimulator
-export IOS_PLATFORM=SIMULATOR
-
-export SDKVERSION=$(xcrun --sdk $SDK --show-sdk-version) # current version
-export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version
-
-#make subsurface set this to a saner value
-export PREFIX=$TOP/install-root
-
-# Binaries
-export CC=$(xcrun --sdk $SDK --find gcc)
-export CPP=$(xcrun --sdk $SDK --find gcc)" -E"
-export CXX=$(xcrun --sdk $SDK --find g++)
-export LD=$(xcrun --sdk $SDK --find ld)
+export IOS_PLATFORM=SIMULATOR64
 
-# Flags
-export CFLAGS="$CFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -miphoneos-version-min=$SDKVERSION"
-export CPPFLAGS="$CPPFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -miphoneos-version-min=$SDKVERSION"
-export CXXFLAGS="$CXXFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include"
-export LDFLAGS="$LDFLAGS -arch $ARCH -isysroot $SDKROOT -L$PREFIX/lib"
-export PKG_CONFIG_PATH="$PKG_CONFIG_PATH":"$SDKROOT/usr/lib/pkgconfig":"$PREFIX/lib/pkgconfig"
+# openssl build stuff.
+export DEVELOPER=$(xcode-select --print-path)\
+export IPHONEOS_SDK_VERSION=$(xcrun --sdk iphoneos --show-sdk-version)
+export IPHONEOS_DEPLOYMENT_VERSION="6.0"
+export IPHONEOS_PLATFORM=$(xcrun --sdk iphoneos --show-sdk-platform-path)
+export IPHONEOS_SDK=$(xcrun --sdk iphoneos --show-sdk-path)
+export IPHONESIMULATOR_PLATFORM=$(xcrun --sdk iphonesimulator --show-sdk-platform-path)
+export IPHONESIMULATOR_SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
+export OSX_SDK_VERSION=$(xcrun --sdk macosx --show-sdk-version)
+export OSX_DEPLOYMENT_VERSION="10.8"
+export OSX_PLATFORM=$(xcrun --sdk macosx --show-sdk-platform-path)
+export OSX_SDK=$(xcrun --sdk macosx --show-sdk-path)
 
 # Which versions are we building against?
 SQLITE_VERSION=3090200
-LIBXML2_VERSION=2.9.3
+LIBXML2_VERSION=2.9.2
 LIBXSLT_VERSION=1.1.28
 LIBZIP_VERSION=1.0.1
 LIBZIP_VERSION=0.11.2
@@ -50,10 +60,8 @@ LIBUSB_VERSION=1.0.19
 OPENSSL_VERSION=1.0.1p
 LIBFTDI_VERSION=1.2
 
-target=i386
-hosttarget=i386
-platform=iPhoneSimulator
-
+target=$ARCH
+hosttarget=$ARCH
 
 if [ ! -e sqlite-autoconf-${SQLITE_VERSION}.tar.gz ] ; then
 	curl -O http://www.sqlite.org/2015/sqlite-autoconf-${SQLITE_VERSION}.tar.gz
@@ -62,8 +70,8 @@ if [ ! -e sqlite-autoconf-${SQLITE_VERSION} ] ; then
 	tar -zxf sqlite-autoconf-${SQLITE_VERSION}.tar.gz
 fi
 if [ ! -e $PKG_CONFIG_LIBDIR/sqlite3.pc ] ; then
-	mkdir -p sqlite-build-$platform
-	pushd sqlite-build-$platform
+	mkdir -p sqlite-build-$ARCH_NAME
+	pushd sqlite-build-$ARCH_NAME
 	CFLAGS="${CFLAGS} -DSQLITE_ENABLE_LOCKING_STYLE=0"
 
 	../sqlite-autoconf-${SQLITE_VERSION}/configure \
@@ -108,8 +116,8 @@ if [ ! -e libxslt-${LIBXSLT_VERSION} ] ; then
 	cp libxml2-${LIBXML2_VERSION}/config.sub libxslt-${LIBXSLT_VERSION}
 fi
 if [ ! -e $PKG_CONFIG_LIBDIR/libxslt.pc ] ; then
-	mkdir -p libxslt-build-$ARCH
-	pushd libxslt-build-$ARCH
+	mkdir -p libxslt-build-$ARCH_NAME
+	pushd libxslt-build-$ARCH_NAME
 	../libxslt-${LIBXSLT_VERSION}/configure --host=${BUILDCHAIN} --prefix=${PREFIX} --with-libxml-prefix=${PREFIX} --without-python --without-crypto --enable-static --disable-shared
 	make
 	make install
@@ -123,14 +131,59 @@ if [ ! -e libzip-${LIBZIP_VERSION} ] ; then
 	tar -zxf libzip-${LIBZIP_VERSION}.tar.gz
 fi
 if [ ! -e $PKG_CONFIG_LIBDIR/libzip.pc ] ; then
-	mkdir -p libzip-build-$ARCH
-	pushd libzip-build-$ARCH
+	mkdir -p libzip-build-$ARCH_NAME
+	pushd libzip-build-$ARCH_NAME
 	../libzip-${LIBZIP_VERSION}/configure --host=${BUILDCHAIN} --prefix=${PREFIX} --enable-static --disable-shared
 	make
 	make install
 	popd
 fi
 
+configure_openssl() {
+    OS=$1
+    ARCH=$2
+    PLATFORM=$3
+    SDK_VERSION=$4
+    DEPLOYMENT_VERSION=$5
+
+    export CROSS_TOP="${PLATFORM}/Developer"
+    export CROSS_SDK="${OS}${SDK_VERSION}.sdk"
+# if [ "$ARCH" == "i386" ]; then
+    ./Configure darwin64-${ARCH}-cc --openssldir="${PREFIX}" --prefix="${PREFIX}"
+    sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -arch $ARCH -mios-simulator-version-min=${DEPLOYMENT_VERSION} !" "Makefile"
+# else
+#   ./Configure iphoneos-cross -no-asm --openssldir="${PREFIX}"
+#  sed -ie "s!^CFLAG=!CFLAG=-mios-simulator-version-min=${DEPLOYMENT_VERSION} !" "Makefile"
+#  perl -i -pe 's|static volatile sig_atomic_t intr_signal|static volatile int intr_signal|' crypto/ui/ui_openssl.c
+# fi
+}
+
+build_openssl()
+{
+   ARCH=$1
+   SDK=$2
+   TYPE=$3
+   export BUILD_TOOLS="${DEVELOPER}"
+   mkdir -p "lib-${TYPE}"
+
+   rm -rf openssl-${OPENSSL_VERSION}
+   tar xfz openssl-${OPENSSL_VERSION}.tar.gz
+   pushd .
+   cd "openssl-${OPENSSL_VERSION}"
+   #fix header for Swift
+   sed -ie "s/BIGNUM \*I,/BIGNUM \*i,/g" crypto/rsa/rsa.h
+   if [ "$TYPE" == "ios" ]; then
+    # if [ "$ARCH" == "i386" ]; then
+         configure_openssl "iPhoneSimulator" $ARCH ${IPHONESIMULATOR_PLATFORM} ${IPHONEOS_SDK_VERSION} ${IPHONEOS_DEPLOYMENT_VERSION}
+    # else
+    #    configure_openssl "iPhoneOS" $ARCH ${IPHONEOS_PLATFORM} ${IPHONEOS_SDK_VERSION} ${IPHONEOS_DEPLOYMENT_VERSION}
+    # fi
+   fi
+   make
+   make install_sw
+   popd
+}
+
 if [ ! -e openssl-${OPENSSL_VERSION}.tar.gz ] ; then
 	wget -O openssl-${OPENSSL_VERSION}.tar.gz http://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
 fi
@@ -139,20 +192,7 @@ if [ ! -e openssl-build-$ARCH ] ; then
 	mv openssl-${OPENSSL_VERSION} openssl-build-$ARCH
 fi
 if [ ! -e $PKG_CONFIG_LIBDIR/libssl.pc ] ; then
-	pushd openssl-build-$ARCH
-	perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
-	if [[ "${ARCH}" != "i386" && "${ARCH}" != "x86_64" ]]; then
-		sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
-	fi
-	./Configure iphoneos-cross --openssldir="$PREFIX"
-	sed -ie "s!^CFLAG=!CFLAG=-isysroot ${BUILDCHAIN} -miphoneos-version-min=${SDKVERSION} !" "Makefile"
-	sed -ie "s!^DIRS=.*!DIRS= crypto ssl !" "Makefile"
-	# Use env to make all these temporary, so they don't pollute later builds.
-#	bash -x ./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=$PREFIX
-	make depend
-	make build_libs
-	make install_sw
-	popd
+	build_openssl "$ARCH" "${IPHONESIMULATOR_SDK}" "ios"
 fi
 
 if [ ! -e libssh2-${LIBSSH2_VERSION}.tar.gz ] ; then
@@ -172,15 +212,6 @@ if [ ! -e $PKG_CONFIG_LIBDIR/libssh2.pc ] ; then
 	popd
 fi
 
-# ios cmake toolchain
-
-if [ ! -e ios-cmake-master.tar.gz ] ; then
-	wget -O ios-cmake-master.tar.gz https://github.com/cristeab/ios-cmake/archive/master.tar.gz
-fi
-if [ ! -e ios-cmake-master ] ; then
-	tar -zxf ios-cmake-master.tar.gz
-fi
-
 if [ ! -e libgit2-${LIBGIT2_VERSION}.tar.gz ] ; then
 	wget -O libgit2-${LIBGIT2_VERSION}.tar.gz https://github.com/libgit2/libgit2/archive/v${LIBGIT2_VERSION}.tar.gz
 fi
@@ -190,12 +221,12 @@ fi
 if [ ! -e $PKG_CONFIG_LIBDIR/libgit2.pc ] ; then
 	mkdir -p libgit2-build-$ARCH
 	pushd libgit2-build-$ARCH
-	PKGCONF=$(which pkg-config)
-	cmake -DCMAKE_TOOLCHAIN_FILE=${TOP}/ios-cmake-master/toolchain/iOS.cmake -DIOS_PLATFORM=${IOS_PLATFORM} \
-		-DCMAKE_SIZEOF_VOID_P=4 \
-		-DPKG_CONFIG_EXECUTABLE=${PKGCONF} \
+	cmake ../libgit2-${LIBGIT2_VERSION} \
+	    -G "Unix Makefiles" \
+	    -DBUILD_SHARED_LIBS="OFF" \
+	    -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_DEV" \
 		-DSHA1_TYPE=builtin \
-		-DBUILD_CLAR=OFF -DBUILD_SHARED_LIBS=OFF \
+		-DBUILD_CLAR=OFF \
 		-DCMAKE_INSTALL_PREFIX=${PREFIX} \
 		-DCMAKE_PREFIX_PATH=${PREFIX} \
 		-DCURL=OFF \
@@ -265,63 +296,29 @@ fi
 # 	rm $PREFIX/lib/libftdi1.so*
 # fi
 #
-# if [ ! -e $PKG_CONFIG_LIBDIR/libdivecomputer.pc ] ; then
-# 	mkdir -p libdivecomputer-build-$ARCH
-# 	pushd libdivecomputer-build-$ARCH
-# 	$SUBSURFACE_SOURCE/../libdivecomputer/configure --host=${BUILDCHAIN} --prefix=${PREFIX} --enable-static --disable-shared --enable-examples=no
-# 	make
-# 	make install
-# 	popd
-# fi
-#
-# if [ ! -e qt-android-cmake ] ; then
-# 	git clone git://github.com/LaurentGomila/qt-android-cmake.git
-# else
-# 	pushd qt-android-cmake
-# 	git pull
-# 	popd
-# fi
-#
-# # Should we build the mobile ui or the desktop ui?
-# if [ ! -z "$SUBSURFACE_MOBILE" ] ; then
-# 	mkdir -p subsurface-mobile-build-$ARCH
-# 	cd subsurface-mobile-build-$ARCH
-# 	MOBILE_CMAKE="-DSUBSURFACE_TARGET_EXECUTABLE=MobileExecutable"
-# 	# FIXME: We should install as a different package and name to.
-# else
-# 	mkdir -p subsurface-build-$ARCH
-# 	cd subsurface-build-$ARCH
-# fi
-#
-# # somehting in the qt-android-cmake-thingies mangles your path, so thats why we need to hard-code ant and pkg-config here.
-# if [ $PLATFORM = Darwin ] ; then
-# 	ANT=/usr/local/bin/ant
-# 	FTDI=OFF
-# else
-# 	ANT=/usr/bin/ant
-# 	FTDI=ON
-# fi
-# PKGCONF=$(which pkg-config)
-# cmake $MOBILE_CMAKE \
-# 	-DQT_ANDROID_ANT=${ANT} \
-# 	-DPKG_CONFIG_EXECUTABLE=${PKGCONF} \
-# 	-DQT_ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT \
-# 	-DQT_ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT \
-# 	-DCMAKE_TOOLCHAIN_FILE=$BUILDROOT/qt-android-cmake/toolchain/android.toolchain.cmake \
-# 	-DQT_ANDROID_CMAKE=$BUILDROOT/qt-android-cmake/AddQtAndroidApk.cmake \
-# 	-DFORCE_LIBSSH=ON \
-# 	-DLIBDC_FROM_PKGCONFIG=ON \
-# 	-DLIBGIT2_FROM_PKGCONFIG=ON \
-# 	-DNO_MARBLE=ON \
-# 	-DNO_PRINTING=ON \
-# 	-DNO_USERMANUAL=ON \
-# 	-DFBSUPPORT=OFF \
-# 	-DCMAKE_PREFIX_PATH:UNINITIALIZED=${QT5_ANDROID}/android_${QT_ARCH}/lib/cmake \
-# 	-DCMAKE_BUILD_TYPE=Debug \
-# 	-DFTDISUPPORT=${FTDI} \
-# 	$SUBSURFACE_SOURCE
-# make
-# #make install INSTALL_ROOT=android_build
-# # bug in androiddeployqt? why is it looking for something with the builddir in it?
-# #ln -fs android-libsubsurface.so-deployment-settings.json android-libsubsurface-build-${ARCH}.so-deployment-settings.json
-# #$QT5_ANDROID_BIN/androiddeployqt --output android_build
+
+# build libdivecomputer
+if [ ! -d libdivecomputer ] ; then
+	git clone -b Subsurface-branch git://subsurface-divelog.org/libdc libdivecomputer
+fi
+cd libdivecomputer
+git pull --rebase
+if ! git checkout Subsurface-branch ; then
+	echo "can't check out the Subsurface-branch branch of libdivecomputer -- giving up"
+	exit 1
+fi
+cd ..
+
+if [ ! -e $PKG_CONFIG_LIBDIR/libdivecomputer.pc ] ; then
+	if [ ! -f ../libvidecomputer/configure ] ; then
+		autoreconf --install ../libdivecomputer
+	fi
+ 	mkdir -p libdivecomputer-build-$ARCH
+ 	pushd libdivecomputer-build-$ARCH
+ 	../libdivecomputer/configure --host=${BUILDCHAIN} --prefix=${PREFIX} --enable-static --disable-shared --enable-examples=no
+ 	make
+ 	make install
+ 	popd
+ fi
+
+# Should we build the mobile ui or the desktop ui?
diff --git a/packaging/ios/configure-for-ios.sh b/packaging/ios/configure-for-ios.sh
deleted file mode 100755
index 1624bc3..0000000
--- a/packaging/ios/configure-for-ios.sh
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/bin/sh
-set -e
-
-usage () {
-  echo "Usage: [VARIABLE...] $(basename $0) architecture"
-  echo ""
-  echo "  architecture   Target architecture. [armv7|armv7s|arm64|i386|x86_64]"
-  echo ""
-  echo "  VARIABLEs are:"
-  echo "    SDKVERSION   Target a specific SDK version."
-  echo "    PREFIX       Custom install prefix, useful for local installs."
-  echo "    CHOST        Configure host, set if not deducable by ARCH."
-  echo "    SDK          SDK target, set if not deducable by ARCH. [iphoneos|iphonesimulator]"
-  echo ""
-  echo "    CFLAGS CPPFLAGS CXXFLAGS LDFLAGS PKG_CONFIG_PATH"
-  echo ""
-  echo "  All additional parameters are passed to the configure script."
-  exit 1
-}
-
-# Sanity checks
-if [ "$#" -lt 1 ]; then
-  echo "Please supply an architecture name."
-  usage
-fi
-
-if [ ! -x "./configure" ] ; then
-  echo "No configure script found."
-  usage
-fi
-
-# Build architecture
-export ARCH=$1
-
-# Export supplied CHOST or deduce by ARCH
-if [ ! -z "$CHOST" ]; then
-  export CHOST
-else
-  case $ARCH in
-    armv7 | armv7s )
-      export CHOST=arm-apple-darwin*
-      ;;
-    arm64 )
-      export CHOST=aarch64-apple-darwin*
-      ;;
-    i386 | x86_64 )
-      export CHOST=$ARCH-apple-darwin*
-      ;;
-    * )
-      usage
-    ;;
-  esac
-fi
-
-# Export supplied SDK or deduce by ARCH
-if [ ! -z "$SDK" ]; then
-  export SDK
-else
-  case $ARCH in
-    armv7 | armv7s | arm64 )
-      export SDK=iphoneos
-      ;;
-    i386 | x86_64 )
-      export SDK=iphonesimulator
-      ;;
-    * )
-      usage
-    ;;
-  esac
-fi
-
-# Export supplied SDKVERSION or use system default
-if [ ! -z "$SDKVERSION" ]; then
-  SDKNAME=$(basename $(xcrun --sdk $SDK --show-sdk-platform-path) .platform)
-  export SDKVERSION
-  export SDKROOT=$(xcrun --sdk $SDK --show-sdk-platform-path)"/Developer/SDKs/$SDKNAME.$SDKVERSION.sdk"
-else
-  export SDKVERSION=$(xcrun --sdk $SDK --show-sdk-version) # current version
-  export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version
-fi
-
-export PREFIX
-
-# Binaries
-export CC=$(xcrun --sdk $SDK --find gcc)
-export CPP=$(xcrun --sdk $SDK --find gcc)" -E"
-export CXX=$(xcrun --sdk $SDK --find g++)
-export LD=$(xcrun --sdk $SDK --find ld)
-
-# Flags
-export CFLAGS="$CFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -miphoneos-version-min=$SDKVERSION"
-export CPPFLAGS="$CPPFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -miphoneos-version-min=$SDKVERSION"
-export CXXFLAGS="$CXXFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include"
-export LDFLAGS="$LDFLAGS -arch $ARCH -isysroot $SDKROOT -L$PREFIX/lib"
-export PKG_CONFIG_PATH="$PKG_CONFIG_PATH":"$SDKROOT/usr/lib/pkgconfig":"$PREFIX/lib/pkgconfig"
-
-# Remove script parameters
-shift 1
-
-# Run configure
-./configure \
-	--prefix="$PREFIX" \
-	--host="$CHOST" \
-	--enable-static \
-	--disable-shared \
-	$@
diff --git a/packaging/ios/deployment.pri b/packaging/ios/deployment.pri
new file mode 100644
index 0000000..265ce71
--- /dev/null
+++ b/packaging/ios/deployment.pri
@@ -0,0 +1,13 @@
+unix:!android {
+    isEmpty(target.path) {
+        qnx {
+            target.path = /tmp/$${TARGET}/bin
+        } else {
+            target.path = /opt/$${TARGET}/bin
+        }
+        export(target.path)
+    }
+    INSTALLS += target
+}
+
+export(INSTALLS)
diff --git a/packaging/ios/iPhoneDeviceCMakeToolchain b/packaging/ios/iPhoneDeviceCMakeToolchain
new file mode 100644
index 0000000..f74dc09
--- /dev/null
+++ b/packaging/ios/iPhoneDeviceCMakeToolchain
@@ -0,0 +1,29 @@
+INCLUDE(CMakeForceCompiler)
+
+SET (CMAKE_CROSSCOMPILING   TRUE)
+SET (CMAKE_SYSTEM_NAME      "Darwin")
+SET (CMAKE_SYSTEM_PROCESSOR "arm")
+SET (CMAKE_OSX_SYSROOT      "$ENV{PLATFORM_DIR}")
+
+SET (CMAKE_C_COMPILER       $ENV{CC})
+SET (CMAKE_CXX_COMPILER	    $ENV{CXX})
+
+SET (CMAKE_FIND_ROOT_PATH               "$ENV{SDK_DIR}" "$ENV{PLATFORM_DIR}")
+SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM  NEVER)
+SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY  ONLY)
+SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE  ONLY)
+
+MESSAGE	(STATUS	"PLATFORM_DIR = $ENV{PLATFORM_DIR}")
+MESSAGE	(STATUS	"SDK_DIR = $ENV{SDK_DIR}")
+MESSAGE	(STATUS	"CC = $ENV{CC}")
+MESSAGE	(STATUS	"CXX = $ENV{CXX}")
+MESSAGE	(STATUS	"LD = $ENV{LD}")
+
+
+
+
+
+
+
+
+
diff --git a/packaging/ios/iPhoneSimulatorCMakeToolchain b/packaging/ios/iPhoneSimulatorCMakeToolchain
new file mode 100644
index 0000000..16219f0
--- /dev/null
+++ b/packaging/ios/iPhoneSimulatorCMakeToolchain
@@ -0,0 +1,22 @@
+INCLUDE(CMakeForceCompiler)
+
+SET (CMAKE_CROSSCOMPILING   TRUE)
+SET (CMAKE_SYSTEM_NAME      "Darwin")
+SET (CMAKE_SYSTEM_PROCESSOR "i386")
+SET (CMAKE_OSX_SYSROOT      "$ENV{PLATFORM_DIR}")
+
+SET (CMAKE_C_COMPILER       $ENV{CC})
+SET (CMAKE_CXX_COMPILER	    $ENV{CXX})
+
+SET (CMAKE_FIND_ROOT_PATH               "$ENV{SDK_DIR}" "$ENV{PLATFORM_DIR}")
+SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM  NEVER)
+SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY  ONLY)
+SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE  ONLY)
+
+MESSAGE	(STATUS	"PLATFORM_DIR = $ENV{PLATFORM_DIR}")
+MESSAGE	(STATUS	"SDK_DIR = $ENV{SDK_DIR}")
+MESSAGE	(STATUS	"CC = $ENV{CC}")
+MESSAGE	(STATUS	"CXX = $ENV{CXX}")
+MESSAGE	(STATUS	"LD = $ENV{LD}")
+
+
diff --git a/packaging/ios/subsurface-ios/MainForm.ui.qml b/packaging/ios/subsurface-ios/MainForm.ui.qml
new file mode 100644
index 0000000..7913bb2
--- /dev/null
+++ b/packaging/ios/subsurface-ios/MainForm.ui.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.6
+import QtQuick.Controls 1.5
+import QtQuick.Layouts 1.3
+
+Item {
+    width: 640
+    height: 480
+
+    property alias button1: button1
+    property alias button2: button2
+
+    RowLayout {
+        anchors.centerIn: parent
+
+        Button {
+            id: button1
+            text: qsTr("Press Me 1")
+        }
+
+        Button {
+            id: button2
+            text: qsTr("Press Me 2")
+        }
+    }
+}
diff --git a/packaging/ios/subsurface-ios/deployment.pri b/packaging/ios/subsurface-ios/deployment.pri
new file mode 100644
index 0000000..265ce71
--- /dev/null
+++ b/packaging/ios/subsurface-ios/deployment.pri
@@ -0,0 +1,13 @@
+unix:!android {
+    isEmpty(target.path) {
+        qnx {
+            target.path = /tmp/$${TARGET}/bin
+        } else {
+            target.path = /opt/$${TARGET}/bin
+        }
+        export(target.path)
+    }
+    INSTALLS += target
+}
+
+export(INSTALLS)
diff --git a/packaging/ios/subsurface-ios/main.qml b/packaging/ios/subsurface-ios/main.qml
new file mode 100644
index 0000000..26b1a79
--- /dev/null
+++ b/packaging/ios/subsurface-ios/main.qml
@@ -0,0 +1,40 @@
+import QtQuick 2.6
+import QtQuick.Controls 1.5
+import QtQuick.Dialogs 1.2
+
+ApplicationWindow {
+    visible: true
+    width: 640
+    height: 480
+    title: qsTr("Hello World")
+
+    menuBar: MenuBar {
+        Menu {
+            title: qsTr("File")
+            MenuItem {
+                text: qsTr("&Open")
+                onTriggered: console.log("Open action triggered");
+            }
+            MenuItem {
+                text: qsTr("Exit")
+                onTriggered: Qt.quit();
+            }
+        }
+    }
+
+    MainForm {
+        anchors.fill: parent
+        button1.onClicked: messageDialog.show(qsTr("Button 1 pressed"))
+        button2.onClicked: messageDialog.show(qsTr("Button 2 pressed"))
+    }
+
+    MessageDialog {
+        id: messageDialog
+        title: qsTr("May I have your attention, please?")
+
+        function show(caption) {
+            messageDialog.text = caption;
+            messageDialog.open();
+        }
+    }
+}
diff --git a/packaging/ios/subsurface-ios/qml.qrc b/packaging/ios/subsurface-ios/qml.qrc
new file mode 100644
index 0000000..7684346
--- /dev/null
+++ b/packaging/ios/subsurface-ios/qml.qrc
@@ -0,0 +1,6 @@
+<RCC>
+    <qresource prefix="/">
+        <file>main.qml</file>
+        <file>MainForm.ui.qml</file>
+    </qresource>
+</RCC>
diff --git a/packaging/ios/subsurface-ios/subsurface-ios.pro b/packaging/ios/subsurface-ios/subsurface-ios.pro
new file mode 100644
index 0000000..278c71d
--- /dev/null
+++ b/packaging/ios/subsurface-ios/subsurface-ios.pro
@@ -0,0 +1,221 @@
+TEMPLATE = app
+
+QT += qml quick widgets positioning concurrent
+
+DEFINES += SUBSURFACE_MOBILE
+
+CONFIG += c++11
+include(subsurface-gen-version.pri)
+
+SOURCES += ../../../subsurface-mobile-main.cpp \
+    ../../../subsurface-mobile-helper.cpp \
+    ../../../subsurface-core/cloudstorage.cpp \
+    ../../../subsurface-core/configuredivecomputerthreads.cpp \
+    ../../../subsurface-core/devicedetails.cpp \
+    ../../../subsurface-core/gpslocation.cpp \
+    ../../../subsurface-core/imagedownloader.cpp \
+    ../../../subsurface-core/qthelper.cpp \
+    ../../../subsurface-core/checkcloudconnection.cpp \
+    ../../../subsurface-core/color.cpp \
+    ../../../subsurface-core/configuredivecomputer.cpp \
+    ../../../subsurface-core/divecomputer.cpp \
+    ../../../subsurface-core/divelogexportlogic.cpp \
+    ../../../subsurface-core/divesite.cpp \
+    ../../../subsurface-core/divesitehelpers.cpp \
+    ../../../subsurface-core/exif.cpp \
+    ../../../subsurface-core/gettextfromc.cpp \
+    ../../../subsurface-core/isocialnetworkintegration.cpp \
+    ../../../subsurface-core/metrics.cpp \
+    ../../../subsurface-core/pluginmanager.cpp \
+    ../../../subsurface-core/qt-init.cpp \
+    ../../../subsurface-core/subsurfacesysinfo.cpp \
+    ../../../subsurface-core/windowtitleupdate.cpp \
+    ../../../subsurface-core/file.c \
+    ../../../subsurface-core/subsurfacestartup.c \
+    ../../../subsurface-core/macos.c \
+    ../../../subsurface-core/profile.c \
+    ../../../subsurface-core/device.c \
+    ../../../subsurface-core/dive.c \
+    ../../../subsurface-core/divelist.c \
+    ../../../subsurface-core/gas-model.c \
+    ../../../subsurface-core/gaspressures.c \
+    ../../../subsurface-core/git-access.c \
+    ../../../subsurface-core/liquivision.c \
+    ../../../subsurface-core/load-git.c \
+    ../../../subsurface-core/parse-xml.c \
+    ../../../subsurface-core/save-html.c \
+    ../../../subsurface-core/statistics.c \
+    ../../../subsurface-core/worldmap-save.c \
+    ../../../subsurface-core/libdivecomputer.c \
+    ../../../subsurface-core/version.c \
+    ../../../subsurface-core/save-git.c \
+    ../../../subsurface-core/datatrak.c \
+    ../../../subsurface-core/ostctools.c \
+    ../../../subsurface-core/planner.c \
+    ../../../subsurface-core/save-xml.c \
+    ../../../subsurface-core/cochran.c \
+    ../../../subsurface-core/deco.c \
+    ../../../subsurface-core/divesite.c \
+    ../../../subsurface-core/equipment.c \
+    ../../../subsurface-core/membuffer.c \
+    ../../../subsurface-core/sha1.c \
+    ../../../subsurface-core/strtod.c \
+    ../../../subsurface-core/taxonomy.c \
+    ../../../subsurface-core/time.c \
+    ../../../subsurface-core/uemis.c \
+    ../../../subsurface-core/subsurface-qt/DiveObjectHelper.cpp \
+    ../../../subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp \
+    ../../../qt-mobile/qmlmanager.cpp \
+    ../../../qt-mobile/qmlprofile.cpp \
+    ../../../qt-models/cylindermodel.cpp \
+    ../../../qt-models/divelistmodel.cpp \
+    ../../../qt-models/diveplotdatamodel.cpp \
+    ../../../qt-models/gpslistmodel.cpp \
+    ../../../qt-models/yearlystatisticsmodel.cpp \
+    ../../../qt-models/diveplannermodel.cpp \
+    ../../../qt-models/cleanertablemodel.cpp \
+    ../../../qt-models/completionmodels.cpp \
+    ../../../qt-models/divecomputerextradatamodel.cpp \
+    ../../../qt-models/divecomputermodel.cpp \
+    ../../../qt-models/divelocationmodel.cpp \
+    ../../../qt-models/divepicturemodel.cpp \
+    ../../../qt-models/divesitepicturesmodel.cpp \
+    ../../../qt-models/divetripmodel.cpp \
+    ../../../qt-models/filtermodels.cpp \
+    ../../../qt-models/models.cpp \
+    ../../../qt-models/tankinfomodel.cpp \
+    ../../../qt-models/treemodel.cpp \
+    ../../../qt-models/weightmodel.cpp \
+    ../../../qt-models/weigthsysteminfomodel.cpp \
+    ../../../qt-models/ssrfsortfilterproxymodel.cpp \
+    ../../../profile-widget/divecartesianaxis.cpp \
+    ../../../profile-widget/diveeventitem.cpp \
+    ../../../profile-widget/diveprofileitem.cpp \
+    ../../../profile-widget/profilewidget2.cpp \
+    ../../../profile-widget/ruleritem.cpp \
+    ../../../profile-widget/animationfunctions.cpp \
+    ../../../profile-widget/divepixmapitem.cpp \
+    ../../../profile-widget/divetooltipitem.cpp \
+    ../../../profile-widget/tankitem.cpp \
+    ../../../profile-widget/divelineitem.cpp \
+    ../../../profile-widget/diverectitem.cpp \
+    ../../../profile-widget/divetextitem.cpp
+
+RESOURCES += qml.qrc ../../../subsurface.qrc ../../../qt-mobile/qml/mobile-resources.qrc
+
+LIBS += ../install-root/lib/libcrypto.a \
+        ../install-root/lib/libdivecomputer.a \
+        ../install-root/lib/libgit2.a \
+        ../install-root/lib/libsqlite3.a \
+        ../install-root/lib/libzip.a \
+        ../install-root/lib/libxslt.a \
+        ../install-root/lib/libxml2.a \
+        ../install-root/lib/libssh2.a \
+        ../install-root/lib/libssl.a \
+        -liconv
+
+INCLUDEPATH += ../install-root/include/ \
+               ../install-root/lib/libzip/include \
+               ../install-root/include/libxml2 \
+               ../install-root/include/libxstl \
+               ../install-root/include/libexstl \
+               ../install-root/include/openssl \
+               ../../.. \
+               ../../../subsurface-core
+
+HEADERS += \
+    ../../../subsurface-core/libdivecomputer.h \
+    ../../../subsurface-core/cloudstorage.h \
+    ../../../subsurface-core/configuredivecomputerthreads.h \
+    ../../../subsurface-core/device.h \
+    ../../../subsurface-core/devicedetails.h \
+    ../../../subsurface-core/dive.h \
+    ../../../subsurface-core/git-access.h \
+    ../../../subsurface-core/gpslocation.h \
+    ../../../subsurface-core/helpers.h \
+    ../../../subsurface-core/imagedownloader.h \
+    ../../../subsurface-core/pref.h \
+    ../../../subsurface-core/profile.h \
+    ../../../subsurface-core/qthelper.h \
+    ../../../subsurface-core/save-html.h \
+    ../../../subsurface-core/statistics.h \
+    ../../../subsurface-core/units.h \
+    ../../../subsurface-core/qthelperfromc.h \
+    ../../../subsurface-core/version.h \
+    ../../../subsurface-core/planner.h \
+    ../../../subsurface-core/divesite.h \
+    ../../../subsurface-core/checkcloudconnection.h \
+    ../../../subsurface-core/cochran.h \
+    ../../../subsurface-core/color.h \
+    ../../../subsurface-core/configuredivecomputer.h \
+    ../../../subsurface-core/datatrak.h \
+    ../../../subsurface-core/deco.h \
+    ../../../subsurface-core/display.h \
+    ../../../subsurface-core/divecomputer.h \
+    ../../../subsurface-core/divelist.h \
+    ../../../subsurface-core/divelogexportlogic.h \
+    ../../../subsurface-core/divesitehelpers.h \
+    ../../../subsurface-core/exif.h \
+    ../../../subsurface-core/file.h \
+    ../../../subsurface-core/gaspressures.h \
+    ../../../subsurface-core/gettext.h \
+    ../../../subsurface-core/gettextfromc.h \
+    ../../../subsurface-core/isocialnetworkintegration.h \
+    ../../../subsurface-core/membuffer.h \
+    ../../../subsurface-core/metrics.h \
+    ../../../subsurface-core/pluginmanager.h \
+    ../../../subsurface-core/prefs-macros.h \
+    ../../../subsurface-core/qt-gui.h \
+    ../../../subsurface-core/sha1.h \
+    ../../../subsurface-core/strndup.h \
+    ../../../subsurface-core/subsurfacestartup.h \
+    ../../../subsurface-core/subsurfacesysinfo.h \
+    ../../../subsurface-core/taxonomy.h \
+    ../../../subsurface-core/uemis.h \
+    ../../../subsurface-core/webservice.h \
+    ../../../subsurface-core/windowtitleupdate.h \
+    ../../../subsurface-core/worldmap-options.h \
+    ../../../subsurface-core/worldmap-save.h \
+    ../../../subsurface-core/subsurface-qt/DiveObjectHelper.h \
+    ../../../subsurface-core/subsurface-qt/SettingsObjectWrapper.h \
+    ../../../qt-mobile/qmlmanager.h \
+    ../../../qt-mobile/qmlprofile.h \
+    ../../../qt-models/divelistmodel.h \
+    ../../../qt-models/diveplotdatamodel.h \
+    ../../../qt-models/gpslistmodel.h \
+    ../../../qt-models/divelocationmodel.h \
+    ../../../qt-models/cylindermodel.h \
+    ../../../qt-models/divecomputermodel.h \
+    ../../../qt-models/diveplannermodel.h \
+    ../../../qt-models/divetripmodel.h \
+    ../../../qt-models/models.h \
+    ../../../qt-models/weightmodel.h \
+    ../../../qt-models/cleanertablemodel.h \
+    ../../../qt-models/divepicturemodel.h \
+    ../../../qt-models/ssrfsortfilterproxymodel.h \
+    ../../../qt-models/divesitepicturesmodel.h \
+    ../../../qt-models/completionmodels.h \
+    ../../../qt-models/weigthsysteminfomodel.h \
+    ../../../qt-models/divecomputerextradatamodel.h \
+    ../../../qt-models/filtermodels.h \
+    ../../../qt-models/tankinfomodel.h \
+    ../../../qt-models/treemodel.h \
+    ../../../qt-models/yearlystatisticsmodel.h \
+    ../../../profile-widget/diveprofileitem.h \
+    ../../../profile-widget/profilewidget2.h \
+    ../../../profile-widget/ruleritem.h \
+    ../../../profile-widget/diveeventitem.h \
+    ../../../profile-widget/divetooltipitem.h \
+    ../../../profile-widget/tankitem.h \
+    ../../../profile-widget/animationfunctions.h \
+    ../../../profile-widget/divecartesianaxis.h \
+    ../../../profile-widget/divelineitem.h \
+    ../../../profile-widget/divepixmapitem.h \
+    ../../../profile-widget/diverectitem.h \
+    ../../../profile-widget/divetextitem.h
+
+# Additional import path used to resolve QML modules in Qt Creator's code model
+QML_IMPORT_PATH =
+
+# Default rules for deployment.
+include(deployment.pri)
diff --git a/profile-widget/divepixmapitem.cpp b/profile-widget/divepixmapitem.cpp
index 7b0d499..698172c 100644
--- a/profile-widget/divepixmapitem.cpp
+++ b/profile-widget/divepixmapitem.cpp
@@ -1,6 +1,6 @@
 #include "divepixmapitem.h"
 #include "animationfunctions.h"
-#include "divepicturemodel.h"
+#include "qt-models/divepicturemodel.h"
 #include "pref.h"
 #ifndef SUBSURFACE_MOBILE
 #include "preferences/preferencesdialog.h"
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp
index 4262326..93c954f 100644
--- a/profile-widget/diveprofileitem.cpp
+++ b/profile-widget/diveprofileitem.cpp
@@ -8,7 +8,7 @@
 #ifndef SUBSURFACE_MOBILE
 #include "preferences/preferencesdialog.h"
 #endif
-#include "diveplannermodel.h"
+#include "qt-models/diveplannermodel.h"
 #include "helpers.h"
 #include <subsurface-qt/SettingsObjectWrapper.h>
 #include "libdivecomputer/parser.h"
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 0d6e385..38276b2 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -1,5 +1,5 @@
 #include "profilewidget2.h"
-#include "diveplotdatamodel.h"
+#include "qt-models/diveplotdatamodel.h"
 #include "helpers.h"
 #include "profile.h"
 #include "diveeventitem.h"
@@ -10,15 +10,15 @@
 #include "ruleritem.h"
 #include "tankitem.h"
 #include "pref.h"
-#include "divepicturewidget.h"
-#include "diveplannermodel.h"
-#include "models.h"
-#include "divepicturemodel.h"
+#include "qt-models/diveplannermodel.h"
+#include "qt-models/models.h"
+#include "qt-models/divepicturemodel.h"
 #include "divelist.h"
 #include <subsurface-qt/SettingsObjectWrapper.h>
 #ifndef SUBSURFACE_MOBILE
 #include "diveplanner.h"
 #include "simplewidgets.h"
+#include "divepicturewidget.h"
 #endif
 
 #include <libdivecomputer/parser.h>
@@ -34,7 +34,9 @@
 #ifndef QT_NO_DEBUG
 #include <QTableView>
 #endif
+#ifndef SUBSURFACE_MOBILE
 #include "preferences/preferencesdialog.h"
+#endif
 #include <QtWidgets>
 
 // a couple of helpers we need
diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h
index f3e9cac..185e0bc 100644
--- a/qt-models/divelocationmodel.h
+++ b/qt-models/divelocationmodel.h
@@ -4,7 +4,7 @@
 #include <QAbstractTableModel>
 #include <QStringListModel>
 #include <stdint.h>
-
+#include "units.h"
 #include "ssrfsortfilterproxymodel.h"
 
 class QLineEdit;
diff --git a/subsurface-core/CMakeLists.txt b/subsurface-core/CMakeLists.txt
index d9b1d34..e8572e3 100644
--- a/subsurface-core/CMakeLists.txt
+++ b/subsurface-core/CMakeLists.txt
@@ -19,11 +19,26 @@ if(FTDISUPPORT)
 endif()
 
 if(BTSUPPORT)
+	message(STATUS "building with BT support")
 	add_definitions(-DBT_SUPPORT)
 	set(BT_SRC_FILES desktop-widgets/btdeviceselectiondialog.cpp)
 	set(BT_CORE_SRC_FILES qtserialbluetooth.cpp)
+else()
+	message(STATUS "building without BT support")
 endif()
 
+if(NOT IOS_PLATFORM)
+	add_definitions(-DHAVE_LIBDIVECOMPUTER)
+	set(DIVECOMPUTER_RELATED_SOURCES
+		libdivecomputer.c
+		ostctools.c
+		uemis.c
+		uemis-downloader.c
+		configuredivecomputer.cpp
+		configuredivecomputerthreads.cpp
+	)
+endif()
+		
 # compile the core library, in C.
 set(SUBSURFACE_CORE_LIB_SRCS
 	cochran.c
@@ -38,11 +53,9 @@ set(SUBSURFACE_CORE_LIB_SRCS
 	file.c
 	gas-model.c
 	git-access.c
-	libdivecomputer.c
 	liquivision.c
 	load-git.c
 	membuffer.c
-	ostctools.c
 	parse-xml.c
 	planner.c
 	profile.c
@@ -56,8 +69,6 @@ set(SUBSURFACE_CORE_LIB_SRCS
 	strtod.c
 	subsurfacestartup.c
 	time.c
-	uemis.c
-	uemis-downloader.c
 	version.c
 	# gettextfrommoc should be added because we are using it on the c-code.
 	gettextfromc.cpp
@@ -67,15 +78,12 @@ set(SUBSURFACE_CORE_LIB_SRCS
 	exif.cpp
 	subsurfacesysinfo.cpp
 	devicedetails.cpp
-	configuredivecomputer.cpp
-	configuredivecomputerthreads.cpp
 	divesitehelpers.cpp
 	taxonomy.c
 	checkcloudconnection.cpp
 	windowtitleupdate.cpp
 	divelogexportlogic.cpp
 	qt-init.cpp
-	qtserialbluetooth.cpp
 	metrics.cpp
 	color.cpp
 	pluginmanager.cpp
@@ -90,6 +98,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
 	${SERIAL_FTDI}
 	${PLATFORM_SRC}
 	${BT_CORE_SRC_FILES}
+	${DIVECOMPUTER_RELATED_SOURCES}
 )
 source_group("Subsurface Core" FILES ${SUBSURFACE_CORE_LIB_SRCS})
 
diff --git a/subsurface-core/configuredivecomputerthreads.cpp b/subsurface-core/configuredivecomputerthreads.cpp
index 53a8aa7..0b6487c 100644
--- a/subsurface-core/configuredivecomputerthreads.cpp
+++ b/subsurface-core/configuredivecomputerthreads.cpp
@@ -1,6 +1,7 @@
 #include "configuredivecomputerthreads.h"
 #include "libdivecomputer/hw.h"
 #include "libdivecomputer.h"
+#include <libdivecomputer/version.h>
 
 #define OSTC3_GAS1			0x10
 #define OSTC3_GAS2			0x11
diff --git a/subsurface-core/file.c b/subsurface-core/file.c
index 3f6dd6d..bd54408 100644
--- a/subsurface-core/file.c
+++ b/subsurface-core/file.c
@@ -508,6 +508,7 @@ int parse_file(const char *filename)
 		}
 	}
 
+#if HAVE_LIBDIVECOMPUTER
 	/* Divesoft Freedom */
 	if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
 		if (!parse_dlf_buffer(mem.buffer, mem.size)) {
@@ -528,6 +529,7 @@ int parse_file(const char *filename)
 		ostctools_import(filename, &dive_table);
 		return 0;
 	}
+#endif
 
 	ret = parse_file_buffer(filename, &mem);
 	free(mem.buffer);
@@ -923,13 +925,14 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
 	 * input file added as last parameter.
 	 */
 
+#ifndef SUBSURFACE_MOBILE
 	if (verbose >= 2) {
 		fprintf(stderr, "(echo '<csv>'; cat %s;echo '</csv>') | xsltproc ", filename);
 		for (i=0; params[i]; i+=2)
 			fprintf(stderr, "--stringparam %s %s ", params[i], params[i+1]);
 		fprintf(stderr, "%s/xslt/csv2xml.xslt -\n", SUBSURFACE_SOURCE);
 	}
-
+#endif
 	ret = parse_xml_buffer(filename, mem.buffer, mem.size, &dive_table, (const char **)params);
 
 	free(mem.buffer);
diff --git a/subsurface-core/libdivecomputer.c b/subsurface-core/libdivecomputer.c
index 3990884..6cfcf01 100644
--- a/subsurface-core/libdivecomputer.c
+++ b/subsurface-core/libdivecomputer.c
@@ -11,7 +11,7 @@
 #include "libdivecomputer.h"
 #include <libdivecomputer/uwatec.h>
 #include <libdivecomputer/hw.h>
-
+#include <libdivecomputer/version.h>
 
 /* Christ. Libdivecomputer has the worst configuration system ever. */
 #ifdef HW_FROG_H
diff --git a/subsurface-core/libdivecomputer.h b/subsurface-core/libdivecomputer.h
index f52f695..99f1c24 100644
--- a/subsurface-core/libdivecomputer.h
+++ b/subsurface-core/libdivecomputer.h
@@ -7,7 +7,9 @@
 #ifdef DC_VERSION /* prevent a warning with wingdi.h */
 #undef DC_VERSION
 #endif
+#ifdef HAVE_LIBDIVECOMPUTER
 #include <libdivecomputer/version.h>
+#endif
 #include <libdivecomputer/device.h>
 #include <libdivecomputer/parser.h>
 
diff --git a/subsurface-core/macos.c b/subsurface-core/macos.c
index aa2be4b..fdfcebb 100644
--- a/subsurface-core/macos.c
+++ b/subsurface-core/macos.c
@@ -6,7 +6,9 @@
 #include "dive.h"
 #include "display.h"
 #include <CoreFoundation/CoreFoundation.h>
+#if !defined(__IPHONE_5_0)
 #include <CoreServices/CoreServices.h>
+#endif
 #include <mach-o/dyld.h>
 #include <sys/syslimits.h>
 #include <stdio.h>
diff --git a/subsurface-core/profile.c b/subsurface-core/profile.c
index 8d5cebd..83fb124 100644
--- a/subsurface-core/profile.c
+++ b/subsurface-core/profile.c
@@ -14,7 +14,9 @@
 #include "gaspressures.h"
 #include "deco.h"
 #include "libdivecomputer/parser.h"
+#ifdef HAVE_LIBDIVECOMPUTER
 #include "libdivecomputer/version.h"
+#endif
 #include "membuffer.h"
 
 //#define DEBUG_GAS 1
diff --git a/subsurface-core/qt-gui.h b/subsurface-core/qt-gui.h
index ca038b1..92532d2 100644
--- a/subsurface-core/qt-gui.h
+++ b/subsurface-core/qt-gui.h
@@ -1,8 +1,6 @@
 #ifndef QT_GUI_H
 #define QT_GUI_H
 
-#include <QApplication>
-
 void init_qt_late();
 void init_ui();
 
diff --git a/subsurface-core/subsurfacestartup.c b/subsurface-core/subsurfacestartup.c
index c39c89c..b1d4764 100644
--- a/subsurface-core/subsurfacestartup.c
+++ b/subsurface-core/subsurfacestartup.c
@@ -136,7 +136,9 @@ bool imported = false;
 static void print_version()
 {
 	printf("Subsurface v%s, ", subsurface_git_version());
+#if HAVE_LIBDIVECOMPUTER
 	printf("built with libdivecomputer v%s\n", dc_version(NULL));
+#endif
 }
 
 void print_files()
-- 
2.5.4 (Apple Git-61)

