From 8d1112054d86fd0ffb46b9d3b011e24e80b5672f Mon Sep 17 00:00:00 2001
From: Moritz Maxeiner <mm@ucw.sh>
Date: Thu, 13 Dec 2018 15:40:25 +0100
Subject: [PATCH] Update bash&powershell cmake functions

- Split package extraction & package discovery enabling
- windows: Use junctions instead of copying
  This allows keeping the files in the build folder so they
  can be transferred between jobs, but still serves as a
  workaround for Qt5's MOC being unable to access headers
  in the build directory.
---
 ubuntu18.04/base/profile.sh | 14 ++++++++++++--
 windows/base/Profile.ps1    | 25 ++++++++++++++++---------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/ubuntu18.04/base/profile.sh b/ubuntu18.04/base/profile.sh
index c43e018..d10a25e 100644
--- a/ubuntu18.04/base/profile.sh
+++ b/ubuntu18.04/base/profile.sh
@@ -7,8 +7,18 @@ function gitlab-trigger-pipeline {
     curl --request POST --form "token=$2" --form "ref=$3" "https://git.imp.fu-berlin.de/api/v4/projects/$1/trigger/pipeline"
 }
 
-function cmake-integrate-package {
+function cmake-extract-package {
     7z e $1-*.tar.xz; rm $1-*.tar.xz
     7z x $1-*.tar; rm $1-*.tar
-    ln -s $(realpath $1-*) /usr/local/$1
+    mkdir -p vendor
+    mv $1-* vendor/$1
+}
+
+function cmake-enable-package-discovery {
+    ln -s $(realpath vendor/$1) /usr/local/$1
+}
+
+function cmake-integrate-package {
+    cmake-extract-package $1
+    cmake-enable-package-discovery $1
 }
diff --git a/windows/base/Profile.ps1 b/windows/base/Profile.ps1
index ed9d871..670db7e 100644
--- a/windows/base/Profile.ps1
+++ b/windows/base/Profile.ps1
@@ -36,22 +36,29 @@ function GitLab-Fetch-Artifacts {
 }
 
 #
-# Sets up a CMake package for find_package from a tarball without copying
+# Unpacks a CMake package from its tarball into the vendor directory
 #
-function CMake-Integrate-Package {
+function CMake-Extract-Package {
     $name = $args[0]
     7z e $name-*.tar.xz; Remove-Item -Force $name-*.tar.xz
     7z x $name-*.tar; Remove-Item -Force $name-*.tar
-    [Environment]::SetEnvironmentVariable("${name}_ROOT", "$(resolve-path $name-*)")
+    New-Item -ItemType Directory -Force 'vendor'
+    Move-Item $name-* vendor/$name
 }
 
 #
-# Sets up a CMake package for find_package from a tarball
+# Enable discovery of a CMake package in the vendor directory via find_package
 #
-function CMake-Install-Package {
+function CMake-Enable-Package-Discovery {
     $name = $args[0]
-    7z e $name-*.tar.xz; Remove-Item -Force $name-*.tar.xz
-    7z x $name-*.tar; Remove-Item -Force $name-*.tar
-    Copy-Item -Recurse $name-* "C:/Program Files/"
-    Remove-Item -Recurse -Force $name-*
+    & cmd.exe /c mklink /J "C:/Program Files/$name" "$(resolve-path vendor/$name)"
+}
+
+#
+# Sets up a tarballed CMake package for find_package discovery
+#
+function CMake-Integrate-Package {
+    $name = $args[0]
+    CMake-Extract-Package $name
+    CMake-Enable-Package-Discovery $name
 }
-- 
GitLab