Skip to content

Commit 8926945

Browse files
tony-josi-awsphelteramazonKamathactions-user
authored
CMake changes from main branch [PR: FreeRTOS#557, PR: FreeRTOS#742] (FreeRTOS#803)
* 556 Initial Cmake Module definition. FreeRTOS#557 * renaming variables that have conflicting names with MSC and *nix headers * fix build issue for posix port * Fix warning: -Waddress-of-packed-member when calculating checksum directly from network packets * fix warnings with prvInitialiseTCPFields declaration * removing macros that hides the structure fields * Updating build check enable all config to enable all config macros * CMake: Fix GIT_REPOSITORY and GIT_TAG (FreeRTOS#742) * moving ipTRUE_BOOL and ipFALSE_BOOL out of #ifndef pdTRUE_SIGNED check as they are not defined in kernel * minor fix to the cmake files and main file * Uncrustify: triggered by comment. * adding doxygen comments to new functions * Uncrustify: triggered by comment * Add more warnings check and fix warnings * Uncrustify: triggered by comment * fix review feedback and more debug printf warnings fix * more warnings fix * fix misra issues * Uncrustify: triggered by comment * replace sin_addr with sin_address.ulIP_IPv4 in +TCP demos * replace sin_addr6 with sin_address.xIP_IPv6 in +TCP demos * replace freertos_sockaddr6 with freertos_sockaddr in +TCP demos * review feedback changes * removing duplicate def for prvStreamBufferAdd from winpcap * fix more warnings from MSVC * Uncrustify: triggered by comment * review feedback changes * Uncrustify: triggered by comment --------- Co-authored-by: phelter <[email protected]> Co-authored-by: Nikhil Kamath <[email protected]> Co-authored-by: GitHub Action <[email protected]>
1 parent de62c2c commit 8926945

File tree

68 files changed

+1706
-368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1706
-368
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- name: Clone This Repo
5252
uses: actions/checkout@v2
5353
with:
54-
path: ./tcp
54+
path: ./tcp
5555
- name: Install spell
5656
run: |
5757
sudo apt-get install spell
@@ -111,23 +111,23 @@ jobs:
111111
runs-on: ubuntu-latest
112112
steps:
113113
- uses: actions/checkout@v2
114-
- name: Update submodules
115-
run: git submodule update --init --checkout
114+
- name: Build Install Dependencies
115+
run: |
116+
sudo apt-get install -y libpcap-dev
116117
- name: Build checks (Enable all functionalities)
117118
run: |
118-
cmake -S test/build-combination -B test/build-combination/build/ \
119-
-DTEST_CONFIGURATION=ENABLE_ALL
120-
make -C test/build-combination/build/
119+
cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL
120+
cmake --build build --target freertos_plus_tcp_build_test
121121
- name: Build checks (Disable all functionalities)
122122
run: |
123-
cmake -S test/build-combination -B test/build-combination/build/ \
124-
-DTEST_CONFIGURATION=DISABLE_ALL
125-
make -C test/build-combination/build/
123+
cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DISABLE_ALL
124+
cmake --build build --target clean
125+
cmake --build build --target freertos_plus_tcp_build_test
126126
- name: Build checks (Default configuration)
127127
run: |
128-
cmake -S test/build-combination -B test/build-combination/build/ \
129-
-DTEST_CONFIGURATION=DEFAULT_CONF
130-
make -C test/build-combination/build/
128+
cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DEFAULT_CONF
129+
cmake --build build --target clean
130+
cmake --build build --target freertos_plus_tcp_build_test
131131
132132
complexity:
133133
runs-on: ubuntu-latest

CMakeLists.txt

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
2+
cmake_minimum_required(VERSION 3.15)
3+
cmake_policy(SET CMP0048 NEW) # project version
4+
cmake_policy(SET CMP0076 NEW) # full paths
5+
6+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
7+
8+
########################################################################
9+
# Project Details
10+
project(FreeRTOS-Plus-TCP
11+
VERSION 3.1.0
12+
DESCRIPTION "FreeRTOS TCP/UDP Network Layer"
13+
HOMEPAGE_URL https://freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html
14+
LANGUAGES C)
15+
16+
# Do not allow in-source build.
17+
if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
18+
message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
19+
endif()
20+
21+
# Options
22+
option(FREERTOS_PLUS_TCP_BUILD_TEST "Build the test for FreeRTOS Plus TCP" OFF)
23+
24+
# Configuration
25+
# Override these at project level with:
26+
# Optional: set(FREERTOS_PLUS_TCP_BUFFER_ALLOCATION "1" CACHE STRING "" FORCE)
27+
# Optional: set(FREERTOS_PLUS_TCP_COMPILER "" CACHE STRING "" FORCE)
28+
# Required: set(FREERTOS_PLUS_TCP_NETWORK_IF "POSIX" CACHE STRING "" FORCE)
29+
30+
# Select the appropriate buffer allocaiton method.
31+
# See: https://freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Ethernet_Buffer_Management.html
32+
if (NOT FREERTOS_PLUS_TCP_BUFFER_ALLOCATION)
33+
message(STATUS "Using default FREERTOS_PLUS_TCP_BUFFER_ALLOCATION = 2")
34+
set(FREERTOS_PLUS_TCP_BUFFER_ALLOCATION "2" CACHE STRING "FreeRTOS buffer allocation model number. 1 .. 2.")
35+
endif()
36+
37+
# Select the Compiler - if left blank will detect using CMake
38+
# Note relies on CMake to detect over any setting here.
39+
# Valid options are:
40+
# FREERTOS_PLUS_TCP_COMPILER | Detected | CMake
41+
# -------------------------------------------------
42+
# CCS | No | ?TBD?
43+
# GCC | Yes | GNU
44+
# IAR | Yes | IAR
45+
# Keil | Yes | ARMCC
46+
# MSVC | Yes | MSVC # Note only for MinGW
47+
# Renesas | No | ?TBD?
48+
# Will always a attempt to detect and if detectable double checks that the compiler is set correctly.
49+
set(FREERTOS_PLUS_TCP_COMPILER "" CACHE STRING "FreeRTOS Plus TCP Compiler Selection")
50+
51+
52+
# Select the appropriate network interface
53+
# This will fail the CMake preparation step if not set to one of those values.
54+
set(FREERTOS_PLUS_TCP_NETWORK_IF "" CACHE STRING "FreeRTOS Plus TCP Network Interface selection")
55+
set(FREERTOS_PLUS_TCP_NETWORK_IF_LIST
56+
A_CUSTOM_NETWORK_IF
57+
ATSAM43 ATSAME5x # AT
58+
DRIVER_SAM
59+
ESP32
60+
KSZ8851SNL
61+
LPC17xx LPC18xx LPC54018
62+
M487
63+
MPS2_AN385
64+
MW300_RD
65+
PIC32MZEF_ETH PIC32MZEF_WIFI
66+
POSIX WIN_PCAP # Native Linux & Windows respectively
67+
RX
68+
SH2A
69+
STM32FXX STM32HXX # ST Micro
70+
MSP432
71+
TM4C
72+
XILINX_ULTRASCALE ZYNQ # AMD/Xilinx
73+
)
74+
if(NOT FREERTOS_PLUS_TCP_NETWORK_IF)
75+
# Attempt to detect the system.
76+
if(UNIX)
77+
message(STATUS "Detected UNIX/Posix system setting FREERTOS_PLUS_TCP_NETWORK_IF = POSIX")
78+
set(FREERTOS_PLUS_TCP_NETWORK_IF POSIX)
79+
elseif(MINGW)
80+
message(STATUS "Detected Windows MinGW system setting FREERTOS_PLUS_TCP_NETWORK_IF = WIN_PCAP")
81+
set(FREERTOS_PLUS_TCP_NETWORK_IF WIN_PCAP)
82+
endif()
83+
endif()
84+
85+
if(NOT FREERTOS_PLUS_TCP_NETWORK_IF IN_LIST FREERTOS_PLUS_TCP_NETWORK_IF_LIST )
86+
message(FATAL_ERROR " FREERTOS_PLUS_TCP_NETWORK_IF is '${FREERTOS_PLUS_TCP_NETWORK_IF}'.\n"
87+
" Please specify it from top-level CMake file (example):\n"
88+
" set(FREERTOS_PLUS_TCP_NETWORK_IF POSIX CACHE STRING \"\")\n"
89+
" or from CMake command line option:\n"
90+
" -DFREERTOS_PLUS_TCP_NETWORK_IF=POSIX\n"
91+
" \n"
92+
" Available port options: (Tested means compiled with that variant)\n"
93+
" A_CUSTOM_NETWORK_IF Target: User Defined\n"
94+
" ATSAM4E Target: ATSAM4E Tested: TODO\n"
95+
" ATSAME5x Target: ATSAME5x Tested: TODO\n"
96+
" DRIVER_SAM Target: Driver SAM Tested: TODO\n"
97+
" ESP32 Target: ESP-32 Tested: TODO\n"
98+
" KSZ8851SNL Target: ksz8851snl Tested: TODO\n"
99+
" POSIX Target: linux/Posix\n"
100+
" LPC17xx Target: LPC17xx Tested: TODO\n"
101+
" LPC18xx Target: LPC18xx Tested: TODO\n"
102+
" LPC54018 Target: LPC54018 Tested: TODO\n"
103+
" M487 Target: M487 Tested: TODO\n"
104+
" MPS2_AN385 Target: MPS2_AN385 Tested: TODO\n"
105+
" MW300_RD Target: mw300_rd Tested: TODO\n"
106+
" PIC32MZEF_ETH Target: pic32mzef ethernet Tested: TODO\n"
107+
" PIC32MZEF_WIFI Target: pic32mzef Wifi Tested: TODO\n"
108+
" RX Target: RX Tested: TODO\n"
109+
" SH2A Target: SH2A Tested: TODO\n"
110+
" STM32FXX Target: STM32Fxx Tested: TODO\n"
111+
" STM32HXX Target: STM32Hxx Tested: TODO\n"
112+
" MSP432 Target: MSP432 Tested: TODO\n"
113+
" TM4C Target: TM4C Tested: TODO\n"
114+
" WIN_PCAP Target: Windows Tested: TODO\n"
115+
" XILINX_ULTRASCALE Target: Xilinx Ultrascale Tested: TODO\n"
116+
" ZYNQ Target: Xilinx Zynq")
117+
elseif((FREERTOS_PORT STREQUAL "A_CUSTOM_PORT") AND (NOT TARGET freertos_kernel_port) )
118+
message(FATAL_ERROR " FREERTOS_PLUS_TCP_NETWORK_IF is set to A_CUSTOM_NETWORK_IF.\n"
119+
" Please specify the custom network interface target with all necessary files.\n"
120+
" For example, assuming a directory of:\n"
121+
" FreeRTOSCustomNetworkInterface/\n"
122+
" CMakeLists.txt\n"
123+
" NetworkInterface.c\n\n"
124+
" Where FreeRTOSCustomNetworkInterface/CMakeLists.txt is a modified version of:\n"
125+
" add_library(freertos_plus_tcp_network_if STATIC)\n\n"
126+
" target_sources(freertos_plus_tcp_network_if\n"
127+
" PRIVATE\n"
128+
" NetworkInterface.c)\n\n"
129+
" target_include_directories(freertos_plus_tcp_network_if\n"
130+
" PUBLIC\n"
131+
" .)\n\n"
132+
" taget_link_libraries(freertos_plus_tcp_network_if\n"
133+
" PUBLIC\n"
134+
" freertos_plus_tcp_port\n"
135+
" freertos_plus_tcp_network_if_common\n"
136+
" PRIVATE\n"
137+
" freertos_kernel)")
138+
endif()
139+
140+
# There is also the need to add a target - typically an interface library that describes the
141+
# Configuration for FreeRTOS-Kernel and FreeRTOS-Plus-TCP.
142+
# This is called freertos_config
143+
# If not defined will be default compile with one of the test build combinations AllEnable.
144+
145+
# Select the appropriate Build Test configuration
146+
# This is only used when freertos_config is not defined, otherwise the build test will be performed
147+
# on the config defined in the freertos_config
148+
set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION "CUSTOM" CACHE STRING "FreeRTOS Plus TCP Build Test configuration")
149+
set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST
150+
CUSTOM # Custom (external) configuration -eg from a top-level project
151+
ENABLE_ALL # Enable all configuration settings
152+
DISABLE_ALL # Disable all configuration settings
153+
DEFAULT_CONF # Default (typical) configuration
154+
)
155+
if(NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION IN_LIST FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST)
156+
message(FATAL_ERROR "Invalid FREERTOS_PLUS_TCP_TEST_CONFIGURATION value '${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}' should be one of: ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST}")
157+
else()
158+
message(STATUS "Using FreeRTOS-Plus-TCP Test Configuration : ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}")
159+
if (NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION STREQUAL "CUSTOM")
160+
message(WARNING "FreeRTOS-Kernel configuration settings are configured by FreeRTOS-Plus-TCP")
161+
endif()
162+
endif()
163+
164+
########################################################################
165+
# Requirements
166+
set(CMAKE_C_STANDARD 90) # Note FreeRTOS-Kernel uses C99 constructs.
167+
set(CMAKE_C_STANDARD_REQUIRED ON)
168+
169+
########################################################################
170+
# Overall Compile Options
171+
# Note the compile option strategy is to error on everything and then
172+
# Per library opt-out of things that are warnings/errors.
173+
# This ensures that no matter what strategy for compilation you take, the
174+
# builds will still occur.
175+
#
176+
# Only tested with GNU and Clang.
177+
# Other options are https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_%3CLANG%3E_COMPILER_ID
178+
# Naming of compilers translation map:
179+
# For the ?TBD? - Suggest trying GNU-based and adding the appropriate toolchain file.
180+
# For Toolchain examples see _deps/cmake-src/toolchain/arm-none-eabil-gcc.toolchain.cmake
181+
#
182+
# FreeRTOS | CMake
183+
# -------------------
184+
# CCS | ?TBD?
185+
# GCC | GNU, Clang, *Clang Others?
186+
# IAR | IAR
187+
# Keil | ARMCC
188+
# MSVC | MSVC # Note only for MinGW?
189+
# Renesas | ?TBD?
190+
191+
add_compile_options(
192+
### Gnu/Clang C Options
193+
$<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>
194+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-fcolor-diagnostics>
195+
196+
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wall>
197+
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wextra>
198+
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wpedantic>
199+
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Werror>
200+
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wunused-variable>
201+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>
202+
203+
# TODO: Add in other Compilers here.
204+
)
205+
206+
########################################################################
207+
# External Dependencies
208+
# Note: For backwards compatibility - still have .gitmodules defining submodules
209+
# To support fetching content in a higher level project see
210+
# README.md `Consume with CMake`
211+
# This will allow you to upgrade submodules and have one common submodule for
212+
# all your builds despite multiple submodules having different versions.
213+
include(FetchContent)
214+
215+
FetchContent_Declare( freertos_kernel
216+
GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
217+
GIT_TAG main
218+
)
219+
220+
FetchContent_Declare( cmock
221+
GIT_REPOSITORY https://github.com/ThrowTheSwitch/CMock
222+
GIT_TAG v2.5.3
223+
)
224+
225+
add_subdirectory(source)
226+
add_subdirectory(tools)
227+
add_subdirectory(test)
228+
229+
FetchContent_MakeAvailable(freertos_kernel cmock)
230+
231+
# Note following are can be removed once FreeRTOS-Kernel v10.5.0 + fixes their issues.
232+
# To ignore header specific issues - change all of the headers to SYSTEM
233+
set(_freertos_kernel_targets freertos_kernel freertos_kernel_port)
234+
# foreach (_target ${_freertos_kernel_targets} )
235+
# get_target_property( interface_directories ${_target} INTERFACE_INCLUDE_DIRECTORIES )
236+
# set_target_properties(${_target} PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${interface_directories}" )
237+
# endforeach()

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,40 @@ Once python is downloaded and installed, you can verify the version from your te
3939
To run the script, you should switch to the FreeRTOS-Plus-TCP directory that was created using the [Cloning this repository](#cloning-this-repository) step above.
4040
And then run `python <Path/to/the/script>/GenerateOriginalFiles.py`.
4141

42-
## Cloning this repository
42+
## To consume FreeRTOS+TCP
43+
44+
### Consume with CMake
45+
If using CMake, it is recommended to use this repository using FetchContent.
46+
Add the following into your project's main or a subdirectory's `CMakeLists.txt`:
47+
48+
- Define the source and version/tag you want to use:
49+
50+
```cmake
51+
FetchContent_Declare( freertos_plus_tcp
52+
GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git
53+
GIT_TAG master #Note: Best practice to use specific git-hash or tagged version
54+
GIT_SUBMODULES "" # Don't grab any submodules since not latest
55+
)
56+
```
57+
58+
- Configure the FreeRTOS-Kernel and make it available
59+
- this particular example supports a native and cross-compiled build option.
60+
61+
```cmake
62+
set( FREERTOS_PLUS_FAT_DEV_SUPPORT OFF CACHE BOOL "" FORCE)
63+
# Select the native compile PORT
64+
set( FREERTOS_PLUS_FAT_PORT "POSIX" CACHE STRING "" FORCE)
65+
# Select the cross-compile PORT
66+
if (CMAKE_CROSSCOMPILING)
67+
# Eg. Zynq 2019_3 version of port
68+
set(FREERTOS_PLUS_FAT_PORT "ZYNQ_2019_3" CACHE STRING "" FORCE)
69+
endif()
70+
71+
FetchContent_MakeAvailable(freertos_plus_tcp)
72+
```
73+
74+
### Consuming stand-alone
75+
4376
This repository uses [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to bring in dependent components.
4477

4578
Note: If you download the ZIP file provided by GitHub UI, you will not get the contents of the submodules. (The ZIP file is also not a valid Git repository)

cmake_modules/FindPCAP.cmake

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# - Try to find libpcap include dirs and libraries
2+
#
3+
# Usage of this module as follows:
4+
#
5+
# find_package(PCAP)
6+
#
7+
# Variables used by this module, they can change the default behaviour and need
8+
# to be set before calling find_package:
9+
#
10+
# PCAP_ROOT_DIR Set this variable to the root installation of
11+
# libpcap if the module has problems finding the
12+
# proper installation path.
13+
#
14+
# Variables defined by this module:
15+
#
16+
# PCAP_FOUND System has libpcap, include and library dirs found
17+
# PCAP_INCLUDE_DIR The libpcap include directories.
18+
# PCAP_LIBRARY The libpcap library (possibly includes a thread
19+
# library e.g. required by pf_ring's libpcap)
20+
# HAVE_PF_RING If a found version of libpcap supports PF_RING
21+
22+
find_path(PCAP_ROOT_DIR
23+
NAMES include/pcap.h
24+
)
25+
26+
find_path(PCAP_INCLUDE_DIR
27+
NAMES pcap.h
28+
HINTS ${PCAP_ROOT_DIR}/include
29+
)
30+
31+
find_library(PCAP_LIBRARY
32+
NAMES pcap
33+
HINTS ${PCAP_ROOT_DIR}/lib
34+
)
35+
36+
include(FindPackageHandleStandardArgs)
37+
find_package_handle_standard_args(PCAP DEFAULT_MSG
38+
PCAP_LIBRARY
39+
PCAP_INCLUDE_DIR
40+
)
41+
42+
include(CheckCSourceCompiles)
43+
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
44+
check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
45+
set(CMAKE_REQUIRED_LIBRARIES)
46+
47+
# check if linking against libpcap also needs to link against a thread library
48+
if (NOT PCAP_LINKS_SOLO)
49+
find_package(Threads)
50+
if (THREADS_FOUND)
51+
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
52+
check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS)
53+
set(CMAKE_REQUIRED_LIBRARIES)
54+
endif ()
55+
if (THREADS_FOUND AND PCAP_NEEDS_THREADS)
56+
set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
57+
list(REMOVE_DUPLICATES _tmp)
58+
set(PCAP_LIBRARY ${_tmp}
59+
CACHE STRING "Libraries needed to link against libpcap" FORCE)
60+
else ()
61+
message(FATAL_ERROR "Couldn't determine how to link against libpcap")
62+
endif ()
63+
endif ()
64+
65+
include(CheckFunctionExists)
66+
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
67+
check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
68+
check_function_exists(pcap_dump_open_append HAVE_PCAP_DUMP_OPEN_APPEND)
69+
set(CMAKE_REQUIRED_LIBRARIES)
70+
71+
mark_as_advanced(
72+
PCAP_ROOT_DIR
73+
PCAP_INCLUDE_DIR
74+
PCAP_LIBRARY
75+
)

0 commit comments

Comments
 (0)