From a09ee4b1444f1a4dcbe53b82ad7578c02fde61b5 Mon Sep 17 00:00:00 2001 From: Konrad Breitsprecher Date: Wed, 3 Jun 2026 14:30:48 +0200 Subject: [PATCH 1/4] Add .vscode setting/scripts to enabele out-of-the-box cmake configure/build with VS Code Signed-off-by: Konrad Breitsprecher --- .gitignore | 1 - .vscode/cmake-vs.cmd | 32 +++++++++++++++ .vscode/settings.json | 22 +++++++++++ .vscode/tasks.json | 53 +++++++++++++++++++++++++ .vscode/vs-dev-shell.ps1 | 85 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 .vscode/cmake-vs.cmd create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 .vscode/vs-dev-shell.ps1 diff --git a/.gitignore b/.gitignore index ea7296c26..919ad84cd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ build*/ _build*/ install*/ _install*/ -.vscode .vs out diff --git a/.vscode/cmake-vs.cmd b/.vscode/cmake-vs.cmd new file mode 100644 index 000000000..86002e47c --- /dev/null +++ b/.vscode/cmake-vs.cmd @@ -0,0 +1,32 @@ +@REM Wrapper used by VS Code tasks and CMake Tools. +@REM It discovers a Visual Studio installation, initializes the MSVC dev environment, +@REM then forwards all arguments to cmake so configure/build use consistent toolchains. +@echo off +setlocal + +set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" +if not exist "%VSWHERE%" ( + echo ERROR: Could not find vswhere at "%VSWHERE%". + exit /b 1 +) + +set "VSINSTALL=" +for /f "usebackq delims=" %%I in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSINSTALL=%%I" + +if "%VSINSTALL%"=="" ( + for /f "usebackq delims=" %%I in (`"%VSWHERE%" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do set "VSINSTALL=%%I" +) + +if "%VSINSTALL%"=="" ( + echo ERROR: Could not find a Visual Studio installation with C++ tools. + exit /b 1 +) + +call "%VSINSTALL%\Common7\Tools\VsDevCmd.bat" -no_logo -arch=x64 -host_arch=x64 >nul +if errorlevel 1 ( + echo ERROR: Failed to initialize VS developer environment. + exit /b 1 +) + +cmake %* +exit /b %ERRORLEVEL% diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..c98303d1d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + // Workspace-local tooling settings for Windows/MSVC development. + // CMake calls are routed through .vscode/cmake-vs.cmd and terminals default + // to a profile that preloads the Visual Studio developer environment. + "cmake.useCMakePresets": "always", + "cmake.cmakePath": "${workspaceFolder}\\.vscode\\cmake-vs.cmd", + "terminal.integrated.profiles.windows": { + "VS Dev PowerShell (x64)": { + "source": "PowerShell", + "args": [ + "-NoExit", + "-ExecutionPolicy", + "Bypass", + "-File", + "${workspaceFolder}\\.vscode\\vs-dev-shell.ps1", + "-Arch", + "x64" + ] + } + }, + "terminal.integrated.defaultProfile.windows": "VS Dev PowerShell (x64)" +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..59f6e010b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,53 @@ +{ + // VS Code task definitions for configuring/building with the debug CMake preset. + // Both tasks call .vscode/cmake-vs.cmd so they always run inside a VS toolchain env. + "version": "2.0.0", + "tasks": [ + { + "label": "CMake Configure (debug preset, VS env)", + "type": "shell", + "command": "${workspaceFolder}\\.vscode\\cmake-vs.cmd", + "options": { + "shell": { + "executable": "C:\\Windows\\System32\\cmd.exe", + "args": [ + "/d", + "/c" + ] + } + }, + "args": [ + "--preset", + "debug" + ], + "group": "build", + "problemMatcher": [] + }, + { + "label": "CMake Build (debug preset, VS env)", + // Default build task; runs configure first via dependsOn. + "type": "shell", + "command": "${workspaceFolder}\\.vscode\\cmake-vs.cmd", + "options": { + "shell": { + "executable": "C:\\Windows\\System32\\cmd.exe", + "args": [ + "/d", + "/c" + ] + } + }, + "args": [ + "--build", + "--preset", + "debug" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "dependsOn": "CMake Configure (debug preset, VS env)", + "problemMatcher": [] + } + ] +} diff --git a/.vscode/vs-dev-shell.ps1 b/.vscode/vs-dev-shell.ps1 new file mode 100644 index 000000000..786096d1f --- /dev/null +++ b/.vscode/vs-dev-shell.ps1 @@ -0,0 +1,85 @@ +# Loads a Visual Studio developer shell into the current PowerShell session. +# Usage examples: +# .\.vscode\vs-dev-shell.ps1 +# .\.vscode\vs-dev-shell.ps1 -Arch x64 +# .\.vscode\vs-dev-shell.ps1 -Arch x64 cmake --build --preset debug +param( + [ValidateSet("x64", "x86", "arm64")] + [string]$Arch = "x64", + + [Parameter(ValueFromRemainingArguments = $true)] + [string[]]$Command +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" + +function Get-VsInstallationPath { + $vswherePath = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe" + if (-not (Test-Path $vswherePath)) { + throw "Could not find vswhere at '$vswherePath'. Install Visual Studio Installer first." + } + + $path = & $vswherePath -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath + if (-not $path) { + $path = & $vswherePath -latest -products * -requires Microsoft.Component.MSBuild -property installationPath + } + if (-not $path) { + throw "Could not find a Visual Studio installation with C++ tools." + } + + return $path.Trim() +} + +function Import-VsDevEnvironment { + param( + [Parameter(Mandatory = $true)] + [string]$VsInstallPath, + + [Parameter(Mandatory = $true)] + [string]$TargetArch + ) + + $vsDevCmd = Join-Path $VsInstallPath "Common7\Tools\VsDevCmd.bat" + if (-not (Test-Path $vsDevCmd)) { + throw "Could not find VsDevCmd.bat at '$vsDevCmd'." + } + + $envDump = & cmd.exe /s /c "`"$vsDevCmd`" -no_logo -arch=$TargetArch -host_arch=$TargetArch && set" + if ($LASTEXITCODE -ne 0) { + throw "VsDevCmd failed with exit code $LASTEXITCODE." + } + + foreach ($line in $envDump) { + if ($line -match "^([^=]+)=(.*)$") { + $name = $matches[1] + $value = $matches[2] + Set-Item -Path "Env:$name" -Value $value + } + } +} + +try { + $env:VSCMD_SKIP_SENDTELEMETRY = "1" + $installPath = Get-VsInstallationPath + Import-VsDevEnvironment -VsInstallPath $installPath -TargetArch $Arch + + Write-Host "Loaded Visual Studio dev environment:" -ForegroundColor Green + Write-Host " VS Path: $installPath" + Write-Host " Target: $Arch" + + if ($null -ne $Command -and $Command.Length -gt 0 -and -not [string]::IsNullOrWhiteSpace($Command[0])) { + $exe = $Command[0] + $args = @() + if ($Command.Length -gt 1) { + $args = $Command[1..($Command.Length - 1)] + } + + & $exe @args + exit $LASTEXITCODE + } +} +catch { + Write-Error $_ + exit 1 +} From c4f0cf45d25823c201fc7a0d42aafb3a8af6f240 Mon Sep 17 00:00:00 2001 From: Konrad Breitsprecher Date: Wed, 3 Jun 2026 14:40:08 +0200 Subject: [PATCH 2/4] Remove tasks.json Signed-off-by: Konrad Breitsprecher --- .vscode/tasks.json | 53 ---------------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 59f6e010b..000000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - // VS Code task definitions for configuring/building with the debug CMake preset. - // Both tasks call .vscode/cmake-vs.cmd so they always run inside a VS toolchain env. - "version": "2.0.0", - "tasks": [ - { - "label": "CMake Configure (debug preset, VS env)", - "type": "shell", - "command": "${workspaceFolder}\\.vscode\\cmake-vs.cmd", - "options": { - "shell": { - "executable": "C:\\Windows\\System32\\cmd.exe", - "args": [ - "/d", - "/c" - ] - } - }, - "args": [ - "--preset", - "debug" - ], - "group": "build", - "problemMatcher": [] - }, - { - "label": "CMake Build (debug preset, VS env)", - // Default build task; runs configure first via dependsOn. - "type": "shell", - "command": "${workspaceFolder}\\.vscode\\cmake-vs.cmd", - "options": { - "shell": { - "executable": "C:\\Windows\\System32\\cmd.exe", - "args": [ - "/d", - "/c" - ] - } - }, - "args": [ - "--build", - "--preset", - "debug" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "dependsOn": "CMake Configure (debug preset, VS env)", - "problemMatcher": [] - } - ] -} From 1ee7cb4fa62e915189b6ec59eb6d2f484d9db9b1 Mon Sep 17 00:00:00 2001 From: Konrad Breitsprecher Date: Wed, 3 Jun 2026 14:48:38 +0200 Subject: [PATCH 3/4] Add copyright headers Signed-off-by: Konrad Breitsprecher --- .vscode/cmake-vs.cmd | 1 + .vscode/settings.json | 1 + .vscode/vs-dev-shell.ps1 | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/.vscode/cmake-vs.cmd b/.vscode/cmake-vs.cmd index 86002e47c..dd969569e 100644 --- a/.vscode/cmake-vs.cmd +++ b/.vscode/cmake-vs.cmd @@ -1,3 +1,4 @@ +@REM SPDX-FileCopyrightText: 2025 Vector Informatik GmbH @REM Wrapper used by VS Code tasks and CMake Tools. @REM It discovers a Visual Studio installation, initializes the MSVC dev environment, @REM then forwards all arguments to cmake so configure/build use consistent toolchains. diff --git a/.vscode/settings.json b/.vscode/settings.json index c98303d1d..985618f24 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ +// SPDX-FileCopyrightText: 2025 Vector Informatik GmbH { // Workspace-local tooling settings for Windows/MSVC development. // CMake calls are routed through .vscode/cmake-vs.cmd and terminals default diff --git a/.vscode/vs-dev-shell.ps1 b/.vscode/vs-dev-shell.ps1 index 786096d1f..df674ffe8 100644 --- a/.vscode/vs-dev-shell.ps1 +++ b/.vscode/vs-dev-shell.ps1 @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Vector Informatik GmbH +# +# SPDX-License-Identifier: MIT + # Loads a Visual Studio developer shell into the current PowerShell session. # Usage examples: # .\.vscode\vs-dev-shell.ps1 From 62135971473b7b6c5f31ab3eaf83edd5c140334b Mon Sep 17 00:00:00 2001 From: Konrad Breitsprecher Date: Wed, 3 Jun 2026 15:10:48 +0200 Subject: [PATCH 4/4] Exclude cmake-vs.cmd from the lisence check Signed-off-by: Konrad Breitsprecher --- SilKit/ci/check_licenses.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SilKit/ci/check_licenses.sh b/SilKit/ci/check_licenses.sh index cf20a4e78..ebc7ff41c 100644 --- a/SilKit/ci/check_licenses.sh +++ b/SilKit/ci/check_licenses.sh @@ -22,7 +22,7 @@ assemble_file_string() # Yes this is weird that we single out some directories and the include "." # But the regex filters only work if more than one path is provided result="$(licensecheck --check='\.c.*$|\.h.*$|\.py|CMakeLists.txt|\.sh' \ - --ignore='ThirdParty|.git|.clang-format' \ + --ignore='ThirdParty|.git|.clang-format|\.vscode/cmake-vs\.cmd' \ --recursive -- ./SilKit/* ./Demos/* ./Utilities/* .)" numfiles=$(echo "$result" | wc -l)