Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Update cmake-multi-platform.yml #5

Update cmake-multi-platform.yml

Update cmake-multi-platform.yml #5

name: CMake Build and Release
on:
push:
branches: [ "main" ]
tags: [ "v*" ] # Trigger on version tags
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
executable_suffix: ".exe"
archive_name: "windows"
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
executable_suffix: ""
archive_name: "linux"
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
executable_suffix: ""
archive_name: "linux-clang"
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
executable_suffix: ""
archive_name: "macos"
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
- os: macos-latest
c_compiler: gcc
- os: macos-latest
c_compiler: cl
steps:
- uses: actions/checkout@v4
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
# Install dependencies (libsndfile)
- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libsndfile1-dev
- name: Install dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install libsndfile
- name: Install dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
# You might need to set up vcpkg or download libsndfile manually
# This is a placeholder - adjust based on your Windows setup
echo "Set up libsndfile for Windows"
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
# Package binaries
- name: Package binaries
shell: bash
run: |
mkdir -p release
# Adjust these paths based on your CMake target names
# Replace 'your_executable_name' with your actual executable name
if [ "${{ matrix.os }}" == "windows-latest" ]; then
cp ${{ steps.strings.outputs.build-output-dir }}/${{ matrix.build_type }}/Main${{ matrix.executable_suffix }} release/
else
cp ${{ steps.strings.outputs.build-output-dir }}/Main${{ matrix.executable_suffix }} release/
fi
# Create archive
if [ "${{ matrix.os }}" == "windows-latest" ]; then
7z a your_project_name-${{ matrix.archive_name }}.zip release/*
else
tar -czf your_project_name-${{ matrix.archive_name }}.tar.gz -C release .
fi
# Upload artifacts for every build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.archive_name }}
path: |
*.zip
*.tar.gz
# Create release only on tags
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
artifacts/**/*.zip
artifacts/**/*.tar.gz
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}