From d6a87e47a99f91f0a03417992a3263ae486e8a52 Mon Sep 17 00:00:00 2001 From: Thomas Li Fredriksen Date: Wed, 8 Nov 2017 12:40:29 +0100 Subject: [PATCH] Fixed examples linker issue (missing pthread link). Added two cmake-options GATTLIB_BUILD_EXAMPLES and GATTLIB_SHARED_LIB --- CMakeLists.txt | 23 ++++++++++++++--------- bluez/CMakeLists.txt | 13 +++++++++---- examples/discover/CMakeLists.txt | 2 +- examples/gatttool/CMakeLists.txt | 2 +- examples/nordic_uart/CMakeLists.txt | 2 +- examples/notification/CMakeLists.txt | 2 +- examples/read_write/CMakeLists.txt | 2 +- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebf1d52..466563d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,9 @@ include(CrossCompilation.cmake) project(gattlib) +option(GATTLIB_BUILD_EXAMPLES "Build GattLib examples" YES) +option(GATTLIB_SHARED_LIB "Build GattLib as a shared library" YES) + find_package(PkgConfig REQUIRED) # Show all the warnings @@ -77,16 +80,18 @@ configure_file(dbus/gattlib.pc.in ${PROJECT_BINARY_DIR}/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) -add_subdirectory(examples/read_write) -add_subdirectory(examples/notification) -add_subdirectory(examples/nordic_uart) +if(GATTLIB_BUILD_EXAMPLES) + # Examples + add_subdirectory(examples/ble_scan) + add_subdirectory(examples/discover) + add_subdirectory(examples/read_write) + add_subdirectory(examples/notification) + add_subdirectory(examples/nordic_uart) -# Some examples require Bluez code and other DBus support -if (NOT GATTLIB_DBUS) - add_subdirectory(examples/gatttool) + # Some examples require Bluez code and other DBus support + if (NOT GATTLIB_DBUS) + add_subdirectory(examples/gatttool) + endif() endif() # diff --git a/bluez/CMakeLists.txt b/bluez/CMakeLists.txt index e67d929..03893cf 100644 --- a/bluez/CMakeLists.txt +++ b/bluez/CMakeLists.txt @@ -98,7 +98,12 @@ else() endif() # gattlib -add_library(gattlib SHARED ${gattlib_SRCS}) -target_link_libraries(gattlib ${gattlib_LIBS}) - -install(TARGETS gattlib LIBRARY DESTINATION lib) +if(GATTLIB_SHARED_LIB) + add_library(gattlib SHARED ${gattlib_SRCS}) + target_link_libraries(gattlib ${gattlib_LIBS}) + + install(TARGETS gattlib LIBRARY DESTINATION lib) +else() + add_library(gattlib ${gattlib_SRCS}) + target_link_libraries(gattlib ${gattlib_LIBS}) +endif() diff --git a/examples/discover/CMakeLists.txt b/examples/discover/CMakeLists.txt index c450979..be4c233 100644 --- a/examples/discover/CMakeLists.txt +++ b/examples/discover/CMakeLists.txt @@ -28,4 +28,4 @@ pkg_search_module(GATTLIB REQUIRED gattlib) set(discover_SRCS discover.c) add_executable(discover ${discover_SRCS}) -target_link_libraries(discover ${GATTLIB_LDFLAGS}) +target_link_libraries(discover ${GATTLIB_LDFLAGS} pthread) diff --git a/examples/gatttool/CMakeLists.txt b/examples/gatttool/CMakeLists.txt index 3819809..fc75b3c 100644 --- a/examples/gatttool/CMakeLists.txt +++ b/examples/gatttool/CMakeLists.txt @@ -51,4 +51,4 @@ endif() set(gatttool_SRCS gatttool.c interactive.c utils.c) add_executable(gatttool ${gatttool_SRCS}) -target_link_libraries(gatttool ${GATTLIB_LDFLAGS} ${GLIB_LDFLAGS} readline) +target_link_libraries(gatttool ${GATTLIB_LDFLAGS} ${GLIB_LDFLAGS} readline pthread) diff --git a/examples/nordic_uart/CMakeLists.txt b/examples/nordic_uart/CMakeLists.txt index 533007a..ee12175 100644 --- a/examples/nordic_uart/CMakeLists.txt +++ b/examples/nordic_uart/CMakeLists.txt @@ -29,4 +29,4 @@ 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 ${GATTLIB_LDFLAGS}) +target_link_libraries(nordic_uart ${GATTLIB_LDFLAGS} pthread) diff --git a/examples/notification/CMakeLists.txt b/examples/notification/CMakeLists.txt index 768859b..7a0747f 100644 --- a/examples/notification/CMakeLists.txt +++ b/examples/notification/CMakeLists.txt @@ -31,4 +31,4 @@ include_directories(${GLIB_INCLUDE_DIRS}) set(notification_SRCS notification.c) add_executable(notification ${notification_SRCS}) -target_link_libraries(notification ${GATTLIB_LDFLAGS} ${GLIB_LDFLAGS}) +target_link_libraries(notification ${GATTLIB_LDFLAGS} ${GLIB_LDFLAGS} pthread) diff --git a/examples/read_write/CMakeLists.txt b/examples/read_write/CMakeLists.txt index 740becc..7eac946 100644 --- a/examples/read_write/CMakeLists.txt +++ b/examples/read_write/CMakeLists.txt @@ -29,4 +29,4 @@ 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 ${GATTLIB_LDFLAGS}) +target_link_libraries(read_write ${GATTLIB_LDFLAGS} pthread)