name: "CI: Build Test"

on:
  push:
    branches:
      - main
    paths-ignore:
      - "**.md"
      - "**.png"
      - "**.jpg"
      - "**.jpeg"
      - ".gitignore"
  workflow_dispatch:
  pull_request:

jobs:
  build:
    name: Build
    strategy:
      matrix:
        qt-version: [5.15.2, 6.5.0]
        library-type: [shared, static]
        platform: [windows-latest, ubuntu-latest, macos-latest]
        include:
          - platform: windows-latest
            CC: cl
            CXX: cl
          - platform: ubuntu-latest
            CC: gcc
            CXX: g++
          - platform: macos-latest
            CC: clang
            CXX: clang++
          - library-type: shared
            lib_type_flag: -DFRAMELESSHELPER_BUILD_STATIC=OFF
          - library-type: static
            lib_type_flag: -DFRAMELESSHELPER_BUILD_STATIC=ON

    runs-on: ${{ matrix.platform }}

    steps:
      - name: Check out repository
        uses: actions/checkout@v3
        with:
          submodules: recursive

      - name: Install Qt SDK
        uses: jurplel/install-qt-action@v3
        with:
          version: ${{ matrix.qt-version }}
          cache: true

      - name: Set up Ninja
        uses: seanmiddleditch/gha-setup-ninja@v3
        with:
          version: 1.11.1 # Current latest version.

      - name: Set up MSVC environment
        if: ${{ matrix.platform == 'windows-latest' }}
        uses: ilammy/msvc-dev-cmd@v1

      - name: Install Linux dependencies
        if: ${{ matrix.platform == 'ubuntu-latest' }}
        run: |
          sudo apt install -y libgl1-mesa-dev libxcb1-dev libgtk-3-dev

      - name: Build library with CMake
        run: |
          mkdir ci
          cd ci
          cmake -DCMAKE_MESSAGE_LOG_LEVEL=STATUS -DCMAKE_C_COMPILER=${{ matrix.CC }} -DCMAKE_CXX_COMPILER=${{ matrix.CXX }} -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_BUILD_TYPE=Release -DFRAMELESSHELPER_BUILD_EXAMPLES=ON ${{ matrix.lib_type_flag }} -DFRAMELESSHELPER_ENABLE_SPECTRE=ON -DFRAMELESSHELPER_ENABLE_INTELCET=ON -DFRAMELESSHELPER_ENABLE_INTELJCC=ON -DFRAMELESSHELPER_ENABLE_CFGUARD=ON -GNinja ..
          cmake --build . --target all --config Release --parallel
          cmake --install . --config Release --strip
