Skip to content

Commit 981492b

Browse files
Update cmake-multi-platform.yml
1 parent 09eb7be commit 981492b

File tree

1 file changed

+218
-52
lines changed

1 file changed

+218
-52
lines changed
Lines changed: 218 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Cmake build test for multiple platform with cache optimised for better build times.
2-
name: CMake on multiple platforms
1+
name: CMake on multiple platforms with Qt and COLMAP
32

43
on:
54
push:
@@ -10,17 +9,8 @@ on:
109
jobs:
1110
build:
1211
runs-on: ${{ matrix.os }}
13-
1412
strategy:
15-
# 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.
1613
fail-fast: false
17-
18-
# Set up a matrix to run the following 3 configurations:
19-
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
20-
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
21-
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
22-
#
23-
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
2414
matrix:
2515
os: [ubuntu-latest, windows-latest]
2616
build_type: [Release]
@@ -32,7 +22,7 @@ jobs:
3222
- os: ubuntu-latest
3323
c_compiler: gcc
3424
cpp_compiler: g++
35-
- os: ubuntu-latest
25+
- os: ubuntu-lest
3626
c_compiler: clang
3727
cpp_compiler: clang++
3828
exclude:
@@ -43,46 +33,222 @@ jobs:
4333
- os: ubuntu-latest
4434
c_compiler: cl
4535

36+
env:
37+
BUILD_DIR: ${{ github.workspace }}/build
38+
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
39+
QT_DIR_LINUX: ${{ github.workspace }}/Qt
40+
QT_VER: 6.6.3
41+
4642
steps:
47-
- uses: actions/checkout@v4
48-
49-
#use previous cache
50-
- name: Restore CCache Cache
51-
uses: actions/cache@v4.2.4
52-
with:
53-
path: ~/.ccache
54-
key: ${{ runner.os }}-ccache-${{ matrix.c_compiler }}-${{ matrix.build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
43+
- uses: actions/checkout@v4
44+
45+
# Common: cache compiler artifacts (ccache) for speed
46+
- name: Restore ccache
47+
uses: actions/cache@v3
48+
with:
49+
path: ~/.ccache
50+
key: ${{ runner.os }}-ccache-${{ matrix.c_compiler }}-${{ matrix.build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
51+
52+
# ----------------------
53+
# Ubuntu setup
54+
# ----------------------
55+
- name: Install dependencies (Ubuntu)
56+
if: runner.os == 'Linux'
57+
run: |
58+
sudo apt-get update
59+
sudo apt-get install -y build-essential ninja-build ccache git cmake
60+
# Optional: install Qt5 from apt (works for many projects)
61+
# sudo apt-get install -y qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools
62+
# We will install Qt 6 via aqtinstall for consistent versions
63+
64+
- name: Install Python tools (Ubuntu)
65+
if: runner.os == 'Linux'
66+
run: |
67+
python3 -m pip install --upgrade pip
68+
python3 -m pip install aqtinstall
69+
70+
- name: Install Qt via aqtinstall (Ubuntu)
71+
if: runner.os == 'Linux'
72+
run: |
73+
python3 -m aqt install-qt linux desktop ${QT_VER} --outputdir "${QT_DIR_LINUX}"
74+
echo "QT_PREFIX=$(echo ${QT_DIR_LINUX}/${QT_VER}/gcc_64)" >> $GITHUB_ENV
75+
76+
# Option A (Ubuntu): Install COLMAP via vcpkg (builds from source)
77+
- name: Setup vcpkg (Ubuntu)
78+
if: runner.os == 'Linux'
79+
run: |
80+
git clone https://github.com/microsoft/vcpkg.git "${VCPKG_ROOT}"
81+
"${VCPKG_ROOT}/bootstrap-vcpkg.sh"
82+
echo "VCPKG_ROOT=${VCPKG_ROOT}" >> $GITHUB_ENV
83+
echo "VCPKG_DEFAULT_TRIPLET=x64-linux" >> $GITHUB_ENV
84+
85+
- name: Install COLMAP with vcpkg (Ubuntu)
86+
if: runner.os == 'Linux'
87+
run: |
88+
"${VCPKG_ROOT}/vcpkg" install colmap:x64-linux
89+
echo "VCPKG_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" >> $GITHUB_ENV
90+
91+
# Alternative Option (Ubuntu): Install COLMAP quickly via snap (no dev cmake config; not suitable for find_package)
92+
# - name: Install COLMAP via snap (Ubuntu)
93+
# if: runner.os == 'Linux'
94+
# run: sudo snap install colmap
95+
96+
# ----------------------
97+
# Windows setup
98+
# ----------------------
99+
- name: Setup vcpkg (Windows)
100+
if: runner.os == 'Windows'
101+
shell: pwsh
102+
run: |
103+
git clone https://github.com/microsoft/vcpkg $env:VCPKG_ROOT
104+
& "$env:VCPKG_ROOT\bootstrap-vcpkg.bat"
105+
echo "VCPKG_ROOT=$env:VCPKG_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
106+
echo "VCPKG_DEFAULT_TRIPLET=x64-windows" | Out-File -FilePath $env:GITHUB_ENV -Append
107+
108+
- name: Install COLMAP with vcpkg (Windows)
109+
if: runner.os == 'Windows'
110+
shell: pwsh
111+
run: |
112+
& "$env:VCPKG_ROOT\vcpkg.exe" install colmap:x64-windows
113+
echo "VCPKG_TOOLCHAIN_FILE=$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
114+
115+
- name: Install Qt via aqtinstall (Windows)
116+
if: runner.os == 'Windows'
117+
shell: pwsh
118+
run: |
119+
py -m pip install --upgrade pip
120+
py -m pip install aqtinstall
121+
py -m aqt install-qt windows desktop ${env:QT_VER} --outputdir "$env:QT_DIR_WIN"
122+
env:
123+
QT_DIR_WIN: ${{ github.workspace }}\Qt
124+
125+
- name: Locate Qt CMake path (Windows)
126+
if: runner.os == 'Windows'
127+
shell: pwsh
128+
run: |
129+
$qt = Get-ChildItem "$env:QT_DIR_WIN" -Recurse -Filter Qt6Config.cmake | Select-Object -First 1
130+
if (-not $qt) { throw "Qt6Config.cmake not found" }
131+
$qtPrefix = Split-Path -Parent $qt.FullName
132+
echo "QT_PREFIX=$qtPrefix" | Out-File -FilePath $env:GITHUB_ENV -Append
133+
134+
# ----------------------
135+
# Configure + Build + Test (common)
136+
# ----------------------
137+
- name: Configure CMake
138+
run: >
139+
cmake -B "${{ env.BUILD_DIR }}"
140+
-G Ninja
141+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
142+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
143+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
144+
-DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_TOOLCHAIN_FILE }}"
145+
-DCMAKE_PREFIX_PATH="${{ env.QT_PREFIX }}"
146+
-S "${{ github.workspace }}"
147+
148+
- name: Build
149+
run: cmake --build "${{ env.BUILD_DIR }}" --config ${{ matrix.build_type }} --parallel
150+
151+
- name: Test
152+
working-directory: ${{ env.BUILD_DIR }}
153+
run: ctest --output-on-failure --build-config ${{ matrix.build_type }}
154+
155+
- name: Save ccache
156+
uses: actions/cache@v3
157+
with:
158+
path: ~/.ccache
159+
key: ${{ runner.os }}-ccache-${{ matrix.c_compiler }}-${{ matrix.build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
160+
161+
162+
163+
164+
165+
166+
167+
# # Cmake build test for multiple platform with cache optimised for better build times.
168+
# name: CMake on multiple platforms
169+
170+
# on:
171+
# push:
172+
# branches: [ "main" ]
173+
# pull_request:
174+
# branches: [ "main" ]
175+
176+
# jobs:
177+
# build:
178+
# runs-on: ${{ matrix.os }}
179+
180+
# strategy:
181+
# # 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.
182+
# fail-fast: false
183+
184+
# # Set up a matrix to run the following 3 configurations:
185+
# # 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
186+
# # 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
187+
# # 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
188+
# #
189+
# # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
190+
# matrix:
191+
# os: [ubuntu-latest, windows-latest]
192+
# build_type: [Release]
193+
# c_compiler: [gcc, clang, cl]
194+
# include:
195+
# - os: windows-latest
196+
# c_compiler: cl
197+
# cpp_compiler: cl
198+
# - os: ubuntu-latest
199+
# c_compiler: gcc
200+
# cpp_compiler: g++
201+
# - os: ubuntu-latest
202+
# c_compiler: clang
203+
# cpp_compiler: clang++
204+
# exclude:
205+
# - os: windows-latest
206+
# c_compiler: gcc
207+
# - os: windows-latest
208+
# c_compiler: clang
209+
# - os: ubuntu-latest
210+
# c_compiler: cl
211+
212+
# steps:
213+
# - uses: actions/checkout@v4
214+
215+
# #use previous cache
216+
# - name: Restore CCache Cache
217+
# uses: actions/cache@v4.2.4
218+
# with:
219+
# path: ~/.ccache
220+
# key: ${{ runner.os }}-ccache-${{ matrix.c_compiler }}-${{ matrix.build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
55221

56-
- name: Set reusable strings
57-
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
58-
id: strings
59-
shell: bash
60-
run: |
61-
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
62-
63-
- name: Configure CMake
64-
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
65-
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
66-
run: >
67-
cmake -B ${{ steps.strings.outputs.build-output-dir }}
68-
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
69-
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
70-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
71-
-S ${{ github.workspace }}
72-
73-
- name: Build
74-
# 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).
75-
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
76-
77-
# Save the cache for future build
78-
- name: Save CCache Cache
79-
uses: actions/cache@v4.2.4
80-
with:
81-
path: ~/.ccache
82-
key: ${{ runner.os }}-ccache-${{ matrix.c_compiler }}-${{ matrix.build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
222+
# - name: Set reusable strings
223+
# # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
224+
# id: strings
225+
# shell: bash
226+
# run: |
227+
# echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
228+
229+
# - name: Configure CMake
230+
# # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
231+
# # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
232+
# run: >
233+
# cmake -B ${{ steps.strings.outputs.build-output-dir }}
234+
# -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
235+
# -DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
236+
# -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
237+
# -S ${{ github.workspace }}
238+
239+
# - name: Build
240+
# # 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).
241+
# run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
242+
243+
# # Save the cache for future build
244+
# - name: Save CCache Cache
245+
# uses: actions/cache@v4.2.4
246+
# with:
247+
# path: ~/.ccache
248+
# key: ${{ runner.os }}-ccache-${{ matrix.c_compiler }}-${{ matrix.build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
83249

84-
- name: Test
85-
working-directory: ${{ steps.strings.outputs.build-output-dir }}
86-
# 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).
87-
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
88-
run: ctest --build-config ${{ matrix.build_type }}
250+
# - name: Test
251+
# working-directory: ${{ steps.strings.outputs.build-output-dir }}
252+
# # 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).
253+
# # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
254+
# run: ctest --build-config ${{ matrix.build_type }}

0 commit comments

Comments
 (0)