Skip to content

Instantly share code, notes, and snippets.

@alecjacobson
Created February 18, 2022 06:57
Show Gist options
  • Save alecjacobson/689cc395ceebc04ff075757f4eafab0b to your computer and use it in GitHub Desktop.
Save alecjacobson/689cc395ceebc04ff075757f4eafab0b to your computer and use it in GitHub Desktop.
bash script proof of concept showing how to build libigl using rosetta on m1 mac
#!/bin/bash
# arch -x86_64 ./build-x86_64-gmp-mpfr-libigl.sh
if [[ $(arch) == *arm64* ]]; then
#echo "int main(){}" | clang++ -x c++ - -o test.o
echo "Re-issue as `arch -x86_64 ./build-x86_64-gmp-mpfr-libigl.sh`"
exit 1
fi
# Download and compile GMP
if [ ! -d gmp-6.2.1 ]; then
curl https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz | tar -xz
cd gmp-6.2.1
curl "https://gmplib.org/repo/gmp/raw-rev/5f32dbc41afc" | git apply -v
cd ..
fi
if [ ! -f gmp-6.2.1/.libs/libgmp.a ]; then
cd gmp-6.2.1
./configure --disable-debug --disable-dependency-tracking --enable-cxx --with-pic
make -j8
cd ..
fi
# Download and compile MPFR
if [ ! -d mpfr-4.1.0 ]; then
curl https://ftp.gnu.org/gnu/mpfr/mpfr-4.1.0.tar.xz | tar -xz
cd mpfr-4.1.0
curl "https://raw.githubusercontent.com/Homebrew/formula-patches/03cf8088210822aa2c1ab544ed58ea04c897d9c4/libtool/configure-big_sur.diff" | git apply -v
cd ..
fi
if [ ! -f mpfr-4.1.0/src/.libs/libmpfr.a ]; then
cd mpfr-4.1.0
./configure --disable-debug --disable-dependency-tracking --disable-silent-rules --with-gmp-include=../gmp-6.2.1 --with-gmp-lib=../gmp-6.2.1/.libs
make -j8
cd ..
fi
# Download and compile libigl (and its dependencies)
if [ ! -d libigl ]; then
git clone git@github.com:libigl/libigl.git libigl
fi
cd libigl
mkdir -p build
cd build
cmake ../ \
-DGMP_INCLUDES=../../gmp-6.2.1 -DGMP_LIBRARIES=../../gmp-6.2.1/.libs/libgmp.a \
-DMPFR_INCLUDES=../../mpfr-4.1.0/src/ -DMPFR_LIBRARIES=../../mpfr-4.1.0/src/.libs/libmpfr.a \
-DLIBIGL_RESTRICTED_MATLAB=ON
make -j8
cd ../../
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment