From a09f7b2c7a4ce2682d19345d4972b660366e2450 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Thu, 25 Feb 2021 12:07:44 +0100
Subject: [PATCH] [ci,cmake] Changed to out-of-source builds.

---
 CMakePresets.json                           |  2 +-
 scripts/ci/extends/template-build-linux.yml |  3 ++-
 scripts/ci/extends/template-build-win.yml   |  3 ++-
 scripts/ci/extends/test-artifacts.yml       | 12 ++++++------
 scripts/ci/jobs/build-linux.yml             |  2 +-
 scripts/ci/jobs/build-mac.yml               |  2 +-
 scripts/ci/jobs/build-win.yml               |  2 +-
 scripts/ci/jobs/check-header.yml            |  2 +-
 scripts/ci/jobs/checks.yml                  |  9 +++------
 scripts/ci/jobs/clang-sanitizer.yml         |  2 +-
 scripts/ci/jobs/clang-tidy.yml              |  2 +-
 scripts/ci/jobs/code-coverage.yml           |  2 +-
 12 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/CMakePresets.json b/CMakePresets.json
index a396bed3afa..0e28a4c22f5 100644
--- a/CMakePresets.json
+++ b/CMakePresets.json
@@ -9,7 +9,7 @@
     {
       "name": "_binary_dir",
       "hidden": true,
-      "binaryDir": "${sourceDir}/build/${presetName}"
+      "binaryDir": "${sourceParentDir}/build/${presetName}"
     },
     {
       "name": "_release",
diff --git a/scripts/ci/extends/template-build-linux.yml b/scripts/ci/extends/template-build-linux.yml
index 06840e8708c..cbf8518c8d4 100644
--- a/scripts/ci/extends/template-build-linux.yml
+++ b/scripts/ci/extends/template-build-linux.yml
@@ -6,11 +6,12 @@
 
   before_script:
     - "echo \"For debugging run: docker run --rm -it -v $CI_BUILDS_DIR:/builds -w=$CI_PROJECT_DIR $CI_JOB_IMAGE\""
+    - rm -rf ../build
     - ([ "${CONAN_USER_HOME}" == "${CI_PROJECT_DIR}/.conan" ]) && conan remove --system-reqs '*'
     - ([[ $BUILD_CTEST_LARGE_ON_MASTER && "${CI_COMMIT_BRANCH}" == "master" && "${CMAKE_ARGS}" == *"USE_PYTHON=ON"* ]]) && export BUILD_CTEST_LARGE=true
   script:
     - cmake -S . --preset=$CMAKE_PRESET $CMAKE_ARGS -DOGS_BUILD_PROCESSES=$BUILD_PROCESSES
-    - build_dir=${BUILD_DIR:-build/$CMAKE_PRESET}
+    - build_dir=${BUILD_DIR:-../build/$CMAKE_PRESET}
     - cd $build_dir
     - |
       if [[ -z "$TARGETS" ]]; then
diff --git a/scripts/ci/extends/template-build-win.yml b/scripts/ci/extends/template-build-win.yml
index e2927c09d6a..2c0ddd3642d 100644
--- a/scripts/ci/extends/template-build-win.yml
+++ b/scripts/ci/extends/template-build-win.yml
@@ -8,7 +8,8 @@
   dependencies: [meta]
   variables:
   script:
-    - $build_directory = if ($env:BUILD_DIR) { $env:BUILD_DIR } else { "build/" + $env:CMAKE_PRESET }
+    - $build_directory = if ($env:BUILD_DIR) { $env:BUILD_DIR } else { "..\build\" + $env:CMAKE_PRESET }
+    - (rm -r -fo $build_directory)
     - $cmake_cmd = "cmake -S . --preset=$env:CMAKE_PRESET
       $env:CMAKE_ARGS
       -DOGS_BUILD_PROCESSES=$env:BUILD_PROCESSES"
diff --git a/scripts/ci/extends/test-artifacts.yml b/scripts/ci/extends/test-artifacts.yml
index 424ff0e992e..22e86f06424 100644
--- a/scripts/ci/extends/test-artifacts.yml
+++ b/scripts/ci/extends/test-artifacts.yml
@@ -1,12 +1,12 @@
 .test-artifacts:
   artifacts:
     paths:
-      - build/*/Tests/ctest.xml
-      - build/*/Tests/testrunner.xml
-      - build/*/make.output
-      - build/*/*.zip
-      - build/*/*.tar.gz
+      - ../build/*/Tests/ctest.xml
+      - ../build/*/Tests/testrunner.xml
+      - ../build/*/make.output
+      - ../build/*/*.zip
+      - ../build/*/*.tar.gz
     expire_in: 1 week
     reports:
       junit:
-        - build/*/Tests/testrunner.xml
+        - ../build/*/Tests/testrunner.xml
diff --git a/scripts/ci/jobs/build-linux.yml b/scripts/ci/jobs/build-linux.yml
index e88d27c8ed4..b9f81ba3b12 100644
--- a/scripts/ci/jobs/build-linux.yml
+++ b/scripts/ci/jobs/build-linux.yml
@@ -47,7 +47,7 @@ build linux (no unity):
   needs: [meta, "pre commit"]
   timeout: 1h
   variables:
-    BUILD_DIR: "build/no-unity"
+    BUILD_DIR: "../build/no-unity"
     BUILD_TESTS: "false"
     BUILD_CTEST: "false"
     CMAKE_PRESET: release
diff --git a/scripts/ci/jobs/build-mac.yml b/scripts/ci/jobs/build-mac.yml
index 6ec7e87f642..6ed9a7a51a7 100644
--- a/scripts/ci/jobs/build-mac.yml
+++ b/scripts/ci/jobs/build-mac.yml
@@ -6,7 +6,7 @@ build mac:
     - .test-artifacts
   needs: [meta]
   variables:
-    BUILD_DIR: "build/mac-release"
+    BUILD_DIR: "../build/mac-release"
     CMAKE_PRESET: release
     CMAKE_ARGS: >-
       -DOGS_INSTALL_DEPENDENCIES=ON
diff --git a/scripts/ci/jobs/build-win.yml b/scripts/ci/jobs/build-win.yml
index 5fc3a970ff0..baae2c5e22a 100644
--- a/scripts/ci/jobs/build-win.yml
+++ b/scripts/ci/jobs/build-win.yml
@@ -7,7 +7,7 @@ build win:
     - when: manual
       allow_failure: true
   variables:
-    BUILD_DIR: build/win-release
+    BUILD_DIR: ..\build\win-release
     CMAKE_PRESET: release
     CMAKE_ARGS: >-
       -DOGS_CI_TESTRUNNER_REPEAT=1
diff --git a/scripts/ci/jobs/check-header.yml b/scripts/ci/jobs/check-header.yml
index e0ce70d3d63..1468fdf85c6 100644
--- a/scripts/ci/jobs/check-header.yml
+++ b/scripts/ci/jobs/check-header.yml
@@ -5,7 +5,7 @@ check header:
     - .rules-master-manual
   dependencies: [meta]
   variables:
-    BUILD_DIR: "build-check-header"
+    BUILD_DIR: "../build/check-header"
     CMAKE_ARGS: "-DOGS_CHECK_HEADER_COMPILATION=ON -DOGS_BUILD_GUI=ON -DBUILD_SHARED_LIBS=ON"
   image: $CONTAINER_GCC_GUI_IMAGE
   script:
diff --git a/scripts/ci/jobs/checks.yml b/scripts/ci/jobs/checks.yml
index e02ffef696c..c3a993ce5ef 100644
--- a/scripts/ci/jobs/checks.yml
+++ b/scripts/ci/jobs/checks.yml
@@ -10,10 +10,7 @@ compiler warnings:
     - job: build mac
   script:
     - exit_code=0
-    - cd build/no-unity
-    - "if [[ $(cat make.output | grep warning -i) ]]; then printf 'There were GCC compiler warnings:\n\n'; cat make.output | grep warning -i; exit_code=1; fi"
-    - cd ../win-release
-    - "if [[ $(cat make.output | grep ': warning' -i) ]]; then printf 'There were MSVC compiler warnings:\n\n'; cat make.output | grep ': warning' -i; exit_code=1; fi"
-    - cd ../mac-release
-    - "if [[ $(cat make.output | grep warning -i) ]]; then printf 'There were Clang (macOS) compiler warnings:\n\n'; cat make.output | grep warning -i; exit_code=1; fi"
+    - "if [[ $(cat build/no-unity/make.output | grep warning -i) ]]; then printf 'There were GCC compiler warnings:\n\n'; cat make.output | grep warning -i; exit_code=1; fi"
+    - "if [[ $(cat build/win-release/make.output | grep ': warning' -i) ]]; then printf 'There were MSVC compiler warnings:\n\n'; cat make.output | grep ': warning' -i; exit_code=1; fi"
+    - "if [[ $(cat build/mac-release/make.output | grep warning -i) ]]; then printf 'There were Clang (macOS) compiler warnings:\n\n'; cat make.output | grep warning -i; exit_code=1; fi"
     - exit $exit_code
diff --git a/scripts/ci/jobs/clang-sanitizer.yml b/scripts/ci/jobs/clang-sanitizer.yml
index 281d20e93b4..20077bab3be 100644
--- a/scripts/ci/jobs/clang-sanitizer.yml
+++ b/scripts/ci/jobs/clang-sanitizer.yml
@@ -4,7 +4,7 @@ clang sanitizer:
     - .rules-manual
   needs: ["pre commit"]
   variables:
-    BUILD_DIR: "build-sanitizer"
+    BUILD_DIR: "../build/sanitizer"
     CMAKE_ARGS: "-DOGS_ADDRESS_SANITIZER=ON -DOGS_UNDEFINED_BEHAVIOR_SANITIZER=ON"
     UBSAN_OPTIONS: "print_stacktrace=1"
     LSAN_OPTIONS: "suppressions=$CI_PROJECT_DIR/scripts/test/leak_sanitizer.suppressions"
diff --git a/scripts/ci/jobs/clang-tidy.yml b/scripts/ci/jobs/clang-tidy.yml
index adf3829a0eb..110eaf7921e 100644
--- a/scripts/ci/jobs/clang-tidy.yml
+++ b/scripts/ci/jobs/clang-tidy.yml
@@ -4,7 +4,7 @@ clang tidy:
     - .rules-manual
   needs: ["pre commit"]
   variables:
-    BUILD_DIR: "build-tidy"
+    BUILD_DIR: "../build/tidy"
     CMAKE_ARGS: "-DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DCMAKE_CXX_CLANG_TIDY=clang-tidy-9"
 
   image:
diff --git a/scripts/ci/jobs/code-coverage.yml b/scripts/ci/jobs/code-coverage.yml
index b357898bc59..c71c572afa0 100644
--- a/scripts/ci/jobs/code-coverage.yml
+++ b/scripts/ci/jobs/code-coverage.yml
@@ -14,7 +14,7 @@ code coverage:
     # HACK to easier linking to the generated pages
     - echo '<meta http-equiv="REFRESH" content="0;URL=build/coverage/coverage_report/index.html">' >> Coverage.html
   after_script:
-    - cd build/coverage
+    - cd ../build/coverage
     - poetry run fastcov -C testrunner_coverage.info ctest_coverage.info --lcov -o coverage.info
     - poetry run fastcov -C testrunner_coverage.info ctest_coverage.info -o coverage.json
     - genhtml --demangle-cpp -o coverage_report coverage.info
-- 
GitLab