From 6a083a84969695aef92c3d9f16b4e6f35fb83280 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Tue, 14 Mar 2017 12:17:02 +0100 Subject: [PATCH] examples: Use 'gattlib' pkg-config to build the examples --- CMakeLists.txt | 6 +++++- examples/ble_scan/CMakeLists.txt | 27 +++++++++++++++++++++++++-- examples/discover/CMakeLists.txt | 9 +++++---- examples/gatttool/CMakeLists.txt | 8 +++++--- examples/nordic_uart/CMakeLists.txt | 6 ++++-- examples/read_write/CMakeLists.txt | 8 +++++--- 6 files changed, 49 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd6128c..e8d3bf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,11 @@ set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall") add_library(gattlib SHARED ${gattlib_SRCS}) target_link_libraries(gattlib ${gattlib_LIBS}) +# Generate pkg-config file before building the examples +configure_file(gattlib.pc.in gattlib.pc @ONLY) +# Add the build directory to PKG_CONFIG_PATH +set(ENV{PKG_CONFIG_PATH} "${PROJECT_BINARY_DIR}:$ENV{PKG_CONFIG_PATH}") + # Examples add_subdirectory(examples/ble_scan) add_subdirectory(examples/discover) @@ -138,7 +143,6 @@ set(CPACK_DEBIAN_PACKAGE_DEPENDS "libglib2.0-0") # # List of file to install # -configure_file(gattlib.pc.in gattlib.pc @ONLY) install(TARGETS gattlib LIBRARY DESTINATION lib) install(FILES include/gattlib.h DESTINATION include) install(FILES ${PROJECT_BINARY_DIR}/gattlib.pc DESTINATION lib/pkgconfig) diff --git a/examples/ble_scan/CMakeLists.txt b/examples/ble_scan/CMakeLists.txt index 6006dd6..d890fe5 100644 --- a/examples/ble_scan/CMakeLists.txt +++ b/examples/ble_scan/CMakeLists.txt @@ -1,8 +1,31 @@ +# +# GattLib - GATT Library +# +# Copyright (C) 2016-2017 Olivier Martin +# +# +# 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) -set(ble_scan_LIBS gattlib pthread) +find_package(PkgConfig REQUIRED) + +pkg_search_module(GATTLIB REQUIRED gattlib) set(ble_scan_SRCS ble_scan.c) add_executable(ble_scan ${ble_scan_SRCS}) -target_link_libraries(ble_scan ${ble_scan_LIBS}) +target_link_libraries(ble_scan ${GATTLIB_LIBRARIES} pthread) diff --git a/examples/discover/CMakeLists.txt b/examples/discover/CMakeLists.txt index 4fdd99d..3378988 100644 --- a/examples/discover/CMakeLists.txt +++ b/examples/discover/CMakeLists.txt @@ -1,8 +1,7 @@ # -# # GattLib - GATT Library # -# Copyright (C) 2016 Olivier Martin +# Copyright (C) 2016-2017 Olivier Martin # # # This program is free software; you can redistribute it and/or modify @@ -22,9 +21,11 @@ cmake_minimum_required(VERSION 2.6) -set(discover_LIBS gattlib) +find_package(PkgConfig REQUIRED) + +pkg_search_module(GATTLIB REQUIRED gattlib) set(discover_SRCS discover.c) add_executable(discover ${discover_SRCS}) -target_link_libraries(discover ${discover_LIBS}) +target_link_libraries(discover ${GATTLIB_LIBRARIES}) diff --git a/examples/gatttool/CMakeLists.txt b/examples/gatttool/CMakeLists.txt index 5efa86e..4490da9 100644 --- a/examples/gatttool/CMakeLists.txt +++ b/examples/gatttool/CMakeLists.txt @@ -2,7 +2,7 @@ # # GattLib - GATT Library # -# Copyright (C) 2016 Olivier Martin +# Copyright (C) 2016-2017 Olivier Martin # # # This program is free software; you can redistribute it and/or modify @@ -22,9 +22,11 @@ cmake_minimum_required(VERSION 2.6) -set(gatttool_LIBS gattlib readline) +find_package(PkgConfig REQUIRED) + +pkg_search_module(GATTLIB REQUIRED gattlib) set(gatttool_SRCS gatttool.c interactive.c utils.c) add_executable(gatttool ${gatttool_SRCS}) -target_link_libraries(gatttool ${gatttool_LIBS}) +target_link_libraries(gatttool ${GATTLIB_LIBRARIES} readline) diff --git a/examples/nordic_uart/CMakeLists.txt b/examples/nordic_uart/CMakeLists.txt index 76762d7..76d7a5e 100644 --- a/examples/nordic_uart/CMakeLists.txt +++ b/examples/nordic_uart/CMakeLists.txt @@ -22,9 +22,11 @@ cmake_minimum_required(VERSION 2.6) -set(nordic_uart_LIBS gattlib) +find_package(PkgConfig REQUIRED) + +pkg_search_module(GATTLIB REQUIRED gattlib) set(nordic_uart_SRCS nordic_uart.c) add_executable(nordic_uart ${nordic_uart_SRCS}) -target_link_libraries(nordic_uart ${nordic_uart_LIBS}) +target_link_libraries(nordic_uart ${GATTLIB_LIBRARIES}) diff --git a/examples/read_write/CMakeLists.txt b/examples/read_write/CMakeLists.txt index e0bba4f..3625524 100644 --- a/examples/read_write/CMakeLists.txt +++ b/examples/read_write/CMakeLists.txt @@ -2,7 +2,7 @@ # # GattLib - GATT Library # -# Copyright (C) 2016 Olivier Martin +# Copyright (C) 2016-2017 Olivier Martin # # # This program is free software; you can redistribute it and/or modify @@ -22,9 +22,11 @@ cmake_minimum_required(VERSION 2.6) -set(read_write_LIBS gattlib) +find_package(PkgConfig REQUIRED) + +pkg_search_module(GATTLIB REQUIRED gattlib) set(read_write_SRCS read_write.c) add_executable(read_write ${read_write_SRCS}) -target_link_libraries(read_write ${read_write_LIBS}) +target_link_libraries(read_write ${GATTLIB_LIBRARIES})