From a87bd33aa7be1f46ad70f060b0b9f1f10fb229a1 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Thu, 7 Dec 2023 12:41:08 +0100 Subject: [PATCH] iiod: Support compiling without v0.x compatibility Add WITH_IIOD_V0_COMPAT option, which defaults to ON. When set to OFF, IIOD won't support the old ASCII protocol of Libiio v0.x, and will only support the new binary protocol of Libiio v1.x. Signed-off-by: Paul Cercueil --- README_BUILD.md | 1 + iio-config.h.cmakein | 1 + iiod/CMakeLists.txt | 27 ++++++++++++++++----------- iiod/interpreter.c | 4 +++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README_BUILD.md b/README_BUILD.md index 22913ba9e..d6cb32fa6 100644 --- a/README_BUILD.md +++ b/README_BUILD.md @@ -107,6 +107,7 @@ Cmake Options | Default | Description | `WITH_IIOD` | ON | Build the IIO Daemon | `WITH_IIOD_SERIAL` | ON | Add serial (UART) support | `WITH_IIOD_USBD` | ON | Add support for USB through FunctionFS within IIOD | +`WITH_IIOD_V0_COMPAT` | ON | Add support for Libiio v0.x protocol and clients | `WITH_AIO` | ON | Build IIOD with async. I/O support | `WITH_SYSTEMD` | OFF | Enable installation of systemd service file for iiod | `SYSTEMD_UNIT_INSTALL_DIR` | /lib/systemd/system | default install path for systemd unit files | diff --git a/iio-config.h.cmakein b/iio-config.h.cmakein index 9b617105b..1d186246d 100644 --- a/iio-config.h.cmakein +++ b/iio-config.h.cmakein @@ -30,6 +30,7 @@ #cmakedefine01 WITH_NETWORK_EVENTFD #cmakedefine01 WITH_IIOD_USBD #cmakedefine01 WITH_IIOD_SERIAL +#cmakedefine01 WITH_IIOD_V0_COMPAT #cmakedefine01 WITH_LOCAL_CONFIG #cmakedefine01 WITH_LOCAL_DMABUF_API #cmakedefine01 WITH_LOCAL_MMAP_API diff --git a/iiod/CMakeLists.txt b/iiod/CMakeLists.txt index 3a6dd99b3..ec4ed61ff 100644 --- a/iiod/CMakeLists.txt +++ b/iiod/CMakeLists.txt @@ -1,15 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(iiod C) -include(FindBISON) -include(FindFLEX) - -flex_target(lexer - ${CMAKE_CURRENT_SOURCE_DIR}/lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.c) -bison_target(parser - ${CMAKE_CURRENT_SOURCE_DIR}/parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.c) -add_flex_bison_dependency(lexer parser) - include(CheckSymbolExists) set(CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARIES}) set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) @@ -21,8 +12,7 @@ set(CMAKE_REQUIRED_LIBRARIES) set(CMAKE_REQUIRED_DEFINITIONS) add_executable(iiod - iiod.c interpreter.c ops.c responder.c thread-pool.c - ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS} + iiod.c interpreter.c responder.c thread-pool.c ) set_target_properties(iiod PROPERTIES C_STANDARD 99 @@ -41,6 +31,20 @@ if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") set_source_files_properties(${BISON_parser_OUTPUTS} PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") endif () +option(WITH_IIOD_V0_COMPAT "Build support for Libiio v0.x protocol" ON) +if (WITH_IIOD_V0_COMPAT) + include(FindBISON) + include(FindFLEX) + + flex_target(lexer + ${CMAKE_CURRENT_SOURCE_DIR}/lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.c) + bison_target(parser + ${CMAKE_CURRENT_SOURCE_DIR}/parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.c) + add_flex_bison_dependency(lexer parser) + + target_sources(iiod PRIVATE ops.c ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS}) +endif (WITH_IIOD_V0_COMPAT) + option(WITH_AIO "Build IIOD with async. I/O support" ON) if (WITH_AIO) find_library(LIBAIO_LIBRARIES aio) @@ -133,6 +137,7 @@ if (WITH_UPSTART) endif() toggle_iio_feature("${WITH_IIOD_SERIAL}" iiod-serial) +toggle_iio_feature("${WITH_IIOD_V0_COMPAT}" iiod-v0-compat) toggle_iio_feature("${WITH_AIO}" iiod-aio) toggle_iio_feature("${WITH_IIOD_USBD}" iiod-usb) toggle_iio_feature("${WITH_SYSTEMD}" iiod-systemd) diff --git a/iiod/interpreter.c b/iiod/interpreter.c index ac6d670de..7e6c94a34 100644 --- a/iiod/interpreter.c +++ b/iiod/interpreter.c @@ -243,6 +243,7 @@ void interpreter(struct iio_context *ctx, int fd_in, int fd_out, bool verbose, pdata.fd_out = fd_out; pdata.verbose = verbose; pdata.pool = pool; + pdata.binary = !WITH_IIOD_V0_COMPAT; pdata.xml_zstd = xml_zstd; pdata.xml_zstd_len = xml_zstd_len; @@ -287,7 +288,8 @@ void interpreter(struct iio_context *ctx, int fd_in, int fd_out, bool verbose, pdata.writefd = writefd_io; } - ascii_interpreter(&pdata, verbose); + if (WITH_IIOD_V0_COMPAT) + ascii_interpreter(&pdata, verbose); if (pdata.binary) binary_parse(&pdata);