Skip to content

Commit e07473b

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

File tree

5 files changed

+467
-0
lines changed

5 files changed

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