name: GitHub actions

on:
  push:
    branches: [ "**" ]
  pull_request:
    branches: [ "**" ]

env:
  BUILD_TYPE: Debug
  EIGEN3_WIN_INSTALL_DIR: C:/ProgramData/chocolatey/lib/eigen/include

jobs:
  build:
    strategy:
      matrix:
        os: [ ubuntu-latest, macos-latest, windows-latest ]
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v3

      - name: Install Eigen3
        shell: bash
        run: |
          if [ "$RUNNER_OS" == "Windows" ]; then
            choco install eigen
          elif [ "$RUNNER_OS" == "Linux" ]; then
            sudo apt-get install -y libeigen3-dev
          elif [ "$RUNNER_OS" == "macOS" ]; then
            brew install eigen
          else
            echo "$RUNNER_OS not supported"
            exit 1
          fi

      - name: Configure Quantum++
        shell: bash
        run: |
          if [ "$RUNNER_OS" == "Windows" ]; then
            export EIGEN3_INSTALL_DIR="${{env.EIGEN3_WIN_INSTALL_DIR}}"
          fi
          cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
            -DWITH_UNIT_TESTS=ON -DWITH_EXAMPLES=ON

      - name: Install Quantum++
        shell: bash
        run: |
          if [ "$RUNNER_OS" == "Windows" ]; then
            cmake --build build --target install
          else
            sudo cmake --build build --target install
          fi

      - name: Configure standalone example
        shell: bash
        run: |
          if [ "$RUNNER_OS" == "Windows" ]; then
            export EIGEN3_INSTALL_DIR="${{env.EIGEN3_WIN_INSTALL_DIR}}"
          fi
          cmake -S examples/standalone -B examples/standalone/build

      - name: Build standalone example
        run: |
          cmake --build examples/standalone/build --target standalone

      - name: Run standalone example
        shell: bash
        run: |
          if [ "$RUNNER_OS" == "Windows" ]; then
            ./examples/standalone/build/${{env.BUILD_TYPE}}/standalone.exe
          else
            ./examples/standalone/build/standalone
          fi

      - name: Build examples
        run: cmake --build build --target examples

      - name: Build unit tests
        run: cmake --build build --target unit_tests

      - name: Run unit tests
        run: ctest --test-dir build -E qpp_Timer

      - name: Install pyqpp
        shell: bash
        run: |
          if [ "$RUNNER_OS" == "Windows" ]; then
            export EIGEN3_INSTALL_DIR="${{env.EIGEN3_WIN_INSTALL_DIR}}"
          fi
          pip3 install .
