Skip to content

Instantly share code, notes, and snippets.

@carbocation
Last active May 23, 2026 21:55
Show Gist options
  • Select an option

  • Save carbocation/2c3be9c2b2ef0a7129e4830c7f1b8466 to your computer and use it in GitHub Desktop.

Select an option

Save carbocation/2c3be9c2b2ef0a7129e4830c7f1b8466 to your computer and use it in GitHub Desktop.
Installing OpenFOAM on Apple Silicon macOS without docker

Native OpenFOAM v2512 On Apple Silicon macOS

This guide describes how to compile OpenFOAM v2512 natively on Apple Silicon macOS without Docker. The build described here produced native arm64 OpenFOAM binaries using Homebrew GCC and OpenMPI.

Overview

The main macOS-specific issue is that OpenFOAM should be built on a case-sensitive filesystem. The default macOS APFS volume is normally case-insensitive, which can cause include collisions such as OpenFOAM's wchar.H versus the system wchar.h.

The approach is:

  1. Install build dependencies with Homebrew.
  2. Create a case-sensitive APFS sparsebundle.
  3. Download and extract OpenFOAM and ThirdParty sources.
  4. Add Apple Silicon/Homebrew build preferences.
  5. Configure OpenFOAM's dependency paths.
  6. Apply two small macOS/Homebrew fixes.
  7. Build and verify.
  8. Add a zsh helper to mount and source OpenFOAM.

1. Install Dependencies

brew install gcc open-mpi boost cgal scotch fftw gnuplot gawk make flex autoconf automake libtool gmp mpfr

This guide assumes Homebrew is installed in the default Apple Silicon location:

/opt/homebrew

2. Create A Case-Sensitive Build Volume

Create and mount a case-sensitive sparsebundle under ~/OpenFOAM:

mkdir -p ~/OpenFOAM

hdiutil create \
  -size 80g \
  -type SPARSEBUNDLE \
  -fs 'Case-sensitive APFS' \
  -volname OpenFOAM-v2512-CS \
  ~/OpenFOAM/OpenFOAM-v2512-CS.sparsebundle

mkdir -p ~/OpenFOAM/OpenFOAM-v2512-CS

hdiutil attach \
  ~/OpenFOAM/OpenFOAM-v2512-CS.sparsebundle \
  -mountpoint ~/OpenFOAM/OpenFOAM-v2512-CS

The mounted volume path used throughout this guide is:

~/OpenFOAM/OpenFOAM-v2512-CS

3. Download And Extract Sources

Download the OpenFOAM v2512 and ThirdParty v2512 source archives from the official OpenFOAM source locations:

Extract them so the layout is:

~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512
~/OpenFOAM/OpenFOAM-v2512-CS/ThirdParty-v2512

4. Add Homebrew Build Preferences

Create this file:

~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512/etc/prefs.sh

With these contents:

# Local Apple Silicon/Homebrew build settings for OpenFOAM v2512.
export PATH="/opt/homebrew/opt/make/libexec/gnubin:/opt/homebrew/opt/gawk/libexec/gnubin:/opt/homebrew/opt/flex/bin:/opt/homebrew/opt/libtool/libexec/gnubin:/opt/homebrew/bin:$PATH"
export WM_COMPILE_CONTROL="version=15"
export OMPI_CC="gcc-15"
export OMPI_CXX="g++-15"
export BOOST_INC_DIR="/opt/homebrew/opt/boost/include"
export FOAM_EXTRA_CXXFLAGS="-D_Static_assert=static_assert ${FOAM_EXTRA_CXXFLAGS:-}"

Notes:

  • WM_COMPILE_CONTROL="version=15" selects Homebrew GCC 15.
  • OMPI_CC and OMPI_CXX ensure OpenMPI uses the same compiler family.
  • BOOST_INC_DIR helps with Homebrew Boost installs.
  • _Static_assert is mapped to static_assert because newer macOS SDK headers expose C-style _Static_assert in places that Homebrew GCC sees while compiling C++.

5. Configure Dependency Paths

Source OpenFOAM and configure the Homebrew dependency locations:

cd ~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512
source etc/bashrc

foamConfigurePaths \
  -boost-brew \
  -cgal-brew \
  -fftw-brew \
  -readline-brew \
  -scotch-brew \
  -gmp-brew \
  -mpfr-brew

6. Fix Flex Header Selection

OpenFOAM can accidentally pick Apple's older flex header. Point it at Homebrew flex:

cd ~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512/src/OSspecific/POSIX
ln -sf /opt/homebrew/opt/flex/include/FlexLexer.h FlexLexer.h

7. Patch CGAL Header-Only Boost Detection

With newer Homebrew Boost, OpenFOAM's CGAL header-only rule may fail to add the Boost include directory, causing errors like:

fatal error: boost/config.hpp: No such file or directory

Patch:

~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512/wmake/rules/General/cgal-header-only

Add this near the top of the file, before the existing CGAL checks:

# BOOST include/library directories - synthesize from ARCH_PATH as required.
# This covers header-only Boost installs where OpenFOAM's boost probe does not
# find libboost_system but CGAL still needs boost headers.
ifeq (,$(strip $(BOOST_INC_DIR)))
ifneq (,$(strip $(BOOST_ARCH_PATH)))
  BOOST_INC_DIR = $(BOOST_ARCH_PATH)/include
  BOOST_LIB_DIR = $(BOOST_ARCH_PATH)/lib \
    $(BOOST_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH)
endif
endif

# CGAL include/library directories - synthesize from ARCH_PATH as required.
ifeq (,$(strip $(CGAL_INC_DIR)))
ifneq (,$(strip $(CGAL_ARCH_PATH)))
  CGAL_INC_DIR = $(CGAL_ARCH_PATH)/include
  CGAL_LIB_DIR = $(CGAL_ARCH_PATH)/lib \
    $(CGAL_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH)
endif
endif

This is needed because some OpenFOAM utilities include cgal-header-only directly instead of the fuller CGAL rule that already synthesizes these paths.

8. Build OpenFOAM

cd ~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512
source etc/bashrc
./Allwmake -j 10 -l

Do not use -q here. In OpenFOAM's build scripts, -q means queued build mode, not quiet mode.

On a successful build, the summary should look similar to:

OpenFOAM-v2512
Gcc system compiler
darwin64GccDPInt32Opt, with SYSTEMOPENMPI sys-openmpi

bin =      288 entries
lib =      154 entries

9. Verify The Installation

Run OpenFOAM's installation check:

source ~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512/etc/bashrc
foamInstallationTest

Expected result:

Base configuration ok.
Critical systems ok.

Confirm a few important tools exist:

command -v icoFoam
command -v simpleFoam
command -v blockMesh
command -v viewFactorsGen

Confirm the binaries are native Apple Silicon:

file "$FOAM_APPBIN/icoFoam"
file "$FOAM_LIBBIN/libOpenFOAM.dylib"

Expected architecture:

Mach-O 64-bit executable arm64
Mach-O 64-bit dynamically linked shared library arm64

10. Run A Tutorial Smoke Test

source ~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512/etc/bashrc

tdir=$(mktemp -d /private/tmp/openfoam-test.XXXXXX)
cp -R "$FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily" "$tdir/"
cd "$tdir/pitzDaily"

blockMesh
simpleFoam -case .

A working build should complete both blockMesh and simpleFoam.

11. Add A zsh Convenience Loader

Add this to ~/.zshrc:

# OpenFOAM v2512 native Apple Silicon build
openfoam2512() {
  local foam_bundle="$HOME/OpenFOAM/OpenFOAM-v2512-CS.sparsebundle"
  local foam_mount="$HOME/OpenFOAM/OpenFOAM-v2512-CS"
  local foam_root="$foam_mount/OpenFOAM-v2512"

  if [[ ! -f "$foam_root/etc/bashrc" ]]; then
    mkdir -p "$foam_mount"
    hdiutil attach "$foam_bundle" -mountpoint "$foam_mount" -nobrowse -quiet
  fi

  source "$foam_root/etc/bashrc"
}

Then load OpenFOAM in a new terminal with:

openfoam2512

To load it automatically in every new terminal, add this after the function:

openfoam2512

Known Optional Omissions

The native build can still be useful even when some optional integrations are skipped.

In this build:

  • PETSc external solver support was skipped because PETSc headers were not installed.
  • ParaView, VTK, and Catalyst visualization integration were skipped because ParaView/VTK were not configured.
  • Core OpenFOAM solvers and utilities built and ran natively.

Troubleshooting

Case-insensitive filesystem errors

If the build fails with confusing standard-library or system-header include problems, verify that the source tree is on a case-sensitive filesystem:

mount | rg OpenFOAM-v2512-CS

boost/config.hpp not found

Apply the cgal-header-only patch in this guide and rebuild the failed target or rerun:

./Allwmake -j 10 -l

Flex parser build errors

Verify that OpenFOAM is seeing Homebrew flex:

which flex
flex --version
ls -l ~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512/src/OSspecific/POSIX/FlexLexer.h

The symlink should point to:

/opt/homebrew/opt/flex/include/FlexLexer.h

New macOS SDK _Static_assert errors

Confirm etc/prefs.sh contains:

export FOAM_EXTRA_CXXFLAGS="-D_Static_assert=static_assert ${FOAM_EXTRA_CXXFLAGS:-}"

Then source the environment and rebuild.

Result

The result is a native Apple Silicon OpenFOAM v2512 install:

~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512

The sparsebundle is:

~/OpenFOAM/OpenFOAM-v2512-CS.sparsebundle

The zsh loader function mounts the sparsebundle when needed and sources the OpenFOAM environment, so users do not need to remember the hdiutil attach command.

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