Pieter Hijma

Compiling FreeCAD and OCCT

In this section we discuss how to compile FreeCAD and Open CASCADE Technology (OCCT), the underlying geometry library of FreeCAD. The goal is to be able to debug and add features to the two projects. We will create two scripts that take as argument whether the build is a debug build or a release build. The build is performed on Arch Linux in April 2022.

OCCT

To compile OCCT for a release and a debug version, we first have to establish some locations for where the source, the build, and the distribution have to live. With the build directory I mean the directory in which we compile OCCT and with the distribution directory, I mean the directory where we install OCCT to link it to FreeCAD later. I keep my source code separate from the binary builds and distribution, so I have a variable SRC_DIR_OCCT and a BUILD_ROOT_DIR that I use to base the distribution and build directories on.

After determining the SRC_DIR_OCCT directory, we can clone OCCT:

git clone https://git.dev.opencascade.org/repos/occt.git \
    $SRC_DIR_OCCT

We then create the cmake-occt script in which we define the SRC_DIR_OCCT and BUILD_DIR_OCCT:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash

# accept no or the argument "release"
if [ $# = 0 ]
then
    RELEASE=""
elif [ "$1" = "release" ]
then
    RELEASE="-rel"
else
    echo 'expecting no or the argument "release"'
    exit 1
fi

SRC_DIR_OCCT= #your directory here
BUILD_ROOT_DIR= #your directory here

DIST_DIR_OCCT=$BUILD_ROOT_DIR/occt-dist$RELEASE
BUILD_DIR_OCCT=$BUILD_ROOT_DIR/occt-build$RELEASE

mkdir -p $BUILD_DIR_OCCT

if [ -n "$RELEASE" ]
then
    cmake -DCMAKE_BUILD_TYPE=RELEASE \
          -DCMAKE_INSTALL_PREFIX=$DIST_DIR_OCCT \
          -S $SRC_DIR_OCCT \
          -B $BUILD_DIR_OCCT
else
    cmake -DCMAKE_BUILD_TYPE=DEBUG \
          -DCMAKE_INSTALL_PREFIX=$DIST_DIR_OCCT \
          -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
          -S $SRC_DIR_OCCT \
          -B $BUILD_DIR_OCCT
fi

OCCT requires the following packages to compile: freetype2, tcl, tk, and libglvnd. With this script above we can now configure our system:

cmake-occt

Then we can move to the build directory, compile, and if everything went well, install:

cd $BUILD_DIR_OCCT
make
make install

The last command installs a distribution in $DIST_DIR_OCCT to which the FreeCAD build will link.

FreeCAD

Similar to what we did with OCCT, we will create a release and debug version of FreeCAD, again by creating the script cmake-freecad that calls CMake. First we establish the directories again: We define SRC_DIR_FREECAD and we reuse BUILD_ROOT_DIR and DIST_DIR_OOCT with the same location as in the OCCT build.

We can clone FreeCAD now:

git clone https://github.com/FreeCAD/FreeCAD.git \
    $SRC_DIR_FREECAD

We then create the cmake-freecad script in which we define SRC_DIR_FREECAD and BUILD_ROOT_DIR (the same as used in OCCT to make sure we can find OCCT automatically).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
if [ $# = 0 ]
then
    RELEASE=""
elif [ "$1" = "release" ]
then
    RELEASE="-rel"
else
    echo 'expecting no or the argument "release"'
    exit 1
fi

SRC_DIR_FREECAD= #your directory here
BUILD_ROOT_DIR= #your directory here

DIST_DIR_OCCT=$BUILD_ROOT_DIR/occt-dist$RELEASE
BUILD_DIR_FREECAD=$BUILD_ROOT_DIR/freecad-build$RELEASE

mkdir -p $BUILD_DIR_FREECAD

if [ -n "$RELEASE" ]
then
    cmake -DCMAKE_BUILD_TYPE=RELEASE \
      -DFREECAD_USE_OCC_VARIANT="Official Version" \
      -DOpenCASCADE_DIR:PATH=$DIST_DIR_OCCT/lib/cmake/opencascade \
      -S $SRC_DIR_FREECAD \
      -B $BUILD_DIR_FREECAD
else
    cmake -DCMAKE_BUILD_TYPE=DEBUG \
      -DFREECAD_USE_OCC_VARIANT="Official Version" \
      -DOpenCASCADE_DIR:PATH=$DIST_DIR_OCCT/lib/cmake/opencascade \
      -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
      -DFREECAD_USE_PYBIND11=ON \
      -S $SRC_DIR_FREECAD \
      -B $BUILD_DIR_FREECAD
fi

To compile FreeCAD we require the following packages to be installed. Note that we install here opencascade as well just to make sure we have all these dependencies. We have to pay attention to the output of CMake to verify whether our self-compiled distribution of OCCT has been selected.

sudo pacman -S --needed boost curl desktop-file-utils \
     glew hicolor-icon-theme jsoncpp libspnav opencascade \
     shiboken2 xerces-c pyside2 python-matplotlib \
     python-netcdf4 qt5-svg qt5-webkit qt5-webengine \
     cmake eigen git gcc-fortran pyside2-tools swig \
     qt5-tools shared-mime-info coin python-pivy med \
     pybind11 openmpi

We can now configure the system:

cmake-freecad

It is wise to check whether the configuration selected our self-compiled distribution of OCCT before we compile FreeCAD. In the “Summary report”, it should state that OCC has the lib and include directories in $DIST_DIR_OCCT.

cd $BUILD_DIR_FREECAD
make

We can now run FreeCAD with our own OCCT build with the command:

$BUILD_DIR_FREECAD/bin/FreeCAD

In the above examples we compiled debug versions that may run slower than the release versions. Repeating the steps by calling cmake-occt release and cmake-freecad release will build the release versions that run on full speed.

Last updated: 1 May 2022