fix problem#5 #167
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CMake on multiple platforms | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, windows-latest] | |
| build_type: [Release] | |
| include: | |
| - os: ubuntu-latest | |
| c_compiler: gcc | |
| cpp_compiler: g++ | |
| - os: ubuntu-latest | |
| c_compiler: clang | |
| cpp_compiler: clang++ | |
| - os: windows-latest | |
| c_compiler: gcc | |
| cpp_compiler: g++ | |
| steps: | |
| ################################# | |
| # Checkout repository and submodules | |
| ################################# | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Update submodules to latest commits | |
| run: | | |
| git submodule sync | |
| git submodule update --init --remote --merge | |
| ################################# | |
| # Set build output dir | |
| ################################# | |
| - name: Set build output dir | |
| shell: bash | |
| id: strings | |
| run: echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" | |
| ################################# | |
| # Cache build dependencies | |
| ################################# | |
| - name: Cache build dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ steps.strings.outputs.build-output-dir }}/_deps | |
| ~/.cache/vcpkg | |
| key: ${{ runner.os }}-${{ matrix.c_compiler }}-deps-${{ hashFiles('**/CMakeLists.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-${{ matrix.c_compiler }}-deps- | |
| ################################# | |
| # Linux-specific setup | |
| ################################# | |
| - name: Install dependencies (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| shell: bash | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential cmake \ | |
| libgl1-mesa-dev libx11-dev libxrandr-dev libxinerama-dev \ | |
| libxcursor-dev libxi-dev libasound2-dev libglu1-mesa-dev \ | |
| xvfb ccache | |
| - name: Clean build directory (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| shell: bash | |
| run: rm -rf ${{ steps.strings.outputs.build-output-dir }} | |
| ################################# | |
| # Windows-specific setup | |
| ################################# | |
| - name: Install MinGW (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| choco install mingw --no-progress | |
| echo "C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin" >> $env:GITHUB_PATH | |
| - name: Clean build directory (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: Remove-Item -Path "${{ steps.strings.outputs.build-output-dir }}" -Recurse -Force -ErrorAction SilentlyContinue | |
| ################################# | |
| # Configure CMake | |
| ################################# | |
| - name: Configure CMake (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| shell: bash | |
| run: | | |
| cmake -B ${{ steps.strings.outputs.build-output-dir }} \ | |
| -G "Unix Makefiles" \ | |
| -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \ | |
| -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \ | |
| -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ | |
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | |
| -S ${{ github.workspace }} | |
| - name: Configure CMake (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| cmake -B "${{ steps.strings.outputs.build-output-dir }}" ` | |
| -G "MinGW Makefiles" ` | |
| -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} ` | |
| -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} ` | |
| -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ` | |
| -S "${{ github.workspace }}" | |
| ################################# | |
| # Build project | |
| ################################# | |
| - name: Build (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| shell: bash | |
| run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -- -j$(nproc) --target unit_tests | |
| - name: Build (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | |
| cmake --build "${{ steps.strings.outputs.build-output-dir }}" --config ${{ matrix.build_type }} --target unit_tests | |
| ################################# | |
| # Run tests (Linux) | |
| ################################# | |
| - name: Run unit tests (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| shell: bash | |
| run: | | |
| chmod +x ${{ steps.strings.outputs.build-output-dir }}/unit_tests | |
| ${{ steps.strings.outputs.build-output-dir }}/unit_tests | |
| ################################# | |
| # Run tests (Windows) | |
| ################################# | |
| - name: Run unit tests (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| & "${{ steps.strings.outputs.build-output-dir }}\unit_tests.exe" |