From ab724a30ec59219b6556a95a76247277aa90854f Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 8 Sep 2025 21:52:49 +0200 Subject: [PATCH] cmake: Enable usage of UHD:: module Instead of relying on CMake variables like ${UHD_LIBRARIES}, downstream projects can now use the UHD::uhd target to link against UHD. --- CHANGELOG | 7 +++++++ host/CMakeLists.txt | 14 ++++++++++++++ host/cmake/Modules/UHDConfig.cmake.in | 17 +++++++++++++++++ host/lib/CMakeLists.txt | 14 ++++++++++---- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b23108a8d..7f9f1513a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,13 @@ Change Log for Releases ============================== +## 004.next + + +* New Features + - CMake: Create UHD::uhd package for improved integration in downstream build + processes. The init_usrp example is used to showcase this feature. + ## 004.009.000.000 * Highlights / Main Changes - Support for USRP B206mini-i diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index f62897312..9e78c71d0 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -610,6 +610,13 @@ configure_file( @ONLY ) +include(CMakePackageConfigHelpers) +export( + EXPORT uhdTargets + FILE ${UHD_BINARY_DIR}/cmake/Modules/UHDTargets.cmake + NAMESPACE UHD:: +) + set(uhd_cmake_scripts ${UHD_BINARY_DIR}/cmake/Modules/UHDConfig.cmake ${UHD_BINARY_DIR}/cmake/Modules/UHDConfigVersion.cmake @@ -624,6 +631,13 @@ UHD_INSTALL( DESTINATION ${CMAKE_MODULES_DIR}/uhd COMPONENT "devel" ) +install( + EXPORT uhdTargets + FILE UHDTargets.cmake + NAMESPACE UHD:: + DESTINATION ${CMAKE_MODULES_DIR}/uhd + COMPONENT "devel" +) ######################################################################## diff --git a/host/cmake/Modules/UHDConfig.cmake.in b/host/cmake/Modules/UHDConfig.cmake.in index 6cec05ba1..85fc3e158 100644 --- a/host/cmake/Modules/UHDConfig.cmake.in +++ b/host/cmake/Modules/UHDConfig.cmake.in @@ -21,6 +21,23 @@ # Allows us to use all .cmake files in this directory list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}") +include("${CMAKE_CURRENT_LIST_DIR}/UHDMinDepVersions.cmake") + +include(CMakeFindDependencyMacro) +find_dependency(Boost ${UHD_BOOST_MIN_VERSION} + COMPONENTS + chrono + date_time + filesystem + program_options + system + serialization + thread + unit_test_framework +) + +include("${CMAKE_CURRENT_LIST_DIR}/UHDTargets.cmake") + # Set that this file was found, for use in GNU Radio's FindUHD.cmake. # Have to use the ENV, since this file might not allow CACHE changes. set(ENV{UHD_CONFIG_USED} TRUE) diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index c92d1195c..ac1e98c11 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -196,6 +196,7 @@ if(ENABLE_MPMD) add_subdirectory(deps) UHD_LIB_ADD_RPCLIB(uhd) endif() + if(ENABLE_DPDK) add_definitions(-DHAVE_DPDK) # The compile flags DPDK_CFLAGS add the DPDK_INCLUDE_DIRS include @@ -247,10 +248,13 @@ if(ENABLE_SIM) endif(ENABLE_SIM) if(NOT UHDHOST_PKG) # Syntax makes it unusable by UHD_INSTALL - install(TARGETS uhd - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries # .so file - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries # .lib file - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries # .dll file + install( + TARGETS uhd + EXPORT uhdTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries # .so file + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries # .lib/.a file + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries # .dll file + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) endif(NOT UHDHOST_PKG) @@ -286,7 +290,9 @@ function(UHD_ADD_STATIC_LIB) UHD_LIB_ADD_PYTHON(uhd_static) endif() install(TARGETS uhd_static + EXPORT uhdTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries # .lib or .a file + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) endfunction(UHD_ADD_STATIC_LIB)