xref: /FreeRTOS-Plus-TCP-v4.0.0/CMakeLists.txt (revision df5aed9e58a72e2489b6c1936788885672c62981)
1
2cmake_minimum_required(VERSION 3.15)
3cmake_policy(SET CMP0048 NEW) # project version
4cmake_policy(SET CMP0076 NEW) # full paths
5
6list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
7
8########################################################################
9# Project Details
10project(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.
17if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
18message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
19endif()
20
21# Options
22option(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
32if (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.")
35endif()
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.
49set(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.
54set(FREERTOS_PLUS_TCP_NETWORK_IF "" CACHE STRING "FreeRTOS Plus TCP Network Interface selection")
55set(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)
74if(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()
83endif()
84
85if(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")
117elseif((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)")
138endif()
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
148set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION "CUSTOM" CACHE STRING "FreeRTOS Plus TCP Build Test configuration")
149set(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    ENABLE_ALL_IPV4         # Enable all configuration settings IPv4 UDP
153    ENABLE_ALL_IPV6         # Enable all configuration settings IPv6 UDP
154    ENABLE_ALL_IPV4_TCP     # Enable all configuration settings IPv4 TCP
155    ENABLE_ALL_IPV6_TCP     # Enable all configuration settings IPv6 TCP
156    ENABLE_ALL_IPV4_IPV6    # Enable all configuration settings IPv4 IPv6 UDP
157    DISABLE_ALL             # Disable all configuration settings
158    HEADER_SELF_CONTAIN     # Enable header self contain test
159    DEFAULT_CONF            # Default (typical) configuration
160)
161if(NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION IN_LIST FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST)
162    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}")
163else()
164    message(STATUS "Using FreeRTOS-Plus-TCP Test Configuration : ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}")
165    if (NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION STREQUAL "CUSTOM")
166        message(WARNING "FreeRTOS-Kernel configuration settings are configured by FreeRTOS-Plus-TCP")
167    endif()
168endif()
169
170########################################################################
171# Overall Compile Options
172# Note the compile option strategy is to error on everything and then
173# Per library opt-out of things that are warnings/errors.
174# This ensures that no matter what strategy for compilation you take, the
175# builds will still occur.
176#
177# Only tested with GNU and Clang.
178# Other options are https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_%3CLANG%3E_COMPILER_ID
179# Naming of compilers translation map:
180# For the ?TBD? - Suggest trying GNU-based and adding the appropriate toolchain file.
181#   For Toolchain examples see _deps/cmake-src/toolchain/arm-none-eabil-gcc.toolchain.cmake
182#
183#   FreeRTOS    | CMake
184#   -------------------
185#   CCS         | ?TBD?
186#   GCC         | GNU, Clang, *Clang Others?
187#   IAR         | IAR
188#   Keil        | ARMCC
189#   MSVC        | MSVC # Note only for MinGW?
190#   Renesas     | ?TBD?
191
192add_compile_options(
193    ### Gnu/Clang C Options
194    $<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>
195    $<$<COMPILE_LANG_AND_ID:C,Clang>:-fcolor-diagnostics>
196
197    $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wall>
198    $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wextra>
199    $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Werror>
200    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wpedantic>
201    $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wconversion>
202    $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wunused-variable>
203    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>
204
205    # Suppressions required to build clean with clang.
206    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
207    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-qual>
208    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-switch-enum>
209    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-declaration-after-statement>
210    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-padded>
211    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-variable-declarations>
212    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-covered-switch-default>
213    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-extra-semi-stmt>
214    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-noreturn>
215    $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align>
216)
217
218########################################################################
219# External Dependencies
220# Note: For backwards compatibility - still have .gitmodules defining submodules
221# To support fetching content in a higher level project see
222#   README.md `Consume with CMake`
223# This will allow you to upgrade submodules and have one common submodule for
224# all your builds despite multiple submodules having different versions.
225include(FetchContent)
226
227FetchContent_Declare( freertos_kernel
228  GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
229  GIT_TAG        main
230)
231
232FetchContent_Declare( cmock
233  GIT_REPOSITORY https://github.com/ThrowTheSwitch/CMock
234  GIT_TAG        v2.5.3
235)
236
237add_subdirectory(source)
238add_subdirectory(tools)
239add_subdirectory(test)
240
241FetchContent_MakeAvailable(freertos_kernel cmock)
242
243# Note following are can be removed once FreeRTOS-Kernel v10.5.0 + fixes their issues.
244# To ignore header specific issues - change all of the headers to SYSTEM
245set(_freertos_kernel_targets freertos_kernel freertos_kernel_port)
246# foreach (_target ${_freertos_kernel_targets} )
247#   get_target_property( interface_directories ${_target} INTERFACE_INCLUDE_DIRECTORIES )
248#   set_target_properties(${_target}  PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${interface_directories}" )
249# endforeach()
250