Skip to content

Commit

Permalink
Remove the config.h.in and do things through compile defs (#103)
Browse files Browse the repository at this point in the history
* Remove the config.h.in and do things through compile defs

* Improve CMake a little

* Rename NETWORK_POSIX_TCP -> NETWORK_CHANNEL_TCP_POSIX
  • Loading branch information
erlingrj authored Oct 26, 2024
1 parent dedbf16 commit 82e72f6
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 34 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
cmake-build-debug
cmake-build-release
.idea
include/reactor-uc/config.h
!lfc/bin

26 changes: 13 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ set(BUILD_UNIT_TESTS OFF CACHE BOOL "Build unit tests")
set(TEST_COVERAGE OFF CACHE BOOL "Compute test coverage")
set(ASAN OFF CACHE BOOL "Compile with AddressSanitizer")
set(PLATFORM "POSIX" CACHE STRING "Platform to target")
set(EVENT_QUEUE_SIZE 10 CACHE STRING "Static size of the event queue")
set(REACTION_QUEUE_SIZE 10 CACHE STRING "Static size of the reaction queue")
set(NETWORK_POSIX_TCP OFF CACHE BOOL "Use POSIX TCP NetworkChannel")
set(EVENT_QUEUE_SIZE 32 CACHE STRING "Static size of the event queue")
set(REACTION_QUEUE_SIZE 32 CACHE STRING "Static size of the reaction queue")
set(NETWORK_CHANNEL_TCP_POSIX OFF CACHE BOOL "Use POSIX TCP NetworkChannel")

# Code coverage setup
if(TEST_COVERAGE)
Expand All @@ -30,7 +30,7 @@ endif()
if(BUILD_TESTS)
set(BUILD_LF_TESTS ON)
set(BUILD_UNIT_TESTS ON)
set(NETWORK_POSIX_TCP ON) # TODO: This is currently needed because one of the tests uses this stack, we need a nicer way of selecting build options for tests and apps.
set(NETWORK_CHANNEL_TCP_POSIX ON) # TODO: This is currently needed because one of the tests uses this stack, we need a nicer way of selecting build options for tests and apps.
set(CMAKE_BUILD_TYPE "Debug")
find_program(CLANG_TIDY clang-tidy)
if (CLANG_TIDY)
Expand Down Expand Up @@ -68,21 +68,21 @@ else ()
message(FATAL_ERROR "No valid platform specified")
endif ()

add_compile_definitions("PLATFORM_${PLATFORM}")
# TODO: Improve this here
if(NETWORK_POSIX_TCP)
target_compile_definitions(reactor-uc PRIVATE NETWORK_POSIX_TCP)
# Add compile definitions for platform and network channel specifics.
target_compile_definitions(reactor-uc PRIVATE "PLATFORM_${PLATFORM}")

# Add compile definitions for event and reaction queue sizes. Has to be PUBLIC because they are used in the header files.
target_compile_definitions(reactor-uc PUBLIC EVENT_QUEUE_SIZE=${EVENT_QUEUE_SIZE})
target_compile_definitions(reactor-uc PUBLIC REACTION_QUEUE_SIZE=${REACTION_QUEUE_SIZE})

if(NETWORK_CHANNEL_TCP_POSIX)
target_compile_definitions(reactor-uc PRIVATE NETWORK_CHANNEL_TCP_POSIX)
endif()

target_compile_options(reactor-uc PRIVATE -Wall -Wextra -Werror)
add_compile_options (-fdiagnostics-color=always)
target_include_directories(reactor-uc PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include ${CMAKE_CURRENT_LIST_DIR}/external)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/reactor-uc/config.h.in
${CMAKE_CURRENT_SOURCE_DIR}/include/reactor-uc/config.h
)

if(BUILD_UNIT_TESTS)
set(UNITY_DIR ${CMAKE_CURRENT_LIST_DIR}/external/Unity)
include(CTest)
Expand Down
2 changes: 1 addition & 1 deletion examples/posix/federated/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20.0)
project(reactor-uc-posix-hello)

set(PLATFORM "POSIX" CACHE STRING "")
set(NETWORK_POSIX_TCP ON CACHE STRING "")
set(NETWORK_CHANNEL_TCP_POSIX ON CACHE STRING "")
add_subdirectory(../../../ reactor-uc)

add_executable(sender sender.c)
Expand Down
2 changes: 1 addition & 1 deletion examples/riot/blinky/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ DEVELHELP ?= 1
QUIET ?= 1

# Enable reactor-uc features
CFLAGS += -DNETWORK_POSIX_TCP
CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX

include $(CURDIR)/../../../make/riot/riot.mk
2 changes: 1 addition & 1 deletion examples/riot/hello/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ DEVELHELP ?= 1
QUIET ?= 1

# Enable reactor-uc features
# CFLAGS += -DNETWORK_POSIX_TCP
# CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX

include $(CURDIR)/../../../make/riot/riot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(reactor-uc-zephyr)

# TODO: Improve the way of pickng which Network channels to add to the build.
set(NETWORK_POSIX_TCP ON CACHE BOOL "blah")
set(NETWORK_CHANNEL_TCP_POSIX ON CACHE BOOL "blah")
set(PLATFORM "ZEPHYR" CACHE STRING "Platform to target")
add_subdirectory(../../../../ reactor-uc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(reactor-uc-zephyr)

# TODO: Improve the way of pickng which Network channels to add to the build.
set(NETWORK_POSIX_TCP ON CACHE BOOL "blah")
set(NETWORK_CHANNEL_TCP_POSIX ON CACHE BOOL "blah")
set(PLATFORM "ZEPHYR" CACHE STRING "Platform to target")
add_subdirectory(../../../../ reactor-uc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(reactor-uc-zephyr)

# TODO: Improve the way of pickng which Network channels to add to the build.
set(NETWORK_POSIX_TCP ON CACHE BOOL "blah")
set(NETWORK_CHANNEL_TCP_POSIX ON CACHE BOOL "blah")
set(PLATFORM "ZEPHYR" CACHE STRING "Platform to target")
add_subdirectory(../../../../ reactor-uc)

Expand Down
9 changes: 0 additions & 9 deletions include/reactor-uc/config.h.in

This file was deleted.

1 change: 0 additions & 1 deletion include/reactor-uc/queues.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef REACTOR_UC_QUEUES_H
#define REACTOR_UC_QUEUES_H

#include "reactor-uc/config.h"
#include "reactor-uc/error.h"
#include "reactor-uc/event.h"
#include "reactor-uc/reaction.h"
Expand Down
4 changes: 2 additions & 2 deletions make/riot/external_modules/reactor-uc/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ USEMODULE += ztimer64_usec
USEMODULE += nanopb
USEMODULE += proto

# If Feature NETWORK_POSIX_TCP is enabled
ifeq ($(filter -DNETWORK_POSIX_TCP, $(CFLAGS)), -DNETWORK_POSIX_TCP)
# If Feature NETWORK_CHANNEL_TCP_POSIX is enabled
ifeq ($(filter -DNETWORK_CHANNEL_TCP_POSIX, $(CFLAGS)), -DNETWORK_CHANNEL_TCP_POSIX)
# Enable networking
USEMODULE += netdev_default
USEMODULE += auto_init_gnrc_netif
Expand Down
24 changes: 22 additions & 2 deletions src/network_channel.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
#ifdef NETWORK_POSIX_TCP
#if defined(PLATFORM_POSIX)
#ifdef NETWORK_CHANNEL_TCP_POSIX
#include "platform/posix/tcp_ip_channel.c"
#endif
#endif

#elif defined(PLATFORM_ZEPHYR)
#ifdef NETWORK_CHANNEL_TCP_POSIX
#include "platform/posix/tcp_ip_channel.c"
#endif

#elif defined(PLATFORM_RIOT)
#ifdef NETWORK_CHANNEL_TCP_POSIX
#include "platform/posix/tcp_ip_channel.c"
#endif

#elif defined(PLATFORM_PICO)
#ifdef NETWORK_CHANNEL_TCP_POSIX
#error "NETWORK_POSIC_TCP not supported on PICO"
#endif

#else
#error "Platform not supported"
#endif

0 comments on commit 82e72f6

Please sign in to comment.