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.
This commit is contained in:
Martin Braun 2025-09-08 21:52:49 +02:00 committed by Jörg Hofrichter
parent db95a49e76
commit ab724a30ec
4 changed files with 48 additions and 4 deletions

View File

@ -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

View File

@ -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"
)
########################################################################

View File

@ -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)

View File

@ -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)