Compiling OCCT for the ARPen Project
Table of Contents
1 Building OCCT with XCode
This is my guide on how to build OCCT for iOS. By the time writing this, 7.3.0 is the latest version, so you might have to make changes to some links if this no longer applies.
- Download and unpack the Open CASCADE source code from https://www.opencascade.com/content/latest-release.
For the rest of this tutorial,
${OCCT}
will refer to the root folder. - Follow the build guide from https://www.opencascade.com/doc/occt-7.3.0/overview/html/occt_dev_guides__building_xcode.html.
Before you do anything, please read and understand both the official guide, as well the following comments (not a step-by-step list! Just my additions to the official tutorial):
- Don't follow the guide on building 3rd-party libraries I'm not sure if Freetype2 is actually necessary for building only the OCCT library. I however built it using this project: https://github.com/cdave1/freetype2-ios. Tcl should ship with your Mac. Check this first, before making a duplicate install.
- In the Projects generation step, follow the guide for building the static libraries.
In my case, I needed to add
#include <V3d_View.hxx>
to
${OCCT}/inc/StdSelect_ViewerSelector3d.hxx
. Bug?- For step Building,
xcode.sh
launches the wrong project. In my case, the correct one was located at${OCCT}/adm/ios/xcd
. I suggest to build the entire OCCT as described in the guide. The resulting .a files will be at:${HOME}/Library/Developer/Xcode/DerivedData/${YOUR PROJECT}
2 Assembling the static framework
This is how you bundle the generated static libraries into a single framework. This guide assumes that your current working directory is ${OCCT}
.
- Copy the static libaries (.a files) to another folder. I chose
${OCCT}/samples/ios/occt/lib/
because that is where the sample project expected them to be. If you choose another location, make sure to adjust thelibtool
command later on accordingly. You don't have to copy all files. The minimum subset required to build the current ARPen implementation is:libTK{BO, Bool, BRep, ernel, G2d, G3d, GeomAlgo, GeomBase, Math, Mesh, Offset, Prim, ShHealing, STL, TopAlgo}.a
If you need additional toolkits later, the OCCT documentation shows you which one it is in the breadcrumbs. Change include syntax in OCCT header files (this is python code):
import re import os # folder which includes headers, assuming this script is called from ${OCCT} header_folder = 'inc' new_header_folder = 'inc_framework' os.mkdir(os.getcwd() + '/' + new_header_folder) for filename in os.listdir(header_folder): path = header_folder + '/' + filename new_path = new_header_folder + '/' + filename inp = open(path, 'r') out = open(new_path, 'w') for line in inp: out.write(re.sub(r'#include <(.*)>', r'#include "\1"', line)) inp.close() out.close()
Setup the framework folder structure and copy headers:
mkdir -p "occt.framework/Versions/A/Headers" # Link the "Current" version to "A" ln -sfh "A" "occt.framework/Versions/Current" ln -sfh "Versions/Current/Headers" "occt.framework/Headers" ln -sfh "Versions/Current/occt" "occt.framework/occt" # The -a ensures that the headers maintain the source modification date so that we don't constantly # cause propagating rebuilds of files that import these headers. cp -a "inc_framework/" "occt.framework/Versions/A/Headers"
Group archive files into single archive within framework using libtool:
# run from ${OCCT} libtool -static -o occt.framework/Versions/A/occt samples/ios/occt/lib/*
- Place the framework file in the root folder of the ARPen iOS Project.
If you want to commit the updated framework, compress it into parts of <100mb, e.g. using (now executed from the root of the ARPen iOS project:
rm Open\ CASCADE/* zip -r -y -s 50m "Open CASCADE/occt.framework.zip" occt.framework -x "*.DS_Store"