mirror of https://github.com/labapart/gattlib
Select gattlib backend (bluez code or DBus API) following Bluez version
parent
c702d74b23
commit
a40b8f9724
|
@ -27,8 +27,6 @@ include(CrossCompilation.cmake)
|
|||
|
||||
project(gattlib)
|
||||
|
||||
set(GATTLIB_DBUS TRUE CACHE BOOLEAN "Build gattlib with D-Bus support")
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
# Show all the warnings
|
||||
|
@ -36,6 +34,29 @@ set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
|||
# Expose 'gattlib.h' to all sub-directories
|
||||
include_directories(include)
|
||||
|
||||
# Check version of Bluez to know which backend we use (ie: Bluez code or DBus)
|
||||
pkg_search_module(BLUEZ REQUIRED bluez)
|
||||
|
||||
# Extract Bluez version
|
||||
string(REPLACE "." ";" BLUEZ_VERSIONS "${BLUEZ_VERSION}")
|
||||
list(GET BLUEZ_VERSIONS 0 BLUEZ_VERSION_MAJOR)
|
||||
list(GET BLUEZ_VERSIONS 1 BLUEZ_VERSION_MINOR)
|
||||
add_definitions(-DBLUEZ_VERSION_MAJOR=${BLUEZ_VERSION_MAJOR} -DBLUEZ_VERSION_MINOR=${BLUEZ_VERSION_MINOR})
|
||||
|
||||
set(GATTLIB_FORCE_DBUS FALSE CACHE BOOLEAN "Build gattlib with D-Bus support on Bluez version < v5.42")
|
||||
|
||||
if (BLUEZ_VERSION_MAJOR LESS 5)
|
||||
set(GATTLIB_DBUS FALSE)
|
||||
elseif (BLUEZ_VERSION_MINOR LESS 42)
|
||||
if (GATTLIB_FORCE_DBUS)
|
||||
set(GATTLIB_DBUS TRUE)
|
||||
else()
|
||||
set(GATTLIB_DBUS FALSE)
|
||||
endif()
|
||||
else()
|
||||
set(GATTLIB_DBUS TRUE)
|
||||
endif()
|
||||
|
||||
if (GATTLIB_DBUS)
|
||||
# Build dbus-based gattlib
|
||||
add_subdirectory(dbus)
|
||||
|
|
12
README.md
12
README.md
|
@ -1,9 +1,15 @@
|
|||
GattLib is a library used to access Generic Attribute Profile (GATT) protocol of BLE (Bluetooth Low Energy) devices.
|
||||
|
||||
It is based on Bluez 4.101 and Bluez 5.43 GATT code. Some changes has been made to support additional features and former versions of Bluez.
|
||||
|
||||
It has been introduced to allow to build applications that could easily communicate with BLE devices.
|
||||
|
||||
It supports Bluez v4 and v5. On Bluez versions prior to v5.42, gattlib used Bluez source code while it uses D-Bus API
|
||||
from v5.42. D-Bus API can be used on version prior to Bluez v5.42 by using the CMake flag `-DGATTLIB_FORCE_DBUS=TRUE`:
|
||||
|
||||
```
|
||||
mkdir build && cd build
|
||||
cmake -DGATTLIB_FORCE_DBUS=TRUE ..
|
||||
make
|
||||
```
|
||||
|
||||
Latest GattLib Release packages
|
||||
===============================
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ cmake_minimum_required(VERSION 2.6)
|
|||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
message("Build gattlib for Bluez v${BLUEZ_VERSION_MAJOR}.${BLUEZ_VERSION_MINOR}")
|
||||
|
||||
set(bluez4_DIR bluez4)
|
||||
set(bluez5_DIR bluez5)
|
||||
|
||||
|
@ -82,15 +84,9 @@ include_directories(${GLIB_INCLUDE_DIRS})
|
|||
list(APPEND gattlib_LIBS ${GLIB_LIBRARIES})
|
||||
|
||||
# Added Bluetooth support
|
||||
pkg_search_module(BLUEZ REQUIRED bluez)
|
||||
include_directories(${BLUEZ_INCLUDE_DIRS})
|
||||
link_directories(${BLUEZ_LIBRARY_DIRS})
|
||||
list(APPEND gattlib_LIBS ${BLUEZ_LIBRARIES})
|
||||
# Extract Bluez version
|
||||
string(REPLACE "." ";" BLUEZ_VERSIONS "${BLUEZ_VERSION}")
|
||||
list(GET BLUEZ_VERSIONS 0 BLUEZ_VERSION_MAJOR)
|
||||
list(GET BLUEZ_VERSIONS 1 BLUEZ_VERSION_MINOR)
|
||||
add_definitions(-DBLUEZ_VERSION_MAJOR=${BLUEZ_VERSION_MAJOR} -DBLUEZ_VERSION_MINOR=${BLUEZ_VERSION_MINOR})
|
||||
|
||||
include_directories(.)
|
||||
if(BLUEZ_VERSION_MAJOR STREQUAL "4")
|
||||
|
|
|
@ -32,6 +32,8 @@ pkg_search_module(GIO_UNIX REQUIRED gio-unix-2.0)
|
|||
# Needed by 'bluez5/lib/uuid.c'
|
||||
pkg_search_module(BLUEZ REQUIRED bluez)
|
||||
|
||||
message("Build DBus gattlib for Bluez v${BLUEZ_VERSION_MAJOR}.${BLUEZ_VERSION_MINOR}")
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-adaptater1.c
|
||||
COMMAND gdbus-codegen --interface-prefix org.bluez.Adapter1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-adaptater1 ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Adapter1.xml
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Adapter1.xml
|
||||
|
@ -62,13 +64,6 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattdescriptor1.
|
|||
COMMENT "Generate D-Bus 'org.bluez.GattDescriptor1.xml'"
|
||||
)
|
||||
|
||||
# Extract Bluez version
|
||||
string(REPLACE "." ";" BLUEZ_VERSIONS "${BLUEZ_VERSION}")
|
||||
list(GET BLUEZ_VERSIONS 0 BLUEZ_VERSION_MAJOR)
|
||||
list(GET BLUEZ_VERSIONS 1 BLUEZ_VERSION_MINOR)
|
||||
add_definitions(-DBLUEZ_VERSION_MAJOR=${BLUEZ_VERSION_MAJOR} -DBLUEZ_VERSION_MINOR=${BLUEZ_VERSION_MINOR})
|
||||
message("Build gattlib for Bluez v${BLUEZ_VERSION_MAJOR}.${BLUEZ_VERSION_MINOR}")
|
||||
|
||||
include_directories(. ${CMAKE_CURRENT_BINARY_DIR} ${GIO_UNIX_INCLUDE_DIRS} ${BLUEZ_INCLUDE_DIRS})
|
||||
|
||||
set(gattlib_SRCS gattlib.c
|
||||
|
|
Loading…
Reference in New Issue