@@ -10,6 +10,15 @@ Param(
10
10
' The argument "{0}" does not match the "{1}" pattern.' )]
11
11
[string ] $QtVersion ,
12
12
13
+ [Parameter (Position = 1 ,
14
+ HelpMessage = ' Specifies the MySQL Server version against which to build ' +
15
+ ' the QMYSQL driver (version number of the MySQL Server installation folder).' )]
16
+ [ValidateNotNullOrEmpty ()]
17
+ [ValidatePattern (' ^[8-12]\.\d{1,2}\$' ,
18
+ ErrorMessage = ' The argument "{0}" is not the correct Qt version number. ' +
19
+ ' The argument "{0}" does not match the "{1}" pattern.' )]
20
+ [string ] $MySQLVersion = ' 8.2' ,
21
+
13
22
[Parameter (HelpMessage = ' Clean CMake build (delete the $QtVersion build folder).' )]
14
23
[switch ] $CleanBuild
15
24
)
@@ -23,7 +32,8 @@ Set-Variable STACK_NAME -Option Constant -Value $MyInvocation.MyCommand.Name
23
32
$Script :QtMajorVersion = $null
24
33
$Script :QtEnvVersion = $null
25
34
$Script :VisualStudioVersion = ' 17.0'
26
- $Script :MySqlServerPath = ' C:/Program Files/MySQL/MySQL Server 8.1'
35
+ $Script :MySqlServerPath = " C:/Program Files/MySQL/MySQL Server $MySQLVersion "
36
+ $Script :BOL = ' '
27
37
28
38
# Functions section
29
39
# ---
@@ -34,7 +44,7 @@ function Initialize-QtVersions
34
44
{
35
45
# Extract major and minor versions from the passed $QtVersion
36
46
if (-not ($QtVersion -match ' ^(?<major>[5-8])\.(?<minor>\d{1,2})\.\d{1,2}$' )) {
37
- throw ' Match for the '' $QtEnvVersion'' variable failed.'
47
+ Write-ExitError ' Match for the '' $QtEnvVersion'' variable failed.' - NoNewlineBefore
38
48
}
39
49
40
50
$Script :QtMajorVersion = $Matches [' major' ]
@@ -44,38 +54,52 @@ function Initialize-QtVersions
44
54
# Check if the Qt version is >5
45
55
function Test-QtVersion
46
56
{
47
- Write-Host ' Testing if the Qt version is >5' - ForegroundColor DarkYellow
57
+ Write-Progress ' Testing if the Qt version is >5'
48
58
49
59
if ($Script :QtMajorVersion -gt 5 ) {
50
60
return
51
61
}
52
62
53
- throw " The passed '$QtVersion ' is not supported because it doesn't support the CMake build."
63
+ Write-ExitError (" The passed Qt version '$QtVersion ' is not supported because it doesn't " +
64
+ ' support the CMake build.' )
54
65
}
55
66
56
67
# Check whether the passed QtVersion is installed
57
68
function Test-QtVersionInstalled
58
69
{
59
- Write-Host " Testing whether Qt $QtVersion is installed" - ForegroundColor DarkYellow
70
+ Write-Progress " Testing whether Qt $QtVersion is installed"
60
71
61
72
if (Test-Path " C:\Qt\$QtVersion " ) {
62
73
return
63
74
}
64
75
65
- throw " The passed '$QtVersion ' version is not installed in the 'C:\Qt\$QtVersion \' folder."
76
+ Write-ExitError (" The passed Qt version '$QtVersion ' is not installed " +
77
+ " in the 'C:\Qt\$QtVersion \' folder." )
66
78
}
67
79
68
80
# Check whether the source files to build the Qt MySQL plugin are installed
69
81
function Test-QtSourcesInstalled {
70
- Write-Host " Testing whether Qt $QtVersion source files are installed" `
71
- - ForegroundColor DarkYellow
82
+ Write-Progress " Testing whether Qt $QtVersion source files are installed"
72
83
73
84
if (Test-Path " C:\Qt\$QtVersion \Src\qtbase\src\plugins\sqldrivers" ) {
74
85
return
75
86
}
76
87
77
- throw " Source files to build the Qt MySQL plugin for the passed '$QtVersion ' version are not " +
78
- " installed in the 'C:\Qt\$QtVersion \Src\qtbase\src\plugins\sqldrivers' folder."
88
+ Write-ExitError (" Source files to build the Qt MySQL plugin for the passed " +
89
+ " Qt version '$QtVersion ' are not installed " +
90
+ " in the 'C:\Qt\$QtVersion \Src\qtbase\src\plugins\sqldrivers' folder." )
91
+ }
92
+
93
+ # Check whether the MySQL Server is installed
94
+ function Test-MySQLServerInstalled
95
+ {
96
+ Write-Progress " Testing whether MySQL Server is installed"
97
+
98
+ if (Test-Path $Script :MySqlServerPath ) {
99
+ return
100
+ }
101
+
102
+ Write-ExitError " The MySQL Server is not installed in the '$Script :MySqlServerPath ' folder."
79
103
}
80
104
81
105
# Remove $QtVersion build folder if the $CleanBuild was passed
@@ -85,53 +109,52 @@ function Invoke-CleanBuild
85
109
return
86
110
}
87
111
88
- Write-Host " Removing $QtVersion build folder (Clean build)" - ForegroundColor DarkYellow
112
+ Write-Progress " Removing $QtVersion build folder (Clean build)"
89
113
90
- Remove-Item - Force - Recurse " $QtVersion "
114
+ Remove-Item - Force - Recurse " ./ $QtVersion " - ErrorAction SilentlyContinue
91
115
}
92
116
93
117
# Create the build folders for debug and release builds
94
118
function New-BuildFolders
95
119
{
96
- Write-Host ' Creating build folders' - ForegroundColor DarkYellow
120
+ Write-Progress ' Creating build folders'
97
121
98
- $created = $false
99
- $relWithDebInfoPath = " $QtVersion /msvc2019_64/RelWithDebInfo"
122
+ $relWithDebInfoPath = Join-Path - Path $PWD - ChildPath " ./$QtVersion /msvc2019_64/RelWithDebInfo"
100
123
101
124
if (-not (Test-Path $relWithDebInfoPath )) {
102
- mkdir - p $relWithDebInfoPath
103
- $created = $true
125
+ New-Item - Type Directory - Path $relWithDebInfoPath | Out-Null
126
+
127
+ Write-Progress " ${ Script:BOL } Created the Release folder at: $relWithDebInfoPath "
104
128
}
105
129
else {
106
- Write-Host " Release folder already exists ($relWithDebInfoPath )" - ForegroundColor DarkRed
130
+ Write-Error " $ { Script: BOL } Release folder already exists ($relWithDebInfoPath )"
107
131
}
108
132
109
- $debugPath = " $QtVersion /msvc2019_64/Debug"
133
+ $debugPath = Join-Path - Path $PWD - ChildPath " $QtVersion /msvc2019_64/Debug"
110
134
111
135
if (-not (Test-Path $debugPath )) {
112
- mkdir - p $debugPath
113
- $created = $true
136
+ New-Item - Type Directory - Path $debugPath | Out-Null
137
+
138
+ Write-Progress " ${ Script:BOL } Created the Debug folder at: $debugPath "
114
139
}
115
140
else {
116
- Write-Host " Debug folder already exists ($debugPath )" - ForegroundColor DarkRed
117
- }
118
-
119
- if ($created ) {
120
- NewLine
141
+ Write-Error " ${ Script:BOL } Debug folder already exists ($debugPath )"
121
142
}
122
143
}
123
144
124
145
# Test whether a Qt environment initialization was successful
125
146
function Test-BuildEnvironment
126
147
{
127
- Write-Host ' Testing whether the build environment is ready' - ForegroundColor DarkYellow
148
+ Newline
149
+ Write-Progress ' Testing whether the build environment is ready'
128
150
129
151
# Test MSVC build environment
130
152
if (-not (Test-Path env:VisualStudioVersion) -or `
131
153
$env: VisualStudioVersion -ne $Script :VisualStudioVersion
132
154
) {
133
155
$majorVersion = ($Script :VisualStudioVersion -split ' \.' , 2 )[0 ]
134
- throw " The Visual Studio '$majorVersion ' build environment is not on the system path."
156
+ Write-ExitError (" The Visual Studio '$majorVersion ' build environment is not " +
157
+ ' on the system path.' )
135
158
}
136
159
137
160
# Test Qt build environment
@@ -141,20 +164,21 @@ function Test-BuildEnvironment
141
164
# [System.Version] $qtVersion = (Get-Command qmake -ErrorAction SilentlyContinue).Version
142
165
143
166
if (-not $qtVersionOnPath -or $qtVersionOnPath -ne $QtVersion ) {
144
- throw " The requested Qt version '$QtVersion ' is not on the system path."
167
+ Write-ExitError ( " The requested Qt version '$QtVersion ' is not on the system path." )
145
168
}
146
169
147
- Write-Host ' Build environment is ready 🥳' - ForegroundColor DarkGreen
170
+ Write-Info ' Build environment is ready 🥳'
171
+ Newline
148
172
}
149
173
150
174
# Initialize the Qt and MSVC2022 build environment if it's not already there
151
175
function Initialize-QtEnvironment
152
176
{
153
- Write-Host ' Initializing Qt and MSVC2022 build environment' - ForegroundColor DarkYellow
177
+ Write-Progress ' Initializing Qt and MSVC2022 build environment'
154
178
155
179
if (Test-Path env:WindowsSDKLibVersion) {
156
- Write-Host (' The MSVC build environment already initialized. Exiting the Qt environment ' +
157
- ' initialization!' ) - ForegroundColor DarkRed
180
+ Write-Error (' The MSVC build environment already initialized. Exiting the Qt environment ' +
181
+ ' initialization!' )
158
182
159
183
return
160
184
}
@@ -176,7 +200,13 @@ Initialize-QtVersions
176
200
Test-QtVersion
177
201
Test-QtVersionInstalled
178
202
Test-QtSourcesInstalled
203
+ Test-MySQLServerInstalled
204
+
205
+ # Initialize the Qt and MSVC2022 build environment if it's not already there
206
+ Initialize-QtEnvironment
207
+ Test-BuildEnvironment
179
208
209
+ # Prepare the build folder
180
210
Push-Location - StackName $STACK_NAME
181
211
182
212
Set-Location " E:\c_libs\qt${ Script:QtMajorVersion } _sqldrivers"
@@ -186,18 +216,14 @@ Invoke-CleanBuild
186
216
# Create the build folders for debug and release builds
187
217
New-BuildFolders
188
218
189
- # Initialize the Qt and MSVC2022 build environment if it's not already there
190
- Initialize-QtEnvironment
191
- Test-BuildEnvironment
192
-
193
219
# Debug build
194
220
# ---
195
221
Write-Header ' Debug Build'
196
222
197
223
Set-Location " $QtVersion /msvc2019_64/Debug"
198
224
199
225
# Configure
200
- Write-Host ' Configuring...' - ForegroundColor DarkYellow
226
+ Write-Progress ' Configuring...'
201
227
202
228
qt- cmake `
203
229
- S " C:/Qt/$QtVersion /Src/qtbase/src/plugins/sqldrivers" `
@@ -214,7 +240,7 @@ qt-cmake `
214
240
NewLine
215
241
216
242
# Build and install
217
- Write-Host ' Building and installing...' - ForegroundColor DarkYellow
243
+ Write-Progress ' Building and installing...'
218
244
219
245
cmake -- build . -- target install
220
246
@@ -224,7 +250,7 @@ Write-Header 'Release Build'
224
250
225
251
Set-Location ' ../RelWithDebInfo'
226
252
227
- Write-Host ' Configuring...' - ForegroundColor DarkYellow
253
+ Write-Progress ' Configuring...'
228
254
229
255
qt- cmake `
230
256
- S " C:/Qt/$QtVersion /Src/qtbase/src/plugins/sqldrivers" `
@@ -241,13 +267,15 @@ qt-cmake `
241
267
NewLine
242
268
243
269
# Build and install
244
- Write-Host ' Building and installing...' - ForegroundColor DarkYellow
270
+ Write-Progress ' Building and installing...'
245
271
246
272
cmake -- build . -- target install
247
273
248
274
# Done
249
275
# ---
250
276
Pop-Location - StackName $STACK_NAME
251
277
252
- Write-Host " The QMYSQL driver for Qt $QtVersion was built and installed successfully. 🥳" `
253
- - ForegroundColor DarkGreen
278
+ Write-Progress " Linked against the MySQL Server at: $Script :MySqlServerPath "
279
+
280
+ Newline
281
+ Write-Info " The QMYSQL driver for Qt $QtVersion was built and installed successfully. 🥳"
0 commit comments