Skip to content

Commit

Permalink
Merge pull request #25 from tlercher/rework_cmake_search
Browse files Browse the repository at this point in the history
Rework CMake modules
  • Loading branch information
mikeryan authored Oct 4, 2023
2 parents 489d75a + 50965d7 commit 2d504c7
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 117 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ if(NOT CMAKE_BUILD_TYPE)
endif(NOT CMAKE_BUILD_TYPE)

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${HACKRF_INCLUDE_DIR})
include_directories(${BLADERF_INCLUDE_DIR})
include_directories(${LIBHACKRF_INCLUDE_DIR})
include_directories(${LIBBLADERF_INCLUDE_DIR})
include_directories(${UHD_INCLUDE_DIR})
include_directories(${LIQUID_INCLUDE_DIR})

Expand Down Expand Up @@ -129,8 +129,8 @@ endif()
target_link_libraries(ice9-bluetooth
PRIVATE Threads::Threads
m
${HACKRF_LIBRARIES}
${BLADERF_LIBRARIES}
${LIBHACKRF_LIBRARIES}
${LIBBLADERF_LIBRARIES}
${UHD_LIBRARIES}
${LIQUID_LIBRARIES}
)
Expand Down
85 changes: 54 additions & 31 deletions cmake/Modules/FindBladeRF.cmake
Original file line number Diff line number Diff line change
@@ -1,43 +1,66 @@
# - Find BLADERF
# Find the native BLADERF includes and library
# - Find LIBBLADERF
# Find the native LIBBLADERF includes and library
# This module defines
# BLADERF_INCLUDE_DIR, where to find bladerf.h, etc.
# BLADERF_LIBRARIES, the libraries needed to use BLADERF.
# BLADERF_FOUND, If false, do not try to use BLADERF.
# LIBBLADERF_INCLUDE_DIR, where to find bladerf.h, etc.
# LIBBLADERF_LIBRARIES, the libraries needed to use LIBBLADERF.
# LIBBLADERF_FOUND, If false, do not try to use LIBBLADERF.
# also defined, but not for general use are
# BLADERF_LIBRARY, where to find the BLADERF library.
# LIBBLADERF_LIBRARY, where to find LIBBLADERF.

FIND_PATH(BLADERF_INCLUDE_DIR libbladeRF.h
${BLADERF_DIR}/include
find_package(PkgConfig)
pkg_check_modules(PC_LIBHACKRF QUIET libbladeRF)

find_path(LIBBLADERF_INCLUDE_DIR
NAMES libbladeRF.h
HINTS
${LIBBLADERF_DIR}/include
${PC_LIBBLADERF_INCLUDEDIR}
${PC_LIBBLADERF_INCLUDE_DIRS}
/opt/homebrew/include
/opt/local/include
/usr/include
/usr/local/include
)

FIND_LIBRARY(BLADERF_LIBRARY bladeRF)

IF (BLADERF_LIBRARY AND BLADERF_INCLUDE_DIR)
SET(BLADERF_LIBRARIES ${BLADERF_LIBRARY})
SET(BLADERF_FOUND "YES")
ELSE (BLADERF_LIBRARY AND BLADERF_INCLUDE_DIR)
SET(BLADERF_FOUND "NO")
ENDIF (BLADERF_LIBRARY AND BLADERF_INCLUDE_DIR)

IF (BLADERF_FOUND)
IF (NOT BLADERF_FIND_QUIETLY)
MESSAGE(STATUS "Found bladeRF: ${BLADERF_LIBRARIES}")
ENDIF (NOT BLADERF_FIND_QUIETLY)
ELSE (BLADERF_FOUND)
IF (BLADERF_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find bladeRF library")
ENDIF (BLADERF_FIND_REQUIRED)
ENDIF (BLADERF_FOUND)
find_library(LIBBLADERF_LIBRARY
NAMES bladeRF
HINTS
$ENV{LIBBLADERF_DIR}/lib
${PC_LIBBLADERF_LIBDIR}
${PC_LIBBLADERF_LIBRARY_DIRS}
/opt/homebrew/lib
/opt/local/lib
/usr/lib
/usr/local/lib
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(BladeRF DEFAULT_MSG LIBBLADERF_LIBRARY LIBBLADERF_INCLUDE_DIR)

if (LIBBLADERF_LIBRARY AND LIBBLADERF_INCLUDE_DIR)
set(LIBBLADERF_LIBRARIES ${LIBBLADERF_LIBRARY})
set(LIBBLADERF_FOUND "YES")
else (LIBBLADERF_LIBRARY AND LIBBLADERF_INCLUDE_DIR)
set(LIBBLADERF_FOUND "NO")
endif (LIBBLADERF_LIBRARY AND LIBBLADERF_INCLUDE_DIR)

if (LIBBLADERF_FOUND)
if (NOT LIBBLADERF_FIND_QUIETLY)
message(STATUS "Found bladeRF: ${LIBBLADERF_LIBRARIES}")
endif (NOT LIBBLADERF_FIND_QUIETLY)
else (LIBBLADERF_FOUND)
if (LIBBLADERF_FIND_REQUIRED)
message(FATAL_ERROR "Could not find bladeRF library")
endif (LIBBLADERF_FIND_REQUIRED)
endif (LIBBLADERF_FOUND)

# Deprecated declarations.
GET_FILENAME_COMPONENT (NATIVE_BLADERF_LIB_PATH ${BLADERF_LIBRARY} PATH)
get_filename_component(NATIVE_LIBBLADERF_LIB_PATH ${LIBBLADERF_LIBRARY} PATH)

mark_as_advanced(
LIBBLADERF_LIBRARY
LIBBLADERF_INCLUDE_DIR
)

MARK_AS_ADVANCED(
BLADERF_LIBRARY
BLADERF_INCLUDE_DIR
)
set(LIBBLADERF_INCLUDE_DIRS ${LIBBLADERF_INCLUDE_DIR})
set(LIBBLADERF_LIBRARIES ${LIBBLADERF_LIBRARY})
94 changes: 59 additions & 35 deletions cmake/Modules/FindHackRF.cmake
Original file line number Diff line number Diff line change
@@ -1,44 +1,68 @@
# - Find HACKRF
# - Find LIBHACKRF
# Find the native HACKRF includes and library
# This module defines
# HACKRF_INCLUDE_DIR, where to find hackrf.h, etc.
# HACKRF_LIBRARIES, the libraries needed to use HACKRF.
# HACKRF_FOUND, If false, do not try to use HACKRF.
# LIBHACKRF_INCLUDE_DIR, where to find hackrf.h, etc.
# LIBHACKRF_LIBRARIES, the libraries needed to use HACKRF.
# LIBHACKRF_FOUND, If false, do not try to use HACKRF.
# also defined, but not for general use are
# HACKRF_LIBRARY, where to find the HACKRF library.

FIND_PATH(HACKRF_INCLUDE_DIR hackrf.h
${HACKRF_DIR}/include/libhackrf
/opt/homebrew/include/libhackrf
/opt/local/include/libhackrf
/home/linuxbrew/.linuxbrew/include/libhackrf
/usr/include/libhackrf
/usr/local/include/libhackrf
# LIBHACKRF_LIBRARY, where to find the HACKRF library.

find_package(PkgConfig)
pkg_check_modules(PC_LIBHACKRF QUIET libhackrf)

find_path(LIBHACKRF_INCLUDE_DIR
NAMES hackrf.h
HINTS
$ENV{LIBHACKRF_DIR}/include
${PC_LIBHACKRF_INCLUDEDIR}
${PC_LIBHACKRF_INCLUDE_DIRS}
/opt/homebrew/include
/opt/local/include
/home/linuxbrew/.linuxbrew/include
/usr/include
/usr/local/include
PATH_SUFFIXES libhackrf
)

find_library(LIBHACKRF_LIBRARY
NAMES hackrf
HINTS
$ENV{LIBHACKRF_DIR}/lib
${PC_LIBHACKRF_LIBDIR}
${PC_LIBHACKRF_LIBRARY_DIRS}
/opt/homebrew/lib
/opt/local/lib
/usr/lib
/usr/local/lib
)

FIND_LIBRARY(HACKRF_LIBRARY hackrf)

IF (HACKRF_LIBRARY AND HACKRF_INCLUDE_DIR)
SET(HACKRF_LIBRARIES ${HACKRF_LIBRARY})
SET(HACKRF_FOUND "YES")
ELSE (HACKRF_LIBRARY AND HACKRF_INCLUDE_DIR)
SET(HACKRF_FOUND "NO")
ENDIF (HACKRF_LIBRARY AND HACKRF_INCLUDE_DIR)

IF (HACKRF_FOUND)
IF (NOT HACKRF_FIND_QUIETLY)
MESSAGE(STATUS "Found HackRF: ${HACKRF_LIBRARIES}")
ENDIF (NOT HACKRF_FIND_QUIETLY)
ELSE (HACKRF_FOUND)
IF (HACKRF_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find HackRF library")
ENDIF (HACKRF_FIND_REQUIRED)
ENDIF (HACKRF_FOUND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HackRF DEFAULT_MSG LIBHACKRF_LIBRARY LIBHACKRF_INCLUDE_DIR)

if(LIBHACKRF_LIBRARY AND HACKRF_INCLUDE_DIR)
set(LIBHACKRF_LIBRARIES ${LIBHACKRF_LIBRARY})
set(LIBHACKRF_FOUND "YES")
else (LIBHACKRF_LIBRARY AND HACKRF_INCLUDE_DIR)
set(LIBHACKRF_FOUND "NO")
endif(LIBHACKRF_LIBRARY AND HACKRF_INCLUDE_DIR)

if(LIBHACKRF_FOUND)
if(NOT HACKRF_FIND_QUIETLY)
message(STATUS "Found HackRF: ${LIBHACKRF_LIBRARIES}")
endif(NOT HACKRF_FIND_QUIETLY)
else (LIBHACKRF_FOUND)
if(HACKRF_FIND_REQUIRED)
message(FATAL_ERROR "Could not find HackRF library")
endif(HACKRF_FIND_REQUIRED)
endif(LIBHACKRF_FOUND)

# Deprecated declarations.
GET_FILENAME_COMPONENT (NATIVE_HACKRF_LIB_PATH ${HACKRF_LIBRARY} PATH)
get_filename_component(NATIVE_LIBHACKRF_LIB_PATH ${LIBHACKRF_LIBRARY} PATH)

MARK_AS_ADVANCED(
HACKRF_LIBRARY
HACKRF_INCLUDE_DIR
mark_as_advanced(
LIBHACKRF_LIBRARY
LIBHACKRF_INCLUDE_DIR
)

set(LIBHACKRF_INCLUDE_DIRS ${LIBHACKRF_INCLUDE_DIR})
set(LIBHACKRF_LIBRARIES ${LIBHACKRF_LIBRARY})
78 changes: 51 additions & 27 deletions cmake/Modules/FindLiquid.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,62 @@
# also defined, but not for general use are
# LIQUID_LIBRARY, where to find the LIQUID library.

FIND_PATH(LIQUID_INCLUDE_DIR liquid.h
${LIQUID_DIR}/include/liquid
/opt/homebrew/include/liquid
/home/linuxbrew/.linuxbrew/include/liquid
/opt/local/include/liquid
/usr/include/liquid
/usr/local/include/liquid
find_package(PkgConfig)
pkg_check_modules(PC_LIQUID QUIET liquid)

find_path(LIQUID_INCLUDE_DIR
NAMES liquid.h
HINTS
${LIQUID_DIR}/include
${PC_LIQUID_INCLUDEDIR}
${PC_LIQUID_INCLUDE_DIRS}
/opt/homebrew/include
/home/linuxbrew/.linuxbrew/include
/opt/local/include
/usr/include
/usr/local/include
PATH_SUFFIXES liquid
)

find_library(LIQUID_LIBRARY
NAMES liquid
HINTS
$ENV{LIQUID_DIR}/lib
${PC_LIQUID_LIBDIR}
${PC_LIQUID_LIBRARY_DIRS}
/opt/homebrew/lib
/opt/local/lib
/usr/lib
/usr/local/lib
)

FIND_LIBRARY(LIQUID_LIBRARY liquid)

IF (LIQUID_LIBRARY AND LIQUID_INCLUDE_DIR)
SET(LIQUID_LIBRARIES ${LIQUID_LIBRARY})
SET(LIQUID_FOUND "YES")
ELSE (LIQUID_LIBRARY AND LIQUID_INCLUDE_DIR)
SET(LIQUID_FOUND "NO")
ENDIF (LIQUID_LIBRARY AND LIQUID_INCLUDE_DIR)

IF (LIQUID_FOUND)
IF (NOT LIQUID_FIND_QUIETLY)
MESSAGE(STATUS "Found liquid-sdr: ${LIQUID_LIBRARIES}")
ENDIF (NOT LIQUID_FIND_QUIETLY)
ELSE (LIQUID_FOUND)
IF (LIQUID_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find liquid-sdr library")
ENDIF (LIQUID_FIND_REQUIRED)
ENDIF (LIQUID_FOUND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Liquid DEFAULT_MSG LIQUID_LIBRARY LIQUID_INCLUDE_DIR)

if (LIQUID_LIBRARY AND LIQUID_INCLUDE_DIR)
set(LIQUID_LIBRARIES ${LIQUID_LIBRARY})
set(LIQUID_FOUND "YES")
else (LIQUID_LIBRARY AND LIQUID_INCLUDE_DIR)
set(LIQUID_FOUND "NO")
endif (LIQUID_LIBRARY AND LIQUID_INCLUDE_DIR)

if (LIQUID_FOUND)
if (NOT LIQUID_FIND_QUIETLY)
message(STATUS "Found liquid-sdr: ${LIQUID_LIBRARIES}")
endif (NOT LIQUID_FIND_QUIETLY)
else (LIQUID_FOUND)
if (LIQUID_FIND_REQUIRED)
message(FATAL_ERROR "Could not find liquid-sdr library")
endif (LIQUID_FIND_REQUIRED)
endif (LIQUID_FOUND)

# Deprecated declarations.
GET_FILENAME_COMPONENT (NATIVE_LIQUID_LIB_PATH ${LIQUID_LIBRARY} PATH)
get_filename_component(NATIVE_LIQUID_LIB_PATH ${LIQUID_LIBRARY} PATH)

MARK_AS_ADVANCED(
mark_as_advanced(
LIQUID_LIBRARY
LIQUID_INCLUDE_DIR
)

set(LIQUID_INCLUDE_DIRS ${LIQUID_INCLUDE_DIR})
set(LIQUID_LIBRARIES ${LIQUID_LIBRARY})
57 changes: 37 additions & 20 deletions cmake/Modules/FindUHD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,60 @@
# also defined, but not for general use are
# UHD_LIBRARY, where to find the UHD library.

FIND_PATH(UHD_INCLUDE_DIR uhd/config.hpp
find_package(PkgConfig)
pkg_check_modules(PC_UHD QUIET uhd)

find_path(UHD_INCLUDE_DIR
NAMES uhd/config.hpp
HINTS
${UHD_DIR}/include
${PC_UHD_INCLUDEDIR}
${PC_UHD_INCLUDE_DIRS}
/opt/homebrew/include
/opt/local/include
/usr/include
/usr/local/include
)

FIND_LIBRARY(UHD_LIBRARY uhd
find_library(UHD_LIBRARY
NAMES uhd
HINTS
${UHD_DIR}/lib
${PC_UHD_LIBDIR}
${PC_UHD_LIBRARY_DIRS}
/opt/homebrew/lib
/opt/local/lib
/usr/lib
/usr/local/lib
)

IF (UHD_LIBRARY AND UHD_INCLUDE_DIR)
SET(UHD_LIBRARIES ${UHD_LIBRARY})
SET(UHD_FOUND "YES")
ELSE (UHD_LIBRARY AND UHD_INCLUDE_DIR)
SET(UHD_FOUND "NO")
ENDIF (UHD_LIBRARY AND UHD_INCLUDE_DIR)

IF (UHD_FOUND)
IF (NOT UHD_FIND_QUIETLY)
MESSAGE(STATUS "Found UHD: ${UHD_LIBRARIES}")
ENDIF (NOT UHD_FIND_QUIETLY)
ELSE (UHD_FOUND)
IF (UHD_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find UHD library")
ENDIF (UHD_FIND_REQUIRED)
ENDIF (UHD_FOUND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(UHD DEFAULT_MSG UHD_LIBRARY UHD_INCLUDE_DIR)

if (UHD_LIBRARY AND UHD_INCLUDE_DIR)
set(UHD_LIBRARIES ${UHD_LIBRARY})
set(UHD_FOUND "YES")
else (UHD_LIBRARY AND UHD_INCLUDE_DIR)
set(UHD_FOUND "NO")
endif (UHD_LIBRARY AND UHD_INCLUDE_DIR)

if (UHD_FOUND)
if (NOT UHD_FIND_QUIETLY)
message(STATUS "Found UHD: ${UHD_LIBRARIES}")
endif (NOT UHD_FIND_QUIETLY)
else (UHD_FOUND)
if (UHD_FIND_REQUIRED)
message(FATAL_ERROR "Could not find UHD library")
endif (UHD_FIND_REQUIRED)
endif (UHD_FOUND)

# Deprecated declarations.
GET_FILENAME_COMPONENT (NATIVE_UHD_LIB_PATH ${UHD_LIBRARY} PATH)
get_filename_component(NATIVE_UHD_LIB_PATH ${UHD_LIBRARY} PATH)

MARK_AS_ADVANCED(
mark_as_advanced(
UHD_LIBRARY
UHD_INCLUDE_DIR
)

set(UHD_INCLUDE_DIRS ${UHD_INCLUDE_DIR})
set(UHD_LIBRARIES ${UHD_LIBRARY})

0 comments on commit 2d504c7

Please sign in to comment.