Make sysrepo dependency optional

This project is useful as a standalone NETCONF client, too. Do not
require sysrepo unconditionally. If not available, just build the main
NETCONF client (and a `yang-cli`, too, because it's essentially free).

The CMake setup is a wee bit complex. CMake's OPTION statement doesn't
really support tri-state dependencies, and I like automagic stuff:

- OFF for disabling stuff unconditionally, even if the deps are there,
- ON for enabling stuff, and failing if it cannot be built,
- AUTO for trying to enable stuff if possible, and gracefully disabling
  it if not available

Of course this has a potential of introducing nasty surprises to the CI,
so make sure the CI fails if the sysrepo backend gets disabled for some
reason.

Change-Id: I9c38245c3eea767ad20f42240328c483b6f80dd4
diff --git a/ci/build.sh b/ci/build.sh
index 1ce6c23..d6b75f4 100755
--- a/ci/build.sh
+++ b/ci/build.sh
@@ -73,7 +73,7 @@
 
 if [[ -z "${ARTIFACT_URL}" ]]; then
     # fallback to a promoted artifact
-    ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/dependencies/${ZUUL_JOB_NAME%%-cover?(-previous)}/${DEP_SUBMODULE_COMMIT}.tar.zst"
+    ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/dependencies/${ZUUL_JOB_NAME%%+(-cover?(-previous)|-netconf-cli-no-sysrepo)}/${DEP_SUBMODULE_COMMIT}.tar.zst"
 fi
 
 ARTIFACT_FILE=$(basename ${ARTIFACT_URL})
@@ -84,11 +84,24 @@
 fi
 curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf -
 
+if [[ ${ZUUL_JOB_NAME} =~ .*-no-sysrepo ]]; then
+    rm -rf ${PREFIX}/include/sysrepo*
+    rm ${PREFIX}/lib*/libsysrepo*
+    rm ${PREFIX}/lib*/pkgconfig/sysrepo*
+    rm ${PREFIX}/bin/sysrepo*
+fi
+
 cd ${BUILD_DIR}
 cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
 ninja-build
 ctest -j${CI_PARALLEL_JOBS} --output-on-failure
 
+if [[ ! ${ZUUL_JOB_NAME} =~ .*-no-sysrepo ]]; then
+    # Normal builds should have the sysrepo and NETCONF tests
+    ctest --show-only=json-v1 | jq -r '.["tests"] | map(.name)' | grep -q test_datastore_access_netconf
+    ctest --show-only=json-v1 | jq -r '.["tests"] | map(.name)' | grep -q test_datastore_access_sysrepo
+fi
+
 if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then
     ninja-build doc
     pushd html