Skip to content

Commit

Permalink
examples/cmake : Add a cmake to the examples directory
Browse files Browse the repository at this point in the history
The CI never checks the exampels, which is pretty bad form, so add this.
The will allow easier build checking, and we can also then check
the examples with Coverity (which only checks things that are built).

Format the cmake with cmake-format to get ready for new standard.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz authored and commodo committed Apr 21, 2020
1 parent 32aa6df commit f69ac5f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ endif()

option(WITH_NETWORK_BACKEND "Enable the network backend" ON)
option(WITH_TESTS "Build the test programs" ON)
option(WITH_EXAMPLES "Build examples" OFF)

if (WITH_TESTS)
set(NEED_THREADS 1)
Expand Down Expand Up @@ -341,6 +342,9 @@ endif()
if(WITH_TESTS)
add_subdirectory(tests)
endif()
if(WITH_EXAMPLES)
add_subdirectory(examples)
endif()

if (WIN32)
set(LIBIIO_ORIGINAL_FILENAME libiio.dll)
Expand Down
74 changes: 74 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
cmake_minimum_required(VERSION 2.8.7)

project(ad9361-iiostream C)
project(ad9371-iiostream C)
project(adrv9009-iiostream C)
project(dummy-iiostream C)

if (APPLE)
# Add relative rpath to iio library (which is in the same framework)
set(CMAKE_INSTALL_RPATH "@executable_path/../..")
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
endif ()

if (MSVC)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../deps/wingetopt/src)
set(GETOPT_C_FILE
${CMAKE_CURRENT_SOURCE_DIR}/../deps/wingetopt/src/getopt.c
)
endif (MSVC)

if (WIN32)
set(LIBIIO_ORIGINAL_FILENAME)
set(LIBIIO_RC ${CMAKE_CURRENT_BINARY_DIR}/properties.rc)
configure_file(../properties.rc.cmakein ${LIBIIO_RC} @ONLY)
endif ()

if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIIO_CHECK_RET")
endif ()

add_executable(
ad9361-iiostream ad9361-iiostream.c ${GETOPT_C_FILE} ${LIBIIO_RC}
)
add_executable(
ad9371-iiostream ad9371-iiostream.c ${GETOPT_C_FILE} ${LIBIIO_RC}
)
add_executable(
adrv9009-iiostream adrv9009-iiostream.c ${GETOPT_C_FILE} ${LIBIIO_RC}
)
add_executable(dummy-iiostream dummy-iiostream.c ${GETOPT_C_FILE} ${LIBIIO_RC})

target_link_libraries(ad9361-iiostream iio)
target_link_libraries(ad9371-iiostream iio)
target_link_libraries(adrv9009-iiostream iio)
target_link_libraries(dummy-iiostream iio)

set(IIO_EXAMPLES_TARGETS ad9361-iiostream ad9371-iiostream adrv9009-iiostream
dummy-iiostream
)

find_library(CURSES_LIBRARY curses)
find_library(CDK_LIBRARY cdk)

if (PTHREAD_LIBRARIES
AND CURSES_LIBRARY
AND CDK_LIBRARY
)
find_path(LIBCKD_INCLUDE_DIR cdk.h PATH_SUFFIXES cdk)
include_directories(${LIBCKD_INCLUDE_DIR})
project(iio-monitor C)
add_executable(iio-monitor iio-monitor.c)
target_link_libraries(
iio-monitor iio ${PTHREAD_LIBRARIES} ${CURSES_LIBRARY} ${CDK_LIBRARY}
)
set(IIO_TESTS_TARGETS ${IIO_TESTS_TARGETS} iio-monitor)
endif ()

set_target_properties(
${IIO_TESTS_TARGETS} PROPERTIES C_STANDARD 99 C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
)

# We don't install any of these, they are examples, not tools. We build them to
# make sure they build/work, not to deploy them.
49 changes: 0 additions & 49 deletions examples/Makefile

This file was deleted.

5 changes: 3 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
The libiio is a cross platform library for interfacing with Linux IIO devices.

These are some primitive examples of using the libiio library.
These are not compiled or tested during a nominal library cmake/make process and must be compiled separately.
A linux Makefile is included.

These are only build if the -DWITH_EXAMPLES=ON is provided to the standard Cmake.

While the libiio library is tested on many operating systems, these examples are only tested on Linux.

More examples using all languages supported by libiio are encouraged to be added here.
Expand Down
2 changes: 1 addition & 1 deletion examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define _GNU_SOURCE
#define _DEFAULT_SOURCE

#include <cdk/cdk.h>
#include <cdk.h>
#include <locale.h>
#include <pthread.h>
#include <stdbool.h>
Expand Down

0 comments on commit f69ac5f

Please sign in to comment.