name: CMake on multiple platforms on: push: tags: - "v*" workflow_dispatch: jobs: build: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, ubuntu-latest] build_type: [Release] c_compiler: [gcc, clang, cl, emcc] include: - os: windows-latest c_compiler: cl cpp_compiler: cl platform: Windows - os: ubuntu-latest c_compiler: gcc cpp_compiler: g++ platform: Linux-gcc - os: ubuntu-latest c_compiler: clang cpp_compiler: clang++ platform: Linux-clang - os: macos-latest c_compiler: clang cpp_compiler: clang++ platform: MacOS - os: ubuntu-latest c_compiler: emcc cpp_compiler: em++ build_type: Release platform: Web exclude: - os: windows-latest c_compiler: gcc - os: windows-latest c_compiler: clang - os: windows-latest c_compiler: emcc - os: ubuntu-latest c_compiler: cl - os: macos-latest c_compiler: gcc - os: macos-latest c_compiler: cl - os: macos-latest c_compiler: emcc steps: - uses: actions/checkout@v4 - name: Set reusable strings id: strings shell: bash run: | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - name: Cache CMake files uses: actions/cache@v3 with: path: | ~/.cmake ${{ github.workspace }}/build/_deps key: ${{ runner.os }}-cmake-${{ matrix.c_compiler }}-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} restore-keys: | ${{ runner.os }}-cmake-${{ matrix.c_compiler }}- ${{ runner.os }}-cmake- - name: Cache emsdk if: matrix.c_compiler == 'emcc' uses: actions/cache@v3 with: path: | emsdk-cache key: ${{ runner.os }}-emsdk-${{ hashFiles('.github/workflows/**') }} restore-keys: | ${{ runner.os }}-emsdk- - name: Setup Emscripten if: matrix.c_compiler == 'emcc' uses: mymindstorm/setup-emsdk@v12 with: actions-cache-folder: emsdk-cache - 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 }} ${{ matrix.c_compiler == 'emcc' && '-DPLATFORM=Web' || '' }} -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 }} - name: Upload Web Build if: matrix.platform == 'Web' uses: actions/upload-artifact@v4 with: name: ${{ matrix.platform }}-build path: ${{ steps.strings.outputs.build-output-dir }}/*.html - name: Upload Windows Build if: matrix.platform == 'Windows' uses: actions/upload-artifact@v4 with: name: ${{ matrix.platform }}-build path: ${{ steps.strings.outputs.build-output-dir }}/${{ matrix.build_type }}/*.exe - name: Upload Linux Build if: contains(matrix.platform, 'Linux') uses: actions/upload-artifact@v4 with: name: ${{ matrix.platform }}-build path: ${{ steps.strings.outputs.build-output-dir }}/* exclude: | **/*.cmake **/*.txt **/*.json **/*.a **/*.o **/*.d **/*.make **/*.internal **/*.marks **/Makefile **/.ninja* **/*.ninja **/CMakeFiles/** - name: Upload MacOS Build if: matrix.platform == 'MacOS' uses: actions/upload-artifact@v4 with: name: ${{ matrix.platform }}-build path: ${{ steps.strings.outputs.build-output-dir }}/* exclude: | **/*.cmake **/*.txt **/*.json **/*.a **/*.o **/*.d **/*.make **/*.internal **/*.marks **/Makefile **/.ninja* **/*.ninja **/CMakeFiles/**