Using include to specify compiler and os seems not working for me

Hello, I know the problem is with me but I can’t find a way to use the msvc compiler on windows.

This is my workflow:

unit_test.yml

name: Unit tests Linux/Windows

on: [push]

jobs:
  unit-tests:
    name: Build and run unit tests
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
        
        include:
         - os: ubuntu-latest
           compiler: gcc
           version: 10.1
         - os: windows-latest
           compiler: msvc
           version: 14.2


    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: CMake
      run: |
        cd ./build
        cmake -G"Unix Makefiles" ./..
    - name: Make
      run: |
        cd ./build
        make
    - name: Execute unit tests
      run: |
        cd ./build
        ./tests/unit_tests/UnitTests.out --gtest_also_run_disabled_tests


How can I get CMake to use MSVC on windows and GCC on Ubuntu?

  1. use an image with gcc, clang and or cl preinstalled.
ubuntu-18.04-gcc-4.8,
ubuntu-18.04-gcc-4.9,
ubuntu-18.04-gcc-5,
ubuntu-18.04-gcc-6,
ubuntu-18.04-gcc-7,
ubuntu-18.04-gcc-8,
ubuntu-18.04-gcc-9,
ubuntu-18.04-clang-3.5,
ubuntu-18.04-clang-3.6,
ubuntu-18.04-clang-3.7,
ubuntu-18.04-clang-3.8,
ubuntu-18.04-clang-3.9,
ubuntu-18.04-clang-4.0,
ubuntu-18.04-clang-5.0,
ubuntu-18.04-clang-6.0,
ubuntu-18.04-clang-7,
ubuntu-18.04-clang-8,
ubuntu-18.04-clang-9,
windows-2016-cl,
windows-2016-clang-cl,
windows-2016-clang,
windows-2016-gcc,
windows-2019-cl,
windows-2019-clang-cl,
windows-2019-clang,
windows-2019-gcc,
macOS-latest-xcode-11.0,
macOS-latest-xcode-11.3,
  1. Use if statement to add extra steps depending on the operating system, to install any tools you need before running the builds/tests steps.
- name: Prepare Linux tools
    if: runner.os == 'Linux'
   run: # Linux Setup 

- name: Prepare Windows tools
    if: runner.os == 'Windows'
 shell: powershell
   run: # Windows Setup

- name: Build & Test
  run: # profit

for example:


- name: Prepare Windows tools (gcc)
    if: runner.os == 'Windows'
 shell: powershell
   run: |
          Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
          scoop install ninja --global
          if ("${{ matrix.compiler }}".StartsWith("clang")) {
            scoop install llvm --global
          }
          if ("${{ matrix.compiler }}" -eq "gcc") {
            # Chocolatey GCC is broken on the windows-2019 image.
            # See: https://github.community/t5/GitHub-Actions/Something-is-wrong-with-the-chocolatey-installed-version-of-gcc/td-p/32413
            scoop install gcc --global
            echo "::set-env name=CC::gcc"
            echo "::set-env name=CXX::g++"
          } elseif ("${{ matrix.compiler }}" -eq "clang") {
            echo "::set-env name=CC::clang"
            echo "::set-env name=CXX::clang++"
          } else {
            echo "::set-env name=CC::${{ matrix.compiler }}"
            echo "::set-env name=CXX::${{ matrix.compiler }}"
          }
          # Scoop modifies the PATH so we make the modified PATH global.
          echo "::set-env name=PATH::$env:PATH"

Hope that helps. :v:t4:

Thanks, that helps me a lot. I finally split workflow into two, one for windows and one for Linux.

unit_tests_linux.yml

name: Unit tests Linux

on: [push]

jobs:
  unit-tests:
    name: Build and run
    runs-on: ubuntu-latest

    steps:
    - name: Checkout the project
      uses: actions/checkout@v2
    - name: CMake
      run: |
        cd ./build
        CC=gcc-9 CXX=/usr/bin/g++-9 cmake -G"Unix Makefiles" ./.. -DCMAKE_BUILD_TYPE=Release
    - name: Make
      run: |
        cd ./build
        make
    - name: Execute unit tests
      run: |
        cd ./build
        ./tests/unit_tests/UnitTests --gtest_also_run_disabled_tests

and

unit_tests_windows.yml

name: Unit tests Windows

on: [push]

jobs:
  unit-tests:
    name: Build and run
    runs-on: windows-latest

    steps:
    - name: Checkout the project
      uses: actions/checkout@v2
    - name: Checkout msvc-dev-cmd
      uses: ilammy/msvc-dev-cmd@v1.3.0
    - name: CMake
      run: |
        cd ./build
        cmake -G"NMake Makefiles" ./.. -DCMAKE_BUILD_TYPE=Release
    - name: Make
      run: |
        cd ./build
        nmake
    - name: Execute unit tests
      run: |
        cd ./build
        ./tests/unit_tests/UnitTests --gtest_also_run_disabled_tests