cmake: use pkg-config to discover docopt

The upstream project provides a CMake file which attempts to import both
static and shared libraries. This is a problem on any reasonable
distribution because Nobody Ships Static Libraries Anymore (for
reasonable reasons). So we have distros shipping CMake files from
upstream which are broken because distros actively remove the static
library from their packaging.

This was not caught by the CI because I cannot type `Depends-on`
properly, and therefore Zuul would feed oldish prebuilt dependencies
which still included the custom-built docopt library in both static and
shared versions. We need a linter for commit footers :p.

Fixes: Ib246d39f975c00bc6489f683f1f21f34cc808201
Fixes: 4e473f1 CI: use system docopt-cpp
Bug: https://github.com/docopt/docopt.cpp/pull/134
Change-Id: Ief13813210199d8d58b82659e522a941033f6302
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f19b57..91cfc16 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,12 +30,12 @@
 option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
 
 find_package(Boost REQUIRED)
-find_package(docopt REQUIRED)
 find_package(spdlog REQUIRED)
 find_package(sdbus-c++ "1.0.0" REQUIRED)
 find_package(PkgConfig)
 find_package(fmt)
 find_package(nlohmann_json REQUIRED)
+pkg_check_modules(DOCOPT REQUIRED IMPORTED_TARGET docopt)
 
 pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
 if(${SYSTEMD_VERSION} VERSION_EQUAL 245)
@@ -103,7 +103,7 @@
     src/utils/waitUntilSignalled.cpp
     src/utils/waitUntilSignalled.h
     )
-target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt docopt)
+target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt PkgConfig::DOCOPT)
 
 # - health
 add_library(velia-health STATIC
@@ -262,7 +262,7 @@
 target_link_libraries(veliad-health
     PUBLIC
         velia-health
-        docopt
+        PkgConfig::DOCOPT
     )
 add_dependencies(veliad-health target-VELIA_VERSION)
 target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
@@ -273,7 +273,7 @@
 target_link_libraries(veliad-system
     PUBLIC
         velia-system
-        docopt
+        PkgConfig::DOCOPT
     )
 add_dependencies(veliad-system target-VELIA_VERSION)
 target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
@@ -285,7 +285,7 @@
     PUBLIC
         velia-firewall
         velia-utils
-        docopt
+        PkgConfig::DOCOPT
     )
 add_dependencies(veliad-firewall target-VELIA_VERSION)
 target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
@@ -299,7 +299,7 @@
     PUBLIC
         velia-ietf-hardware
         velia-ietf-hardware-sysrepo
-        docopt
+        PkgConfig::DOCOPT
     )
 add_dependencies(veliad-hardware target-VELIA_VERSION)
 target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})