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..dd969569e --- /dev/null +++ b/.vscode/cmake-vs.cmd @@ -0,0 +1,33 @@ +@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. +@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..985618f24 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,23 @@ +// 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 + // 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/vs-dev-shell.ps1 b/.vscode/vs-dev-shell.ps1 new file mode 100644 index 000000000..df674ffe8 --- /dev/null +++ b/.vscode/vs-dev-shell.ps1 @@ -0,0 +1,89 @@ +# 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 +# .\.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 +} 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)