Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script for building GDAL for iOS and the iOS simulators
#!/bin/bash
PREFIX=`pwd`/install/
rm -rf $PREFIX
mkdir $PREFIX
LOG=./log
rm -rf $LOG
mkdir $LOG
if [ -e ${PREFIX} ]
then
echo removing ${PREFIX}
rm -rf ${PREFIX}
fi
mkdir ${PREFIX}
for f in "armv7" "armv7s" "arm64"; do
echo Building $f
./build_gdal_ios.sh -p ${PREFIX} -a $f device 2>&1 | tee "${LOG}/${f}.txt"
done
echo Building i386 simulator
./build_gdal_ios.sh -p ${PREFIX} simulator_i386 2>&1 | tee "${LOG}/simulator_i386.txt"
echo Building x86_64 simulator
./build_gdal_ios.sh -p ${PREFIX} simulator_x86_64 2>&1 | tee "${LOG}/simulator_x86_64.txt"
SDK_VERSION=8.1
lipo \
${PREFIX}/i386/iphonesimulator${SDK_VERSION}.sdk/lib/libgdal.a \
${PREFIX}/x86_64/iphonesimulator${SDK_VERSION}.sdk/lib/libgdal.a \
${PREFIX}/armv7/iphoneos${SDK_VERSION}.sdk/lib/libgdal.a \
${PREFIX}/armv7s/iphoneos${SDK_VERSION}.sdk/lib/libgdal.a \
${PREFIX}/arm64/iphoneos${SDK_VERSION}.sdk/lib/libgdal.a \
-output ${PREFIX}/libgdal.a \
-create | tee $LOG/lipo.txt
lipo \
${PREFIX}/i386/iphonesimulator${SDK_VERSION}.sdk/lib/libproj.a \
${PREFIX}/x86_64/iphonesimulator${SDK_VERSION}.sdk/lib/libproj.a \
${PREFIX}/armv7/iphoneos${SDK_VERSION}.sdk/lib/libproj.a \
${PREFIX}/armv7s/iphoneos${SDK_VERSION}.sdk/lib/libproj.a \
${PREFIX}/arm64/iphoneos${SDK_VERSION}.sdk/lib/libproj.a \
-output ${PREFIX}/libproj.a \
-create | tee $LOG/lipo-proj.txt
#!/bin/bash
set -u
default_iphoneos_version=8.1
default_architecture=armv7
export IPHONEOS_DEPLOYMENT_TARGET="${IPHONEOS_DEPLOYMENT_TARGET:-$default_iphoneos_version}"
DEFAULT_ARCHITECTURE="${DEFAULT_ARCHITECTURE:-$default_architecture}"
DEFAULT_PREFIX="${HOME}/Desktop/iOS_GDAL"
usage ()
{
cat >&2 << EOF
Usage: ${0} [-h] [-p prefix] [-a arch] target [configure_args]
-h Print help message
-p Installation prefix (default: \$HOME/Documents/iOS_GDAL...)
-a Architecture target for compilation (default: armv7)
The target must be "device", "simulator_i386" or "simulator_x86_64". Any additional arguments
are passed to configure.
The following environment variables affect the build process:
IPHONEOS_DEPLOYMENT_TARGET (default: $default_iphoneos_version)
DEFAULT_PREFIX (default: $default_prefix)
EOF
}
prefix="${DEFAULT_PREFIX}"
while getopts ":hp:a:" opt; do
case $opt in
h ) usage ; exit 0 ;;
p ) prefix="$OPTARG" ;;
a ) DEFAULT_ARCHITECTURE="$OPTARG" ;;
\? ) usage ; exit 2 ;;
esac
done
shift $(( $OPTIND - 1 ))
if (( $# < 1 )); then
usage
exit 2
fi
target=$1
shift
case $target in
device )
arch="${DEFAULT_ARCHITECTURE}"
platform=iphoneos
extra_cflags=" "
;;
simulator_i386 )
arch=i386
platform=iphonesimulator
extra_cflags="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000"
;;
simulator_x86_64 )
arch=x86_64
platform=iphonesimulator
extra_cflags="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000"
;;
* )
echo No target found!!!
usage
exit 2
esac
if [ $arch = "arm64" ]
then
host="arm-apple-darwin"
else
host="${arch}-apple-darwin"
fi
echo "building for host ${host}"
platform_dir=`xcrun -find -sdk ${platform} --show-sdk-platform-path`
platform_sdk_dir=`xcrun -find -sdk ${platform} --show-sdk-path`
prefix="${prefix}/${arch}/${platform}${IPHONEOS_DEPLOYMENT_TARGET}.sdk"
echo
echo library will be exported to $prefix
#setup compiler flags
export CC=`xcrun -find -sdk iphoneos gcc`
export CFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future -Wno-error=implicit-function-declaration -arch ${arch} -pipe -Os -gdwarf-2 -isysroot ${platform_sdk_dir} ${extra_cflags}"
export LDFLAGS="-arch ${arch} -isysroot ${platform_sdk_dir}"
export CXX=`xcrun -find -sdk iphoneos g++`
export CXXFLAGS="${CFLAGS}"
export CPP=`xcrun -find -sdk iphoneos cpp`
export CXXCPP="${CPP}"
echo CFLAGS ${CFLAGS}
#set proj4 install destination
proj_prefix=$prefix
echo install proj to $proj_prefix
#download proj4 if necesary
if [ ! -e proj-4.8.0 ]
then
echo proj4 missing, downloading
curl -O http://download.osgeo.org/proj/proj-4.8.0.tar.gz
tar -xzf proj-4.8.0.tar.gz
fi
#configure and build proj4
pushd proj-4.8.0
echo
echo "cleaning proj"
make clean
echo
echo "configure proj"
./configure \
--prefix=${proj_prefix} \
--enable-shared=no \
--enable-static=yes \
--host=$host \
"$@" || exit
echo
echo "make install proj"
time make install || exit
popd
#download gdal if necesary
if [ ! -e gdal-1.11.0 ]
then
curl -O http://download.osgeo.org/gdal/1.11.0/gdal-1.11.0.tar.gz
tar -xzf gdal-1.11.0.tar.gz
fi
#configure and build gdal
cd gdal-1.11.0
echo "cleaning gdal"
make clean
echo
echo "configure gdal"
./configure \
--prefix="${prefix}" \
--host=$host \
--disable-shared \
--enable-static \
--with-hide-internal-symbols \
--with-unix-stdio-64=no \
--with-geos=no \
--without-pg \
--without-grass \
--without-libgrass \
--without-cfitsio \
--without-pcraster \
--without-netcdf \
--without-ogdi \
--without-fme \
--without-hdf4 \
--without-hdf5 \
--without-jasper \
--without-kakadu \
--without-grib \
--without-mysql \
--without-ingres \
--without-xerces \
--without-odbc \
--without-curl \
--without-idb \
--without-sde \
--with-sse=no \
--with-avx=no \
--with-static-proj4=${prefix} \
--with-sqlite3=${platform_sdk_dir} \
|| exit
#echo '#include "cpl_config_extras.h"' >> port/cpl_config.h
echo
echo "building gdal"
time make
echo
echo "installing"
time make install
echo "Gdal build complete"
@lachlanhurst
Copy link
Author

lachlanhurst commented Jan 19, 2015

The following libs need to be included in the XCode project:

  • libxml2.dylib
  • libc++.dylib
  • libc.dylib
  • libsqlite3.dylib
  • libiconv.dylib
  • libz.dylib
  • libstdc++.6.0.9.dylib

And the freshly built gdal libs:

  • libgdal.a
  • libproj.a

Be sure to include one of the include dirs for the header files.

@gunnarblom
Copy link

gunnarblom commented Mar 14, 2016

@lachlanhurst works perfectly, thanks! I'm trying to modify the script to include GEOS support, but I can't figure out how. Do you happen to know how to do that?

@jeffmacintosh10
Copy link

jeffmacintosh10 commented Sep 1, 2018

I download the goal version 2.3.1 and ran the script above. The terminal shows a lot of warnings, two errors and it didn't generate the libgdal.a. Could you help me to have libgdal.a?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment