Skip to content

Commit 317381c

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

File tree

6 files changed

+454
-5
lines changed

6 files changed

+454
-5
lines changed
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
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 ZIP
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: ls -la ${{ github.workspace }}/build/
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: Upload checksums
175+
# if: startsWith(github.ref, 'refs/tags/')
176+
uses: actions/upload-artifact@v4
177+
with:
178+
name: ${{ matrix.artifact_prefix }}-checksums
179+
path: ${{ github.workspace }}/build/*.sha256
180+
retention-days: 30
181+
182+
release:
183+
needs: build
184+
runs-on: ubuntu-latest
185+
# if: startsWith(github.ref, 'refs/tags/')
186+
name: Create Release
187+
188+
steps:
189+
- name: Checkout code
190+
uses: actions/checkout@v4
191+
192+
- name: Download all artifacts
193+
uses: actions/download-artifact@v4
194+
with:
195+
path: artifacts
196+
197+
- name: Create Release
198+
uses: softprops/action-gh-release@v1
199+
with:
200+
draft: false
201+
prerelease: false
202+
generate_release_notes: true
203+
files: artifacts/**/*
204+
env:
205+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
206+
207+
test:
208+
strategy:
209+
matrix:
210+
os: [ubuntu-latest, windows-latest, macos-latest]
211+
runs-on: ${{ matrix.os }}
212+
name: Test on ${{ matrix.os }}
213+
214+
steps:
215+
- name: Checkout code
216+
uses: actions/checkout@v4
217+
218+
- name: Install Qt (Windows)
219+
if: runner.os == 'Windows'
220+
uses: jurplel/install-qt-action@v4
221+
with:
222+
version: ${{ env.QT_VERSION }}
223+
modules: 'qtbase qtgui qtwidgets'
224+
225+
- name: Install Qt (macOS)
226+
if: runner.os == 'macOS'
227+
uses: jurplel/install-qt-action@v4
228+
with:
229+
version: ${{ env.QT_VERSION }}
230+
modules: 'qtbase qtgui qtwidgets'
231+
232+
- name: Install Qt (Linux)
233+
if: runner.os == 'Linux'
234+
run: |
235+
sudo apt-get update
236+
sudo apt-get install -y qt6-base-dev
237+
238+
- name: Install dependencies
239+
if: runner.os != 'Windows'
240+
run: |
241+
if [ "$RUNNER_OS" == "macOS" ]; then
242+
brew install cmake ninja
243+
else
244+
sudo apt-get install -y cmake ninja-build
245+
fi
246+
247+
- name: Install dependencies (Windows)
248+
if: runner.os == 'Windows'
249+
run: |
250+
choco install cmake ninja
251+
252+
- name: Configure and build
253+
run: |
254+
cmake -B build -DBUILD_EXAMPLES=ON
255+
cmake --build build
256+
257+
- name: Run tests
258+
run: |
259+
cd build
260+
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)