From 5f440c1a15e92e27622fb2eaece4c9c6169ecb3c Mon Sep 17 00:00:00 2001
From: "A. Maitland Bottoms" <bottoms@debian.org>
Date: Thu, 8 Nov 2018 12:06:51 -0500
Subject: [PATCH 3/4] modern cmake targets

Use CMake install(EXPORT ... to export UHD targets in Modern CMake usage,
so that find_package(UHD) does the right things.
---
 host/CMakeLists.txt                   | 10 +++++++++-
 host/cmake/Modules/UHDConfig.cmake.in |  5 ++++-
 host/lib/CMakeLists.txt               |  2 ++
 3 files changed, 15 insertions(+), 2 deletions(-)

--- a/host/CMakeLists.txt
+++ b/host/CMakeLists.txt
@@ -556,9 +556,17 @@
 
 UHD_INSTALL(
     FILES ${cmake_configs}
-    DESTINATION ${CMAKE_MODULES_DIR}/uhd
+    DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIBRARY_DIR}/cmake/uhd
     COMPONENT "devel"
 )
+install(EXPORT UHD-export
+  FILE
+  UHDTargets.cmake
+  NAMESPACE
+  UHD::
+  DESTINATION
+  ${CMAKE_INSTALL_PREFIX}/${LIBRARY_DIR}/cmake/uhd
+  )
 
 ########################################################################
 # Handle pre-built UHD Images for packaging
--- a/host/cmake/Modules/UHDConfig.cmake.in
+++ b/host/cmake/Modules/UHDConfig.cmake.in
@@ -36,7 +36,6 @@
     list(APPEND UHD_LIBDIR_HINTS ${UHD_DIR}/lib)
 endif()
 
-include(FindPkgConfig)
 if(PKG_CONFIG_FOUND)
   if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.0")
     set(UHD_QUIET "QUIET")
@@ -107,3 +106,7 @@
   message(FATAL_ERROR "UHD is required, but was not found.")
 
 endif()
+
+if(NOT TARGET UHD::uhd)
+  include("${CMAKE_CURRENT_LIST_DIR}/UHDTargets.cmake")
+endif()
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -186,6 +186,7 @@
 
 if(NOT UHDHOST_PKG) #Syntax makes it unusable by UHD_INSTALL
     install(TARGETS uhd
+        EXPORT UHD-export
         LIBRARY DESTINATION ${LIBRARY_DIR} COMPONENT libraries # .so file
         ARCHIVE DESTINATION ${LIBRARY_DIR} COMPONENT libraries # .lib file
         RUNTIME DESTINATION ${RUNTIME_DIR} COMPONENT libraries # .dll file
@@ -200,6 +201,7 @@
     set_target_properties(uhd_static PROPERTIES OUTPUT_NAME uhd)
     set_target_properties(uhd_static PROPERTIES COMPILE_DEFINITIONS UHD_STATIC_LIB)
     install(TARGETS uhd_static
+        EXPORT UHD-export
         ARCHIVE DESTINATION lib${LIB_SUFFIX} # .lib or .a file
     )
 endif(ENABLE_STATIC_LIBS)
