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

#556 Initial Cmake Module definition. #557

Merged
merged 27 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4c292eb
#556 Initial Cmake Module definition.
phelter Sep 23, 2022
20ea305
Fixing CI builds, rely on pcap. (#556)
phelter Sep 25, 2022
5f15260
Updating tested configurations and minor clean-up of missing network …
phelter Sep 29, 2022
dad63ec
Further clean-up based on testing with build environment. (#555)
phelter Sep 30, 2022
5560d9b
Using single definition for libraries everywhere. (#555)
phelter Sep 30, 2022
4cf6101
Fixing A_CUSTOM_NETWORK_IF compile option.
phelter Oct 6, 2022
88739fd
Identifying and fixing compile issues.
phelter Oct 6, 2022
ca51334
Merge branch 'main' into feature/cmake-support
AniruddhaKanhere Oct 10, 2022
cf5aa7f
Merge branch 'main' into feature/cmake-support
phelter Oct 23, 2022
afb1e28
Adding in additional warnings for GNU to ignore for now.
phelter Oct 23, 2022
27a9f4f
Fixing formatting issues with uncrustify.
phelter Oct 23, 2022
ecc9d85
More warnings for GNU used by CI/CD pipeline.
phelter Oct 23, 2022
88c5872
Assuming custom for build tests and using latest freertos-kernel code…
phelter Oct 24, 2022
c46edd8
Fixing up issues identified in the PR. Making the build_test EXCLUDE_…
phelter Nov 3, 2022
7845936
Merge branch 'main' into feature/cmake-support
AniruddhaKanhere Nov 4, 2022
9f6ca62
Changing to support C89 instead of C99. Renaming tcp_tools to tcp_uti…
phelter Nov 5, 2022
e846d3c
Using C90 ISO. Fixing compiler warnings.
phelter Nov 5, 2022
c3bc360
Fixing non C90 compliant declaration after statement
phelter Nov 5, 2022
7957c29
Separating out CMakeLists so each port is independent.
phelter Nov 5, 2022
50d2e8b
Updating warning list in code.
phelter Nov 5, 2022
eb9653a
Fixed formatting with uncrustify.
phelter Nov 5, 2022
4fdb9fe
Merge branch 'main' into feature/cmake-support
phelter Nov 12, 2022
c193574
Merge branch 'main' into feature/cmake-support
AniruddhaKanhere Feb 15, 2023
57d3364
Merge branch 'main' into feature/cmake-support
AniruddhaKanhere Feb 23, 2023
79985b2
Fix failing tests
AniruddhaKanhere Feb 23, 2023
f12741d
Fix failing unit-test
AniruddhaKanhere Feb 23, 2023
97a3c4d
Fix a typo.
AniruddhaKanhere Feb 23, 2023
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
17 changes: 7 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Clone This Repo
uses: actions/checkout@v2
with:
path: ./tcp
path: ./tcp
- name: Install spell
run: |
sudo apt-get install spell
Expand Down Expand Up @@ -115,19 +115,16 @@ jobs:
run: git submodule update --init --checkout
- name: Build checks (Enable all functionalities)
run: |
cmake -S test/build-combination -B test/build-combination/build/ \
-DTEST_CONFIGURATION=ENABLE_ALL
make -C test/build-combination/build/
cmake -S . -B build/ -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL
make -C build/
- name: Build checks (Disable all functionalities)
run: |
cmake -S test/build-combination -B test/build-combination/build/ \
-DTEST_CONFIGURATION=DISABLE_ALL
make -C test/build-combination/build/
cmake -S . -B build/ -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DISABLE_ALL
make -C build/
- name: Build checks (Default configuration)
run: |
cmake -S test/build-combination -B test/build-combination/build/ \
-DTEST_CONFIGURATION=DEFAULT_CONF
make -C test/build-combination/build/
cmake -S . -B build/ -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DEFAULT_CONF
make -C build/

complexity:
runs-on: ubuntu-latest
Expand Down
279 changes: 279 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@

cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0048 NEW) # project version
cmake_policy(SET CMP0076 NEW) # full paths

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")

########################################################################
# Project Details
project(FreeRTOS-Plus-TCP
VERSION 3.1.0
DESCRIPTION "FreeRTOS TCP/UDP Network Layer"
HOMEPAGE_URL https://freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html
LANGUAGES C)

# Do not allow in-source build.
if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
phelter marked this conversation as resolved.
Show resolved Hide resolved
message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
endif()

# Options
option(FREERTOS_PLUS_TCP_BUILD_TEST "Build the test for FreeRTOS Plus TCP" OFF)

# Configuration
# Override these at project level with:
# Optional: set(FREERTOS_PLUS_TCP_BUFFER_ALLOCATION "1" CACHE STRING "" FORCE)
# Optional: set(FREERTOS_PLUS_TCP_COMPILER "" CACHE STRING "" FORCE)
# Required: set(FREERTOS_PLUS_TCP_NETWORK_IF "POSIX" CACHE STRING "" FORCE)

# Select the appropriate buffer allocaiton method.
# See: https://freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Ethernet_Buffer_Management.html
if (NOT FREERTOS_PLUS_TCP_BUFFER_ALLOCATION)
phelter marked this conversation as resolved.
Show resolved Hide resolved
message(STATUS "Using default FREERTOS_PLUS_TCP_BUFFER_ALLOCATION = 2")
set(FREERTOS_PLUS_TCP_BUFFER_ALLOCATION "2" CACHE STRING "FreeRTOS buffer allocation model number. 1 .. 2.")
endif()

# Select the Compiler - if left blank will detect using CMake
# Note relies on CMake to detect over any setting here.
# Valid options are:
# FREERTOS_PLUS_TCP_COMPILER | Detected | CMake
# -------------------------------------------------
# CCS | No | ?TBD?
# GCC | Yes | GNU
# IAR | Yes | IAR
# Keil | Yes | ARMCC
# MSVC | Yes | MSVC # Note only for MinGW
# Renesas | No | ?TBD?
# Will always a attempt to detect and if detectable double checks that the compiler is set correctly.
set(FREERTOS_PLUS_TCP_COMPILER "" CACHE STRING "FreeRTOS Plus TCP Compiler Selection")


# Select the appropriate network interface
# This will fail the CMake preparation step if not set to one of those values.
set(FREERTOS_PLUS_TCP_NETWORK_IF "" CACHE STRING "FreeRTOS Plus TCP Network Interface selection")
phelter marked this conversation as resolved.
Show resolved Hide resolved
set(FREERTOS_PLUS_TCP_NETWORK_IF_LIST
A_CUSTOM_NETWORK_IF
ATSAM43 ATSAME5x # AT
DRIVER_SAM
ESP32
KSZ8851SNL
LPC17xx LPC18xx LPC54018
M487
MPS2_AN385
MW300_RD
PIC32MZEF_ETH PIC32MZEF_WIFI
POSIX WIN_PCAP # Native Linux & Windows respectively
RX
SH2A
STM32FXX STM32HXX # ST Micro
MSP432
TM4C
XILINX_ULTRASCALE ZYNQ # AMD/Xilinx
)
if(NOT FREERTOS_PLUS_TCP_NETWORK_IF)
# Attempt to detect the system.
if(UNIX)
message(STATUS "Detected UNIX/Posix system setting FREERTOS_PLUS_TCP_NETWORK_IF = POSIX")
set(FREERTOS_PLUS_TCP_NETWORK_IF POSIX)
elseif(MINGW)
message(STATUS "Detected Windows MinGW system setting FREERTOS_PLUS_TCP_NETWORK_IF = WIN_PCAP")
set(FREERTOS_PLUS_TCP_NETWORK_IF WIN_PCAP)
endif()
endif()

if(NOT FREERTOS_PLUS_TCP_NETWORK_IF IN_LIST FREERTOS_PLUS_TCP_NETWORK_IF_LIST )
message(FATAL_ERROR " FREERTOS_PLUS_TCP_NETWORK_IF is '${FREERTOS_PLUS_TCP_NETWORK_IF}'.\n"
" Please specify it from top-level CMake file (example):\n"
" set(FREERTOS_PLUS_TCP_NETWORK_IF POSIX CACHE STRING \"\")\n"
" or from CMake command line option:\n"
" -DFREERTOS_PLUS_TCP_NETWORK_IF=POSIX\n"
" \n"
" Available port options:\n"
" A_CUSTOM_NETWORK_IF Target: User Defined\n"
" ATSAM4E Target: ATSAM4E - TODO\n"
" ATSAME5x Target: ATSAME5x - TODO\n"
" DRIVER_SAM Target: Driver SAM - TODO\n"
" ESP32 Target: ESP-32 - TODO\n"
" KSZ8851SNL Target: ksz8851snl - TODO\n"
" POSIX Target: linux/Posix\n"
" LPC17xx Target: LPC17xx - TODO\n"
" LPC18xx Target: LPC18xx - TODO\n"
" LPC54018 Target: LPC54018 - TODO\n"
" M487 Target: M487- TODO\n"
" MPS2_AN385 Target: MPS2_AN385 - TODO\n"
" MW300_RD Target: mw300_rd - TODO\n"
" PIC32MZEF_ETH Target: pic32mzef ethernet- TODO\n"
" PIC32MZEF_WIFI Target: pic32mzef Wifi- TODO\n"
" RX Target: RX- TODO\n"
" SH2A Target: SH2A- TODO\n"
" STM32FXX Target: STM32Fxx - TODO\n"
" STM32HXX Target: STM32Hxx - TODO\n"
" MSP432 Target: MSP432 - TODO\n"
" TM4C Target: TM4C- TODO\n"
" WIN_PCAP Target: Windows - TODO\n"
" XILINX_ULTRASCALE Target: Xilinx Ultrascale - TODO\n"
" ZYNQ Target: Xilinx Zynq")
elseif((FREERTOS_PORT STREQUAL "A_CUSTOM_PORT") AND (NOT TARGET freertos_kernel_port) )
message(FATAL_ERROR " FREERTOS_PLUS_TCP_NETWORK_IF is set to A_CUSTOM_NETWORK_IF.\n"
" Please specify the custom network interface target with all necessary files.\n"
" For example, assuming a directory of:\n"
" FreeRTOSCustomNetworkInterface/\n"
" CMakeLists.txt\n"
" NetworkInterface.c\n\n"
" Where FreeRTOSCustomNetworkInterface/CMakeLists.txt is a modified version of:\n"
" add_library(freertos_plus_tcp_network_if STATIC)\n\n"
" target_sources(freertos_plus_tcp_network_if\n"
" PRIVATE\n"
" NetworkInterface.c)\n\n"
" target_include_directories(freertos_plus_tcp_network_if\n"
" PUBLIC\n"
" .)\n\n"
" taget_link_libraries(freertos_plus_tcp_network_if\n"
" PRIVATE\n"
" freertos_kernel)")
endif()

# There is also the need to add a target - typically an interface library that describes the
# Configuration for FreeRTOS-Kernel and FreeRTOS-Plus-TCP.
# This is called FreeRTOS::Config
# If not defined will be default compile with one of the test build combinations AllEnable.

# Select the appropriate Build Test configuration
# This is only used when FreeRTOS::Config is not defined, otherwise the build test will be performed
# on the config defined in the FreeRTOS::Config
set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION "DEFAULT_CONF" CACHE STRING "FreeRTOS Plus TCP Build Test configuration")
set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST
CUSTOM # Custom (external) configuration -eg from a top-level project
ENABLE_ALL # Enable all configuration settings
DISABLE_ALL # Disable all configuration settings
DEFAULT_CONF # Default (typical) configuration)
)
if(NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION IN_LIST FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST)
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}")
else()
message(WARNING "Using FreeRTOS-Plus-TCP Test Configuration : ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}"
" FreeRTOS-Kernel configuration settings are configured by FreeRTOS-Plus-TCP")
if (NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION STREQUAL "CUSTOM")
# Configuration for FreeRTOS-Kernel
set(FREERTOS_CONFIG_FILE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/test/build-combination/Common" CACHE STRING "" FORCE)
if(UNIX)
set(FREERTOS_PORT GCC_POSIX CACHE STRING "" FORCE)
elseif(MINGW)
set(FREERTOS_PORT MSVC_MINGW CACHE STRING "" FORCE)
endif()
endif()
endif()

########################################################################
# Requirements
set(CMAKE_C_STANDARD 99) # Note FreeRTOS-Kernel uses C99 constructs.
phelter marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_C_STANDARD_REQUIRED ON)

########################################################################
# Overall Compile Options
# Note the compile option strategy is to error on everything and then
# Per library opt-out of things that are warnings/errors.
# This ensures that no matter what strategy for compilation you take, the
# builds will still occur.
#
# Only tested with GNU and Clang.
# Other options are https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_%3CLANG%3E_COMPILER_ID
# Naming of compilers translation map:
# For the ?TBD? - Suggest trying GNU-based and adding the appropriate toolchain file.
# For Toolchain examples see _deps/cmake-src/toolchain/arm-none-eabil-gcc.toolchain.cmake
#
# FreeRTOS | CMake
# -------------------
# CCS | ?TBD?
# GCC | GNU, Clang, *Clang Others?
# IAR | IAR
# Keil | ARMCC
# MSVC | MSVC # Note only for MinGW?
# Renesas | ?TBD?

add_compile_options(
### Gnu/Clang C Options
$<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-fcolor-diagnostics>

$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wall>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wextra>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wpedantic>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Werror>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>

# Documentation types - add unrecognized but supported doxygen commands
# $<$<COMPILE_LANG_AND_ID:C,Clang>:-fcomment-block-commands=retval>
# $<$<COMPILE_LANG_AND_ID:C,Clang>:-fcomment-block-commands=copydetails>

# TODO: Add in other Compilers here.
)

########################################################################
# External Dependencies
# Note: For backwards compatibility - still have .gitmodules defining submodules
# To support fetching content in a higher level project add:
#
# FetchContent_Declare( freertos_plus_tcp
# GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git
# GIT_TAG V3.0.0
# GIT_SUBMODULES "" # Don't grab any submodules - rely on FetchContent
# )
#
# This will allow you to upgrade submodules and have one common submodule for
# all your builds despite multiple submodules having different versions.
include(FetchContent)

FetchContent_Declare( freertos_kernel
GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
GIT_TAG V10.5.0
)

FetchContent_Declare( cmock
GIT_REPOSITORY https://github.com/ThrowTheSwitch/CMock
GIT_TAG v2.5.3
)

add_subdirectory(source)
add_subdirectory(tools)
add_subdirectory(test)

FetchContent_MakeAvailable(freertos_kernel cmock)

# Note following are can be removed once FreeRTOS-Kernel v10.5.0 + fixes their issues.
# To ignore header specific issues - change all of the headers to SYSTEM
set(_freertos_kernel_targets freertos_kernel freertos_kernel_port)
foreach (_target ${_freertos_kernel_targets} )
get_target_property( interface_directories ${_target} INTERFACE_INCLUDE_DIRECTORIES )
set_target_properties(${_target} PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${interface_directories}" )
endforeach()
target_compile_options( freertos_kernel
PRIVATE
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-covered-switch-default>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-documentation>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-extra-semi-stmt>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-int-to-pointer-cast>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-noreturn>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-variable-declarations>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-padded>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-pointer-to-int-cast>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-shorten-64-to-32>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-sign-conversion>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wno-unused-variable>
)
target_compile_options( freertos_kernel_port
PRIVATE
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-disabled-macro-expansion>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-documentation>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-noreturn>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-variable-declarations>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-padded>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-pointer-to-int-cast>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-reserved-macro-identifier>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-sign-conversion>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-type-limits>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
)
75 changes: 75 additions & 0 deletions cmake_modules/FindPCAP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# - Try to find libpcap include dirs and libraries
#
# Usage of this module as follows:
#
# find_package(PCAP)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# PCAP_ROOT_DIR Set this variable to the root installation of
# libpcap if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# PCAP_FOUND System has libpcap, include and library dirs found
# PCAP_INCLUDE_DIR The libpcap include directories.
# PCAP_LIBRARY The libpcap library (possibly includes a thread
# library e.g. required by pf_ring's libpcap)
# HAVE_PF_RING If a found version of libpcap supports PF_RING

find_path(PCAP_ROOT_DIR
NAMES include/pcap.h
)

find_path(PCAP_INCLUDE_DIR
NAMES pcap.h
HINTS ${PCAP_ROOT_DIR}/include
)

find_library(PCAP_LIBRARY
NAMES pcap
HINTS ${PCAP_ROOT_DIR}/lib
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PCAP DEFAULT_MSG
PCAP_LIBRARY
PCAP_INCLUDE_DIR
)

include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
set(CMAKE_REQUIRED_LIBRARIES)

# check if linking against libpcap also needs to link against a thread library
if (NOT PCAP_LINKS_SOLO)
find_package(Threads)
if (THREADS_FOUND)
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS)
set(CMAKE_REQUIRED_LIBRARIES)
endif ()
if (THREADS_FOUND AND PCAP_NEEDS_THREADS)
set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
list(REMOVE_DUPLICATES _tmp)
set(PCAP_LIBRARY ${_tmp}
CACHE STRING "Libraries needed to link against libpcap" FORCE)
else ()
message(FATAL_ERROR "Couldn't determine how to link against libpcap")
endif ()
endif ()

include(CheckFunctionExists)
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
check_function_exists(pcap_dump_open_append HAVE_PCAP_DUMP_OPEN_APPEND)
set(CMAKE_REQUIRED_LIBRARIES)

mark_as_advanced(
PCAP_ROOT_DIR
PCAP_INCLUDE_DIR
PCAP_LIBRARY
)
Loading