CMake default compiler options and Microchip XC16 compatibility


I’m working on a project where I’m using a custom CMake-based build system for PIC24FJ256GA7 MCU.

I’ve added the freeRTOS repository as a git submodule into my project but after configuring my CMake to make use of it i faced the compiler options issues…

In the FreeRTOS repository CMakeLists.txt file, there are such options:

target_compile_options(freertos_kernel PRIVATE
    ### Gnu/Clang C Options


    # Suppressions required to build clean with clang.

To make my build pass a had to cut out these three options:

The first two seems to not be supported by the XC16 compiler at all…

[build] elf-cc1: error: unrecognized command line option “-Wpedantic”
[build] elf-cc1: error: unrecognized command line option “-fdiagnostics-color=always”

And the -Werror was causing the SIZE_MAX macro redefinition error… It is strange for me because the SIZE_MAX macro is redefined in the portmacro.h file which is also provided by the freeRTOS repo and it seems like a default choice to use it.

I’m wondering if anyone could suggest to me the best way of handling it?

For now, I’ve just commented it out and created a git patch file which is being applied at the beginning of every build but I would like to know a better solution than modifying the submodule…

Hi @eMKa94,
Welcome to FreeRTOS community!

Thanks for reporting this back to us. We’re going to discuss this internally.
Will get back to you with conclusion. For now, please use git patch as workaround.


1 Like

Hi @eMKa94,
Sorry for late response. We’ve merged Kernel PR#872 to not set compile options by default. You can still pick your options by command target_compile_options(freertos_kernel PRIVATE ...) in your cmake file. Take cmake_example as example.


1 Like