diff --git a/.github/workflows/build_and_test-mac.yaml b/.github/workflows/build_and_test-mac.yaml new file mode 100644 index 0000000..8966999 --- /dev/null +++ b/.github/workflows/build_and_test-mac.yaml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1918e68..ec377ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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}/") diff --git a/README.md b/README.md index faf8c09..0abbd0f 100644 --- a/README.md +++ b/README.md @@ -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