Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: support old Cmake for -std=c99 #462

Merged
merged 4 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
message(STATUS "cmake verison: ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 2.8.7)
project(libiio C)

Expand Down Expand Up @@ -77,6 +78,16 @@ 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()
if(DEFINED ENV{TRAVIS} AND DEFINED ENV{CI})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()
endif()

if(APPLE)
Expand Down
13 changes: 13 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,26 @@ 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})
Comment on lines +60 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, there's a possibility that cdk.h exists but at the same time not include symbol CDK_CSTRING2?
If yes, then cmake should print a message with the reason why iio-monitor will not be included in the build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On old versions of CDK - it doesn't do it. I can add a message there.

endif()

if(HAS_CDK_CSTRING2)
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)
else()
message(STATUS "Curses Development Kit (CDK) missing or too old, skipping iio-monitor")
endif ()

set_target_properties(
Expand Down
17 changes: 12 additions & 5 deletions examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static struct {
{ "power", "W" },
{ "temp", "°C" },
{ "voltage", "V" },
{ 0, },
{ NULL, NULL },
};

static const char *id_to_unit(const char *id)
Expand Down Expand Up @@ -265,18 +265,25 @@ static struct iio_context *show_contexts_screen(void)
}

for (i = 0; i < num_contexts; i++) {
asprintf(&items[i], "</%d>%s<!%d> </%d>[%s]<!%d>", YELLOW,
ret = asprintf(&items[i], "</%d>%s<!%d> </%d>[%s]<!%d>", 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);
Expand All @@ -298,7 +305,7 @@ static struct iio_context *show_contexts_screen(void)
ctx = iio_create_context_from_uri(uri);
if (ctx == NULL) {
char *msg[] = { "</16>Failed to create IIO context.<!16>" };
popupLabel(screen, msg, 1);
popupLabel(screen, (CDK_CSTRING2)msg, 1);
}

if (free_uri)
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion tests/iio_stresstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <errno.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/sysctl.h>

#include "iio_common.h"

Expand Down