Skip to content

Commit 1de96db

Browse files
committed
Add CmakeUserPreset template and easy build script
1 parent 6e85d7f commit 1de96db

File tree

3 files changed

+310
-1
lines changed

3 files changed

+310
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ deploy/*
4444
.*cache/
4545

4646
# User defined CMake preset file.
47-
CMakeUserPresets.json
47+
/CMakeUserPresets.json
4848

4949
#Configurations created under config for testing
5050
/configs

bin/scripts/build.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python3
2+
import platform
3+
import subprocess
4+
import sys
5+
import argparse
6+
import multiprocessing
7+
import shutil
8+
import os
9+
10+
# Argument parser
11+
parser = argparse.ArgumentParser(description="Qt CMake Preset Runner")
12+
parser.add_argument("--qt5", action="store_true", help="Use Qt5 (default is Qt6)")
13+
parser.add_argument("-r", action="store_true", help="Use release build (default is debug)")
14+
parser.add_argument("variant", nargs="?", default="all", choices=["all", "light", "minimum"], help="Build variant (all, light, minimum)")
15+
parser.add_argument("--preset", action="store_true", help="Run cmake with --preset")
16+
parser.add_argument("--build", action="store_true", help="Run cmake --build build --parallel <n>")
17+
parser.add_argument("--full", action="store_true", help="Run cmake preset + build (requires --clean)")
18+
parser.add_argument("--clean", action="store_true", help="Delete build directory before configuration")
19+
parser.add_argument("-n", type=int, help="Number of CPUs for parallel build")
20+
21+
args = parser.parse_args()
22+
23+
# Require at least one action
24+
if not (args.preset or args.build or args.full):
25+
print("❌ You must specify at least one of: --preset, --build, or --full")
26+
parser.print_help()
27+
sys.exit(1)
28+
29+
# Automatically enable --clean if --full or --preset is passed without it
30+
if (args.full or args.preset) and not args.clean:
31+
print("ℹ️ --full or --preset implies --clean. Cleaning build directory...")
32+
args.clean = True
33+
34+
# Build path and parallelism
35+
build_dir = "build"
36+
parallel = args.n if args.n else multiprocessing.cpu_count()
37+
38+
# If only --build is given
39+
if args.build and not args.full:
40+
print(f"▶ Running cmake --build {build_dir} --parallel {parallel}")
41+
try:
42+
subprocess.run(["cmake", "--build", build_dir, "--parallel", str(parallel)], check=True)
43+
except subprocess.CalledProcessError as e:
44+
print(f"❌ Build failed: {e}")
45+
sys.exit(e.returncode)
46+
sys.exit(0)
47+
48+
# Configure preset name
49+
qt_version = "qt5" if args.qt5 else "qt6"
50+
build_type = "release" if args.r else "debug"
51+
variant = args.variant.lower()
52+
53+
system = platform.system()
54+
if system == "Windows":
55+
suffix = "-windows"
56+
elif system == "Linux":
57+
suffix = "-linux"
58+
else:
59+
print(f"❌ Unsupported platform: {system}")
60+
sys.exit(1)
61+
62+
preset_name = f"{build_type}-{qt_version}-{variant}{suffix}"
63+
64+
# Handle --clean (used by --preset or --full)
65+
if args.clean:
66+
if os.path.exists(build_dir):
67+
print(f"🧹 Deleting build directory: {build_dir}")
68+
shutil.rmtree(build_dir)
69+
70+
# Run cmake --preset (with --fresh if cleaned)
71+
if args.preset or args.full:
72+
cmake_cmd = ["cmake", "--preset", preset_name]
73+
if args.clean:
74+
cmake_cmd.append("--fresh")
75+
76+
print(f"▶ Running {' '.join(cmake_cmd)}")
77+
try:
78+
subprocess.run(cmake_cmd, check=True)
79+
except subprocess.CalledProcessError as e:
80+
print(f"❌ CMake configure failed: {e}")
81+
sys.exit(e.returncode)
82+
83+
# Follow-up build if --full
84+
if args.full:
85+
print(f"▶ Running cmake --build {build_dir} --parallel {parallel}")
86+
try:
87+
subprocess.run(["cmake", "--build", build_dir, "--parallel", str(parallel)], check=True)
88+
except subprocess.CalledProcessError as e:
89+
print(f"❌ Build failed: {e}")
90+
sys.exit(e.returncode)
91+
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
{
2+
"version": 9,
3+
"configurePresets": [
4+
{
5+
"name": "env-common",
6+
"hidden": true,
7+
"cacheVariables": {
8+
}
9+
},
10+
{
11+
"name": "env-windows",
12+
"hidden": true,
13+
"inherits": [ "env-common" ],
14+
"condition": {
15+
"type": "equals",
16+
"lhs": "${hostSystemName}",
17+
"rhs": "Windows"
18+
},
19+
"environment": {
20+
"WIN_DEV_ROOT_DIR": "D:/development",
21+
"WIN_QT_ROOT_DIR": "$env{WIN_DEV_ROOT_DIR}/Qt",
22+
"WIN_PYTHON_ROOT_DIR": "$env{WIN_DEV_ROOT_DIR}/python",
23+
"WIN_TURBO_JPEG_ROOT_DIR": "$env{WIN_DEV_ROOT_DIR}/libjpeg-turbo64",
24+
"OPENSSL_ROOT_DIR": "$env{WIN_QT_ROOT_DIR}/Tools/OpenSSLv3/Win_x64"
25+
},
26+
"cacheVariables": {
27+
"TurboJPEG_INCLUDE_DIR": "$env{WIN_TURBO_JPEG_ROOT_DIR}/include",
28+
"TurboJPEG_LIBRARY": "$env{WIN_TURBO_JPEG_ROOT_DIR}/lib/turbojpeg.lib",
29+
"ENABLE_DX": "OFF"
30+
}
31+
},
32+
{
33+
"name": "qt5-env-windows",
34+
"hidden": true,
35+
"inherits": [ "env-windows" ],
36+
"condition": {
37+
"type": "equals",
38+
"lhs": "${hostSystemName}",
39+
"rhs": "Windows"
40+
},
41+
"cacheVariables": {
42+
"Python3_EXECUTABLE": "$env{WIN_PYTHON_ROOT_DIR}/Python312/python.exe"
43+
},
44+
"environment": {
45+
"QTDIR": "$env{WIN_QT_ROOT_DIR}/5.15.2/msvc2019_64/"
46+
}
47+
},
48+
{
49+
"name": "qt6-env-windows",
50+
"hidden": true,
51+
"inherits": [ "env-windows" ],
52+
"cacheVariables": {
53+
"Python3_EXECUTABLE": "$env{WIN_PYTHON_ROOT_DIR}/Python313/python.exe"
54+
},
55+
"environment": {
56+
"QTDIR": "$env{WIN_QT_ROOT_DIR}/6.8.1/msvc2022_64/"
57+
}
58+
},
59+
60+
{
61+
"name": "env-linux",
62+
"hidden": true,
63+
"inherits": [ "env-common" ],
64+
"condition": {
65+
"type": "equals",
66+
"lhs": "${hostSystemName}",
67+
"rhs": "Linux"
68+
},
69+
"cacheVariables": {
70+
},
71+
"environment": {
72+
"LINUX_QT_ROOT_DIR": "$env{HOME}/Qt",
73+
}
74+
},
75+
{
76+
"name": "qt5-env-linux",
77+
"hidden": true,
78+
"inherits": [ "env-linux" ],
79+
"condition": {
80+
"type": "equals",
81+
"lhs": "${hostSystemName}",
82+
"rhs": "Linux"
83+
},
84+
"cacheVariables": {
85+
},
86+
"environment": {
87+
}
88+
},
89+
{
90+
"name": "qt6-env-linux",
91+
"hidden": true,
92+
"inherits": [ "env-linux" ],
93+
"condition": {
94+
"type": "equals",
95+
"lhs": "${hostSystemName}",
96+
"rhs": "Linux"
97+
},
98+
"cacheVariables": {
99+
},
100+
"environment": {
101+
"QTDIR": "$env{LINUX_QT_ROOT_DIR}/6.9.0/gcc_64"
102+
}
103+
},
104+
{
105+
"name": "qt5-env-windows-wrapper",
106+
"hidden": true,
107+
"condition": {
108+
"type": "equals",
109+
"lhs": "${hostSystemName}",
110+
"rhs": "Windows"
111+
},
112+
"inherits": [ "qt5-env-windows" ],
113+
"binaryDir": "${sourceDir}/build"
114+
},
115+
116+
{
117+
"name": "qt5-env-linux-wrapper",
118+
"hidden": true,
119+
"condition": {
120+
"type": "equals",
121+
"lhs": "${hostSystemName}",
122+
"rhs": "Linux"
123+
},
124+
"inherits": [ "qt5-env-linux" ],
125+
"binaryDir": "${sourceDir}/build"
126+
},
127+
128+
{
129+
"name": "qt6-env-windows-wrapper",
130+
"hidden": true,
131+
"condition": {
132+
"type": "equals",
133+
"lhs": "${hostSystemName}",
134+
"rhs": "Windows"
135+
},
136+
"inherits": [ "qt6-env-windows" ],
137+
"binaryDir": "${sourceDir}/build"
138+
},
139+
{
140+
"name": "qt6-env-linux-wrapper",
141+
"hidden": true,
142+
"condition": {
143+
"type": "equals",
144+
"lhs": "${hostSystemName}",
145+
"rhs": "Linux"
146+
},
147+
"inherits": [ "qt6-env-linux" ],
148+
"binaryDir": "${sourceDir}/build"
149+
},
150+
{
151+
"name": "debug-qt5-all-windows",
152+
"inherits": [ "debug", "qt5-env-windows-wrapper" ],
153+
"hidden": false
154+
},
155+
{
156+
"name": "debug-qt5-light",
157+
"inherits": [ "debug", "qt5-env-windows-wrapper", "hyperion-light" ]
158+
},
159+
{
160+
"name": "debug-qt5-minimum",
161+
"inherits": [ "debug", "qt5-env-windows-wrapper", "hyperion-bare-minimum" ]
162+
},
163+
{
164+
"name": "release-qt5-all",
165+
"inherits": [ "release", "qt5-env-windows-wrapper" ]
166+
},
167+
{
168+
"name": "debug-qt5-all-linux",
169+
"inherits": [ "debug", "qt5-env-linux-wrapper" ],
170+
"hidden": false
171+
},
172+
{
173+
"name": "debug-qt5-light-linux",
174+
"inherits": [ "debug", "qt5-env-linux-wrapper", "hyperion-light" ]
175+
},
176+
{
177+
"name": "debug-qt5-minimum-linux",
178+
"inherits": [ "debug", "qt5-env-linux-wrapper", "hyperion-bare-minimum" ]
179+
},
180+
{
181+
"name": "release-qt5-all-linux",
182+
"inherits": [ "release", "qt5-env-linux-wrapper" ]
183+
},
184+
{
185+
"name": "debug-qt6-all-windows",
186+
"inherits": [ "debug", "qt6-env-windows-wrapper" ]
187+
},
188+
{
189+
"name": "debug-qt6-light-windows",
190+
"inherits": [ "debug", "qt6-env-windows-wrapper", "hyperion-light" ]
191+
},
192+
{
193+
"name": "debug-qt6-minimum-windows",
194+
"inherits": [ "debug", "qt6-env-windows-wrapper", "hyperion-bare-minimum" ]
195+
},
196+
{
197+
"name": "release-qt6-all-windows",
198+
"inherits": [ "release", "qt6-env-windows-wrapper" ]
199+
},
200+
{
201+
"name": "debug-qt6-all-linux",
202+
"inherits": [ "debug", "qt6-env-linux-wrapper" ]
203+
},
204+
{
205+
"name": "debug-qt6-light-linux",
206+
"inherits": [ "debug", "qt6-env-linux-wrapper", "hyperion-light" ]
207+
},
208+
{
209+
"name": "debug-qt6-minimum-linux",
210+
"inherits": [ "debug", "qt6-env-linux-wrapper", "hyperion-bare-minimum" ]
211+
},
212+
{
213+
"name": "release-qt6-all-linux",
214+
"inherits": [ "release", "qt6-env-linux-wrapper" ]
215+
}
216+
]
217+
}
218+

0 commit comments

Comments
 (0)