on:
  push:
    branches: [ master ]
  pull_request:
jobs:
  linux-release-shared:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - run: sudo apt-get install -y liblapacke-dev
    - run: cmake -DBUILD_EXAMPLES=ON .
    - run: make -j$(nproc)
    - run: ctest
  linux-debug-shared:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - run: sudo apt-get install -y liblapacke-dev
    - run: cmake -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Debug .
    - run: make -j$(nproc)
    - run: ctest
  linux-release-static:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - run: sudo apt-get install -y liblapacke-dev
    - run: cmake -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=OFF .
    - run: make -j$(nproc)
    - run: ctest
  linux-clang:
    env:
      CC: clang
      CXX: clang++
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - run: sudo apt-get install -y liblapacke-dev
    - run: cmake -DBUILD_EXAMPLES=ON .
    - run: make -j$(nproc)
    - run: ctest
  macos:
    runs-on: macos-latest
    env:
      LDFLAGS: -L/opt/homebrew/opt/openblas/lib
      CPPFLAGS: -I/opt/homebrew/opt/openblas/include
    steps:
    - uses: actions/checkout@v3
    - run: brew install openblas
    - run: cmake -DBUILD_EXAMPLES=ON -DCBLAS_INCLUDE_DIR=/opt/homebrew/opt/openblas/include .
    - run: make -j$(sysctl -n hw.logicalcpu)
    - run: ctest
  mingw64:
    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 {0}
    steps:
    - uses: msys2/setup-msys2@v2
      with:
        release: true
        install: >-
          mingw-w64-x86_64-gcc
          mingw-w64-x86_64-openblas
          mingw-w64-x86_64-cmake
          mingw-w64-x86_64-ninja
    - uses: actions/checkout@v3
    - run: cmake -GNinja -DBUILD_EXAMPLES=ON -DCBLAS_INCLUDE_DIR=D:/a/_temp/msys64/mingw64/include/openblas .
    - run: ninja
    - run: ctest
  windows:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v3
      - uses: ilammy/msvc-dev-cmd@v1
      - name: Build
        shell: cmd
        run: |
          curl -fsSLO https://github.com/xianyi/OpenBLAS/releases/download/v0.3.23/OpenBLAS-0.3.23-x64.zip
          7z x OpenBLAS-0.3.23-x64.zip
          xcopy /f /y /s bin\libopenblas.dll .
          cmake -LAH -G Ninja -DBUILD_EXAMPLES=ON -DBLAS_LIBRARIES=%cd:\=/%/lib/libopenblas.dll.a -DCBLAS_LIBRARIES=%cd:\=/%/lib/libopenblas.dll.a -DLAPACKE_LIBRARIES=%cd:\=/%/lib/libopenblas.dll.a -DCBLAS_INCLUDE_DIR=%cd:\=/%/include -DCMAKE_INSTALL_PREFIX=%cd:\=/%/install -DCMAKE_CXX_COMPILER=cl -DCMAKE_C_COMPILER=cl .
          cmake --build . --target install --parallel 4
          ctest --output-on-failure -V
