I figured it would be a good idea to discuss this here before implementing the proposed change. I originally had links to the relevant code and PRs but had to remove them since I am a new user.
FreeRTOS-Plus-TCP/CMakeLists.txt currently sets the compile options used to compile FreeRTOS-Plus-TCP and its dependencies. This can cause problems if a compiler doesn’t support some of these options, or these options trigger compilation errors in FreeRTOS-Plus-TCP or its dependencies. In my specific case (building the GCC_ARM_CM4F port with arm-none-eabi-gcc 9.2.1 on Ubuntu 20.04), I am getting the following error (which I suspect is a false positive):
build/_deps/freertos_kernel-src/portable/GCC/ARM_CM4F/port.c:391:36: error: conversion from 'int' to 'uint8_t' {aka 'volatile unsigned char'} may change value [-Werror=conversion]
ucMaxPriorityValue <<= ( uint8_t ) 0x01;
As far as I am aware the only way a user can override the compile options set by FreeRTOS-Plus-TCP/CMakeLists.txt at this time is to patch that file. A similar problem with the FreeRTOS-Kernel code was addressed by no longer setting compile options in the project’s root CMakeLists.txt file (see PR 872 “Move cmake compile options to the example project”). My proposal for addressing this problem in FreeRTOS-Plus-TCP is to wrap the setting of compile options in a conditional as follows:
if( "${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}" )
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>:-Werror>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wpedantic>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wconversion>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wunused-variable>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>
# Suppressions required to build clean with clang.
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-qual>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-switch-enum>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-declaration-after-statement>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-padded>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-variable-declarations>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-covered-switch-default>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-extra-semi-stmt>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-noreturn>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align>
)
endif()
I’d be happy to submit this change if the FreeRTOS-Plus-TCP maintainers are on board with this approach.