Skip to content

Commit

Permalink
#5: Migrate to CMake Find-Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tlercher committed Jul 22, 2022
1 parent a1a2348 commit 407883f
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 6 deletions.
32 changes: 26 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@ project(ice9-bluetooth C)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" ${CMAKE_MODULE_PATH})

# TODO: Move to Find*-Modules
set(CMAKE_C_FLAGS "-I/opt/homebrew/include -Wall -g -O0 -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "-L/opt/homebrew/lib -lliquid -lbtbb -lhackrf -lbladeRF -fsanitize=address")
set(CMAKE_C_FLAGS "-Wall -g -O0 -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address")

# Use pthreads
# Installation directory
set(EXTCAP_PATH "$ENV{HOME}/.config/wireshark/extcap")

# Prefer pthreads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# Generate Help-Text-Header
# Add required dependencies
find_package(HACKRF REQUIRED)
find_package(BLADERF REQUIRED)
find_package(LIQUID REQUIRED)
find_package(BTBB REQUIRED)

# Generate header for help
add_custom_command(
OUTPUT help.h
COMMAND xxd -i help.txt help.h
DEPENDS help.txt
)

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${HACKRF_INCLUDE_DIR})
include_directories(${BLADERF_INCLUDE_DIR})
include_directories(${LIQUID_INCLUDE_DIR})
include_directories(${BTBB_INCLUDE_DIR})

set(SOURCES
${PROJECT_SOURCE_DIR}/bladerf.c
Expand All @@ -39,4 +51,12 @@ add_executable(ice9-bluetooth
${SOURCES}
)

target_link_libraries(ice9-bluetooth PRIVATE Threads::Threads)
target_link_libraries(ice9-bluetooth
PRIVATE Threads::Threads
${HACKRF_LIBRARIES}
${BLADERF_LIBRARIES}
${LIQUID_LIBRARIES}
${BTBB_LIBRARIES}
)

install(TARGETS ice9-bluetooth DESTINATION ${EXTCAP_PATH})
54 changes: 54 additions & 0 deletions cmake/Modules/FindBTBB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# - Find BTBB
# Find the native BTBB includes and library
# This module defines
# BTBB_INCLUDE_DIR, where to find BTBB.h, etc.
# BTBB_LIBRARIES, the libraries needed to use BTBB.
# BTBB_FOUND, If false, do not try to use BTBB.
# also defined, but not for general use are
# BTBB_LIBRARY, where to find the BTBB library.


FIND_PATH(BTBB_INCLUDE_DIR btbb.h
${BTBB_DIR}/include
/opt/homebrew/include
/opt/local/include
/usr/include
/usr/local/include
)

FIND_LIBRARY(BTBB_LIBRARY
NAMES btbb
PATHS ${BTBB_DIR}/lib
"${BTBB_DIR}\\win32\\lib"
/opt/homebrew/lib
/opt/local/lib
/usr/lib64
/usr/lib
/usr/local/lib
NO_DEFAULT_PATH
)

IF (BTBB_LIBRARY AND BTBB_INCLUDE_DIR)
SET(BTBB_LIBRARIES ${BTBB_LIBRARY})
SET(BTBB_FOUND "YES")
ELSE (BTBB_LIBRARY AND BTBB_INCLUDE_DIR)
SET(BTBB_FOUND "NO")
ENDIF (BTBB_LIBRARY AND BTBB_INCLUDE_DIR)

IF (BTBB_FOUND)
IF (NOT BTBB_FIND_QUIETLY)
MESSAGE(STATUS "Found libBTBB: ${BTBB_LIBRARIES}")
ENDIF (NOT BTBB_FIND_QUIETLY)
ELSE (BTBB_FOUND)
IF (BTBB_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find libBTBB library")
ENDIF (BTBB_FIND_REQUIRED)
ENDIF (BTBB_FOUND)

# Deprecated declarations.
GET_FILENAME_COMPONENT (NATIVE_BTBB_LIB_PATH ${BTBB_LIBRARY} PATH)

MARK_AS_ADVANCED(
BTBB_LIBRARY
BTBB_INCLUDE_DIR
)
53 changes: 53 additions & 0 deletions cmake/Modules/FindBladeRF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# - Find BLADERF
# Find the native BLADERF 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.
# also defined, but not for general use are
# BLADERF_LIBRARY, where to find the BLADERF library.

FIND_PATH(BLADERF_INCLUDE_DIR libbladeRF.h
${BLADERF_DIR}/include
/opt/homebrew/include
/opt/local/include
/usr/include
/usr/local/include
)

FIND_LIBRARY(BLADERF_LIBRARY
NAMES bladeRF
PATHS ${BLADERF_DIR}/lib
"${BLADERF_DIR}\\win32\\lib"
/opt/homebrew/lib
/opt/local/lib
/usr/lib64
/usr/lib
/usr/local/lib
NO_DEFAULT_PATH
)

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)

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

MARK_AS_ADVANCED(
BLADERF_LIBRARY
BLADERF_INCLUDE_DIR
)
53 changes: 53 additions & 0 deletions cmake/Modules/FindHackRF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# - Find HACKRF
# 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.
# 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
/usr/include/libhackrf
/usr/local/include/libhackrf
)

FIND_LIBRARY(HACKRF_LIBRARY
NAMES hackrf
PATHS ${HACKRF_DIR}/lib
"${HACKRF_DIR}\\win32\\lib"
/opt/homebrew/lib
/opt/local/lib
/usr/lib64
/usr/lib
/usr/local/lib
NO_DEFAULT_PATH
)

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)

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

MARK_AS_ADVANCED(
HACKRF_LIBRARY
HACKRF_INCLUDE_DIR
)
53 changes: 53 additions & 0 deletions cmake/Modules/FindLiquid.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# - Find LIQUID
# Find the native LIQUID includes and library
# This module defines
# LIQUID_INCLUDE_DIR, where to find LIQUID.h, etc.
# LIQUID_LIBRARIES, the libraries needed to use LIQUID.
# LIQUID_FOUND, If false, do not try to use LIQUID.
# 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
/opt/local/include/liquid
/usr/include/liquid
/usr/local/include/liquid
)

FIND_LIBRARY(LIQUID_LIBRARY
NAMES liquid
PATHS ${LIQUID_DIR}/lib
"${LIQUID_DIR}\\win32\\lib"
/opt/homebrew/lib
/opt/local/lib
/usr/lib64
/usr/lib
/usr/local/lib
NO_DEFAULT_PATH
)

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)

MARK_AS_ADVANCED(
LIQUID_LIBRARY
LIQUID_INCLUDE_DIR
)

0 comments on commit 407883f

Please sign in to comment.