From 567c8eefb5074493faac062c0417ea957aa37cb8 Mon Sep 17 00:00:00 2001
From: Joscha Schmiedt <schmiedt@uni-bremen.de>
Date: Fri, 6 Sep 2024 20:20:56 +0200
Subject: [PATCH] Add Make-like PowerShell script

---
 make.ps1 | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 make.ps1

diff --git a/make.ps1 b/make.ps1
new file mode 100644
index 0000000..72c2230
--- /dev/null
+++ b/make.ps1
@@ -0,0 +1,65 @@
+param (
+    [string]$target
+)
+
+# check if vswhere is available
+if (-not (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe")) {
+    Write-Output "vswhere is not available. Please install Visual Studio"
+    exit 1
+}
+
+# locate the latest Visual Studio installation
+$currentPath = Get-Location
+$installPath = &"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
+Import-Module (Join-Path $installPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
+Enter-VsDevShell -VsInstallPath $installPath
+Set-Location $currentPath
+
+
+# Windows is with Release only for now
+
+switch ($target) {
+    "build" {
+        Write-Output "Building the project..."
+        # check if msbuild is available
+        if (-not (Get-Command msbuild -ErrorAction SilentlyContinue)) {
+            Write-Output "msbuild is not available. Please install Visual Studio or open the Developer PowerShell:."
+            exit 1
+        }
+        # check if conan install was run
+        if (-not (Test-Path .\build\liblinkahead.sln)) {
+            Write-Output "Please run conan-install first."
+            exit 1
+        }
+	    msbuild .\build\liblinkahead.sln /property:Configuration=Release
+    }
+    "test" {
+        Write-Output "Running tests..."
+        # check if build was run before
+        if (-not (Test-Path .\build\Release\linkahead.dll)) {
+            Write-Output "Please build the project first."
+            exit 1
+        }
+        Set-Location .\build\
+        ctest
+        
+    }
+    "conan-install" {
+        Write-Output "Installing Release dependencies with Conan..."
+        # check if conan is available
+        if (-not (Get-Command conan -ErrorAction SilentlyContinue)) {
+            Write-Output "Conan is not available. Please install Conan or activate the Conan environment venv"
+            exit 1
+        }
+        conan install . --build=missing -s build_type=Release -s compiler.cppstd=17 
+	cmake --preset conan-default
+    }
+    "clean"{
+        Write-Output "Cleaning the project..."
+        Remove-Item -Recurse -Force .\build\*
+    }
+
+    default {
+        Write-Output "Usage: .\script.ps1 [conan-install|build|test|clean]"
+    }
+}
-- 
GitLab