@@ -367,116 +367,118 @@ function Build-CMakeProject {
367
367
368
368
$Stopwatch = [Diagnostics.Stopwatch ]::StartNew()
369
369
370
- # Add additional defines (unless already present)
371
- $Defines = $Defines.Clone ()
372
- TryAdd- KeyValue $Defines CMAKE_BUILD_TYPE $BuildType
373
- TryAdd- KeyValue $Defines CMAKE_MT " mt"
374
-
375
- $GenerateDebugInfo = $Defines [" CMAKE_BUILD_TYPE" ] -ne " Release"
376
- $Zi = if ($GenerateDebugInfo ) { " /Zi" } else { " " }
377
-
378
- $CFlags = " /GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline"
379
- $CXXFlags = " /GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline /Zc:__cplusplus"
380
- if ($UseMSVCCompilers.Contains (" C" )) {
381
- TryAdd- KeyValue $Defines CMAKE_C_COMPILER cl
382
- Append- FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
383
- }
384
- if ($UseMSVCCompilers.Contains (" CXX" )) {
385
- TryAdd- KeyValue $Defines CMAKE_CXX_COMPILER cl
386
- Append- FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
387
- }
388
- if ($UseBuiltCompilers.Contains (" ASM" )) {
389
- TryAdd- KeyValue $Defines CMAKE_ASM_COMPILER " $BinaryCache \1\bin\clang-cl.exe"
390
- Append- FlagsDefine $Defines CMAKE_ASM_FLAGS " --target=$ ( $Arch.LLVMTarget ) "
391
- TryAdd- KeyValue $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL " /MD"
392
- }
393
- if ($UseBuiltCompilers.Contains (" C" )) {
394
- TryAdd- KeyValue $Defines CMAKE_C_COMPILER " $BinaryCache \1\bin\clang-cl.exe"
395
- TryAdd- KeyValue $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
370
+ # Enter the developer command shell early so we can resolve cmake.exe
371
+ # for version checks.
372
+ Isolate- EnvVars {
373
+ Invoke-VsDevShell $Arch
396
374
397
- if ( -not ( Test-CMakeAtLeast - Major 3 - Minor 26 - Patch 3 )) {
398
- # Workaround for https://github.com/ninja-build/ninja/issues/2280
399
- TryAdd- KeyValue $Defines CMAKE_CL_SHOWINCLUDES_PREFIX " Note: including file: "
400
- }
375
+ # Add additional defines (unless already present)
376
+ $Defines = $Defines .Clone ()
377
+ TryAdd- KeyValue $Defines CMAKE_BUILD_TYPE $BuildType
378
+ TryAdd - KeyValue $Defines CMAKE_MT " mt "
401
379
402
- if ($GenerateDebugInfo -and $CDebugFormat -eq " dwarf" ) {
403
- Append- FlagsDefine $Defines CMAKE_C_FLAGS - gdwarf
404
- }
405
- Append- FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
406
- }
407
- if ($UseBuiltCompilers.Contains (" CXX" )) {
408
- TryAdd- KeyValue $Defines CMAKE_CXX_COMPILER " $BinaryCache \1\bin\clang-cl.exe"
409
- TryAdd- KeyValue $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
380
+ $GenerateDebugInfo = $Defines [" CMAKE_BUILD_TYPE" ] -ne " Release"
381
+ $Zi = if ($GenerateDebugInfo ) { " /Zi" } else { " " }
410
382
411
- if (-not (Test-CMakeAtLeast - Major 3 - Minor 26 - Patch 3 )) {
412
- # Workaround for https://github.com/ninja-build/ninja/issues/2280
413
- TryAdd- KeyValue $Defines CMAKE_CL_SHOWINCLUDES_PREFIX " Note: including file: "
383
+ $CFlags = " /GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline"
384
+ $CXXFlags = " /GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline /Zc:__cplusplus"
385
+ if ($UseMSVCCompilers.Contains (" C" )) {
386
+ TryAdd- KeyValue $Defines CMAKE_C_COMPILER cl
387
+ Append- FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
414
388
}
415
-
416
- if ( $GenerateDebugInfo -and $CDebugFormat -eq " dwarf " ) {
417
- Append- FlagsDefine $Defines CMAKE_CXX_FLAGS - gdwarf
389
+ if ( $UseMSVCCompilers .Contains ( " CXX " )) {
390
+ TryAdd - KeyValue $Defines CMAKE_CXX_COMPILER cl
391
+ Append- FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
418
392
}
419
- Append- FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
420
- }
421
- if ($UseBuiltCompilers.Contains (" Swift" )) {
422
- TryAdd- KeyValue $Defines CMAKE_Swift_COMPILER " $BinaryCache \1\bin\swiftc.exe"
423
- TryAdd- KeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget
393
+ if ($UseBuiltCompilers.Contains (" ASM" )) {
394
+ TryAdd- KeyValue $Defines CMAKE_ASM_COMPILER " $BinaryCache \1\bin\clang-cl.exe"
395
+ Append- FlagsDefine $Defines CMAKE_ASM_FLAGS " --target=$ ( $Arch.LLVMTarget ) "
396
+ TryAdd- KeyValue $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL " /MD"
397
+ }
398
+ if ($UseBuiltCompilers.Contains (" C" )) {
399
+ TryAdd- KeyValue $Defines CMAKE_C_COMPILER " $BinaryCache \1\bin\clang-cl.exe"
400
+ TryAdd- KeyValue $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
424
401
425
- $RuntimeBuildDir = Get-ProjectBuildDir $Arch 1
426
- $SwiftResourceDir = " ${RuntimeBuildDir} \lib\swift"
402
+ if (-not (Test-CMakeAtLeast - Major 3 - Minor 26 - Patch 3 )) {
403
+ # Workaround for https://github.com/ninja-build/ninja/issues/2280
404
+ TryAdd- KeyValue $Defines CMAKE_CL_SHOWINCLUDES_PREFIX " Note: including file: "
405
+ }
427
406
428
- $SwiftArgs = [System.Collections.ArrayList ]@ ()
407
+ if ($GenerateDebugInfo -and $CDebugFormat -eq " dwarf" ) {
408
+ Append- FlagsDefine $Defines CMAKE_C_FLAGS - gdwarf
409
+ }
410
+ Append- FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
411
+ }
412
+ if ($UseBuiltCompilers.Contains (" CXX" )) {
413
+ TryAdd- KeyValue $Defines CMAKE_CXX_COMPILER " $BinaryCache \1\bin\clang-cl.exe"
414
+ TryAdd- KeyValue $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
429
415
430
- if ($SwiftSDK -ne " " ) {
431
- $SwiftArgs.Add (" -sdk $SwiftSDK " ) | Out-Null
432
- } else {
433
- $SwiftArgs.Add (" -resource-dir $SwiftResourceDir " ) | Out-Null
434
- $SwiftArgs.Add (" -L $SwiftResourceDir \windows" ) | Out-Null
435
- $SwiftArgs.Add (" -vfsoverlay $RuntimeBuildDir \stdlib\windows-vfs-overlay.yaml" ) | Out-Null
416
+ if (-not (Test-CMakeAtLeast - Major 3 - Minor 26 - Patch 3 )) {
417
+ # Workaround for https://github.com/ninja-build/ninja/issues/2280
418
+ TryAdd- KeyValue $Defines CMAKE_CL_SHOWINCLUDES_PREFIX " Note: including file: "
419
+ }
420
+
421
+ if ($GenerateDebugInfo -and $CDebugFormat -eq " dwarf" ) {
422
+ Append- FlagsDefine $Defines CMAKE_CXX_FLAGS - gdwarf
423
+ }
424
+ Append- FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
436
425
}
426
+ if ($UseBuiltCompilers.Contains (" Swift" )) {
427
+ TryAdd- KeyValue $Defines CMAKE_Swift_COMPILER " $BinaryCache \1\bin\swiftc.exe"
428
+ TryAdd- KeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget
437
429
438
- # Debug Information
439
- if ($GenerateDebugInfo ) {
440
- if ($SwiftDebugFormat -eq " dwarf" ) {
441
- $SwiftArgs.Add (" -g -Xlinker /DEBUG:DWARF -use-ld=lld-link" ) | Out-Null
430
+ $RuntimeBuildDir = Get-ProjectBuildDir $Arch 1
431
+ $SwiftResourceDir = " ${RuntimeBuildDir} \lib\swift"
432
+
433
+ $SwiftArgs = [System.Collections.ArrayList ]@ ()
434
+
435
+ if ($SwiftSDK -ne " " ) {
436
+ $SwiftArgs.Add (" -sdk $SwiftSDK " ) | Out-Null
442
437
} else {
443
- $SwiftArgs.Add (" -g -debug-info-format=codeview -Xlinker -debug" ) | Out-Null
438
+ $SwiftArgs.Add (" -resource-dir $SwiftResourceDir " ) | Out-Null
439
+ $SwiftArgs.Add (" -L $SwiftResourceDir \windows" ) | Out-Null
440
+ $SwiftArgs.Add (" -vfsoverlay $RuntimeBuildDir \stdlib\windows-vfs-overlay.yaml" ) | Out-Null
444
441
}
445
- } else {
446
- $SwiftArgs.Add (" -gnone" ) | Out-Null
447
- }
448
- $SwiftArgs.Add (" -Xlinker /INCREMENTAL:NO" ) | Out-Null
449
442
450
- # Swift Requries COMDAT folding and de-duplication
451
- $SwiftArgs.Add (" -Xlinker /OPT:REF" ) | Out-Null
452
- $SwiftArgs.Add (" -Xlinker /OPT:ICF" ) | Out-Null
443
+ # Debug Information
444
+ if ($GenerateDebugInfo ) {
445
+ if ($SwiftDebugFormat -eq " dwarf" ) {
446
+ $SwiftArgs.Add (" -g -Xlinker /DEBUG:DWARF -use-ld=lld-link" ) | Out-Null
447
+ } else {
448
+ $SwiftArgs.Add (" -g -debug-info-format=codeview -Xlinker -debug" ) | Out-Null
449
+ }
450
+ } else {
451
+ $SwiftArgs.Add (" -gnone" ) | Out-Null
452
+ }
453
+ $SwiftArgs.Add (" -Xlinker /INCREMENTAL:NO" ) | Out-Null
453
454
454
- $SwiftcFlags = $SwiftArgs.ToArray () -Join " "
455
- Append- FlagsDefine $Defines CMAKE_Swift_FLAGS $SwiftcFlags
455
+ # Swift Requries COMDAT folding and de-duplication
456
+ $SwiftArgs.Add (" -Xlinker /OPT:REF" ) | Out-Null
457
+ $SwiftArgs.Add (" -Xlinker /OPT:ICF" ) | Out-Null
456
458
457
- # Workaround CMake 3.26+ enabling `-wmo` by default on release builds
458
- Append- FlagsDefine $Defines CMAKE_Swift_FLAGS_RELEASE " -O"
459
- Append- FlagsDefine $Defines CMAKE_Swift_FLAGS_RELWITHDEBINFO " -O"
460
- }
461
- if (" " -ne $InstallTo ) {
462
- TryAdd- KeyValue $Defines CMAKE_INSTALL_PREFIX $InstallTo
463
- }
459
+ $SwiftcFlags = $SwiftArgs.ToArray () -Join " "
460
+ Append- FlagsDefine $Defines CMAKE_Swift_FLAGS $SwiftcFlags
464
461
465
- # Generate the project
466
- $cmakeGenerateArgs = @ (" -B" , $Bin , " -S" , $Src , " -G" , $Generator )
467
- if (" " -ne $CacheScript ) {
468
- $cmakeGenerateArgs += @ (" -C" , $CacheScript )
469
- }
470
- foreach ($Define in ($Defines.GetEnumerator () | Sort-Object Name)) {
471
- # Avoid backslashes in defines since they are going into CMakeCache.txt,
472
- # where they are interpreted as escapes. Assume all backslashes
473
- # are path separators and can be turned into forward slashes.
474
- $ValueWithForwardSlashes = $Define.Value.Replace (" \" , " /" )
475
- $cmakeGenerateArgs += @ (" -D" , " $ ( $Define.Key ) =$ValueWithForwardSlashes " )
476
- }
462
+ # Workaround CMake 3.26+ enabling `-wmo` by default on release builds
463
+ Append- FlagsDefine $Defines CMAKE_Swift_FLAGS_RELEASE " -O"
464
+ Append- FlagsDefine $Defines CMAKE_Swift_FLAGS_RELWITHDEBINFO " -O"
465
+ }
466
+ if (" " -ne $InstallTo ) {
467
+ TryAdd- KeyValue $Defines CMAKE_INSTALL_PREFIX $InstallTo
468
+ }
477
469
478
- Isolate- EnvVars {
479
- Invoke-VsDevShell $Arch
470
+ # Generate the project
471
+ $cmakeGenerateArgs = @ (" -B" , $Bin , " -S" , $Src , " -G" , $Generator )
472
+ if (" " -ne $CacheScript ) {
473
+ $cmakeGenerateArgs += @ (" -C" , $CacheScript )
474
+ }
475
+ foreach ($Define in ($Defines.GetEnumerator () | Sort-Object Name)) {
476
+ # Avoid backslashes in defines since they are going into CMakeCache.txt,
477
+ # where they are interpreted as escapes. Assume all backslashes
478
+ # are path separators and can be turned into forward slashes.
479
+ $ValueWithForwardSlashes = $Define.Value.Replace (" \" , " /" )
480
+ $cmakeGenerateArgs += @ (" -D" , " $ ( $Define.Key ) =$ValueWithForwardSlashes " )
481
+ }
480
482
481
483
Invoke-Program cmake.exe @cmakeGenerateArgs
482
484
0 commit comments