Last active
June 17, 2025 14:00
-
-
Save adrn/afd9222416e359fcef826b7988b7d69f to your computer and use it in GitHub Desktop.
Mac M4 EXP install script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Run a full compile of exp on a Mac with Apple Silicon (M1, M2, etc.) | |
# by APW, based on a script by Mike P | |
# ----------------------------------------------------------------------------- | |
# NOTES: | |
# - APW used `uv` for Python, but this should also work with Python + virtualenv. This | |
# is not tested with `conda` but it might work? I set up and activated my Python | |
# environment in the EXPDIR (i.e. the cloned exp repository path) using: | |
# | |
# uv venv --python 3.12 | |
# source .venv/bin/activate | |
# | |
# - You probably need to edit these files to avoid a "-fopenmp -Xclang" error: | |
# | |
# expui/CMakeLists.txt | |
# pyEXP/CMakeLists.txt | |
# | |
# to comment out the line (one per file) that looks like: | |
# | |
# target_compile_options(pyEXP PUBLIC ${OpenMP_CXX_FLAGS}) | |
# | |
# - APW installed all dependencies using Homebrew: | |
# | |
# brew install fftw gsl open-mpi hdf5 libomp libpng eigen cmake ninja | |
# | |
# - This installs the exp libaries into `install/lib` (relative to the EXPDIR) | |
# ----------------------------------------------------------------------------- | |
# Edit this path to point to your local clone of the exp repository: | |
export EXPDIR=/Users/aprice-whelan/projects/exp | |
# If your homebrew is installed in a non-standard location, you need to edit this: | |
export HOMEBREW_PATH=/opt/homebrew | |
# ----------------------------------------------------------------------------- | |
# Get the path to the python executable that works even within a virtual environment: | |
export PYTHON_TRUE_BASE=$(python -c "import sys; print(sys.base_prefix)") | |
export PYTHON_VENV_BASE=$(python -c "import sys; print(sys.prefix)") | |
# Get Python version info dynamically | |
export PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") | |
export PYTHON_EXEC=$(python -c "import sys, os; print(os.path.realpath(sys.executable))") | |
export PYTHON_LIBRARY_PATH=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))") | |
export PYTHON_LIBRARY=${PYTHON_LIBRARY_PATH}/libpython${PYTHON_VERSION}.dylib | |
echo "Using Python at: ${PYTHON_TRUE_BASE}" | |
export PATH=${HOMEBREW_PATH}/bin:$PATH | |
export LD_LIBRARY_PATH=${HOMEBREW_PATH}/lib:$LD_LIBRARY_PATH | |
export INCLUDE=${HOMEBREW_PATH}/include:$INCLUDE | |
export OMP_HOME=${HOMEBREW_PATH}/opt/libomp/ | |
export LDFLAGS="-L${OMP_HOME}/lib" | |
export CPPFLAGS="-I${OMP_HOME}/include" | |
export CC=mpicc | |
export CXX=mpicxx | |
cmake \ | |
-G Ninja \ | |
-B build \ | |
--install-prefix $PWD/install \ | |
-DCMAKE_INSTALL_PREFIX=$PWD/install \ | |
-DCMAKE_INSTALL_RPATH=$PWD/install/lib \ | |
-DENABLE_NBODY=on \ | |
-DENABLE_USER=on \ | |
-DENABLE_PYEXP=on \ | |
-DDISABLE_OPENMP_COMPILE_FLAGS=on \ | |
-DPYTHON_EXECUTABLE=${PYTHON_EXEC} \ | |
-DPYTHON_LIBRARY=${PYTHON_LIBRARY} \ | |
-DOpenMP_CXX_INCLUDE_DIR=${OMP_HOME}/include \ | |
-DOpenMP_C_INCLUDE_DIR=${OMP_HOME}/include | |
cmake --build build | |
cmake --install build | |
# Add the pyEXP dir as a pyEXP.pth file in Python site-packages: | |
SITE_PACKAGES=$(python -c "import site; print(site.getsitepackages()[0])") | |
echo "$PWD/install/lib/python${PYTHON_VERSION}/site-packages" > "${SITE_PACKAGES}/pyEXP.pth" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment