Skip to content

Commit

Permalink
Fixed examples linker issue (missing pthread link). Added two cmake-o…
Browse files Browse the repository at this point in the history
…ptions GATTLIB_BUILD_EXAMPLES and GATTLIB_SHARED_LIB
  • Loading branch information
Thomas Li Fredriksen authored and oliviermartin committed Jan 3, 2018
1 parent 5b08f05 commit d6a87e4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
25 changes: 15 additions & 10 deletions CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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)

# Some examples require Bluez code and other DBus support
if (NOT GATTLIB_DBUS)
add_subdirectory(examples/gatttool)
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)
endif()
endif()

#
Expand Down
13 changes: 9 additions & 4 deletions bluez/CMakeLists.txt
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion examples/discover/CMakeLists.txt
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion examples/gatttool/CMakeLists.txt
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion examples/nordic_uart/CMakeLists.txt
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion examples/notification/CMakeLists.txt
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion examples/read_write/CMakeLists.txt
Expand Up @@ -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)

0 comments on commit d6a87e4

Please sign in to comment.