commit 50586277135a0e481e87e5edcea309f713fc5c5b Author: neru Date: Tue May 12 14:36:14 2026 -0300 build: add list and build scripts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..95e9d60 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build/* \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..4ab6964 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,26 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Create project with test solution", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "windows": { + "command": "${workspaceRoot}\\create-test.ps1" + }, + }, + { + "label": "Format code", + "type": "shell", + "group": { + "kind": "none", + }, + "windows": { + "command": "${workspaceRoot}\\format-code.ps1" + }, + } + ], +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..74f6c6b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,29 @@ +# ------------------------------ +# cmake config / project +# ------------------------------ +cmake_minimum_required(VERSION 4.1.0) +project(tinymitm LANGUAGES CXX) + +# ------------------------------ +# options +# ------------------------------ +option(TINYMITM_TEST "Add test project" OFF) + +# ------------------------------ +# proxy +# ------------------------------ +file(GLOB_RECURSE TINYMITM_SOURCES CONFIGURE_DEPENDS "src/proxy/*.cpp" "src/proxy/*.h") +add_library(tinymitm STATIC ${TINYMITM_SOURCES}) +target_include_directories(tinymitm PUBLIC src/proxy) +target_compile_features(tinymitm PUBLIC cxx_std_20) +set_target_properties(tinymitm PROPERTIES CXX_EXTENSIONS OFF) + +# ------------------------------ +# test +# ------------------------------ +if (TINYMITM_TEST) + file(GLOB_RECURSE TINYMITM_TEST_SOURCES CONFIGURE_DEPENDS "src/test/*.h" "src/test/*.cpp") + add_executable(tinymitm-test ${TINYMITM_TEST_SOURCES}) + target_include_directories(tinymitm-test PRIVATE "src/test") + target_link_libraries(tinymitm-test PRIVATE tinymitm) +endif() \ No newline at end of file diff --git a/create-test.ps1 b/create-test.ps1 new file mode 100644 index 0000000..484c473 --- /dev/null +++ b/create-test.ps1 @@ -0,0 +1,53 @@ +$projectFolder = "build" +$slnName = "tinymitm" + +function Initialize-Project { + # generation + Write-Host "Generating project" + Set-Location $projectFolder + + cmake .. -G "Visual Studio 17 2022" -A x64 ` + -DCMAKE_CONFIGURATION_TYPES="Debug;Release" ` + -DCMAKE_VS_PLATFORM_NAME="x64" ` + -DTINYMITM_TEST=ON + + dotnet restore "$slnName.sln" --arch x64 + + $exitCode = $LASTEXITCODE + + if ($exitCode -ne 0) { + Write-Host "CMake generation failed with exit code: $exitCode" -ForegroundColor Red + exit 1 + } + + Set-Location .. + + # sln open + try { + $slnPath = "$projectFolder\$slnName.sln" + + $solutionFile = Get-Item -Path $slnPath -ErrorAction Stop + $solutionFullName = $solutionFile.FullName + + $vsProcesses = Get-CimInstance -Query "SELECT CommandLine FROM Win32_Process WHERE Name = 'devenv.exe'" + $pattern = [Regex]::Escape($solutionFullName) + $isOpen = $vsProcesses | Where-Object { $_.CommandLine -match $pattern } + + if (-not $isOpen) { + Write-Host "Starting Visual Studio..." -ForegroundColor Cyan + Start-Process -FilePath $solutionFullName + } + else { + Write-Host "Solution '$($solutionFile.Name)' is already open." -ForegroundColor Yellow + } + } + catch { + Write-Error "Failed to open solution: $($_.Exception.Message)" + } +} + +if (-not (Test-Path $projectFolder)) { + New-Item -ItemType Directory -Path $projectFolder | Out-Null +} + +Initialize-Project \ No newline at end of file