|
| 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() |
0 commit comments