name: build

on: [push, pull_request]

jobs:

  linux:
    strategy:
      matrix:
        compiler:
          - { pkg: g++, exe: 'g++', version: 12 }
          - { pkg: g++, exe: 'g++', version: 13 }
          - { pkg: g++, exe: 'g++', version: 14 }
          - { pkg: clang, exe: 'clang++', version: 16 }
          - { pkg: clang, exe: 'clang++', version: 17 }
          - { pkg: clang, exe: 'clang++', version: 18 }

    timeout-minutes: 15
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Install compiler
      run: |
        sudo apt update
        sudo apt install -y ${{ matrix.compiler.pkg }}-${{ matrix.compiler.version }}
    - name: Compile tests
      working-directory: build
      env:
        CXX: ${{ matrix.compiler.exe }}-${{ matrix.compiler.version }}
      run: |
        cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
        make -j4
    - name: Run tests
      working-directory: build
      env:
        CTEST_OUTPUT_ON_FAILURE: 1
      run: ctest -C Debug -j4

  windows:
    strategy:
      matrix:
        toolset: [default, v142, clang-cl]
        include:
          - toolset: v142
            toolset_option: -T"v142"
          - toolset: clang-cl
            toolset_option: -T"ClangCl"

    timeout-minutes: 15
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v4
    - name: Compile tests
      working-directory: build
      run: |
        cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ${{ matrix.toolset_option }} ..
        cmake --build . -j 4
    - name: Run tests
      working-directory: build
      env:
        CTEST_OUTPUT_ON_FAILURE: 1
      run: ctest -C Debug -j4

  macos:
    timeout-minutes: 15
    runs-on: macOS-latest

    steps:
    - uses: actions/checkout@v4
    - name: Compile tests
      working-directory: build
      run: |
        cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
        make -j4
    - name: Run tests
      working-directory: build
      env:
        CTEST_OUTPUT_ON_FAILURE: 1
      run: ctest -C Debug -j4

  extra:
    strategy:
      matrix:
        os: [windows-latest, macOS-latest, ubuntu-latest]
        id_type: ["std::uint32_t", "std::uint64_t"]
        cxx_std: [cxx_std_17, cxx_std_20]

    timeout-minutes: 15
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v4
    - name: Compile tests
      working-directory: build
      run: |
        cmake -DENTT_BUILD_TESTING=ON -DENTT_CXX_STD=${{ matrix.cxx_std }} -DENTT_ID_TYPE=${{ matrix.id_type }} ..
        cmake --build . -j 4
    - name: Run tests
      working-directory: build
      env:
        CTEST_OUTPUT_ON_FAILURE: 1
      run: ctest -C Debug -j4
