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: 88db08a6 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 421e99c..e151a3f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -54,7 +54,6 @@
 find_package(Doxygen)
 option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
 
-find_package(docopt REQUIRED)
 find_package(Boost REQUIRED COMPONENTS filesystem)
 # Fixes C++20 build
 # https://github.com/boostorg/asio/issues/312
@@ -62,6 +61,7 @@
 find_package(replxx REQUIRED)
 
 find_package(PkgConfig)
+pkg_check_modules(DOCOPT REQUIRED IMPORTED_TARGET docopt)
 
 set(ENABLE_SYSREPO_CLI AUTO CACHE STRING "Enable the `sysrepo-cli`")
 set_property(CACHE ENABLE_SYSREPO_CLI PROPERTY STRINGS AUTO ON OFF)
@@ -207,7 +207,7 @@
 
 # Links libraries, that aren't specific to a datastore type
 function(cli_link_required cli_target)
-    target_link_libraries(${cli_target} proxydatastore yangschema docopt parser replxx::replxx)
+    target_link_libraries(${cli_target} proxydatastore yangschema PkgConfig::DOCOPT parser replxx::replxx)
     add_dependencies(${cli_target} target-NETCONF_CLI_VERSION)
     target_include_directories(${cli_target} PRIVATE ${PROJECT_BINARY_DIR})
 endfunction()