Use systemd 246 when building on CI

In the next patch, we are going to switch to Fedora 32 builds on CI.
However, Fedora 32 uses systemd 245.8 which unfortunately suffers from
the bug which affects function calls in sdbus-c++ [1].

Therefore we should use systemd<245 or systemd>245 which do not have the
bug.
CMake will fail with FATAL_ERROR if systemd 245 is found.

[1] https://github.com/Kistler-Group/sdbus-cpp/issues/106

Change-Id: I2499b43e5bd3c2a1d99bacb3179eb863c0f2bbf3
diff --git a/.zuul.public.yaml b/.zuul.public.yaml
index 45e4c1e..9b95ba8 100644
--- a/.zuul.public.yaml
+++ b/.zuul.public.yaml
@@ -5,12 +5,17 @@
             requires: CzechLight-deps-f31-gcc
             required-projects: &projects
               - CzechLight/dependencies
+              - name: github/systemd/systemd
+                override-checkout: v246
+            pre-run: ci/pre.yaml
         - f31-clang-asan-ubsan:
             requires: CzechLight-deps-f31-clang-asan-ubsan
             required-projects: *projects
+            pre-run: ci/pre.yaml
         - f31-clang-tsan:
             requires: CzechLight-deps-f31-clang-tsan
             required-projects: *projects
+            pre-run: ci/pre.yaml
         - f31-cpp-coverage-diff:
             voting: false
         - clang-format:
@@ -18,3 +23,4 @@
         - f31-gcc-cover-previous:
             requires: CzechLight-deps-f31-gcc
             required-projects: *projects
+            pre-run: ci/pre.yaml
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9267f23..2b921b7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,6 +35,9 @@
 find_package(PkgConfig)
 
 pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
+if(${SYSTEMD_VERSION} VERSION_EQUAL 245)
+    message(FATAL_ERROR "Systemd 245 has a bug affecting DBus method calls using sdbus-c++. Please see https://github.com/Kistler-Group/sdbus-cpp/issues/106.")
+endif()
 
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
diff --git a/ci/build.sh b/ci/build.sh
index 9effe9e..1f84af9 100755
--- a/ci/build.sh
+++ b/ci/build.sh
@@ -65,6 +65,30 @@
 
 curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf -
 
+BUILD_SD=~/build-sd
+pushd ${ZUUL_PROJECT_SRC_DIR}/../../github/systemd/systemd
+env \
+    -u CC \
+    -u CXX \
+    -u LD \
+    -u CFLAGS \
+    -u CXXFLAGS \
+    -u LDFLAGS \
+    meson ${BUILD_SD} \
+        -Drootprefix=${PREFIX} \
+        -Dprefix=${PREFIX} \
+        -Dsysconfdir=${PREFIX}/etc \
+        -Dlocalstatedir=${PREFIX}/var \
+        -Dsysvinit-path=${PREFIX}/etc/init.d \
+        -Dsysvrcnd-path=${PREFIX}/etc/rc.d \
+        -Drc-local=${PREFIX}/etc/rc.local \
+        -Dcertificate-root=${PREFIX}/etc/ssl \
+        -Dbashcompletiondir=${PREFIX}/share/bash-completion/completions \
+        -Dcreate-log-dirs=false \
+        -Dhwdb=false
+ninja-build -C ${BUILD_SD} install
+popd
+
 cd ${BUILD_DIR}
 cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
 ninja-build
diff --git a/ci/pre.yaml b/ci/pre.yaml
new file mode 100644
index 0000000..9efd046
--- /dev/null
+++ b/ci/pre.yaml
@@ -0,0 +1,6 @@
+- hosts: all
+  tasks:
+    - name: install systemd's build deps
+      shell:
+        cmd: dnf -y builddep systemd
+      become: true