Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

New features for v0.6 #8

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
91 changes: 54 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.16)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/find")

project(SimpleBluez VERSION 0.1 LANGUAGES CXX)
project(
simplebluez
VERSION 0.6.0 # Make sure this matches the version in the changelog.
DESCRIPTION "A simple C++ wrapper around Bluez with a commercially-friendly licence."
HOMEPAGE_URL "https://github.com/OpenBluetoothToolbox/SimpleBluez"
LANGUAGES CXX
)

option(LIBFMT_VENDORIZE "Enable vendorized libfmt" ON)
option(SIMPLEDBUS_VENDORIZE "Enable vendorized SimpleDBus" ON)

# Include all necessary CMake modules
include(FetchContent)

# Detect if the project is being build within a project or standalone.
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(STANDALONE true)
Expand All @@ -18,61 +22,74 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Nice hack to automatically ignore the build directory
file(WRITE ${CMAKE_BINARY_DIR}/.gitignore "*")
else()
set(STANDALONE false)
endif()

# For now, include dependencies as static packages on purpose.
set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}")
set(BUILD_SHARED_LIBS OFF)
set(SIMPLEDBUS_SANITIZE ${SIMPLEBLUEZ_SANITIZE})
find_package(simpledbus REQUIRED)
find_package(fmt REQUIRED)
set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_SAVED}")

if(NOT SIMPLEBLUEZ_LOG_LEVEL)
set(SIMPLEBLUEZ_LOG_LEVEL "FATAL")
endif()

include_directories(${SIMPLEDBUS_INCLUDES})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/legacy)
set(
SIMPLEBLUEZ_USER_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/include
)

message(STATUS "Configuring SimpleBluez")
file(GLOB_RECURSE SRC_simplebluez_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")

add_library(simplebluez-static STATIC ${SRC_simplebluez_FILES})
add_library(simplebluez SHARED ${SRC_simplebluez_FILES})

target_compile_definitions(simplebluez-static PRIVATE SIMPLEBLUEZ_LOG_LEVEL=${SIMPLEBLUEZ_LOG_LEVEL})
target_compile_definitions(simplebluez PRIVATE SIMPLEBLUEZ_LOG_LEVEL=${SIMPLEBLUEZ_LOG_LEVEL})
add_library(simplebluez ${SRC_simplebluez_FILES})
add_library(simplebluez::simplebluez ALIAS simplebluez)

# Append additional flags for address and thread sanitization
if(SIMPLEBLUEZ_SANITIZE MATCHES "Address")
set(EXTRA_COMPILE_OPTIONS ${EXTRA_COMPILE_OPTIONS} -fsanitize=address -fsanitize-recover=address -fno-omit-frame-pointer -fno-common -g)
set(EXTRA_LINK_OPTIONS ${EXTRA_LINK_OPTIONS} -fsanitize=address)
elseif(SIMPLEBLUEZ_SANITIZE MATCHES "Thread")
set(EXTRA_COMPILE_OPTIONS ${EXTRA_COMPILE_OPTIONS} -fsanitize=thread -fno-omit-frame-pointer -fno-common -g)
set(EXTRA_LINK_OPTIONS ${EXTRA_LINK_OPTIONS} -fsanitize=thread)
endif()
set_target_properties(
simplebluez PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN YES
CXX_STANDARD 17
POSITION_INDEPENDENT_CODE ON
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
EXPORT_NAME simplebluez
OUTPUT_NAME simplebluez
)

target_compile_options(simplebluez-static PRIVATE -std=c++17 -fPIC -Wfatal-errors -Wpedantic -O3 -Og ${EXTRA_COMPILE_OPTIONS})
target_compile_options(simplebluez PRIVATE -std=c++17 -fPIC -Wfatal-errors -Wpedantic -O3 -Og ${EXTRA_COMPILE_OPTIONS})
target_include_directories(simplebluez PRIVATE ${SIMPLEBLUEZ_USER_INCLUDE_DIRS})

target_link_libraries(simplebluez-static PUBLIC simpledbus-static pthread ${EXTRA_LINK_OPTIONS})
target_link_libraries(simplebluez PUBLIC simpledbus-static pthread ${EXTRA_LINK_OPTIONS})
target_compile_definitions(simplebluez PRIVATE SIMPLEBLUEZ_LOG_LEVEL=${SIMPLEBLUEZ_LOG_LEVEL})
target_compile_options(simplebluez PRIVATE -Wfatal-errors -Wpedantic -O3 -Og)

target_link_libraries(simplebluez-static PRIVATE fmt::fmt-header-only)
target_link_libraries(simplebluez PUBLIC simpledbus::simpledbus pthread)
target_link_libraries(simplebluez PRIVATE fmt::fmt-header-only)

# Export the variables needed by the parent project
if(NOT ${STANDALONE})
set(
SIMPLEBLUEZ_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/legacy
${SIMPLEDBUS_INCLUDES}
PARENT_SCOPE
)
target_include_directories(simplebluez INTERFACE ${SIMPLEBLUEZ_USER_INCLUDE_DIRS})

# Append additional flags for address and thread sanitization
if(SIMPLEBLUEZ_SANITIZE MATCHES "Address")
message(STATUS "Appending address sanitization flags")
set(SANITIZE_ADDRESS_COMPILE_OPTIONS -fsanitize=address -fsanitize-recover=address -fno-omit-frame-pointer -fno-common -g)
set(SANITIZE_ADDRESS_LINK_OPTIONS -fsanitize=address)

target_compile_options(simplebluez PUBLIC ${SANITIZE_ADDRESS_COMPILE_OPTIONS})
target_link_libraries(simplebluez PUBLIC ${SANITIZE_ADDRESS_LINK_OPTIONS})
endif()

if(SIMPLEBLUEZ_SANITIZE MATCHES "Thread")
message(STATUS "Appending thread sanitization flags")
set(SANITIZE_THREAD_COMPILE_OPTIONS -fsanitize=thread -fno-omit-frame-pointer -fno-common -g)
set(SANITIZE_THREAD_LINK_OPTIONS -fsanitize=thread)

target_compile_options(simplebluez PUBLIC ${SANITIZE_THREAD_COMPILE_OPTIONS})
target_link_libraries(simplebluez PUBLIC ${SANITIZE_THREAD_LINK_OPTIONS})
endif()
2 changes: 1 addition & 1 deletion cmake/find/Findsimpledbus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (SIMPLEDBUS_VENDORIZE)
set(SIMPLEDBUS_GIT_REPOSITORY "https://github.com/OpenBluetoothToolbox/SimpleDBus.git")
endif()
if(NOT SIMPLEDBUS_GIT_TAG)
set(SIMPLEDBUS_GIT_TAG "v2.2.0")
set(SIMPLEDBUS_GIT_TAG "feature/next")
endif()

if(NOT SIMPLEDBUS_LOCAL_PATH)
Expand Down
64 changes: 44 additions & 20 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,85 +6,109 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog`_, and this project adheres to
`Semantic Versioning`_.

[0.6.0] - 2022-XX-XX
--------------------

**Important:** From this version onwards, the CMake target that should be consumed
by downstream projects is ``simplebluez::simplebluez``.

**Added**

- Support for characteristic descriptors. *(Thanks Symbitic!)*

**Changed**

- Selection of build type is now based on the ``BUILD_SHARED_LIBS`` setting.
- Consumable CMake target is now ``simplebluez::simplebluez``.

**Removed**

- CMake target ``simplebluez-static`` was removed in favour of ``BUILD_SHARED_LIBS``.

**Fixed**
- Accessing the ``Paired`` property of ``Device1`` would only use the cached value.
- Using the correct CMake functionality to export headers for all targets.


[0.5.0] - 2022-06-12
--------------------

**Added**

* Log forwarding based on ``logfwd``.
- Log forwarding based on ``logfwd``.

**Changed**

* Updated libfmt to version 8.1.1.
* Cleaned up dependency management for libfmt and SimpleDBus.
- Updated libfmt to version 8.1.1.
- Cleaned up dependency management for libfmt and SimpleDBus.


[0.4.0] - 2022-04-07
--------------------

**Added**

* ``RSSI`` property to ``Device`` class.
* Adapters can now return a list of all paired devices.
- ``RSSI`` property to ``Device`` class.
- Adapters can now return a list of all paired devices.


[0.3.1] - 2022-04-02
--------------------

**Changed**

* By default, all pairing options will succeed.
- By default, all pairing options will succeed.


[0.3.0] - 2022-03-25
--------------------

**Added**

* ``Agent`` and ``AgentManager`` classes to handle pairing.
* Pair and Notify examples.
- ``Agent`` and ``AgentManager`` classes to handle pairing.
- Pair and Notify examples.

**Changed**

* Migrated to using safe callbacks from external vendor (kvn::safe_callback).
- Migrated to using safe callbacks from external vendor (kvn::safe_callback).


[0.2.1] - 2022-02-13
--------------------

**Changed**

* Minor renaming of function for style consistency.
- Minor renaming of function for style consistency.


[0.2.0] - 2022-02-12
--------------------

**Added**

* Support for the ``Battery1`` interface. *(Thanks ptenbrock!)*
- Support for the ``Battery1`` interface. *(Thanks ptenbrock!)*


[0.1.1] - 2021-12-28
--------------------

**Added**

* Function to access currently cached value from characteristics.
* ``Notifying`` property on ``Characteristic1``.
* Added ``OnDisconnected`` callback to ``Device1``.
* Added ``ServicesResolved`` callback to ``Device1``.
* Address and Thread sanitization options.
- Function to access currently cached value from characteristics.
- ``Notifying`` property on ``Characteristic1``.
- Added ``OnDisconnected`` callback to ``Device1``.
- Added ``ServicesResolved`` callback to ``Device1``.
- Address and Thread sanitization options.

**Changed**

* All proxy and interface manipulation is now done through helper functions.
* Access to all interface properties is now thread-safe.
- All proxy and interface manipulation is now done through helper functions.
- Access to all interface properties is now thread-safe.

**Fixed**

* Removed unnecessary ``<iostream>`` includes.
* Made sure all classes have proper virtual destructors.
- Removed unnecessary ``<iostream>`` includes.
- Made sure all classes have proper virtual destructors.


[0.1.0] - 2021-12-14
Expand Down
1 change: 0 additions & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ dependencies, just clone the repository and link to it on your
::

add_subdirectory(<path-to-simplebluez> ${CMAKE_BINARY_DIR}/simplebluez)
include_directories(${SIMPLEBLUEZ_INCLUDES})

Build examples
~~~~~~~~~~~~~~
Expand Down
3 changes: 1 addition & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.0)
cmake_minimum_required(VERSION 3.16)

project(SIMPLEBLUEZ_EXAMPLES)

Expand All @@ -15,7 +15,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
# Include simplebluez
# Build artifacts in a separate folder
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/.. ${CMAKE_BINARY_DIR}/simplebluez)
include_directories(${SIMPLEBLUEZ_INCLUDES})

add_subdirectory(list_adapters)
add_subdirectory(list_paired)
Expand Down
4 changes: 2 additions & 2 deletions examples/ble_nus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.16)

project(EXAMPLE_BLE_NUS)

message("-- [INFO] Building Example")
add_executable(example_ble_nus ble_nus.cpp)
target_link_libraries(example_ble_nus simplebluez-static)
target_link_libraries(example_ble_nus simplebluez)
4 changes: 2 additions & 2 deletions examples/connect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.16)

project(EXAMPLE_CONNECT)

message("-- [INFO] Building Example")
add_executable(example_connect connect.cpp)
target_link_libraries(example_connect simplebluez-static)
target_link_libraries(example_connect simplebluez)
3 changes: 3 additions & 0 deletions examples/connect/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ int main(int argc, char* argv[]) {
std::cout << "Service: " << service->uuid() << std::endl;
for (auto characteristic : service->characteristics()) {
std::cout << " Characteristic: " << characteristic->uuid() << std::endl;
for (auto descriptor : characteristic->descriptors()) {
std::cout << " Descriptor: " << descriptor->uuid() << std::endl;
}
}
}
peripheral->disconnect();
Expand Down
4 changes: 2 additions & 2 deletions examples/list_adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.16)

project(EXAMPLE_LIST_ADAPTERS)

message("-- [INFO] Building Example")
add_executable(example_list_adapters list_adapters.cpp)
target_link_libraries(example_list_adapters simplebluez-static)
target_link_libraries(example_list_adapters simplebluez)
4 changes: 2 additions & 2 deletions examples/list_paired/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.16)

project(EXAMPLE_LIST_PAIRED)

message("-- [INFO] Building Example")
add_executable(example_list_paired list_paired.cpp)
target_link_libraries(example_list_paired simplebluez-static)
target_link_libraries(example_list_paired simplebluez)
4 changes: 2 additions & 2 deletions examples/notify/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.16)

project(EXAMPLE_NOTIFY)

message("-- [INFO] Building Example")
add_executable(example_notify notify.cpp)
target_link_libraries(example_notify simplebluez-static)
target_link_libraries(example_notify simplebluez)
4 changes: 2 additions & 2 deletions examples/pair/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.16)

project(EXAMPLE_PAIR)

message("-- [INFO] Building Example")
add_executable(example_pair pair.cpp)
target_link_libraries(example_pair simplebluez-static)
target_link_libraries(example_pair simplebluez)
3 changes: 3 additions & 0 deletions examples/pair/pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ int main(int argc, char* argv[]) {
std::cout << "Service: " << service->uuid() << std::endl;
for (auto characteristic : service->characteristics()) {
std::cout << " Characteristic: " << characteristic->uuid() << std::endl;
for (auto descriptor : characteristic->descriptors()) {
std::cout << " Descriptor: " << descriptor->uuid() << std::endl;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/read/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.16)

project(EXAMPLE_READ)

message("-- [INFO] Building Example")
add_executable(example_read read.cpp)
target_link_libraries(example_read simplebluez-static)
target_link_libraries(example_read simplebluez)
4 changes: 2 additions & 2 deletions examples/scan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.16)

project(EXAMPLE_SCAN)

message("-- [INFO] Building Example")
add_executable(example_scan scan.cpp)
target_link_libraries(example_scan simplebluez-static)
target_link_libraries(example_scan simplebluez)
Loading