2 Copyright (c) Microsoft Open Technologies, Inc.
7 Redistribution and use in source and binary forms, with or without modification, are permitted provided that
8 the following conditions are met:
10 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
13 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14 following disclaimer in the documentation and/or other materials provided with the distribution.
16 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
17 promote products derived from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
22 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
31 [parameter(Mandatory=$False)]
35 [parameter(Mandatory=$False)]
39 [parameter(Mandatory=$False)]
44 [parameter(Mandatory=$False)]
49 [parameter(Mandatory=$False)]
52 $ARCHITECTURES_IN = "x86",
54 [parameter(Mandatory=$False)]
58 [parameter(Mandatory=$False)]
61 [ValidateSet("Visual Studio 15 2017","Visual Studio 14 2015","Visual Studio 12 2013","Visual Studio 11 2012")]
62 $GENERATOR = "Visual Studio 15 2017",
64 [parameter(Mandatory=$False)]
72 [parameter(Mandatory=$true)]
78 Write-Host "INFO> $str"
83 [parameter(Mandatory=$true)]
89 # Use this trigger to toggle debug output
93 Write-Host "DEBUG> $str"
97 function Get-Batchfile ($file) {
98 $cmd = "`"$file`" & set"
99 cmd /c $cmd | Foreach-Object {
100 $p, $v = $_.split('=')
101 Set-Item -path env:$p -value $v
105 # Enables access to Visual Studio variables via "vsvars32.bat"
109 $vs12comntools = (Get-ChildItem env:VS120COMNTOOLS).Value
110 $batchFile = [System.IO.Path]::Combine($vs12comntools, "vsvars32.bat")
111 Get-Batchfile $BatchFile
112 [System.Console]::Title = "Visual Studio 2010 Windows PowerShell"
114 $ErrorMessage = $_.Exception.Message
115 L "Error: $ErrorMessage"
121 # Executes msbuild to build or install projects
122 # Throws Exception on error
123 function Call-MSBuild($path, $config)
125 $command = "msbuild $path /p:Configuration='$config' /m"
126 L "Executing: $($command)"
127 msbuild $path /p:Configuration="$config" /m
130 Throw "Failure executing command: $($command)"
136 function RunAccuracyTests($path) {
137 md "$path\bin\Release\accuracy"
138 python "$PSScriptRoot\..\..\modules\ts\misc\run.py" -w "$path\bin\Release\accuracy" -a "$path\bin\Release"
141 function RunPerfTests($path) {
142 md "$path\bin\Release\perf"
143 python "$PSScriptRoot\..\..\modules\ts\misc\run.py" -w "$path\bin\Release\perf" "$path\bin\Release"
147 If ($HELP.IsPresent) {
151 # Validating arguments.
152 # This type of validation (rather than using ValidateSet()) is required to make .bat wrapper work
154 D "Input Platforms: $PLATFORMS_IN"
155 $platforms = New-Object System.Collections.ArrayList
156 $PLATFORMS_IN.Split("," ,[System.StringSplitOptions]::RemoveEmptyEntries) | ForEach {
158 if ("WP","WS" -Contains $_) {
159 [void]$platforms.Add($_)
162 Throw "$($_) is not valid! Please use WP, WS"
165 D "Processed Platforms: $platforms"
167 D "Input Versions: $VERSIONS_IN"
168 $versions = New-Object System.Collections.ArrayList
169 $VERSIONS_IN.Split("," ,[System.StringSplitOptions]::RemoveEmptyEntries) | ForEach {
171 if ("8.0","8.1","10.0" -Contains $_) {
172 [void]$versions.Add($_)
175 Throw "$($_) is not valid! Please use 8.0, 8.1, 10.0"
178 D "Processed Versions: $versions"
180 D "Input Architectures: $ARCHITECTURES_IN"
181 $architectures = New-Object System.Collections.ArrayList
182 $ARCHITECTURES_IN.Split("," ,[System.StringSplitOptions]::RemoveEmptyEntries) | ForEach {
184 if ("x86","x64","ARM" -Contains $_) {
185 $architectures.Add($_) > $null
188 Throw "$($_) is not valid! Please use x86, x64, ARM"
192 D "Processed Architectures: $architectures"
194 # Assuming we are in '<ocv-sources>/platforms/winrt' we should move up to sources root directory
199 $def_architectures = @{
205 # Setting up Visual Studio variables to enable build
207 If ($BUILD.IsPresent) {
208 $shouldBuild = Set-VS12
211 foreach($plat in $platforms) {
212 # Set proper platform name.
215 "WP" { $platName = "WindowsPhone" }
216 "WS" { $platName = "WindowsStore" }
219 foreach($vers in $versions) {
221 foreach($arch in $architectures) {
223 # Set proper architecture. For MSVS this is done by selecting proper generator
224 $genName = $GENERATOR
226 "ARM" { $genName = $GENERATOR + $def_architectures['arm'] }
227 "x64" { $genName = $GENERATOR + $def_architectures['x64'] }
230 # Constructing path to the install binaries
231 # Creating these binaries will be done by building CMake-generated INSTALL project from Visual Studio
232 $installPath = "$SRC\bin\install\$plat\$vers\$arch"
234 # Do not add architrecture to the path since it will be added by OCV CMake logic
235 $installPath = "$SRC\$INSTALL\$plat\$vers"
238 $path = "$SRC\bin\$plat\$vers\$arch"
240 L "-----------------------------------------------"
242 L " Directory: $path"
243 L " Platform: $platName"
245 L " Architecture: $arch"
246 L " Generator: $genName"
247 L " Install Directory: $installPath"
249 # Delete target directory if exists to ensure that CMake cache is cleared out.
250 If (Test-Path $path) {
251 Remove-Item -Recurse -Force $path
254 # Validate if required directory exists, create if it doesn't
255 New-Item -ItemType Directory -Force -Path $path
257 # Change location to the respective subdirectory
258 Push-Location -Path $path
260 L "Generating project:"
261 L "cmake -G $genName -DCMAKE_SYSTEM_NAME:String=$platName -DCMAKE_SYSTEM_VERSION:String=$vers -DCMAKE_VS_EFFECTIVE_PLATFORMS:String=$arch -DCMAKE_INSTALL_PREFIX:PATH=$installPath $SRC"
262 cmake -G $genName -DCMAKE_SYSTEM_NAME:String=$platName -DCMAKE_SYSTEM_VERSION:String=$vers -DCMAKE_VS_EFFECTIVE_PLATFORMS:String=$arch -DCMAKE_INSTALL_PREFIX:PATH=$installPath $SRC
263 L "-----------------------------------------------"
266 # Executed from '$SRC/bin' folder.
267 # Targeting x86 WindowsPhone 8.1.
268 # cmake -G "Visual Studio 12 2013" -DCMAKE_SYSTEM_NAME:String=WindowsPhone -DCMAKE_SYSTEM_VERSION:String=8.1 ..
271 # Building and installing project
274 L "Building and installing project:"
276 Call-MSBuild "OpenCV.sln" "Debug"
277 Call-MSBuild "INSTALL.vcxproj" "Debug"
279 Call-MSBuild "OpenCV.sln" "Release"
280 Call-MSBuild "INSTALL.vcxproj" "Release"
283 # Running tests for release versions:
284 If ($TESTS -eq "ALL") {
285 RunAccuracyTests "$path"
288 If($TESTS -eq "ACC") {
289 RunAccuracyTests "$path"
291 If($TESTS -eq "PERF") {
296 $ErrorMessage = $_.Exception.Message
297 L "Error: $ErrorMessage"
302 $ErrorMessage = $_.Exception.Message
303 L "Error: $ErrorMessage"
305 # Exiting at this point will leave command line pointing at the erroneous configuration directory
309 # Return back to Sources folder
315 # Return back to Script folder
319 Function ShowHelp() {
320 Write-Host "Configures OpenCV and generates projects for specified version of Visual Studio/platforms/architectures."
321 Write-Host "Must be executed from the sources folder containing main CMakeLists configuration."
322 Write-Host "Parameter keys can be shortened down to a single symbol (e.g. '-a') and are not case sensitive."
323 Write-Host "Proper parameter sequencing is required when omitting keys."
324 Write-Host "Generates the following folder structure, depending on the supplied parameters: "
329 Write-Host " |-WinRT "
330 Write-Host " | |-8.0 "
331 Write-Host " | |-8.1 "
332 Write-Host " | | |-x86 "
333 Write-Host " | | |-x64 "
334 Write-Host " | | |-ARM "
336 Write-Host " USAGE: "
337 Write-Host " Calling:"
338 Write-Host " PS> setup_winrt.ps1 [params]"
339 Write-Host " cmd> setup_winrt.bat [params]"
340 Write-Host " cmd> PowerShell.exe -ExecutionPolicy Unrestricted -File setup_winrt.ps1 [params]"
341 Write-Host " Parameters:"
342 Write-Host " setup_winrt [options] [platform] [version] [architecture] [tests] [generator] [install-path]"
343 Write-Host " setup_winrt -b 'WP' 'x86,ARM' "
344 Write-Host " setup_winrt -b 'WP' 'x86,ARM' ALL"
345 Write-Host " setup_winrt -b 'WP' 'x86,ARM' -test PERF "
346 Write-Host " setup_winrt -architecture x86 -platform WP "
347 Write-Host " setup_winrt -arc x86 -plat 'WP,WS' "
348 Write-Host " setup_winrt -a x86 -g 'Visual Studio 15 2017' -pl WP "
349 Write-Host " WHERE: "
350 Write-Host " options - Options to call "
351 Write-Host " -h: displays command line help "
352 Write-Host " -b: builds BUILD_ALL and INSTALL projects for each generated configuration in both Debug and Release modes."
353 Write-Host " platform - Array of target platforms. "
354 Write-Host " Default: WP "
355 Write-Host " Example: 'WS,WP' "
356 Write-Host " Options: WP, WS ('WindowsPhone', 'WindowsStore'). "
357 Write-Host " Note that you'll need to use quotes to specify more than one platform. "
358 Write-Host " version - Array of platform versions. "
359 Write-Host " Default: 8.1 "
360 Write-Host " Example: '8.0,8.1' "
361 Write-Host " Options: 8.0, 8.1, 10.0. Available options may be limited depending on your local setup (e.g. SDK availability). "
362 Write-Host " Note that you'll need to use quotes to specify more than one version. "
363 Write-Host " architecture - Array of target architectures to build for. "
364 Write-Host " Default: x86 "
365 Write-Host " Example: 'ARM,x64' "
366 Write-Host " Options: x86, ARM, x64. Available options may be limited depending on your local setup. "
367 Write-Host " Note that you'll need to use quotes to specify more than one architecture. "
368 Write-Host " tests - Test sets to run. Requires -b option otherwise ignored. "
369 Write-Host " Default: None. "
370 Write-Host " Example: 'ALL' "
371 Write-Host " Options: ACC, PERF, ALL. "
372 Write-Host " generator - Visual Studio instance used to generate the projects. "
373 Write-Host " Default: Visual Studio 12 2013 "
374 Write-Host " Example: 'Visual Studio 11 2012' "
375 Write-Host " Use 'cmake --help' to find all available option on your machine. "
376 Write-Host " install-path - Path to install binaries (relative to the sources directory). "
377 Write-Host " Default: <src-dir>\bin\install\<platform>\<version>\<architecture> "
378 Write-Host " Example: '../install' "