param([string]$Configuration = 'Development') $ErrorActionPreference = 'Stop' $root = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..')) $msbuild = 'D:\Program Files\Microsoft VisualStudio\VisualStudio 2026\MSBuild\Current\Bin\MSBuild.exe' $projects = [regex]::Matches([IO.File]::ReadAllText((Join-Path $root 'renderdoc.sln')), '"([^"\r\n]+\.vcxproj)"') | ForEach-Object { $_.Groups[1].Value } $projects = @($projects) + 'kernel_driver\kernel_driver.vcxproj' $entries = [Collections.Generic.List[object]]::new() $summary = @() foreach ($project in ($projects | Select-Object -Unique)) { $path = Join-Path $root $project $config = if ($project -like 'kernel_driver*') { 'Release' } else { $Configuration } $json = & $msbuild $path "/p:Configuration=$config" /p:Platform=x64 "/p:SolutionDir=$root\" /getProperty:IncludePath,VCToolsInstallDir /getItem:ClCompile if ($LASTEXITCODE -ne 0) { throw "MSBuild evaluation failed for $project`: $json" } $data = ($json -join "`n") | ConvertFrom-Json $compiler = Join-Path $data.Properties.VCToolsInstallDir 'bin\Hostx64\x64\cl.exe' $count = 0 foreach ($item in $data.Items.ClCompile) { if ($item.ExcludedFromBuild -eq 'true' -or !(Test-Path -LiteralPath $item.FullPath)) { continue } $arguments = [Collections.Generic.List[string]]::new() $arguments.Add($compiler); $arguments.Add('/nologo'); $arguments.Add('/c') foreach ($inc in (($item.AdditionalIncludeDirectories + ';' + $data.Properties.IncludePath) -split ';')) { if ($inc.Trim()) { $arguments.Add('/I' + $inc.Trim().Trim('"')) } } foreach ($define in ($item.PreprocessorDefinitions -split ';')) { if ($define.Trim()) { $arguments.Add('/D' + $define.Trim()) } } foreach ($undef in ($item.UndefinePreprocessorDefinitions -split ';')) { if ($undef.Trim()) { $arguments.Add('/U' + $undef.Trim()) } } foreach ($forced in ($item.ForcedIncludeFiles -split ';')) { if (!$forced.Trim()) { continue } $header = $forced.Trim().Trim('"') if (![IO.Path]::IsPathRooted($header)) { $searchDirs = @([IO.Path]::GetDirectoryName($item.FullPath), [IO.Path]::GetDirectoryName($path)) $searchDirs += @($data.Items.ClCompile | Where-Object PrecompiledHeader -eq 'Create' | ForEach-Object { [IO.Path]::GetDirectoryName($_.FullPath) }) $searchDirs += @(($item.AdditionalIncludeDirectories -split ';') | Where-Object { $_ }) foreach ($searchDir in $searchDirs) { $candidate = Join-Path $searchDir $header if (Test-Path -LiteralPath $candidate) { $header = [IO.Path]::GetFullPath($candidate); break } } } $arguments.Add('/FI' + $header) } if ($item.CompileAs -eq 'CompileAsC') { $arguments.Add('/TC') } if ($item.CompileAs -eq 'CompileAsCpp') { $arguments.Add('/TP') } if ($item.LanguageStandard -and $item.LanguageStandard -ne 'Default') { $arguments.Add('/std:' + ($item.LanguageStandard -replace '^stdcpp','c++')) } if ($item.LanguageStandard_C -and $item.LanguageStandard_C -ne 'Default') { $arguments.Add('/std:' + ($item.LanguageStandard_C -replace '^stdc','c')) } if ($item.RuntimeLibrary -match 'DLL') { $arguments.Add($(if ($item.RuntimeLibrary -match 'Debug') {'/MDd'} else {'/MD'})) } elseif ($item.RuntimeLibrary) { $arguments.Add($(if ($item.RuntimeLibrary -match 'Debug') {'/MTd'} else {'/MT'})) } if ($item.ExceptionHandling -eq 'Sync') { $arguments.Add('/EHsc') } if ($item.RuntimeTypeInfo -eq 'false') { $arguments.Add('/GR-') } if ($item.TreatWChar_tAsBuiltInType -eq 'false') { $arguments.Add('/Zc:wchar_t-') } if ($item.StructMemberAlignment -match '^([124816]+)Byte') { $arguments.Add('/Zp' + $Matches[1]) } if ($item.AdditionalOptions -match '/kernel') { $arguments.Add('/kernel') } $arguments.Add($item.FullPath) $entries.Add([ordered]@{directory=[IO.Path]::GetDirectoryName($path); file=$item.FullPath; arguments=$arguments.ToArray()}) $count++ } $summary += "$project [$config|x64]: $count" } $out = Join-Path $root 'compile_commands.json' [IO.File]::WriteAllText($out, ($entries.ToArray() | ConvertTo-Json -Depth 6), [Text.UTF8Encoding]::new($false)) $summary | Set-Content (Join-Path $PSScriptRoot 'projects.txt') Write-Output "Exported $($entries.Count) compilation entries to $out" $summary