Late to the thread. FWIW, I've been using TMB with OpenMP support on an M1 Mac for several months now, since before CRAN started releasing prebuilt native R binaries. To get it all to work at the time, I had to piece together from different sections of
R-admin and
R-exts how to build R from sources, with OpenMP support enabled for package installation by default. I documented everything
here, and this continues to be workflow that I use to (re)install R on my machine.
Installing R from sources is no longer necessary now that CRAN is releasing native binaries. Currently, what I believe you need to install TMB with OpenMP support are:
(1) A native build of R ... CRAN binary can be downloaded
here.
(2) Command Line Tools ... Running
xcode-select --install
on the command line will install the most recent version if you do not have any version installed.
(3) A C/C++ compiler with OpenMP support ... The Apple clang toolchain does not support OpenMP. R-admin suggests as an alternative the LLVM clang toolchain, which you can install (if you use Homebrew) by running
brew update
brew install llvm
Mollie's link suggests using the gcc and g++ provided with the experimental gfortran build from
fxcoudert. I'd be curious if people's experiences vary there. LLVM clang may have better warranty...
(4) A $(HOME)/.R/Makevars file specifying compilers and compilation flags that R should use to compile R packages. Here is a provisional version that ought to be sufficient for TMB installation (assuming you have done 1-3):
LIBS_DIR=/opt/R/arm64
LLVM_DIR=/opt/homebrew/opt/llvm
SDK_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CC="${LLVM_DIR}/bin/clang -isysroot ${SDK_PATH} -target arm64-apple-macos11"
CXX="${LLVM_DIR}/bin/clang++ -isysroot ${SDK_PATH} -target arm64-apple-macos11"
CFLAGS="-falign-functions=8 -g -O2 -Wall -pedantic -Wno-implicit-function-declaration"
CXXFLAGS="-g -O2 -Wall -pedantic"
SHLIB_OPENMP_CFLAGS=-fopenmp
SHLIB_OPENMP_CXXFLAGS=-fopenmp
CPPFLAGS="-I${LLVM_DIR}/include -I${LIBS_DIR}/include"
LDFLAGS="-L${LLVM_DIR}/lib -L${LIBS_DIR}/lib"
I haven't tested this recently, so no warranty, as usual... If anyone gets to try before me, then let me know how it goes. If I try and find that these instructions still work (at least on my system), then I'll throw them on GitHub and link here.
Mikael