Skip to content

Commit 8e1cfff

Browse files
committed
2 parents a7b4a89 + 287219b commit 8e1cfff

1 file changed

Lines changed: 134 additions & 0 deletions

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
2+
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
3+
name: CMake on multiple platforms
4+
5+
on:
6+
push:
7+
branches: [ "master" ]
8+
pull_request:
9+
branches: [ "master" ]
10+
11+
jobs:
12+
build:
13+
runs-on: ${{ matrix.os }}
14+
15+
strategy:
16+
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
17+
fail-fast: false
18+
19+
# Set up a matrix to run the following configurations:
20+
# 1. Windows with MSVC
21+
# 2. Linux with GCC
22+
# 3. Linux with Clang
23+
# 4. macOS with Clang
24+
#
25+
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
26+
matrix:
27+
os: [ubuntu-latest, windows-latest, macos-latest]
28+
build_type: [Release]
29+
c_compiler: [gcc, clang, cl]
30+
include:
31+
- os: windows-latest
32+
c_compiler: cl
33+
cpp_compiler: cl
34+
- os: ubuntu-latest
35+
c_compiler: gcc
36+
cpp_compiler: g++
37+
- os: ubuntu-latest
38+
c_compiler: clang
39+
cpp_compiler: clang++
40+
- os: macos-latest
41+
c_compiler: clang
42+
cpp_compiler: clang++
43+
exclude:
44+
- os: windows-latest
45+
c_compiler: gcc
46+
- os: windows-latest
47+
c_compiler: clang
48+
- os: ubuntu-latest
49+
c_compiler: cl
50+
- os: macos-latest
51+
c_compiler: gcc
52+
- os: macos-latest
53+
c_compiler: cl
54+
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Set reusable strings
59+
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
60+
id: strings
61+
shell: bash
62+
run: |
63+
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
64+
echo "artifact-name=${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}" >> "$GITHUB_OUTPUT"
65+
66+
- name: Setup vcpkg
67+
uses: lukka/run-vcpkg@v11
68+
with:
69+
# Optional: specify the vcpkg commit id to use, defaults to the latest one of the vcpkg repository.
70+
vcpkgCommitId: 'a0f95bc760ed5c8f6d553aaff7dde3a9c4f605a2'
71+
# Optional: specify the vcpkg arguments, e.g. to specify the triplet or use a custom vcpkg repository.
72+
vcpkgArguments: '@vcpkg.json'
73+
74+
- name: Configure CMake
75+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
76+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
77+
run: >
78+
cmake -B ${{ steps.strings.outputs.build-output-dir }}
79+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
80+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
81+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
82+
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake
83+
-S ${{ github.workspace }}
84+
85+
- name: Build
86+
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
87+
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
88+
89+
- name: Test
90+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
91+
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
92+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
93+
run: ctest --build-config ${{ matrix.build_type }}
94+
95+
- name: Find built executables
96+
id: find-binaries
97+
shell: bash
98+
run: |
99+
# Find all executable files in the build directory
100+
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
101+
# On Windows, look for .exe files
102+
find ${{ steps.strings.outputs.build-output-dir }} -name "*.exe" -type f | while read file; do
103+
echo "Found executable: $file"
104+
done
105+
# Prepare artifact path for Windows
106+
echo "artifact-path=${{ steps.strings.outputs.build-output-dir }}/**/*.exe" >> "$GITHUB_OUTPUT"
107+
else
108+
# On Linux/macOS, look for executable files without extension
109+
find ${{ steps.strings.outputs.build-output-dir }} -type f -executable | while read file; do
110+
# Exclude directories and non-binary files
111+
if [[ ! -d "$file" ]] && file "$file" | grep -q "ELF\|Mach-O"; then
112+
echo "Found executable: $file"
113+
fi
114+
done
115+
# Prepare artifact path for Unix-like systems
116+
echo "artifact-path=${{ steps.strings.outputs.build-output-dir }}/**/*" >> "$GITHUB_OUTPUT"
117+
fi
118+
119+
- name: Upload build artifacts
120+
uses: actions/upload-artifact@v4
121+
with:
122+
name: ${{ steps.strings.outputs.artifact-name }}
123+
path: ${{ steps.find-binaries.outputs.artifact-path }}
124+
retention-days: 7
125+
126+
- name: Upload test results
127+
if: always() # Upload test results even if tests fail
128+
uses: actions/upload-artifact@v4
129+
with:
130+
name: ${{ steps.strings.outputs.artifact-name }}-test-results
131+
path: |
132+
${{ steps.strings.outputs.build-output-dir }}/Testing/**/*.xml
133+
${{ steps.strings.outputs.build-output-dir }}/**/*.xml
134+
retention-days: 7

0 commit comments

Comments
 (0)