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.
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:
- Install build dependencies with Homebrew.
- Create a case-sensitive APFS sparsebundle.
- Download and extract OpenFOAM and ThirdParty sources.
- Add Apple Silicon/Homebrew build preferences.
- Configure OpenFOAM's dependency paths.
- Apply two small macOS/Homebrew fixes.
- Build and verify.
- Add a zsh helper to mount and source OpenFOAM.
brew install gcc open-mpi boost cgal scotch fftw gnuplot gawk make flex autoconf automake libtool gmp mpfrThis guide assumes Homebrew is installed in the default Apple Silicon location:
/opt/homebrewCreate 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-CSThe mounted volume path used throughout this guide is:
~/OpenFOAM/OpenFOAM-v2512-CSDownload 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
Create this file:
~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512/etc/prefs.shWith 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_CCandOMPI_CXXensure OpenMPI uses the same compiler family.BOOST_INC_DIRhelps with Homebrew Boost installs._Static_assertis mapped tostatic_assertbecause newer macOS SDK headers expose C-style_Static_assertin places that Homebrew GCC sees while compiling C++.
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-brewOpenFOAM 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.hWith 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-onlyAdd 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
endifThis is needed because some OpenFOAM utilities include cgal-header-only directly instead of the fuller CGAL rule that already synthesizes these paths.
cd ~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512
source etc/bashrc
./Allwmake -j 10 -lDo 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
Run OpenFOAM's installation check:
source ~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512/etc/bashrc
foamInstallationTestExpected result:
Base configuration ok.
Critical systems ok.
Confirm a few important tools exist:
command -v icoFoam
command -v simpleFoam
command -v blockMesh
command -v viewFactorsGenConfirm 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
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.
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:
openfoam2512To load it automatically in every new terminal, add this after the function:
openfoam2512The 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.
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-CSApply the cgal-header-only patch in this guide and rebuild the failed target or rerun:
./Allwmake -j 10 -lVerify that OpenFOAM is seeing Homebrew flex:
which flex
flex --version
ls -l ~/OpenFOAM/OpenFOAM-v2512-CS/OpenFOAM-v2512/src/OSspecific/POSIX/FlexLexer.hThe symlink should point to:
/opt/homebrew/opt/flex/include/FlexLexer.h
Confirm etc/prefs.sh contains:
export FOAM_EXTRA_CXXFLAGS="-D_Static_assert=static_assert ${FOAM_EXTRA_CXXFLAGS:-}"Then source the environment and rebuild.
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.