name: Windows

on: [push, pull_request]

jobs:
  build:
    # available environments: https://github.com/actions/virtual-environments
    name: ${{matrix.config.name}} ${{matrix.build_type}}
    runs-on: ${{matrix.config.os}}
    strategy:
      fail-fast: false
      matrix:
        config:
        - {
          name: "VS-15-2017-win64-C++11",
          os: windows-2016,
          generator: "Visual Studio 15 2017",
          std: 11,
          test_target: RUN_TESTS,
          }
        - {
          name: "VS-16-2019-win64-C++98",
          os: windows-2019,
          generator: "Visual Studio 16 2019",
          std: 98,
          test_target: RUN_TESTS,
          }
        - {
          name: "VS-16-2019-win64-C++11",
          os: windows-2019,
          generator: "Visual Studio 16 2019",
          std: 11,
          test_target: RUN_TESTS,
          }
        - {
          name: "VS-16-2019-win64-C++17",
          os: windows-2019,
          generator: "Visual Studio 16 2019",
          std: 17,
          test_target: RUN_TESTS,
          }
        - {
          name: "VS-16-2019-win64-C++20",
          os: windows-2019,
          generator: "Visual Studio 16 2019",
          std: 20,
          test_target: RUN_TESTS,
          }
        - {
          name: "MinGW-C++98",
          os: windows-latest,
          generator: "MinGW Makefiles",
          std: 98,
          test_target: test,
          }
        - {
          name: "MinGW-C++11",
          os: windows-latest,
          generator: "MinGW Makefiles",
          std: 11,
          test_target: test,
          }
        - {
          name: "MinGW-C++14",
          os: windows-latest,
          generator: "MinGW Makefiles",
          std: 14,
          test_target: test,
          }
        - {
          name: "MinGW-C++17",
          os: windows-latest,
          generator: "MinGW Makefiles",
          std: 17,
          test_target: test,
          }
        - {
          name: "MinGW-C++20",
          os: windows-latest,
          generator: "MinGW Makefiles",
          std: 20,
          test_target: test,
          }
        build_type: [Debug] #, Release]
        ARCH: ["x64"]

    steps:
    - uses: actions/checkout@v2

    # Visual Studio build steps
    - name: Configure build MSVC
      if: ${{ startswith(matrix.config.name, 'VS-') }}
      shell: powershell
      run: cmake -S . -B ${{runner.workspace}}/build_${{matrix.config.name}}_${{matrix.build_type}} -G "${{matrix.config.generator}}" -A "${{matrix.ARCH}}" -DCMAKE_CXX_STANDARD=${{matrix.config.std}} -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF
    - name: Build MSVC
      if: ${{ startswith(matrix.config.name, 'VS-') }}
      shell: powershell
      run: cmake --build ${{runner.workspace}}/build_${{matrix.config.name}}_${{matrix.build_type}} --config ${{matrix.build_type}}

    # MinGW build steps
    - name: Configure build MinGW
      if: ${{ startswith(matrix.config.name, 'MinGW-') }}
      shell: powershell
      env:
        CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Werror -Wno-error=variadic-macros -Wno-error=long-long
      run: cmake -S . -B ${{runner.workspace}}/build_${{matrix.config.name}}_${{matrix.build_type}} -G "${{matrix.config.generator}}" -DCMAKE_CXX_STANDARD=${{matrix.config.std}} -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_BUILD_TYPE=${{matrix.build_type}}
    - name: Build MinGW
      if: ${{ startswith(matrix.config.name, 'MinGW-') }}
      shell: powershell
      run: cmake --build ${{runner.workspace}}/build_${{matrix.config.name}}_${{matrix.build_type}}

    - name: Run tests
      shell: powershell
      env:
          CTEST_OUTPUT_ON_FAILURE: 1
      run: cmake --build ${{runner.workspace}}/build_${{matrix.config.name}}_${{matrix.build_type}} --target ${{matrix.config.test_target}}
