Override compile options set by FreeRTOS-Plus-TCP

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.

Hi @apcountryman
Welcome to FreeRTOS community!

Thank you for pointing out the issue. Let us discuss it internally and update to you.

Hi @apcountryman

We would like to suggest that it would be better to resolve the issue in the similar way as done in kernel in PR 872, We can add it to the CI checks easily and it will also remain uniform across FreeRTOS repos.

If that is the case, I will need guidance on what changes to make. FreeRTOS-Kernel PR 872 simply moved the target_compile_options() call for freertos_kernel from the root CMakeLists.txt file to the one for the existing CMake example (examples/cmake_example/CMakeLists.txt), and added a CI job for the CMake example. FreeRTOS-Plus-TCP does not have an existing CMake example to move compile options configuration to.

Also, it looks like the solution I originally proposed will not work since the root of the FreeRTOS-Plus-TCP repository is not the root of the CMake source tree for the repository’s CI jobs.

@apcountryman

You can move the compile options from the root CMakeLists.txt to this CMakeLists.txt file:

target_compile_options(freertos_plus_tcp PRIVATE
    ### 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>
)

This CMake project is used to test the various build combinations in the CI.

Thanks for the info Tony.

For the benefit of any future readers, this issue has been resolved by the merging of Move CMake compile options to test builds by apcountryman · Pull Request #1115 · FreeRTOS/FreeRTOS-Plus-TCP · GitHub.

1 Like

Thank you @apcountryman for providing quick PR.