Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build ForeFire on macOS

on:
push:
branches:
- brew-macos

workflow_dispatch:

jobs:
build-native-macos:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Make install script executable
run: chmod +x ./install-forefire-osx.sh

- name: Build ForeFire using macOS install script
run: ./install-forefire-osx.sh

- name: Check ForeFire version
run: ./bin/forefire -v
86 changes: 86 additions & 0 deletions install-forefire-osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
set -e
echo "====== MAC OS REQUIREMENTS ========"

# Update Homebrew.
brew update

# Ensure Xcode Command Line Tools are installed.
if ! xcode-select -p > /dev/null 2>&1; then
echo "Xcode Command Line Tools not found. Installing..."
xcode-select --install
fi

# Install dependencies via Homebrew.
brew install cmake
brew install netcdf
brew install netcdf-cxx

# Set NETCDF_HOME to the prefix for the NetCDF C library.
export NETCDF_HOME=$(brew --prefix netcdf)
echo "NETCDF_HOME set to $NETCDF_HOME"

# Set NETCDF_CXX_HOME to the prefix for the NetCDF C++ library.
export NETCDF_CXX_HOME=$(brew --prefix netcdf-cxx)
echo "NETCDF_CXX_HOME set to $NETCDF_CXX_HOME"

# Debug: list headers in NETCDF_HOME/include
echo "Contents of $NETCDF_HOME/include:"
ls -l "$NETCDF_HOME/include"

# Create a symlink in NETCDF_HOME/include so that "netcdf" points to "netcdf.h"
cd "$NETCDF_HOME/include"
if [ ! -e netcdf ]; then
echo "Creating symlink for netcdf -> netcdf.h"
ln -s netcdf.h netcdf
else
echo "Symlink for netcdf already exists."
fi
cd - > /dev/null

# Debug: list the contents of NETCDF_CXX_HOME/lib
cd "$NETCDF_CXX_HOME/lib"
echo "Contents of $NETCDF_CXX_HOME/lib:"
ls -l

# Determine target library name.
target=""
if [ -e libnetcdf-cxx4.dylib ]; then
target="libnetcdf-cxx4.dylib"
elif [ -e libnetcdf-cxx.dylib ]; then
target="libnetcdf-cxx.dylib"
else
echo "Error: Neither libnetcdf-cxx4.dylib nor libnetcdf-cxx.dylib found in $NETCDF_CXX_HOME/lib"
exit 1
fi

echo "Using target library: $target"
if [ ! -e libnetcdf_c++4.dylib ]; then
echo "Creating symlink: libnetcdf_c++4.dylib -> $target"
ln -s "$target" libnetcdf_c++4.dylib
else
echo "Symlink libnetcdf_c++4.dylib already exists."
fi
echo "Contents after symlink creation:"
ls -l
cd - > /dev/null

# Set LIBRARY_PATH for the linker.
export LIBRARY_PATH=$NETCDF_CXX_HOME/lib:$LIBRARY_PATH
echo "LIBRARY_PATH set to: $LIBRARY_PATH"

echo "==========================="
echo "========= FOREFIRE ========"
echo "==========================="

# Create build directory, configure, and compile ForeFire.
mkdir -p build
cd build

# Pass include flags for both netcdf-cxx and netcdf,
# and add the netcdf-cxx lib directory to the shared linker flags.
cmake -D NETCDF_HOME=$NETCDF_HOME \
-DCMAKE_CXX_FLAGS="-I$NETCDF_CXX_HOME/include -I$NETCDF_HOME/include" \
-DCMAKE_SHARED_LINKER_FLAGS="-L$NETCDF_CXX_HOME/lib" \
../
make
Loading