2016-04-23 15:42:08 +02:00
|
|
|
#
|
|
|
|
# GattLib - GATT Library
|
|
|
|
#
|
2017-01-30 22:33:16 +01:00
|
|
|
# Copyright (C) 2016-2017 Olivier Martin <olivier@labapart.org>
|
2016-04-23 15:42:08 +02:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 2.6)
|
|
|
|
|
2016-04-29 15:11:41 +02:00
|
|
|
# Add Cross-Compilation support when the environment variables
|
|
|
|
# CROSS_COMPILE and SYSROOT are defined
|
|
|
|
include(CrossCompilation.cmake)
|
|
|
|
|
2016-04-23 18:26:11 +02:00
|
|
|
project(gattlib)
|
|
|
|
|
2016-04-23 15:42:08 +02:00
|
|
|
find_package(PkgConfig REQUIRED)
|
|
|
|
|
2017-02-08 19:06:21 +01:00
|
|
|
# Show all the warnings
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
2017-03-14 12:22:26 +01:00
|
|
|
# Expose 'gattlib.h' to all sub-directories
|
|
|
|
include_directories(include)
|
2017-02-08 19:06:21 +01:00
|
|
|
|
2017-03-17 11:08:24 +01:00
|
|
|
# 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()
|
|
|
|
|
2017-03-14 13:38:45 +01:00
|
|
|
if (GATTLIB_DBUS)
|
|
|
|
# Build dbus-based gattlib
|
|
|
|
add_subdirectory(dbus)
|
|
|
|
else()
|
|
|
|
# Build bluez-based gattlib
|
|
|
|
add_subdirectory(bluez)
|
|
|
|
endif()
|
2016-04-23 15:42:08 +02:00
|
|
|
|
2017-03-14 12:17:02 +01:00
|
|
|
# Generate pkg-config file before building the examples
|
2017-03-14 13:38:45 +01:00
|
|
|
configure_file(dbus/gattlib.pc.in ${PROJECT_BINARY_DIR}/gattlib.pc @ONLY)
|
|
|
|
|
2017-03-14 12:17:02 +01:00
|
|
|
# Add the build directory to PKG_CONFIG_PATH
|
|
|
|
set(ENV{PKG_CONFIG_PATH} "${PROJECT_BINARY_DIR}:$ENV{PKG_CONFIG_PATH}")
|
|
|
|
|
2016-04-23 15:42:08 +02:00
|
|
|
# Examples
|
2016-05-02 10:02:39 +02:00
|
|
|
add_subdirectory(examples/ble_scan)
|
2016-04-28 01:22:00 +02:00
|
|
|
add_subdirectory(examples/discover)
|
|
|
|
add_subdirectory(examples/read_write)
|
2017-03-15 16:00:41 +01:00
|
|
|
add_subdirectory(examples/notification)
|
2017-02-22 12:28:48 +01:00
|
|
|
add_subdirectory(examples/nordic_uart)
|
2016-04-23 18:26:11 +02:00
|
|
|
|
2017-03-14 13:38:45 +01:00
|
|
|
# Some examples require Bluez code and other DBus support
|
|
|
|
if (NOT GATTLIB_DBUS)
|
|
|
|
add_subdirectory(examples/gatttool)
|
|
|
|
endif()
|
|
|
|
|
2016-04-23 18:26:11 +02:00
|
|
|
#
|
|
|
|
# Packaging
|
|
|
|
#
|
|
|
|
set(CPACK_PACKAGE_INSTALL_DIRECTORY /usr CACHE STRING "Install directory (default: /usr).")
|
2016-05-02 10:57:32 +02:00
|
|
|
set(CPACK_PACKAGE_VERSION 0.2)
|
2016-04-23 18:26:11 +02:00
|
|
|
set(CPACK_PACKAGE_CONTACT "Olivier Martin <olivier@labapart.com>")
|
2016-04-28 19:56:49 +02:00
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library to access GATT information from Bluetooth Low Energy (BLE) devices")
|
2016-04-29 15:11:41 +02:00
|
|
|
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}")
|
2016-04-23 18:26:11 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Debian package
|
|
|
|
#
|
|
|
|
set(CPACK_GENERATOR "DEB;RPM;ZIP")
|
|
|
|
|
|
|
|
# Detect platform architecture to use it for the Debian package
|
|
|
|
execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_QUIET)
|
|
|
|
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libglib2.0-0")
|
|
|
|
|
|
|
|
#
|
|
|
|
# List of file to install
|
|
|
|
#
|
|
|
|
install(FILES include/gattlib.h DESTINATION include)
|
|
|
|
install(FILES ${PROJECT_BINARY_DIR}/gattlib.pc DESTINATION lib/pkgconfig)
|
|
|
|
|
|
|
|
include(CPack)
|