@@ -64,15 +64,15 @@ function New-CMakeConfig($name, [string]$buildConfiguration, [hashtable]$buildIn
64
64
. PARAMETER buildInfo
65
65
Hashtable containing the standard build information.
66
66
67
- . PARAMETER cmakrSrcRoot
67
+ . PARAMETER cmakeSrcRoot
68
68
Root of the CMAKE source files to build
69
69
#>
70
70
# start with an empty hash table and build up from there...
71
71
$self = @ {}
72
72
if ($IsWindows )
73
73
{
74
- # TODO: Convert this to use NIJA for faster builds... [Maybe]
75
- $self [' Generator' ] = ' Visual Studio 17 2022 '
74
+ # $self['Generator'] = 'Visual Studio 17 2022'
75
+ $self [' Generator' ] = ' Ninja '
76
76
}
77
77
else
78
78
{
@@ -87,27 +87,35 @@ function New-CMakeConfig($name, [string]$buildConfiguration, [hashtable]$buildIn
87
87
$self [' CMakeCommandArgs' ] = [System.Collections.ArrayList ]@ ()
88
88
$self [' BuildCommandArgs' ] = [System.Collections.ArrayList ]@ ()
89
89
$self [' InheritEnvironments' ] = [System.Collections.ArrayList ]@ ()
90
+ $self [' CMakeBuildVariables' ] = @ {}
90
91
91
- if ($IsWindows )
92
+ # single config generator; Requires setting the configuration type
93
+ # as a build var during generation (Otherwise, debug is assumed...)
94
+ if ($self [' Generator' ] -ieq ' Ninja' )
92
95
{
93
- # running on ARM64 is not tested or supported
94
- # This might not be needed now that the build is auto configuring the "VCVARS"
95
- # Ninja build might also remove the need for this...
96
- if ([System.Runtime.InteropServices.RuntimeInformation ]::ProcessArchitecture -eq " X64" )
97
- {
98
- $self [' CMakeCommandArgs' ].Add(' -Thost=x64' ) | Out-Null
99
- $self [' InheritEnvironments' ].Add(' msvc_x64_x64' ) | Out-Null
100
- }
101
- else
102
- {
103
- $self [' InheritEnvironments' ].Add(' msvc_x64' ) | Out-Null
104
- }
105
-
106
- # pass the /m switch to MSBUILD to enable parallel builds on all available CPU cores
107
- $self [' BuildCommandArgs' ].Add(' /m' ) | Out-Null
96
+ $self [' CMakeBuildVariables' ][' CMAKE_BUILD_TYPE' ]= $self [' ConfigurationType' ]
108
97
}
109
98
110
- $self [' CMakeBuildVariables' ] = @ {}
99
+ # Not needed with Ninja builds
100
+ # if($IsWindows)
101
+ # {
102
+ # # running on ARM64 is not tested or supported
103
+ # # This might not be needed now that the build is auto configuring the "VCVARS"
104
+ # # Ninja build might also remove the need for this...
105
+ # if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq "X64" )
106
+ # {
107
+ # $self['CMakeCommandArgs'].Add('-Thost=x64') | Out-Null
108
+ # $self['InheritEnvironments'].Add('msvc_x64_x64') | Out-Null
109
+ # }
110
+ # else
111
+ # {
112
+ # $self['InheritEnvironments'].Add('msvc_x64') | Out-Null
113
+ # }
114
+ #
115
+ # # pass the /m switch to MSBUILD to enable parallel builds on all available CPU cores
116
+ # $self['BuildCommandArgs'].Add('/m') | Out-Null
117
+ # }
118
+
111
119
Assert-IsCMakeConfig $self
112
120
return $self
113
121
}
@@ -125,7 +133,8 @@ function Invoke-GenerateCMakeConfig([hashtable]$self, [hashtable] $additionalBui
125
133
126
134
# Construct full set of CMAKE args from fixed options and configuration variables
127
135
$cmakeArgs = New-Object System.Collections.ArrayList
128
- $cmakeArgs.Add (" -G $ ( $self [' Generator' ]) " ) | Out-Null
136
+ $cmakeArgs.AddRange (@ (' -G' , " $ ( $self [' Generator' ]) " ) ) | Out-Null
137
+ $cmakeArgs.AddRange (@ (' -B' , " $ ( $self [' BuildRoot' ]) " ) ) | Out-Null
129
138
foreach ( $param in $self [' CMakeCommandArgs' ] )
130
139
{
131
140
$cmakeArgs.Add ( $param ) | Out-Null
@@ -154,21 +163,10 @@ function Invoke-GenerateCMakeConfig([hashtable]$self, [hashtable] $additionalBui
154
163
155
164
$cmakeArgs.Add ( $self [' SrcRoot' ] ) | Out-Null
156
165
Invoke-TimedBlock " CMAKE Generate" {
157
- Push-Location $self [' BuildRoot' ]
158
- try
159
- {
160
- Write-Information " cmake $cmakeArgs "
161
- # Splat the array of args as distinct for external invoke
162
- Invoke-External cmake @cmakeArgs
163
- }
164
- catch
165
- {
166
- throw
167
- }
168
- finally
169
- {
170
- Pop-Location
171
- }
166
+ Write-Information " cmake $ ( $cmakeArgs -join ' ' ) "
167
+
168
+ # Splat the array of args as distinct elements for external invoke
169
+ Invoke-External cmake @cmakeArgs
172
170
}
173
171
}
174
172
@@ -177,14 +175,25 @@ function Invoke-GenerateCMakeConfig([hashtable]$self, [hashtable] $additionalBui
177
175
# see: https://github.com/PowerShell/PowerShell/issues/13637
178
176
New-Alias - Name Generate- CMakeConfig - Value Invoke-GenerateCMakeConfig
179
177
180
- function Build-CmakeConfig ([hashtable ]$self )
178
+ function Build-CmakeConfig ([hashtable ]$self , $targets )
181
179
{
182
180
Assert-IsCMakeConfig $self
181
+ $cmakeArgs = [System.Collections.ArrayList ]@ (' --build' , " $ ( $self [' BuildRoot' ]) " , ' --config' , " $ ( $self [' ConfigurationType' ]) " )
182
+ if ($targets )
183
+ {
184
+ $cmakeArgs.Add (' -t' ) | Out-Null
185
+ $cmakeArgs.AddRange ($targets )
186
+ }
187
+
188
+ if ($self [' BuildCommandArgs' ].Length -gt 0 )
189
+ {
190
+ $cmakeArgs.AddRange ( @ (' --' , " $ ( $self [' BuildCommandArgs' ]) " ) )
191
+ }
192
+
183
193
Invoke-TimedBlock " CMake Building $ ( $self [' Name' ]) " {
184
- $cmakeArgs = @ (' --build' , " $ ( $self [' BuildRoot' ]) " , ' --config' , " $ ( $self [' ConfigurationType' ]) " , ' --' , " $ ( $self [' BuildCommandArgs' ]) " )
185
- Write-Information " cmake $ ( [string ]::Join(' ' , $cmakeArgs )) "
194
+ Write-Information " cmake $ ( $cmakeArgs -join ' ' ) "
186
195
187
- # Splat the array of args as distinct for external invoke
196
+ # Splat the array of args as distinct items for external invoke
188
197
Invoke-External cmake @cmakeArgs
189
198
}
190
199
}
0 commit comments