How to Compile FreeCAD from Source on macOS

Compiling FreeCAD from source on macOS allows developers and enthusiasts to access the latest features, test bug fixes, and contribute directly to the project. This guide outlines the complete process for setting up your development environment using Xcode Command Line Tools and Conda to manage complex dependencies, cloning the official source repository, configuring the build using CMake, and compiling the final executable.

1. Install Command Line Tools

You must have the Apple developer command line tools installed. Open the Terminal application and run:

xcode-select --install

Follow the graphical prompt to download and install the tools.

2. Install Miniforge (Conda)

FreeCAD relies on complex libraries like OpenCASCADE, Coin3D, Qt, and Python. The most reliable method to manage these dependencies on macOS is using Conda via Miniforge.

Install Miniforge using Homebrew or by downloading the installer directly for your architecture (Apple Silicon arm64 or Intel x86_64):

brew install miniforge

Initialize your shell with Conda:

conda init zsh

Restart your terminal to apply the environment changes.

3. Create the FreeCAD Build Environment

Create an isolated Conda environment containing all required build tools and libraries provided by the conda-forge channel:

conda create -n freecad-dev python=3.11
conda activate freecad-dev
conda install -c conda-forge cmake ninja git boost-cpp occt coin3d pyside6 qt-main vtk swig

4. Clone the FreeCAD Source Code

Clone the official FreeCAD repository along with its submodules:

git clone --recurse-submodules https://github.com/FreeCAD/FreeCAD.git freecad-source

5. Configure the Build with CMake

Create a separate build directory to keep the source tree clean:

mkdir freecad-build
cd freecad-build

Run CMake to generate the build files, pointing to your active Conda environment for libraries:

cmake ../freecad-source \
  -G "Ninja" \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \
  -DCMAKE_INSTALL_PREFIX="./install" \
  -DFREECAD_USE_EXTERNAL_BOOST=ON

6. Compile FreeCAD

Use Ninja to run the compilation process. Ninja automatically utilizes all available CPU cores:

ninja

This process may take anywhere from 15 minutes to an hour depending on your machine's hardware specifications.

7. Run FreeCAD

Once the build finishes successfully, you can launch the compiled application directly from the build directory:

./bin/FreeCAD

Ensure your freecad-dev Conda environment remains active whenever you launch or recompile FreeCAD using this setup.