forked from AlexeyAB/darknet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
executable file
·1096 lines (972 loc) · 40.4 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env pwsh
<#
.SYNOPSIS
build
Created By: Stefano Sinigardi
Created Date: February 18, 2019
Last Modified Date: August 10, 2023
.DESCRIPTION
Build tool using CMake, trying to properly setup the environment around compiler
.PARAMETER DisableInteractive
Disable script interactivity (useful for CI runs)
.PARAMETER BuildDebug
Build using the debug toolchain
.PARAMETER DisableDLLcopy
Disable automatic DLL deployment through vcpkg at the end
.PARAMETER EnableCUDA
Enable CUDA feature
.PARAMETER EnableCUDNN
Enable CUDNN feature
.PARAMETER EnableOPENCV
Enable OpenCV feature
.PARAMETER ForceOpenCVVersion
Force a specific OpenCV version
.PARAMETER EnableOPENCV_CUDA
Use a CUDA-enabled OpenCV build
.PARAMETER UseVCPKG
Use vcpkg to build tool dependencies. Clone it if not already found on system
.PARAMETER ForceLocalVCPKG
Use a copy of vcpkg in a subfolder of the tool folder, even if there might be another copy already provided by the system
.PARAMETER InstallDARKNETthroughVCPKG
Use VCPKG to install darknet thanks to the port integrated in it
.PARAMETER InstallDARKNETdependenciesThroughVCPKGManifest
Use VCPKG to install darknet dependencies using vcpkg manifest feature
.PARAMETER ForceVCPKGDarknetHEAD
Install darknet from vcpkg and force it to HEAD version, not latest port release
.PARAMETER DoNotUpdateVCPKG
Do not update vcpkg before running the build (valid only if vcpkg is cloned by this script or the version found on the system is git-enabled)
.PARAMETER VCPKGSuffix
Specify a suffix to the vcpkg local folder for searching, useful to point to a custom version
.PARAMETER VCPKGFork
Specify a fork username to point to a custom version of vcpkg (ex: -VCPKGFork "custom" to point to github.com/custom/vcpkg)
.PARAMETER VCPKGBranch
Specify a branch to checkout in the vcpkg folder, useful to point to a custom version especially for forked vcpkg versions
.PARAMETER DoNotUpdateTOOL
Do not update the tool before running the build (valid only if tool is git-enabled)
.PARAMETER DoNotDeleteBuildFolder
Do not delete temporary cmake build folder at the end of the script
.PARAMETER DoNotSetupVS
Do not setup VisualStudio environment using the vcvars script
.PARAMETER DoNotUseNinja
Do not use Ninja for build
.PARAMETER ForceCPP
Force building darknet using C++ compiler also for plain C code
.PARAMETER ForceStaticLib
Create library as static instead of the default linking mode of your system
.PARAMETER ForceVCPKGCacheRemoval
Force clean up of the local vcpkg binary cache before building
.PARAMETER ForceVCPKGBuildtreesRemoval
Force clean up of vcpkg buildtrees temp folder at the end of the script
.PARAMETER ForceVCPKGBuildtreesPath
Force using a different buildtrees dir for vcpkg
.PARAMETER ForceVCPKGPackagesRemoval
Force clean up of vcpkg packages folder at the end of the script
.PARAMETER ForceSetupVS
Forces Visual Studio setup, also on systems on which it would not have been enabled automatically
.PARAMETER ForceCMakeFromVS
Forces usage of CMake from Visual Studio instead of the system-wide/user installed one
.PARAMETER ForceNinjaFromVS
Forces usage of Ninja from Visual Studio instead of the system-wide/user installed one
.PARAMETER EnableCSharpWrapper
Enables building C# darknet wrapper
.PARAMETER DownloadWeights
Download pre-trained weight files
.PARAMETER Use32bitTriplet
Use 32 bit triplet for target build (windows-only)
.PARAMETER ForceGCCVersion
Force a specific GCC version
.PARAMETER NumberOfBuildWorkers
Forces a specific number of threads for parallel building
.PARAMETER AdditionalBuildSetup
Additional setup parameters to manually pass to CMake
.EXAMPLE
./build -DisableInteractive -DoNotDeleteBuildFolder -UseVCPKG
#>
<#
Copyright (c) Stefano Sinigardi
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>
param (
[switch]$DisableInteractive = $false,
[switch]$BuildDebug = $false,
[switch]$DisableDLLcopy = $false,
[switch]$EnableCUDA = $false,
[switch]$EnableCUDNN = $false,
[switch]$EnableOPENCV = $false,
[Int32]$ForceOpenCVVersion = 0,
[switch]$EnableOPENCV_CUDA = $false,
[switch]$UseVCPKG = $false,
[switch]$ForceLocalVCPKG = $false,
[switch]$InstallDARKNETthroughVCPKG = $false,
[switch]$InstallDARKNETdependenciesThroughVCPKGManifest = $false,
[switch]$ForceVCPKGDarknetHEAD = $false,
[switch]$DoNotUpdateVCPKG = $false,
[string]$VCPKGSuffix = "",
[string]$VCPKGFork = "",
[string]$VCPKGBranch = "",
[switch]$DoNotUpdateTOOL = $false,
[switch]$DoNotDeleteBuildFolder = $false,
[switch]$DoNotSetupVS = $false,
[switch]$DoNotUseNinja = $false,
[switch]$ForceCPP = $false,
[switch]$ForceStaticLib = $false,
[switch]$ForceVCPKGCacheRemoval = $false,
[switch]$ForceVCPKGBuildtreesRemoval = $false,
[string]$ForceVCPKGBuildtreesPath = "",
[switch]$ForceVCPKGPackagesRemoval = $false,
[switch]$ForceSetupVS = $false,
[switch]$ForceCMakeFromVS = $false,
[switch]$ForceNinjaFromVS = $false,
[switch]$EnableCSharpWrapper = $false,
[switch]$DownloadWeights = $false,
[switch]$Use32bitTriplet = $false,
[Int32]$ForceGCCVersion = 0,
[Int32]$NumberOfBuildWorkers = 8,
[string]$AdditionalBuildSetup = "" # "-DCMAKE_CUDA_ARCHITECTURES=30"
)
$global:DisableInteractive = $DisableInteractive
$build_ps1_version = "3.4.1"
$script_name = $MyInvocation.MyCommand.Name
Import-Module -Name $PSScriptRoot/scripts/utils.psm1 -Force
$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
if($IsInGitSubmodule) {
$PSCustomScriptRoot = Split-Path $PSScriptRoot -Parent
}
else {
$PSCustomScriptRoot = $PSScriptRoot
}
$BuildLogPath = "$PSCustomScriptRoot/build.log"
$ReleaseInstallPrefix = "$PSCustomScriptRoot"
$DebugInstallPrefix = "$PSCustomScriptRoot/debug"
$DebugBuildSetup = " -DCMAKE_INSTALL_PREFIX=$DebugInstallPrefix -DCMAKE_BUILD_TYPE=Debug"
$ReleaseBuildSetup = " -DCMAKE_INSTALL_PREFIX=$ReleaseInstallPrefix -DCMAKE_BUILD_TYPE=Release"
Start-Transcript -Path $BuildLogPath
Write-Host "Build script version ${build_ps1_version}, utils module version ${utils_psm1_version}"
Write-Host "Working directory: $PSCustomScriptRoot, log file: $BuildLogPath, $script_name is in submodule: $IsInGitSubmodule"
if ((-Not $global:DisableInteractive) -and (-Not $UseVCPKG)) {
$Result = Read-Host "Enable vcpkg to install dependencies (yes/no)"
if (($Result -eq 'Yes') -or ($Result -eq 'Y') -or ($Result -eq 'yes') -or ($Result -eq 'y')) {
$UseVCPKG = $true
}
}
if ((-Not $DisableInteractive) -and (-Not $EnableCUDA) -and (-Not $IsMacOS)) {
$Result = Read-Host "Enable CUDA integration (yes/no)"
if (($Result -eq 'Yes') -or ($Result -eq 'Y') -or ($Result -eq 'yes') -or ($Result -eq 'y')) {
$EnableCUDA = $true
}
}
if ($EnableCUDA -and (-Not $DisableInteractive) -and (-Not $EnableCUDNN)) {
$Result = Read-Host "Enable CUDNN optional dependency (yes/no)"
if (($Result -eq 'Yes') -or ($Result -eq 'Y') -or ($Result -eq 'yes') -or ($Result -eq 'y')) {
$EnableCUDNN = $true
}
}
if ((-Not $DisableInteractive) -and (-Not $EnableOPENCV)) {
$Result = Read-Host "Enable OpenCV optional dependency (yes/no)"
if (($Result -eq 'Yes') -or ($Result -eq 'Y') -or ($Result -eq 'yes') -or ($Result -eq 'y')) {
$EnableOPENCV = $true
}
}
Write-Host -NoNewLine "PowerShell version:"
$PSVersionTable.PSVersion
if ($IsWindowsPowerShell) {
Write-Host "Running on Windows Powershell, please consider update and running on newer Powershell versions"
}
if ($PSVersionTable.PSVersion.Major -lt 5) {
MyThrow("Your PowerShell version is too old, please update it.")
}
if ($IsLinux -or $IsMacOS) {
$bootstrap_ext = ".sh"
$exe_ext = ""
}
elseif ($IsWindows -or $IsWindowsPowerShell) {
$bootstrap_ext = ".bat"
$exe_ext = ".exe"
}
if ($ForceLocalVCPKG -And -Not $UseVCPKG) {
$UseVCPKG = $true
Write-Host "ForceLocalVCPKG was true but UseVCPKG was false, setting UseVCPKG to true"
}
if ($InstallDARKNETdependenciesThroughVCPKGManifest -and -not $InstallDARKNETthroughVCPKG) {
Write-Host "You requested darknet dependencies to be installed by vcpkg in manifest mode but you didn't enable installation through vcpkg, doing that for you"
$InstallDARKNETthroughVCPKG = $true
}
if ($InstallDARKNETthroughVCPKG -and -not $UseVCPKG) {
Write-Host "You requested darknet to be installed by vcpkg but you didn't enable vcpkg, doing that for you"
$UseVCPKG = $true
}
if ($InstallDARKNETthroughVCPKG -and -not $EnableOPENCV) {
Write-Host "You requested darknet to be installed by vcpkg but you didn't enable OpenCV, doing that for you"
$EnableOPENCV = $true
}
if ($UseVCPKG) {
Write-Host "vcpkg bootstrap script: bootstrap-vcpkg${bootstrap_ext}"
}
if ((-Not $IsWindows) -and (-Not $IsWindowsPowerShell) -and (-Not $ForceSetupVS)) {
$DoNotSetupVS = $true
}
if ($ForceStaticLib) {
Write-Host "Forced CMake to produce a static library"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DBUILD_SHARED_LIBS=OFF "
}
if (($IsLinux -or $IsMacOS) -and ($ForceGCCVersion -gt 0)) {
Write-Host "Manually setting CC and CXX variables to gcc version $ForceGCCVersion"
$env:CC = "gcc-$ForceGCCVersion"
$env:CXX = "g++-$ForceGCCVersion"
}
$vcpkg_triplet_set_by_this_script = $false
$vcpkg_host_triplet_set_by_this_script = $false
if (($IsWindows -or $IsWindowsPowerShell) -and (-Not $env:VCPKG_DEFAULT_TRIPLET)) {
if ($Use32bitTriplet) {
if (-Not $BuildDebug) {
$BuildDebug = $true
Write-Host "Warning: when building for 32bit windows target, only builds with also debug version are possible. Debug has been enabled on your behalf!" -ForegroundColor Yellow
}
if (-Not $DoNotUseNinja) {
$DoNotUseNinja = $true
Write-Host "Warning: when building for 32bit windows target, only msbuild can be used and ninja will be disabled. Doing that for you!" -ForegroundColor Yellow
}
$env:VCPKG_DEFAULT_TRIPLET = "x86-windows"
$vcpkg_triplet_set_by_this_script = $true
}
else {
if($BuildDebug) {
$env:VCPKG_DEFAULT_TRIPLET = "x64-windows"
$vcpkg_triplet_set_by_this_script = $true
}
else {
$env:VCPKG_DEFAULT_TRIPLET = "x64-windows-release"
$vcpkg_triplet_set_by_this_script = $true
}
}
}
if (($IsWindows -or $IsWindowsPowerShell) -and (-Not $env:VCPKG_DEFAULT_HOST_TRIPLET)) {
if ($BuildDebug) {
$env:VCPKG_DEFAULT_HOST_TRIPLET = "x64-windows"
$vcpkg_host_triplet_set_by_this_script = $true
}
else {
$env:VCPKG_DEFAULT_HOST_TRIPLET = "x64-windows-release"
$vcpkg_host_triplet_set_by_this_script = $true
}
}
if ($IsMacOS -and (-Not $env:VCPKG_DEFAULT_TRIPLET)) {
if ($BuildDebug) {
$env:VCPKG_DEFAULT_TRIPLET = "x64-osx"
$vcpkg_triplet_set_by_this_script = $true
}
else {
$env:VCPKG_DEFAULT_TRIPLET = "x64-osx-release"
$vcpkg_triplet_set_by_this_script = $true
}
}
if ($IsMacOS -and (-Not $env:VCPKG_DEFAULT_HOST_TRIPLET)) {
if ($BuildDebug) {
$env:VCPKG_DEFAULT_HOST_TRIPLET = "x64-osx"
$vcpkg_host_triplet_set_by_this_script = $true
}
else {
$env:VCPKG_DEFAULT_HOST_TRIPLET = "x64-osx-release"
$vcpkg_host_triplet_set_by_this_script = $true
}
}
if ($IsLinux -and (-Not $env:VCPKG_DEFAULT_TRIPLET)) {
if ($true) {
if ($BuildDebug) {
$env:VCPKG_DEFAULT_TRIPLET = "x64-linux"
$vcpkg_triplet_set_by_this_script = $true
}
else {
$env:VCPKG_DEFAULT_TRIPLET = "x64-linux-release"
$vcpkg_triplet_set_by_this_script = $true
}
}
}
if ($IsLinux -and (-Not $env:VCPKG_DEFAULT_HOST_TRIPLET)) {
if ($BuildDebug) {
$env:VCPKG_DEFAULT_HOST_TRIPLET = "x64-linux"
$vcpkg_host_triplet_set_by_this_script = $true
}
else {
$env:VCPKG_DEFAULT_HOST_TRIPLET = "x64-linux-release"
$vcpkg_host_triplet_set_by_this_script = $true
}
}
if ($VCPKGSuffix -ne "" -and -not $UseVCPKG) {
Write-Host "You specified a vcpkg folder suffix but didn't enable vcpkg integration, doing that for you" -ForegroundColor Yellow
$UseVCPKG = $true
}
if ($VCPKGFork -ne "" -and -not $UseVCPKG) {
Write-Host "You specified a vcpkg fork but didn't enable vcpkg integration, doing that for you" -ForegroundColor Yellow
$UseVCPKG = $true
}
if ($VCPKGBranch -ne "" -and -not $UseVCPKG) {
Write-Host "You specified a vcpkg branch but didn't enable vcpkg integration, doing that for you" -ForegroundColor Yellow
$UseVCPKG = $true
}
if ($EnableCUDA) {
if ($IsMacOS) {
Write-Host "Cannot enable CUDA on macOS" -ForegroundColor Yellow
$EnableCUDA = $false
}
Write-Host "CUDA is enabled"
}
elseif (-Not $IsMacOS) {
Write-Host "CUDA is disabled, please pass -EnableCUDA to the script to enable"
}
if ($EnableCUDNN) {
if ($IsMacOS) {
Write-Host "Cannot enable CUDNN on macOS" -ForegroundColor Yellow
$EnableCUDNN = $false
}
Write-Host "CUDNN is enabled"
}
elseif (-Not $IsMacOS) {
Write-Host "CUDNN is disabled, please pass -EnableCUDNN to the script to enable"
}
if ($EnableOPENCV) {
Write-Host "OPENCV is enabled"
}
else {
Write-Host "OPENCV is disabled, please pass -EnableOPENCV to the script to enable"
}
if ($EnableCUDA -and $EnableOPENCV -and (-Not $EnableOPENCV_CUDA)) {
Write-Host "OPENCV with CUDA extension is not enabled, you can enable it passing -EnableOPENCV_CUDA"
}
elseif ($EnableOPENCV -and $EnableOPENCV_CUDA -and (-Not $EnableCUDA)) {
Write-Host "OPENCV with CUDA extension was requested, but CUDA is not enabled, you can enable it passing -EnableCUDA"
$EnableOPENCV_CUDA = $false
}
elseif ($EnableCUDA -and $EnableOPENCV_CUDA -and (-Not $EnableOPENCV)) {
Write-Host "OPENCV with CUDA extension was requested, but OPENCV is not enabled, you can enable it passing -EnableOPENCV"
$EnableOPENCV_CUDA = $false
}
elseif ($EnableOPENCV_CUDA -and (-Not $EnableCUDA) -and (-Not $EnableOPENCV)) {
Write-Host "OPENCV with CUDA extension was requested, but OPENCV and CUDA are not enabled, you can enable them passing -EnableOPENCV -EnableCUDA"
$EnableOPENCV_CUDA = $false
}
if ($UseVCPKG) {
Write-Host "VCPKG is enabled"
if ($BuildDebug -and ($env:VCPKG_DEFAULT_TRIPLET -match "release")) {
MyThrow("You asked to build also debug binaries but VCPKG_DEFAULT_TRIPLET is set to a release triplet")
}
if ($DoNotUpdateVCPKG) {
Write-Host "VCPKG will not be updated to latest version if found" -ForegroundColor Yellow
}
else {
Write-Host "VCPKG will be updated to latest version if found"
}
}
else {
Write-Host "VCPKG is disabled, please pass -UseVCPKG to the script to enable"
}
if ($DoNotSetupVS) {
Write-Host "VisualStudio integration is disabled"
}
else {
Write-Host "VisualStudio integration is enabled, please pass -DoNotSetupVS to the script to disable"
}
if ($EnableCSharpWrapper -and ($IsWindowsPowerShell -or $IsWindows)) {
Write-Host "Yolo C# wrapper integration is enabled. Will be built with Visual Studio generator. Disabling Ninja"
$DoNotUseNinja = $true
}
else {
$EnableCSharpWrapper = $false
Write-Host "Yolo C# wrapper integration is disabled, please pass -EnableCSharpWrapper to the script to enable. You must be on Windows!"
}
if ($DoNotUseNinja) {
Write-Host "Ninja is disabled"
}
else {
Write-Host "Ninja is enabled, please pass -DoNotUseNinja to the script to disable"
}
if ($ForceCPP) {
Write-Host "ForceCPP build mode is enabled"
}
else {
Write-Host "ForceCPP build mode is disabled, please pass -ForceCPP to the script to enable"
}
Push-Location $PSCustomScriptRoot
$GIT_EXE = Get-Command "git" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $GIT_EXE) {
MyThrow("Could not find git, please install it")
}
else {
Write-Host "Using git from ${GIT_EXE}"
}
$GitRepoPath = Resolve-Path "$PSCustomScriptRoot/.git" -ErrorAction SilentlyContinue
$GitModulesPath = Resolve-Path "$PSCustomScriptRoot/.gitmodules" -ErrorAction SilentlyContinue
if (Test-Path "$GitRepoPath") {
Write-Host "This tool has been cloned with git and supports self-updating mechanism"
if ($DoNotUpdateTOOL) {
Write-Host "This tool will not self-update sources" -ForegroundColor Yellow
}
else {
Write-Host "This tool will self-update sources, please pass -DoNotUpdateTOOL to the script to disable"
Set-Location "$PSCustomScriptRoot"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $GIT_EXE -ArgumentList "pull"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Updating this tool sources failed! Exited with error code $exitCode.")
}
if (Test-Path "$GitModulesPath") {
$proc = Start-Process -NoNewWindow -PassThru -FilePath $GIT_EXE -ArgumentList "submodule update --init --recursive"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Updating this tool submodule sources failed! Exited with error code $exitCode.")
}
}
Set-Location "$PSCustomScriptRoot"
}
}
if ($ForceCmakeFromVS) {
$vsfound = getLatestVisualStudioWithDesktopWorkloadPath
$cmakePath = "${vsfound}/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin"
$vsCmakePath = "${vsfound}/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe"
$CMAKE_EXE = Get-Command "cmake" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if ((Test-Path "$vsCmakePath") -and -not ($vsCmakePath -eq $CMAKE_EXE)) {
Write-Host "Adding CMake from Visual Studio to PATH"
$env:PATH = '{0}{1}{2}' -f "$cmakePath", [IO.Path]::PathSeparator, $env:PATH
}
elseif ($vsCmakePath -eq $CMAKE_EXE) {
Write-Host "CMake from Visual Studio was already the preferred choice" -ForegroundColor Yellow
}
else {
Write-Host "Unable to find CMake integrated in Visual Studio" -ForegroundColor Red
}
}
$CMAKE_EXE = Get-Command "cmake" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $CMAKE_EXE) {
MyThrow("Could not find CMake, please install it")
}
else {
Write-Host "Using CMake from ${CMAKE_EXE}"
$proc = Start-Process -NoNewWindow -PassThru -FilePath ${CMAKE_EXE} -ArgumentList "--version"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("CMake version check failed! Exited with error code $exitCode.")
}
}
if (-Not $DoNotUseNinja) {
if ($ForceNinjaFromVS) {
$vsfound = getLatestVisualStudioWithDesktopWorkloadPath
$ninjaPath = "${vsfound}/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja"
$vsninjaPath = "${vsfound}/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe"
$NINJA_EXE = Get-Command "ninja" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if ((Test-Path "$vsninjaPath") -and -not ($vsninjaPath -eq $NINJA_EXE) -and (-not $DoNotUseNinja)) {
Write-Host "Adding Ninja from Visual Studio to PATH"
$env:PATH = '{0}{1}{2}' -f "$ninjaPath", [IO.Path]::PathSeparator, $env:PATH
}
elseif ($vsninjaPath -eq $NINJA_EXE) {
Write-Host "Ninja from Visual Studio was already the preferred choice" -ForegroundColor Yellow
}
else {
Write-Host "Unable to find Ninja integrated in Visual Studio" -ForegroundColor Red
}
}
$NINJA_EXE = Get-Command "ninja" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $NINJA_EXE) {
DownloadNinja
$NinjaPath = Join-Path (${PSCustomScriptRoot}) 'ninja'
$env:PATH = '{0}{1}{2}' -f $env:PATH, [IO.Path]::PathSeparator, "$NinjaPath"
$NINJA_EXE = Get-Command "ninja" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $NINJA_EXE) {
$DoNotUseNinja = $true
Write-Host "Could not find Ninja, unable to download a portable ninja, using msbuild or make backends as a fallback" -ForegroundColor Yellow
}
}
if ($NINJA_EXE) {
Write-Host "Using Ninja from ${NINJA_EXE}"
Write-Host -NoNewLine "Ninja version "
$proc = Start-Process -NoNewWindow -PassThru -FilePath ${NINJA_EXE} -ArgumentList "--version"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
$DoNotUseNinja = $true
Write-Host "Unable to run Ninja previously found, using msbuild or make backends as a fallback" -ForegroundColor Yellow
}
else {
$generator = "Ninja"
}
}
}
if (-Not $DoNotSetupVS) {
$CL_EXE = Get-Command "cl" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if ((-Not $CL_EXE) -or ($CL_EXE -match "HostX86\\x86") -or ($CL_EXE -match "HostX64\\x86")) {
$vsfound = getLatestVisualStudioWithDesktopWorkloadPath
Write-Host "Found VS in ${vsfound}"
Push-Location "${vsfound}/Common7/Tools"
cmd.exe /c "VsDevCmd.bat -arch=x64 & set" |
ForEach-Object {
if ($_ -match "=") {
$v = $_.split("="); Set-Item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
Pop-Location
Write-Host "Visual Studio Command Prompt variables set"
}
$tokens = getLatestVisualStudioWithDesktopWorkloadVersion
$tokens = $tokens.split('.')
if ($DoNotUseNinja) {
$debugConfig = " --config Debug "
$releaseConfig = " --config Release "
if ($Use32bitTriplet) {
$targetArchitecture = "`"Win32`""
}
else {
$targetArchitecture = "`"x64`""
}
if ($tokens[0] -eq "14") {
$generator = "Visual Studio 14 2015"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -T `"host=x64`" -A $targetArchitecture"
}
elseif ($tokens[0] -eq "15") {
$generator = "Visual Studio 15 2017"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -T `"host=x64`" -A $targetArchitecture"
}
elseif ($tokens[0] -eq "16") {
$generator = "Visual Studio 16 2019"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -T `"host=x64`" -A $targetArchitecture"
}
elseif ($tokens[0] -eq "17") {
$generator = "Visual Studio 17 2022"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -T `"host=x64`" -A $targetArchitecture"
}
else {
MyThrow("Unknown Visual Studio version, unsupported configuration")
}
}
if (-Not $UseVCPKG) {
$dllfolder = "../3rdparty/pthreads/bin"
}
}
if ($DoNotSetupVS -and $DoNotUseNinja) {
$generator = "Unix Makefiles"
}
Write-Host "Setting up environment to use CMake generator: $generator"
if (-Not $IsMacOS -and $EnableCUDA) {
$NVCC_EXE = Get-Command "nvcc" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $NVCC_EXE) {
if (Test-Path env:CUDA_PATH) {
$env:PATH = '{0}{1}{2}' -f $env:PATH, [IO.Path]::PathSeparator, "${env:CUDA_PATH}/bin"
Write-Host "Found cuda in ${env:CUDA_PATH}"
}
else {
Write-Host "Unable to find CUDA, if necessary please install it or define a CUDA_PATH env variable pointing to the install folder" -ForegroundColor Yellow
}
}
if (Test-Path env:CUDA_PATH) {
if (-Not(Test-Path env:CUDA_TOOLKIT_ROOT_DIR)) {
$env:CUDA_TOOLKIT_ROOT_DIR = "${env:CUDA_PATH}"
Write-Host "Added missing env variable CUDA_TOOLKIT_ROOT_DIR" -ForegroundColor Yellow
}
if (-Not(Test-Path env:CUDACXX)) {
$env:CUDACXX = "${env:CUDA_PATH}/bin/nvcc"
Write-Host "Added missing env variable CUDACXX" -ForegroundColor Yellow
}
}
}
$vcpkg_root_set_by_this_script = $false
if ($UseVCPKG -And -Not $ForceLocalVCPKG) {
if ((Test-Path env:VCPKG_ROOT) -and $VCPKGSuffix -eq "") {
$vcpkg_path = "$env:VCPKG_ROOT"
$vcpkg_path = Resolve-Path $vcpkg_path
Write-Host "Found vcpkg in VCPKG_ROOT: $vcpkg_path"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_VCPKG_INTEGRATION:BOOL=ON"
}
elseif (-not($null -eq ${env:WORKSPACE}) -and (Test-Path "${env:WORKSPACE}/vcpkg${VCPKGSuffix}")) {
$vcpkg_path = "${env:WORKSPACE}/vcpkg${VCPKGSuffix}"
$vcpkg_path = Resolve-Path $vcpkg_path
$env:VCPKG_ROOT = "$vcpkg_path"
$vcpkg_root_set_by_this_script = $true
Write-Host "Found vcpkg in WORKSPACE/vcpkg${VCPKGSuffix}: $vcpkg_path"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_VCPKG_INTEGRATION:BOOL=ON"
}
elseif (-not($null -eq ${RUNVCPKG_VCPKG_ROOT_OUT})) {
if ((Test-Path "${RUNVCPKG_VCPKG_ROOT_OUT}") -and $UseVCPKG) {
$vcpkg_path = "${RUNVCPKG_VCPKG_ROOT_OUT}"
$vcpkg_path = Resolve-Path $vcpkg_path
$env:VCPKG_ROOT = "$vcpkg_path"
$vcpkg_root_set_by_this_script = $true
Write-Host "Found vcpkg in RUNVCPKG_VCPKG_ROOT_OUT: $vcpkg_path"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_VCPKG_INTEGRATION:BOOL=ON"
}
}
}
if (($null -eq $vcpkg_path) -and $UseVCPKG) {
if (-Not (Test-Path "$PWD/vcpkg${VCPKGSuffix}")) {
$proc = Start-Process -NoNewWindow -PassThru -FilePath $GIT_EXE -ArgumentList "clone https://github.com/microsoft/vcpkg vcpkg${VCPKGSuffix}"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-not ($exitCode -eq 0)) {
MyThrow("Cloning vcpkg sources failed! Exited with error code $exitCode.")
}
}
$vcpkg_path = "$PWD/vcpkg${VCPKGSuffix}"
$vcpkg_path = Resolve-Path $vcpkg_path
$env:VCPKG_ROOT = "$vcpkg_path"
$vcpkg_root_set_by_this_script = $true
Write-Host "Found vcpkg in $PWD/vcpkg${VCPKGSuffix}: $vcpkg_path"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_VCPKG_INTEGRATION:BOOL=ON"
}
$vcpkg_branch_set_by_this_script = $false
if ($UseVCPKG -and (Test-Path "$vcpkg_path/.git")) {
Push-Location $vcpkg_path
if ($VCPKGFork -ne "") {
$vcpkgfork_already_setup = $false
$remotes = & $GIT_EXE 'remote'
ForEach ($remote in $remotes) {
if ($remote -eq "vcpkgfork") {
$vcpkgfork_already_setup = $true
Write-Host "remote vcpkgfork already setup"
}
}
if (-Not $vcpkgfork_already_setup) {
$git_args = "remote add vcpkgfork https://github.com/${VCPKGFork}/vcpkg"
Write-Host "setting up remote vcpkgfork"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $GIT_EXE -ArgumentList "$git_args"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Adding remote https://github.com/${VCPKGFork}/vcpkg failed! Exited with error code $exitCode.")
}
}
$git_args = "fetch vcpkgfork"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $GIT_EXE -ArgumentList "$git_args"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Fetching from remote https://github.com/${VCPKGFork}/vcpkg failed! Exited with error code $exitCode.")
}
}
if ($VCPKGBranch -ne "") {
if ($VCPKGFork -ne "") {
$git_args = "checkout vcpkgfork/$VCPKGBranch"
}
else {
$git_args = "checkout $VCPKGBranch"
}
$proc = Start-Process -NoNewWindow -PassThru -FilePath $GIT_EXE -ArgumentList "$git_args"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Checking out branch $VCPKGBranch failed! Exited with error code $exitCode.")
}
$vcpkg_branch_set_by_this_script = $true
}
if (-Not $DoNotUpdateVCPKG -and $VCPKGFork -eq "") {
$proc = Start-Process -NoNewWindow -PassThru -FilePath $GIT_EXE -ArgumentList "pull"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Updating vcpkg sources failed! Exited with error code $exitCode.")
}
$VcpkgBootstrapScript = Join-Path $PWD "bootstrap-vcpkg${bootstrap_ext}"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $VcpkgBootstrapScript -ArgumentList "-disableMetrics"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Bootstrapping vcpkg failed! Exited with error code $exitCode.")
}
}
Pop-Location
}
if ($UseVCPKG -and ($vcpkg_path.length -gt 40) -and ($IsWindows -or $IsWindowsPowerShell)) {
Write-Host "vcpkg path is very long and might fail. Please move it or" -ForegroundColor Yellow
Write-Host "the entire tool folder to a shorter path, like C:\src" -ForegroundColor Yellow
Write-Host "You can use the subst command to ease the process if necessary" -ForegroundColor Yellow
if (-Not $global:DisableInteractive) {
$Result = Read-Host "Do you still want to continue? (yes/no)"
if (($Result -eq 'No') -or ($Result -eq 'N') -or ($Result -eq 'no') -or ($Result -eq 'n')) {
MyThrow("Build aborted")
}
}
}
if ($ForceVCPKGCacheRemoval -and (-Not $UseVCPKG)) {
Write-Host "VCPKG is not enabled, so local vcpkg binary cache will not be deleted even if requested" -ForegroundColor Yellow
}
if (($ForceOpenCVVersion -eq 2) -and $UseVCPKG) {
Write-Host "You requested OpenCV version 2, so vcpkg will install that version" -ForegroundColor Yellow
Write-Host "This requires using vcpkg.json.opencv23 as manifest file" -ForegroundColor Yellow
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DVCPKG_USE_OPENCV4=OFF -DVCPKG_USE_OPENCV2=ON"
}
if (($ForceOpenCVVersion -eq 3) -and $UseVCPKG) {
Write-Host "You requested OpenCV version 3, so vcpkg will install that version" -ForegroundColor Yellow
Write-Host "This requires using vcpkg.json.opencv23 as manifest file" -ForegroundColor Yellow
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DVCPKG_USE_OPENCV4=OFF -DVCPKG_USE_OPENCV3=ON"
}
if($ForceOpenCVVersion -gt 0) {
Move-Item $PSCustomScriptRoot/vcpkg.json $PSCustomScriptRoot/vcpkg.json.bak
Move-Item $PSCustomScriptRoot/vcpkg.json.opencv23 $PSCustomScriptRoot/vcpkg.json
}
if ($UseVCPKG -and $ForceVCPKGCacheRemoval) {
if ($IsWindows -or $IsWindowsPowerShell) {
$vcpkgbinarycachepath = "$env:LOCALAPPDATA/vcpkg/archive"
}
elseif ($IsLinux) {
$vcpkgbinarycachepath = "$env:HOME/.cache/vcpkg/archive"
}
elseif ($IsMacOS) {
$vcpkgbinarycachepath = "$env:HOME/.cache/vcpkg/archive"
}
else {
MyThrow("Unknown OS, unsupported")
}
Write-Host "Removing local vcpkg binary cache from $vcpkgbinarycachepath" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $vcpkgbinarycachepath
}
if (-Not $DisableDLLcopy) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DX_VCPKG_APPLOCAL_DEPS_INSTALL=ON"
}
if ($ForceCPP) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DBUILD_AS_CPP:BOOL=ON"
}
if (-Not $EnableCUDA) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_CUDA:BOOL=OFF"
}
if (-Not $EnableCUDNN) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_CUDNN:BOOL=OFF"
}
if (-Not $EnableOPENCV) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_OPENCV:BOOL=OFF"
}
if (-Not $EnableOPENCV_CUDA) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DVCPKG_BUILD_OPENCV_WITH_CUDA:BOOL=OFF"
}
if ($EnableCSharpWrapper) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_CSHARP_WRAPPER:BOOL=ON"
}
if (-Not $InstallDARKNETthroughVCPKG) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_DEPLOY_CUSTOM_CMAKE_MODULES:BOOL=ON"
}
if ($InstallDARKNETthroughVCPKG) {
if ($ForceVCPKGDarknetHEAD) {
$headMode = " --head "
}
$features = "opencv-base"
$feature_manifest_opencv = "--x-feature=opencv-base"
if ($EnableCUDA) {
$features = $features + ",cuda"
$feature_manifest_cuda = "--x-feature=cuda"
}
if ($EnableCUDNN) {
$features = $features + ",cudnn"
$feature_manifest_cudnn = "--x-feature=cudnn"
}
if (-not (Test-Path "${env:VCPKG_ROOT}/vcpkg${exe_ext}")) {
$proc = Start-Process -NoNewWindow -PassThru -FilePath ${env:VCPKG_ROOT}/bootstrap-vcpkg${bootstrap_ext} -ArgumentList "-disableMetrics"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Bootstrapping vcpkg failed! Exited with error code $exitCode.")
}
}
if ($InstallDARKNETdependenciesThroughVCPKGManifest) {
Write-Host "Running vcpkg in manifest mode to install darknet dependencies"
Write-Host "vcpkg install --x-no-default-features $feature_manifest_opencv $feature_manifest_cuda $feature_manifest_cudnn $headMode"
$proc = Start-Process -NoNewWindow -PassThru -FilePath "${env:VCPKG_ROOT}/vcpkg${exe_ext}" -ArgumentList " install --x-no-default-features $feature_manifest_opencv $feature_manifest_cuda $feature_manifest_cudnn $headMode "
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Installing darknet through vcpkg failed! Exited with error code $exitCode.")
}
}
else {
Write-Host "Running vcpkg to install darknet"
Write-Host "vcpkg install darknet[${features}] $headMode --recurse"
Move-Item $PSCustomScriptRoot/vcpkg.json $PSCustomScriptRoot/vcpkg.json.bak
Push-Location ${env:VCPKG_ROOT}
if ($ForceVCPKGDarknetHEAD) {
$proc = Start-Process -NoNewWindow -PassThru -FilePath "${env:VCPKG_ROOT}/vcpkg${exe_ext}" -ArgumentList " remove darknet --recurse "
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Removing darknet through vcpkg failed! Exited with error code $exitCode.")
}
}
$proc = Start-Process -NoNewWindow -PassThru -FilePath "${env:VCPKG_ROOT}/vcpkg${exe_ext}" -ArgumentList " upgrade --no-dry-run "
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Upgrading vcpkg installed ports failed! Exited with error code $exitCode.")
}
$proc = Start-Process -NoNewWindow -PassThru -FilePath "${env:VCPKG_ROOT}/vcpkg${exe_ext}" -ArgumentList " install darknet[${features}] $headMode --recurse " # "-manifest" disables the manifest feature, so that if vcpkg is a subfolder of darknet, the vcpkg.json inside darknet folder does not trigger errors due to automatic manifest mode
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Installing darknet dependencies through vcpkg failed! Exited with error code $exitCode.")
}
Move-Item $PSCustomScriptRoot/vcpkg.json.bak $PSCustomScriptRoot/vcpkg.json
}
}
else {
if ($BuildDebug -and $UseVCPKG) {
$debug_build_folder = "$PSCustomScriptRoot/build_debug"
if (-Not $DoNotDeleteBuildFolder) {
Write-Host "Removing folder $debug_build_folder" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $debug_build_folder
}
New-Item -Path $debug_build_folder -ItemType directory -Force | Out-Null
Set-Location $debug_build_folder
$cmake_args = "-G `"$generator`" ${DebugBuildSetup} ${AdditionalBuildSetup} -S .."
Write-Host "Configuring debug CMake project" -ForegroundColor Green
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Config failed! Exited with error code $exitCode.")
}
Write-Host "Building debug CMake project" -ForegroundColor Green
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList "--build . ${debugConfig} --parallel ${NumberOfBuildWorkers} --target install"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Build failed! Exited with error code $exitCode.")
}
Get-ChildItem "${debug_build_folder}" -Filter *.pdb |
Foreach-Object {
Write-Host "-- Copying $_ to $DebugInstallPrefix/bin"
Copy-Item $_ $DebugInstallPrefix/bin
}
if (-Not $DoNotDeleteBuildFolder) {
Write-Host "Removing folder $debug_build_folder" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $debug_build_folder
}
}
$release_build_folder = "$PSCustomScriptRoot/build_release"
if (-Not $DoNotDeleteBuildFolder) {
Write-Host "Removing folder $release_build_folder" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $release_build_folder
}
New-Item -Path $release_build_folder -ItemType directory -Force | Out-Null
Set-Location $release_build_folder
$cmake_args = "-G `"$generator`" ${ReleaseBuildSetup} ${AdditionalBuildSetup} -S .."
Write-Host "Configuring release CMake project" -ForegroundColor Green
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()