Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MacOS with ARM CPUs (CMake + GitHub Action) #25

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
639f0d2
First draft of macOS support in CMakeLists and Github Actions recipe …
siggmo Oct 4, 2024
28b16b6
fix typo in FFTW package name for brew
siggmo Oct 4, 2024
06fed09
Rename macOS workflow to not clash with the Ubuntu workflow
siggmo Oct 4, 2024
5670265
test if OpenMP is really required at all
siggmo Oct 4, 2024
f3e52ea
Remove not used dependency OpenMP
siggmo Oct 4, 2024
2a9ccbd
Merge branch 'bugfix/remove-openmp-dependency' into feature/macOS_M1_…
siggmo Oct 4, 2024
6cfc2a0
Test if setting C++ standard to 11 helps with the whitespace required…
siggmo Oct 4, 2024
9d3970b
Test if setting C++ standard to 14 helps with auto not allowed in lam…
siggmo Oct 4, 2024
05272cd
Test brew hdf5 package without mpi
siggmo Oct 4, 2024
ffd4955
Add macOS installation instructions
siggmo Oct 4, 2024
32bd02a
Test both brew packages hdf5 and hdf5-mpi at the same time (conflicti…
siggmo Oct 4, 2024
8672551
Revert "Test both brew packages hdf5 and hdf5-mpi at the same time (c…
siggmo Oct 4, 2024
120f4a4
Add libomp to macOS dependency installation instructions
siggmo Oct 9, 2024
9415190
Merge branch 'develop' into feature/macOS_M1_support
siggmo Oct 9, 2024
026dffe
Revert "Remove not used dependency OpenMP"
siggmo Oct 9, 2024
8e72fd2
Add libomp to github action
siggmo Oct 9, 2024
ec0c126
Set OpenMP_ROOT in github action recipe to enable CMake on macOS to f…
siggmo Oct 9, 2024
b82d5d9
test explicit path to libomp instead
siggmo Oct 9, 2024
7164b6e
Revert "test explicit path to libomp instead"
siggmo Oct 9, 2024
7323793
Merge branch 'develop' into feature/macOS_M1_support
siggmo Oct 9, 2024
019fcde
try another fix for OpenMP problem
siggmo Oct 9, 2024
c8bd9a9
add missing backslash in multiline command
siggmo Oct 9, 2024
f6a550d
remove cmake from brew install commands as it's included in macos-14 …
siggmo Oct 9, 2024
cc551c4
Mention OpenMP macOS issue with CMake in the README
siggmo Oct 9, 2024
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
81 changes: 81 additions & 0 deletions .github/workflows/build_and_test-mac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build and Test macOS 14 (M1)
# Builds FANS for macOS 14 on M1 CPU and runs the tests.

on:
push:
branches:
- main
- develop
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{github.event_name == 'pull_request'}}

jobs:
build:
name: macOS 14 (M1)
runs-on: macos-14
env:
FANS_BUILD_DIR: build
strategy:
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install FANS dependencies
run: brew install libomp hdf5 openmpi eigen fftw

- name: Generate build directory
run: mkdir -p ${{ env.FANS_BUILD_DIR }}

- name: Configure
working-directory: ${{ env.FANS_BUILD_DIR }}
run: |
cmake --version
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DOpenMP_CXX_FLAG="-Xclang -fopenmp" \
-DOpenMP_CXX_INCLUDE_DIR=$(brew --prefix)/opt/libomp/include \
-DOpenMP_CXX_LIB_NAMES=libomp \
-DOpenMP_C_FLAG="-Xclang -fopenmp" \
-DOpenMP_C_INCLUDE_DIR=$(brew --prefix)/opt/libomp/include \
-DOpenMP_C_LIB_NAMES=libomp \
-DOpenMP_libomp_LIBRARY=$(brew --prefix)/opt/libomp/lib/libomp.dylib \
..

- uses: actions/upload-artifact@v4
if: failure()
with:
name: macOS 14 (M1) CMakeCache
path: ${{ env.FANS_BUILD_DIR }}/CMakeCache.txt
- uses: actions/upload-artifact@v4
if: failure()
with:
name: macOS 14 (M1) CMakeLogs
path: '${{ env.FANS_BUILD_DIR }}/CMakeFiles/*.log'
- uses: actions/upload-artifact@v4
if: failure()
with:
name: macOS 14 (M1) CompileCommands
path: ${{ env.FANS_BUILD_DIR }}/compile_commands.json

- name: Compile
working-directory: ${{ env.FANS_BUILD_DIR }}
run:
cmake --build . -j $(nproc) || cmake --build . -j1

- name: Tests
working-directory: ${{ env.FANS_BUILD_DIR }}
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest

- uses: actions/upload-artifact@v4
if: failure()
with:
name: macOS 14 (M1) CTest logs
path: ${{ env.FANS_BUILD_DIR }}/Testing/Temporary/LastTest.log
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include(CMakePackageConfigHelpers)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 14)

# with -fno-implicit-templates I get linker errors when using std:: stuff
# TODO: should be developer specific, by using e.g. CMake Presets
Expand Down Expand Up @@ -56,7 +57,11 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# From https://stackoverflow.com/questions/73248130/how-to-avoid-the-removal-of-the-rpath-during-cmake-install-step

# Set RPATH to be relative and honor user overrides, whether at the command line or FetchContent
set(RPATH_BASE "$ORIGIN")
if(APPLE)
set(RPATH_BASE "@loader_path")
else()
set(RPATH_BASE "$ORIGIN")
endif()
file(RELATIVE_PATH REL_PATH_LIB
"/${CMAKE_INSTALL_BINDIR}/"
"/${CMAKE_INSTALL_LIBDIR}/")
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ apt-get install \
libfftw3-mpi-dev
```

On macOS, you can obtain the dependencies using `brew`. Since Clang is the preferred compiler on macOS, you'll need the `libomp` package to enable OpenMP support:

```zsh
brew install \
libomp \
hdf5 \
openmpi \
eigen \
fftw
```

If you're facing problems regarding CMake and OpenMP, have a look at this [CMake issue](https://gitlab.kitware.com/cmake/cmake/-/issues/24097) providing a workaround, and this [thread](https://discourse.cmake.org/t/how-to-find-openmp-with-clang-on-macos/8860) in the CMake forums also discussing the issue.

Also, we recommend to set up a Python virtual environment for the `FANS_Dashboard`:

```bash
Expand Down
Loading