From a330cc1877f9eb7fc978fa7708af9fca8c392dd0 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Fri, 24 Apr 2020 18:22:26 -0400 Subject: [PATCH 1/4] cmake: support old Cmake for -std=c99 on old verisons of Cmake, they don't support the way we are setting the "C_STANDARD 99" (in set_target_properties), so check for old verison and then set the CMAKE_C_FLAGS by hand. This eliminates all the warnings that happen on the Zynq images we use (2019R1) and some of the older CI images we support, and make it alot easier to see where the real errors/warnings are. Signed-off-by: Robin Getz --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 590fd8d49..b4f3c43f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,4 @@ +message(STATUS "cmake verison: ${CMAKE_VERSION}") cmake_minimum_required(VERSION 2.8.7) project(libiio C) @@ -77,6 +78,13 @@ if (CMAKE_COMPILER_IS_GNUCC) if (HAS_WPEDANTIC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic") endif() + # cmake 2.8 doesn't support C_STANDARD defined in set_target_properties + if (${CMAKE_VERSION} VERSION_LESS "3.2") + check_c_compiler_flag(-std=c99 HAS_C99) + if (HAS_C99) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") + endif() + endif() endif() if(APPLE) From 88b946f4b897ea18a0c7c97ab41149a80fc27179 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Sun, 26 Apr 2020 17:11:38 -0400 Subject: [PATCH 2/4] iio-monitor: Now the c90 warnings are gone, fix real warnings older versions of CDK need things to be casted to it's own type, so check for that and do it. Some libraries flag asprintf as must check return value, since it does a malloc() and can fail, so do that. Signed-off-by: Robin Getz --- examples/CMakeLists.txt | 13 +++++++++++++ examples/iio-monitor.c | 17 ++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a0e9d3d01..b485beec6 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -56,6 +56,17 @@ if (PTHREAD_LIBRARIES AND CDK_LIBRARY ) find_path(LIBCKD_INCLUDE_DIR cdk.h PATH_SUFFIXES cdk) + + set(TEMP ${CMAKE_REQUIRED_LIBRARIES}) + set(TEMP1 ${CMAKE_REQUIRED_INCLUDES}) + list(APPEND CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY} ${CDK_LIBRARY}) + list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBCKD_INCLUDE_DIR}) + check_symbol_exists(CDK_CSTRING2 "cdk.h" HAS_CDK_CSTRING2) + set(CMAKE_REQUIRED_LIBRARIES ${TEMP}) + set(CMAKE_REQUIRED_INCLUDES ${TEMP1}) +endif() + +if(HAS_CDK_CSTRING2) include_directories(${LIBCKD_INCLUDE_DIR}) project(iio-monitor C) add_executable(iio-monitor iio-monitor.c) @@ -63,6 +74,8 @@ if (PTHREAD_LIBRARIES iio-monitor iio ${PTHREAD_LIBRARIES} ${CURSES_LIBRARY} ${CDK_LIBRARY} ) set(IIO_TESTS_TARGETS ${IIO_TESTS_TARGETS} iio-monitor) +else() + message(STATUS "Curses Development Kit (CDK) missing or too old, skipping iio-monitor") endif () set_target_properties( diff --git a/examples/iio-monitor.c b/examples/iio-monitor.c index ef3c99183..6b38cc4d4 100644 --- a/examples/iio-monitor.c +++ b/examples/iio-monitor.c @@ -134,7 +134,7 @@ static struct { { "power", "W" }, { "temp", "°C" }, { "voltage", "V" }, - { 0, }, + { NULL, NULL }, }; static const char *id_to_unit(const char *id) @@ -265,18 +265,25 @@ static struct iio_context *show_contexts_screen(void) } for (i = 0; i < num_contexts; i++) { - asprintf(&items[i], "%s [%s]", YELLOW, + ret = asprintf(&items[i], "%s [%s]", YELLOW, iio_context_info_get_description(info[i]), YELLOW, BLUE, iio_context_info_get_uri(info[i]), BLUE); + if (ret < 0) { + fprintf(stderr, "asprintf failed, out of memory?\n"); + break; + } + } + if (ret < 0) { + break; } items[i] = "Enter location"; list = newCDKScroll(screen, LEFT, TOP, RIGHT, 0, 0, "\n Select a IIO context to use:\n", - items, num_contexts + 1, TRUE, + (CDK_CSTRING2) items, num_contexts + 1, TRUE, A_BOLD | A_REVERSE, TRUE, FALSE); drawCDKScroll(list, TRUE); @@ -298,7 +305,7 @@ static struct iio_context *show_contexts_screen(void) ctx = iio_create_context_from_uri(uri); if (ctx == NULL) { char *msg[] = { "Failed to create IIO context." }; - popupLabel(screen, msg, 1); + popupLabel(screen, (CDK_CSTRING2)msg, 1); } if (free_uri) @@ -364,7 +371,7 @@ static void show_main_screen(struct iio_context *ctx) boxWindow(right, 0); list = newCDKScroll(screen, LEFT, TOP, RIGHT, 0, 0, "\n List of available IIO devices:\n", - dev_names, nb_devices, FALSE, + (CDK_CSTRING2) dev_names, nb_devices, FALSE, A_BOLD | A_REVERSE, TRUE, FALSE); drawCDKScroll(list, TRUE); From 8d7fd5201f951ca025be18842228fdd4f6e778df Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Mon, 27 Apr 2020 00:40:21 -0400 Subject: [PATCH 3/4] iio_stresstest: was including by accident. The GNU C Library version 2.30 includes: The Linux-specific header and the sysctl function have been deprecated and will be removed from a future version of glibc. Application should directly access /proc instead. iio_stresstest was not actually using anything, so remove it. Signed-off-by: Robin Getz --- tests/iio_stresstest.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/iio_stresstest.c b/tests/iio_stresstest.c index 042f98795..ed7cd372b 100644 --- a/tests/iio_stresstest.c +++ b/tests/iio_stresstest.c @@ -28,7 +28,6 @@ #include #include #include -#include #include "iio_common.h" From 0b3949de83fa19aef0c82a2b6826a8177f49bf11 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Mon, 27 Apr 2020 08:52:10 -0400 Subject: [PATCH 4/4] Cmake: Turn on -Werror for CI system For environments which have TRAVIS=1 and CI=1, add -Werrror to the CFLAGS. This will ensure that any warnings are caught easier on the CI system that we use. (At least with GCC). Signed-off-by: Robin Getz --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4f3c43f6..de8bc675a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,9 @@ if (CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") endif() endif() + if(DEFINED ENV{TRAVIS} AND DEFINED ENV{CI}) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + endif() endif() if(APPLE)