Skip to content

Commit 3b5729b

Browse files
committed
Add cross platform build, packaging, and test automation
1 parent cf2ba17 commit 3b5729b

File tree

8 files changed

+480
-13
lines changed

8 files changed

+480
-13
lines changed
Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
branches: [ main, develop ]
10+
workflow_dispatch:
11+
12+
env:
13+
CMAKE_VERSION: "3.28.0"
14+
QT_VERSION: "6.9.3"
15+
16+
jobs:
17+
build:
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
# Windows MSVC builds
23+
- name: "Windows MSVC 2022 x64"
24+
os: windows-2022
25+
preset: "windows-msvc-x64-release"
26+
cmake_generator: "Visual Studio 17 2022"
27+
cmake_platform: "x64"
28+
qt_arch: "win64_msvc2022_64"
29+
artifact_prefix: "windows-msvc-x64"
30+
31+
# macOS builds
32+
- name: "macOS x86_64 (Intel)"
33+
os: macos-13
34+
preset: "macos-x64-release"
35+
cmake_generator: "Ninja"
36+
cmake_build_type: "Release"
37+
qt_arch: "clang_64"
38+
artifact_prefix: "macos-x64"
39+
40+
# Linux builds
41+
- name: "Linux x64"
42+
os: ubuntu-22.04
43+
preset: "linux-x64-release"
44+
cmake_generator: "Ninja"
45+
cmake_build_type: "Release"
46+
qt_arch: "linux_gcc_64"
47+
artifact_prefix: "linux-x64"
48+
49+
# ARM Linux builds
50+
- name: "ARM Linux (aarch64)"
51+
os: ubuntu-22.04
52+
preset: "linux-arm64-release"
53+
cmake_generator: "Ninja"
54+
cmake_build_type: "Release"
55+
qt_arch: "linux_gcc_arm64"
56+
artifact_prefix: "linux-arm64"
57+
58+
runs-on: ${{ matrix.os }}
59+
name: ${{ matrix.name }}
60+
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v4
64+
with:
65+
fetch-depth: 0
66+
67+
- name: Install Qt (Windows)
68+
if: runner.os == 'Windows'
69+
uses: jurplel/install-qt-action@v4
70+
with:
71+
version: ${{ env.QT_VERSION }}
72+
arch: ${{ matrix.qt_arch }}
73+
cache: 'true'
74+
75+
- name: Install Qt (macOS)
76+
if: runner.os == 'macOS'
77+
uses: jurplel/install-qt-action@v4
78+
with:
79+
version: ${{ env.QT_VERSION }}
80+
arch: ${{ matrix.cmake_platform == 'arm64' && 'mac_arm64' || 'mac_x64' }}
81+
modules: 'qtbase qtgui qtwidgets'
82+
cache: 'true'
83+
84+
- name: Install Qt (Linux)
85+
if: runner.os == 'Linux'
86+
run: |
87+
sudo apt-get update
88+
sudo apt-get install -y qt6-base-dev qt6-base-dev-tools
89+
90+
- name: Install dependencies (Windows)
91+
if: runner.os == 'Windows'
92+
run: |
93+
choco install ninja cmake -y
94+
95+
- name: Install dependencies (macOS)
96+
if: runner.os == 'macOS'
97+
run: |
98+
brew install ninja cmake
99+
100+
- name: Install dependencies (Linux)
101+
if: runner.os == 'Linux'
102+
run: |
103+
sudo apt-get install -y ninja-build cmake build-essential
104+
105+
- name: Create build directory
106+
run: cmake -E make_directory ${{ github.workspace }}/build
107+
108+
- name: Configure CMake (Windows)
109+
if: runner.os == 'Windows'
110+
shell: cmd
111+
run: |
112+
cd ${{ github.workspace }}/build
113+
cmake -G "${{ matrix.cmake_generator }}" ^
114+
-A ${{ matrix.cmake_platform }} ^
115+
-DCMAKE_BUILD_TYPE=Release ^
116+
-DBUILD_EXAMPLES=ON ^
117+
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/install" ^
118+
..
119+
120+
- name: Configure CMake (non-Windows)
121+
if: runner.os != 'Windows'
122+
run: |
123+
cd ${{ github.workspace }}/build
124+
cmake -G "${{ matrix.cmake_generator }}" \
125+
-DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \
126+
-DBUILD_EXAMPLES=ON \
127+
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/install" \
128+
..
129+
130+
- name: Build
131+
run: cmake --build ${{ github.workspace }}/build --config Release --parallel
132+
133+
- name: Install
134+
run: cmake --install ${{ github.workspace }}/build --config Release
135+
136+
- name: Create package (Windows)
137+
if: runner.os == 'Windows'
138+
shell: cmd
139+
run: |
140+
cd ${{ github.workspace }}/build
141+
cpack -C Release -G NSIS
142+
143+
- name: Create package (macOS)
144+
if: runner.os == 'macOS'
145+
run: |
146+
cd ${{ github.workspace }}/build
147+
cpack -C Release -G DragNDrop
148+
cpack -C Release -G TGZ
149+
150+
- name: Create package (Linux)
151+
if: runner.os == 'Linux'
152+
run: |
153+
cd ${{ github.workspace }}/build
154+
cpack -C Release -G DEB
155+
cpack -C Release -G RPM
156+
cpack -C Release -G TGZ
157+
158+
- name: List artifacts
159+
run: Get-ChildItem ${{ github.workspace }}/build/ -Force | Format-List
160+
161+
- name: Upload artifacts
162+
uses: actions/upload-artifact@v4
163+
with:
164+
name: ${{ matrix.artifact_prefix }}-packages
165+
path: ${{ github.workspace }}/build/QTradingView-*
166+
retention-days: 30
167+
168+
- name: Generate checksums
169+
# if: startsWith(github.ref, 'refs/tags/')
170+
run: |
171+
cd ${{ github.workspace }}/build
172+
find . -maxdepth 1 -name "QTradingView-*" -type f -exec sh -c 'sha256sum "$1" > "$1.sha256"' _ {} \;
173+
174+
- name: G enerate checksums (Windows)
175+
if: runner.os == 'Windows'
176+
shell: pwsh
177+
run: |
178+
Get-ChildItem -File "QTradingView-*" | ForEach-Object {
179+
Get-FileHash $_.FullName -Algorithm SHA256 |
180+
ForEach-Object { $_.Hash | Out-File ($_.Path + ".sha256") -Encoding ascii }
181+
}
182+
183+
- name: Generate checksums (Linux/macOS)
184+
if: runner.os != 'Windows'
185+
run: |
186+
cd ${{ github.workspace }}/build
187+
find . -maxdepth 1 -name "QTradingView-*" -type f -exec sh -c 'sha256sum "$1" > "$1.sha256"' _ {} \;
188+
189+
190+
- name: Upload checksums
191+
# if: startsWith(github.ref, 'refs/tags/')
192+
uses: actions/upload-artifact@v4
193+
with:
194+
name: ${{ matrix.artifact_prefix }}-checksums
195+
path: ${{ github.workspace }}/build/*.sha256
196+
retention-days: 30
197+
198+
release:
199+
needs: build
200+
runs-on: ubuntu-latest
201+
# if: startsWith(github.ref, 'refs/tags/')
202+
name: Create Release
203+
204+
steps:
205+
- name: Checkout code
206+
uses: actions/checkout@v4
207+
208+
- name: Download all artifacts
209+
uses: actions/download-artifact@v4
210+
with:
211+
path: artifacts
212+
213+
- name: Create Release
214+
uses: softprops/action-gh-release@v1
215+
with:
216+
draft: false
217+
prerelease: false
218+
generate_release_notes: true
219+
files: artifacts/**/*
220+
env:
221+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
222+
223+
test:
224+
strategy:
225+
matrix:
226+
os: [ubuntu-latest, windows-latest, macos-latest]
227+
runs-on: ${{ matrix.os }}
228+
name: Test on ${{ matrix.os }}
229+
230+
steps:
231+
- name: Checkout code
232+
uses: actions/checkout@v4
233+
234+
- name: Install Qt (Windows)
235+
if: runner.os == 'Windows'
236+
uses: jurplel/install-qt-action@v4
237+
with:
238+
version: ${{ env.QT_VERSION }}
239+
modules: 'qtbase qtgui qtwidgets'
240+
241+
- name: Install Qt (macOS)
242+
if: runner.os == 'macOS'
243+
uses: jurplel/install-qt-action@v4
244+
with:
245+
version: ${{ env.QT_VERSION }}
246+
modules: 'qtbase qtgui qtwidgets'
247+
248+
- name: Install Qt (Linux)
249+
if: runner.os == 'Linux'
250+
run: |
251+
sudo apt-get update
252+
sudo apt-get install -y qt6-base-dev
253+
254+
- name: Install dependencies
255+
if: runner.os != 'Windows'
256+
run: |
257+
if [ "$RUNNER_OS" == "macOS" ]; then
258+
brew install cmake ninja
259+
else
260+
sudo apt-get install -y cmake ninja-build
261+
fi
262+
263+
- name: Install dependencies (Windows)
264+
if: runner.os == 'Windows'
265+
run: |
266+
choco install cmake ninja nsis -y
267+
268+
- name: Configure and build
269+
run: |
270+
cmake -B build -DBUILD_EXAMPLES=ON
271+
cmake --build build
272+
273+
- name: Run tests
274+
run: |
275+
cd build
276+
ctest --output-on-failure || true

CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ set(CMAKE_AUTORCC ON)
2828
set(CMAKE_CXX_STANDARD 17)
2929
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3030

31+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
32+
set(CMAKE_SKIP_RPATH OFF)
33+
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
34+
set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
35+
36+
# For Windows DLL exports
37+
if(WIN32)
38+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
39+
endif()
40+
41+
# Add version information
42+
configure_file(
43+
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in"
44+
"${CMAKE_CURRENT_BINARY_DIR}/include/QTradingView/version.h"
45+
)
46+
3147
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui Widgets)
3248
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets)
3349

@@ -90,9 +106,15 @@ endif()
90106

91107
add_library(QTradingView::QTradingView ALIAS QTradingView)
92108

109+
# Pass C++ standard macro for MSVC
110+
if(MSVC)
111+
target_compile_options(QTradingView PRIVATE /Zc:__cplusplus)
112+
endif()
113+
93114
target_include_directories(QTradingView
94115
PUBLIC
95116
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
117+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
96118
$<INSTALL_INTERFACE:include>
97119
)
98120

@@ -105,6 +127,12 @@ set_target_properties(QTradingView PROPERTIES
105127
SOVERSION 1
106128
)
107129

130+
131+
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
132+
if(NOT isMultiConfig)
133+
set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "" FORCE)
134+
endif()
135+
108136
# Installation rules
109137
include(GNUInstallDirs)
110138
install(TARGETS QTradingView
@@ -147,6 +175,9 @@ install(FILES
147175
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/QTradingView
148176
)
149177

178+
# Packaging
179+
include(cmake/cpack.cmake)
180+
150181
# Build examples (optional)
151182
option(BUILD_EXAMPLES "Build example applications" ON)
152183
if(BUILD_EXAMPLES)

0 commit comments

Comments
 (0)