Skip to content

Commit

Permalink
libbladeRF: added cmake find_package() support
Browse files Browse the repository at this point in the history
Fixes #418
  • Loading branch information
rthomp10 committed Jan 18, 2024
1 parent 0c611be commit 4ec99eb
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
23 changes: 23 additions & 0 deletions host/libraries/libbladeRF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ project(libbladeRF C)
set(VERSION_INFO_MAJOR 2)
set(VERSION_INFO_MINOR 5)
set(VERSION_INFO_PATCH 0)
set(LIBBLADERF_VERSION
${VERSION_INFO_MAJOR}.${VERSION_INFO_MINOR}.${VERSION_INFO_PATCH})


if(NOT DEFINED VERSION_INFO_EXTRA)
set(VERSION_INFO_EXTRA "git")
Expand Down Expand Up @@ -522,6 +525,26 @@ install(TARGETS libbladerf_shared
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} # .dll
)

# ###############################################################################
# CMake Config Files
# ###############################################################################
configure_file(
${PROJECT_SOURCE_DIR}/cmake/libbladeRFConfigVersion.cmake.in
${PROJECT_BINARY_DIR}/bladeRFConfigVersion.cmake @ONLY)

configure_file(
${PROJECT_SOURCE_DIR}/cmake/libbladeRFConfig.cmake.in
${PROJECT_BINARY_DIR}/bladeRFConfig.cmake @ONLY)

set(cmake_files
${PROJECT_BINARY_DIR}/bladeRFConfig.cmake
${PROJECT_BINARY_DIR}/bladeRFConfigVersion.cmake)

if(UNIX)
install(FILES ${cmake_files} DESTINATION share/cmake/bladeRF)
elseif(WIN32)
install(FILES ${cmake_files} DESTINATION cmake)
endif()

################################################################################
# Informational output
Expand Down
53 changes: 53 additions & 0 deletions host/libraries/libbladeRF/cmake/libbladeRFConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
if(DEFINED INCLUDED_LIBBLADERF_CONFIG_CMAKE)
return()
endif()

set(INCLUDED_LIBBLADERF_CONFIG_CMAKE TRUE)

# #######################################################################
# libbladeRFConfig - cmake project configuration
#
# The following will be set after find_package(libbladeRF CONFIG):
# libbladeRF_LIBRARIES - development libraries
# libbladeRF_INCLUDE_DIRS - development includes
# #######################################################################

# #######################################################################
# # installation root
# #######################################################################
if(UNIX)
get_filename_component(LIBBLADERF_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
elseif(WIN32)
get_filename_component(LIBBLADERF_ROOT "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
endif()

# #######################################################################
# # locate the library
# #######################################################################
find_library(
LIBBLADERF_LIBRARY bladeRF
PATHS ${LIBBLADERF_ROOT}/lib${LIB_SUFFIX}
PATH_SUFFIXES ${CMAKE_LIBRARY_ARCHITECTURE}
NO_DEFAULT_PATH
)

if(NOT LIBBLADERF_LIBRARY)
message(FATAL_ERROR "cannot find libbladeRF library in ${LIBBLADERF_ROOT}/lib${LIB_SUFFIX}")
endif()

set(libbladeRF_LIBRARIES ${LIBBLADERF_LIBRARY})

# #######################################################################
# # locate the includes
# #######################################################################
find_path(
LIBBLADERF_INCLUDE_DIR libbladeRF.h
PATHS ${LIBBLADERF_ROOT}/include
NO_DEFAULT_PATH
)

if(NOT LIBBLADERF_INCLUDE_DIR)
message(FATAL_ERROR "cannot find libbladeRF includes in ${LIBBLADERF_ROOT}/include/libbladeRF")
endif()

set(libbladeRF_INCLUDE_DIRS ${LIBBLADERF_INCLUDE_DIR})
11 changes: 11 additions & 0 deletions host/libraries/libbladeRF/cmake/libbladeRFConfigVersion.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(PACKAGE_VERSION "@LIBBLADERF_VERSION@")

# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()

0 comments on commit 4ec99eb

Please sign in to comment.