]> begriffs open source - freertos/blob - CMakeLists.txt
Fix possible integer overflow (#836)
[freertos] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.15)
2
3 # User is responsible to one mandatory option:
4 #   FREERTOS_PORT, if not specified and native port detected, uses the native compile.
5 #
6 # User is responsible for one library target:
7 #   freertos_config ,typically an INTERFACE library
8 #
9 # DEPRECATED: FREERTOS_CONFIG_FILE_DIRECTORY - but still supported if no freertos_config defined for now.
10 #             May be removed at some point in the future.
11 # User can choose which heap implementation to use (either the implementations
12 # included with FreeRTOS [1..5] or a custom implementation ) by providing the
13 # option FREERTOS_HEAP. If the option is not set, the cmake will default to
14 # using heap_4.c.
15
16 # `freertos_config` target defines the path to FreeRTOSConfig.h and optionally other freertos based config files
17 if(NOT TARGET freertos_config )
18     if (NOT DEFINED FREERTOS_CONFIG_FILE_DIRECTORY )
19
20         message(FATAL_ERROR " freertos_config target not specified.  Please specify a cmake target that defines the include directory for FreeRTOSConfig.h:\n"
21             "  add_library(freertos_config INTERFACE)\n"
22             "  target_include_directories(freertos_config SYSTEM\n"
23             "    INTERFACE\n"
24             "      include) # The config file directory\n"
25             "  target_compile_definitions(freertos_config\n"
26             "    PUBLIC\n"
27             "    projCOVERAGE_TEST=0)\n")
28     else()
29         message(WARNING " Using deprecated 'FREERTOS_CONFIG_FILE_DIRECTORY' - please update your project CMakeLists.txt file:\n"
30             "  add_library(freertos_config INTERFACE)\n"
31             "  target_include_directories(freertos_config SYSTEM\n"
32             "    INTERFACE\n"
33             "      include) # The config file directory\n"
34             "  target_compile_definitions(freertos_config\n"
35             "    PUBLIC\n"
36             "    projCOVERAGE_TEST=0)\n")
37     endif()
38 endif()
39
40 # Heap number or absolute path to custom heap implementation provided by user
41 set(FREERTOS_HEAP "4" CACHE STRING "FreeRTOS heap model number. 1 .. 5. Or absolute path to custom heap source file")
42
43 # FreeRTOS port option
44 if(NOT FREERTOS_PORT)
45     message(WARNING " FREERTOS_PORT is not set. Please specify it from top-level CMake file (example):\n"
46         "  set(FREERTOS_PORT GCC_ARM_CM4F CACHE STRING \"\")\n"
47         " or from CMake command line option:\n"
48         "  -DFREERTOS_PORT=GCC_ARM_CM4F\n"
49         " \n"
50         " Available port options:\n"
51         " A_CUSTOM_PORT                    - Compiler: User Defined  Target: User Defined\n"
52         " BCC_16BIT_DOS_FLSH186            - Compiler: BCC           Target: 16 bit DOS Flsh186\n"
53         " BCC_16BIT_DOS_PC                 - Compiler: BCC           Target: 16 bit DOS PC\n"
54         " CCS_ARM_CM3                      - Compiler: CCS           Target: ARM Cortex-M3\n"
55         " CCS_ARM_CM4F                     - Compiler: CCS           Target: ARM Cortex-M4 with FPU\n"
56         " CCS_ARM_CR4                      - Compiler: CCS           Target: ARM Cortex-R4\n"
57         " CCS_MSP430X                      - Compiler: CCS           Target: MSP430X\n"
58         " CODEWARRIOR_COLDFIRE_V1          - Compiler: CoreWarrior   Target: ColdFire V1\n"
59         " CODEWARRIOR_COLDFIRE_V2          - Compiler: CoreWarrior   Target: ColdFire V2\n"
60         " CODEWARRIOR_HCS12                - Compiler: CoreWarrior   Target: HCS12\n"
61         " GCC_ARM_CA9                      - Compiler: GCC           Target: ARM Cortex-A9\n"
62         " GCC_ARM_CA53_64_BIT              - Compiler: GCC           Target: ARM Cortex-A53 64 bit\n"
63         " GCC_ARM_CA53_64_BIT_SRE          - Compiler: GCC           Target: ARM Cortex-A53 64 bit SRE\n"
64         " GCC_ARM_CM0                      - Compiler: GCC           Target: ARM Cortex-M0\n"
65         " GCC_ARM_CM3                      - Compiler: GCC           Target: ARM Cortex-M3\n"
66         " GCC_ARM_CM3_MPU                  - Compiler: GCC           Target: ARM Cortex-M3 with MPU\n"
67         " GCC_ARM_CM4_MPU                  - Compiler: GCC           Target: ARM Cortex-M4 with MPU\n"
68         " GCC_ARM_CM4F                     - Compiler: GCC           Target: ARM Cortex-M4 with FPU\n"
69         " GCC_ARM_CM7                      - Compiler: GCC           Target: ARM Cortex-M7\n"
70         " GCC_ARM_CM23_NONSECURE           - Compiler: GCC           Target: ARM Cortex-M23 non-secure\n"
71         " GCC_ARM_CM23_SECURE              - Compiler: GCC           Target: ARM Cortex-M23 secure\n"
72         " GCC_ARM_CM23_NTZ_NONSECURE       - Compiler: GCC           Target: ARM Cortex-M23 non-trustzone non-secure\n"
73         " GCC_ARM_CM33_NONSECURE           - Compiler: GCC           Target: ARM Cortex-M33 non-secure\n"
74         " GCC_ARM_CM33_SECURE              - Compiler: GCC           Target: ARM Cortex-M33 secure\n"
75         " GCC_ARM_CM33_NTZ_NONSECURE       - Compiler: GCC           Target: ARM Cortex-M33 non-trustzone non-secure\n"
76         " GCC_ARM_CM33_TFM                 - Compiler: GCC           Target: ARM Cortex-M33 non-secure for TF-M\n"
77         " GCC_ARM_CM35P_NONSECURE          - Compiler: GCC           Target: ARM Cortex-M35P non-secure\n"
78         " GCC_ARM_CM35P_SECURE             - Compiler: GCC           Target: ARM Cortex-M35P secure\n"
79         " GCC_ARM_CM35P_NTZ_NONSECURE      - Compiler: GCC           Target: ARM Cortex-M35P non-trustzone non-secure\n"
80         " GCC_ARM_CM55_NONSECURE           - Compiler: GCC           Target: ARM Cortex-M55 non-secure\n"
81         " GCC_ARM_CM55_SECURE              - Compiler: GCC           Target: ARM Cortex-M55 secure\n"
82         " GCC_ARM_CM55_NTZ_NONSECURE       - Compiler: GCC           Target: ARM Cortex-M55 non-trustzone non-secure\n"
83         " GCC_ARM_CM55_TFM                 - Compiler: GCC           Target: ARM Cortex-M55 non-secure for TF-M\n"
84         " GCC_ARM_CM85_NONSECURE           - Compiler: GCC           Target: ARM Cortex-M85 non-secure\n"
85         " GCC_ARM_CM85_SECURE              - Compiler: GCC           Target: ARM Cortex-M85 secure\n"
86         " GCC_ARM_CM85_NTZ_NONSECURE       - Compiler: GCC           Target: ARM Cortex-M85 non-trustzone non-secure\n"
87         " GCC_ARM_CM85_TFM                 - Compiler: GCC           Target: ARM Cortex-M85 non-secure for TF-M\n"
88         " GCC_ARM_CR5                      - Compiler: GCC           Target: ARM Cortex-R5\n"
89         " GCC_ARM_CRX_NOGIC                - Compiler: GCC           Target: ARM Cortex-Rx no GIC\n"
90         " GCC_ARM7_AT91FR40008             - Compiler: GCC           Target: ARM7 Atmel AT91R40008\n"
91         " GCC_ARM7_AT91SAM7S               - Compiler: GCC           Target: ARM7 Atmel AT91SAM7S\n"
92         " GCC_ARM7_LPC2000                 - Compiler: GCC           Target: ARM7 LPC2000\n"
93         " GCC_ARM7_LPC23XX                 - Compiler: GCC           Target: ARM7 LPC23xx\n"
94         " GCC_ATMEGA323                    - Compiler: GCC           Target: ATMega323\n"
95         " GCC_AVR32_UC3                    - Compiler: GCC           Target: AVR32 UC3\n"
96         " GCC_COLDFIRE_V2                  - Compiler: GCC           Target: ColdFire V2\n"
97         " GCC_CORTUS_APS3                  - Compiler: GCC           Target: CORTUS APS3\n"
98         " GCC_H8S2329                      - Compiler: GCC           Target: H8S2329\n"
99         " GCC_HCS12                        - Compiler: GCC           Target: HCS12\n"
100         " GCC_IA32_FLAT                    - Compiler: GCC           Target: IA32 flat\n"
101         " GCC_MICROBLAZE                   - Compiler: GCC           Target: MicroBlaze\n"
102         " GCC_MICROBLAZE_V8                - Compiler: GCC           Target: MicroBlaze V8\n"
103         " GCC_MICROBLAZE_V9                - Compiler: GCC           Target: MicroBlaze V9\n"
104         " GCC_MSP430F449                   - Compiler: GCC           Target: MSP430F449\n"
105         " GCC_NIOSII                       - Compiler: GCC           Target: NiosII\n"
106         " GCC_PPC405_XILINX                - Compiler: GCC           Target: Xilinx PPC405\n"
107         " GCC_PPC440_XILINX                - Compiler: GCC           Target: Xilinx PPC440\n"
108         " GCC_RISC_V                       - Compiler: GCC           Target: RISC-V\n"
109         " GCC_RISC_V_PULPINO_VEGA_RV32M1RM - Compiler: GCC           Target: RISC-V Pulpino Vega RV32M1RM\n"
110         " GCC_RL78                         - Compiler: GCC           Target: Renesas RL78\n"
111         " GCC_RX100                        - Compiler: GCC           Target: Renesas RX100\n"
112         " GCC_RX200                        - Compiler: GCC           Target: Renesas RX200\n"
113         " GCC_RX600                        - Compiler: GCC           Target: Renesas RX600\n"
114         " GCC_RX600_V2                     - Compiler: GCC           Target: Renesas RX600 v2\n"
115         " GCC_RX700_V3_DPFPU               - Compiler: GCC           Target: Renesas RX700 v3 with DPFPU\n"
116         " GCC_STR75X                       - Compiler: GCC           Target: STR75x\n"
117         " GCC_TRICORE_1782                 - Compiler: GCC           Target: TriCore 1782\n"
118         " GCC_ARC_EM_HS                    - Compiler: GCC           Target: DesignWare ARC EM HS\n"
119         " GCC_ARC_V1                       - Compiler: GCC           Target: DesignWare ARC v1\n"
120         " GCC_ATMEGA                       - Compiler: GCC           Target: ATmega\n"
121         " GCC_POSIX                        - Compiler: GCC           Target: Posix\n"
122         " GCC_RP2040                       - Compiler: GCC           Target: RP2040 ARM Cortex-M0+\n"
123         " GCC_XTENSA_ESP32                 - Compiler: GCC           Target: Xtensa ESP32\n"
124         " GCC_AVRDX                        - Compiler: GCC           Target: AVRDx\n"
125         " GCC_AVR_MEGA0                    - Compiler: GCC           Target: AVR Mega0\n"
126         " IAR_78K0K                        - Compiler: IAR           Target: Renesas 78K0K\n"
127         " IAR_ARM_CA5_NOGIC                - Compiler: IAR           Target: ARM Cortex-A5 no GIC\n"
128         " IAR_ARM_CA9                      - Compiler: IAR           Target: ARM Cortex-A9\n"
129         " IAR_ARM_CM0                      - Compiler: IAR           Target: ARM Cortex-M0\n"
130         " IAR_ARM_CM3                      - Compiler: IAR           Target: ARM Cortex-M3\n"
131         " IAR_ARM_CM4F                     - Compiler: IAR           Target: ARM Cortex-M4 with FPU\n"
132         " IAR_ARM_CM4F_MPU                 - Compiler: IAR           Target: ARM Cortex-M4 with FPU and MPU\n"
133         " IAR_ARM_CM7                      - Compiler: IAR           Target: ARM Cortex-M7\n"
134         " IAR_ARM_CM23_NONSECURE           - Compiler: IAR           Target: ARM Cortex-M23 non-secure\n"
135         " IAR_ARM_CM23_SECURE              - Compiler: IAR           Target: ARM Cortex-M23 secure\n"
136         " IAR_ARM_CM23_NTZ_NONSECURE       - Compiler: IAR           Target: ARM Cortex-M23 non-trustzone non-secure\n"
137         " IAR_ARM_CM33_NONSECURE           - Compiler: IAR           Target: ARM Cortex-M33 non-secure\n"
138         " IAR_ARM_CM33_SECURE              - Compiler: IAR           Target: ARM Cortex-M33 secure\n"
139         " IAR_ARM_CM33_NTZ_NONSECURE       - Compiler: IAR           Target: ARM Cortex-M33 non-trustzone non-secure\n"
140         " IAR_ARM_CM35P_NONSECURE          - Compiler: IAR           Target: ARM Cortex-M35P non-secure\n"
141         " IAR_ARM_CM35P_SECURE             - Compiler: IAR           Target: ARM Cortex-M35P secure\n"
142         " IAR_ARM_CM35P_NTZ_NONSECURE      - Compiler: IAR           Target: ARM Cortex-M35P non-trustzone non-secure\n"
143         " IAR_ARM_CM55_NONSECURE           - Compiler: IAR           Target: ARM Cortex-M55 non-secure\n"
144         " IAR_ARM_CM55_SECURE              - Compiler: IAR           Target: ARM Cortex-M55 secure\n"
145         " IAR_ARM_CM55_NTZ_NONSECURE       - Compiler: IAR           Target: ARM Cortex-M55 non-trustzone non-secure\n"
146         " IAR_ARM_CM85_NONSECURE           - Compiler: IAR           Target: ARM Cortex-M85 non-secure\n"
147         " IAR_ARM_CM85_SECURE              - Compiler: IAR           Target: ARM Cortex-M85 secure\n"
148         " IAR_ARM_CM85_NTZ_NONSECURE       - Compiler: IAR           Target: ARM Cortex-M85 non-trustzone non-secure\n"
149         " IAR_ARM_CRX_NOGIC                - Compiler: IAR           Target: ARM Cortex-Rx no GIC\n"
150         " IAR_ATMEGA323                    - Compiler: IAR           Target: ATMega323\n"
151         " IAR_ATMEL_SAM7S64                - Compiler: IAR           Target: Atmel SAM7S64\n"
152         " IAR_ATMEL_SAM9XE                 - Compiler: IAR           Target: Atmel SAM9XE\n"
153         " IAR_AVR_AVRDX                    - Compiler: IAR           Target: AVRDx\n"
154         " IAR_AVR_MEGA0                    - Compiler: IAR           Target: AVR Mega0\n"
155         " IAR_AVR32_UC3                    - Compiler: IAR           Target: AVR32 UC3\n"
156         " IAR_LPC2000                      - Compiler: IAR           Target: LPC2000\n"
157         " IAR_MSP430                       - Compiler: IAR           Target: MSP430\n"
158         " IAR_MSP430X                      - Compiler: IAR           Target: MSP430X\n"
159         " IAR_RISC_V                       - Compiler: IAR           Target: RISC-V\n"
160         " IAR_RL78                         - Compiler: IAR           Target: Renesas RL78\n"
161         " IAR_RX100                        - Compiler: IAR           Target: Renesas RX100\n"
162         " IAR_RX600                        - Compiler: IAR           Target: Renesas RX600\n"
163         " IAR_RX700_V3_DPFPU               - Compiler: IAR           Target: Renesas RX700 v3 with DPFPU\n"
164         " IAR_RX_V2                        - Compiler: IAR           Target: Renesas RX v2\n"
165         " IAR_STR71X                       - Compiler: IAR           Target: STR71x\n"
166         " IAR_STR75X                       - Compiler: IAR           Target: STR75x\n"
167         " IAR_STR91X                       - Compiler: IAR           Target: STR91x\n"
168         " IAR_V850ES_FX3                   - Compiler: IAR           Target: Renesas V850ES/Fx3\n"
169         " IAR_V850ES_HX3                   - Compiler: IAR           Target: Renesas V850ES/Hx3\n"
170         " MIKROC_ARM_CM4F                  - Compiler: MikroC        Target: ARM Cortex-M4 with FPU\n"
171         " MPLAB_PIC18F                     - Compiler: MPLAB         Target: PIC18F\n"
172         " MPLAB_PIC24                      - Compiler: MPLAB         Target: PIC24\n"
173         " MPLAB_PIC32MEC14XX               - Compiler: MPLAB         Target: PIC32MEC14xx\n"
174         " MPLAB_PIC32MX                    - Compiler: MPLAB         Target: PIC32MX\n"
175         " MPLAB_PIC32MZ                    - Compiler: MPLAB         Target: PIC32MZ\n"
176         " MSVC_MINGW                       - Compiler: MSVC or MinGW Target: x86\n"
177         " OWATCOM_16BIT_DOS_FLSH186        - Compiler: Open Watcom   Target: 16 bit DOS Flsh186\n"
178         " OWATCOM_16BIT_DOS_PC             - Compiler: Open Watcom   Target: 16 bit DOS PC\n"
179         " PARADIGM_TERN_EE_LARGE           - Compiler: Paradigm      Target: Tern EE large\n"
180         " PARADIGM_TERN_EE_SMALL           - Compiler: Paradigm      Target: Tern EE small\n"
181         " RENESAS_RX100                    - Compiler: Renesas       Target: RX100\n"
182         " RENESAS_RX200                    - Compiler: Renesas       Target: RX200\n"
183         " RENESAS_RX600                    - Compiler: Renesas       Target: RX600\n"
184         " RENESAS_RX600_V2                 - Compiler: Renesas       Target: RX600 v2\n"
185         " RENESAS_RX700_V3_DPFPU           - Compiler: Renesas       Target: RX700 v3 with DPFPU\n"
186         " RENESAS_SH2A_FPU                 - Compiler: Renesas       Target: SH2A with FPU\n"
187         " ROWLEY_MSP430F449                - Compiler: Rowley        Target: MSP430F449\n"
188         " RVDS_ARM_CA9                     - Compiler: RVDS          Target: ARM Cortex-A9\n"
189         " RVDS_ARM_CM0                     - Compiler: RVDS          Target: ARM Cortex-M0\n"
190         " RVDS_ARM_CM3                     - Compiler: RVDS          Target: ARM Cortex-M3\n"
191         " RVDS_ARM_CM4_MPU                 - Compiler: RVDS          Target: ARM Cortex-M4 with MPU\n"
192         " RVDS_ARM_CM4F                    - Compiler: RVDS          Target: ARM Cortex-M4 with FPU\n"
193         " RVDS_ARM_CM7                     - Compiler: RVDS          Target: ARM Cortex-M7\n"
194         " RVDS_ARM7_LPC21XX                - Compiler: RVDS          Target: ARM7 LPC21xx\n"
195         " SDCC_CYGNAL                      - Compiler: SDCC          Target: Cygnal\n"
196         " SOFTUNE_MB91460                  - Compiler: Softune       Target: MB91460\n"
197         " SOFTUNE_MB96340                  - Compiler: Softune       Target: MB96340\n"
198         " TASKING_ARM_CM4F                 - Compiler: Tasking       Target: ARM Cortex-M4 with FPU\n"
199         " TEMPLATE                         - Compiler: HOST          Target: None\n"
200         " CDK_THEAD_CK802                  - Compiler: CDK           Target: T-head CK802\n"
201         " XCC_XTENSA                       - Compiler: XCC           Target: Xtensa\n"
202         " WIZC_PIC18                       - Compiler: WizC          Target: PIC18")
203     # Native FREERTOS_PORT for Linux and Windows MINGW builds
204     if(UNIX)
205         message(STATUS " Auto-Detected Unix, setting FREERTOS_PORT=GCC_POSIX")
206         set(FREERTOS_PORT GCC_POSIX CACHE STRING "FreeRTOS port name")
207     elseif(MINGW)
208         message(STATUS " Auto-Detected MINGW, setting FREERTOS_PORT=MSVC_MINGW")
209         set(FREERTOS_PORT MSVC_MINGW CACHE STRING "FreeRTOS port name")
210     endif()
211 elseif((FREERTOS_PORT STREQUAL "A_CUSTOM_PORT") AND (NOT TARGET freertos_kernel_port) )
212     message(FATAL_ERROR " FREERTOS_PORT is set to A_CUSTOM_PORT. Please specify the custom port target with all necessary files. For example:\n"
213     " Assuming a directory of:\n"
214     "  FreeRTOSCustomPort/\n"
215     "    CMakeLists.txt\n"
216     "    port.c\n"
217     "    portmacro.h\n"
218     " Where FreeRTOSCustomPort/CMakeLists.txt is a modified version of:\n"
219     "   add_library(freertos_kernel_port STATIC)\n"
220     "   target_sources(freertos_kernel_port\n"
221     "     PRIVATE\n"
222     "       port.c\n"
223     "       portmacro.h)\n"
224     "   target_include_directories(freertos_kernel_port\n"
225     "     PUBLIC\n"
226     "      .)\n"
227     "   target_link_libraries(freertos_kernel_port\n"
228     "     PRIVATE\n"
229     "       freertos_kernel_include)")
230 endif()
231
232
233 add_library(freertos_kernel STATIC)
234
235 ########################################################################
236 # Overall Compile Options
237 # Note the compile option strategy is to error on everything and then
238 # Per library opt-out of things that are warnings/errors.
239 # This ensures that no matter what strategy for compilation you take, the
240 # builds will still occur.
241 #
242 # Only tested with GNU and Clang.
243 # Other options are https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_%3CLANG%3E_COMPILER_ID
244 # Naming of compilers translation map:
245 #
246 #   FreeRTOS    | CMake
247 #   -------------------
248 #   CCS         | ?TBD?
249 #   GCC         | GNU, Clang, *Clang Others?
250 #   IAR         | IAR
251 #   Keil        | ARMCC
252 #   MSVC        | MSVC # Note only for MinGW?
253 #   Renesas     | ?TBD?
254
255 target_compile_options(freertos_kernel PRIVATE
256     ### Gnu/Clang C Options
257     $<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>
258     $<$<COMPILE_LANG_AND_ID:C,Clang>:-fcolor-diagnostics>
259
260     $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wall>
261     $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wextra>
262     $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wpedantic>
263     $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Werror>
264     $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wconversion>
265     $<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>
266
267     # Suppressions required to build clean with clang.
268     $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
269     $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-padded>
270     $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-variable-declarations>
271     $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-covered-switch-default>
272     $<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align>
273 )
274
275
276 ########################################################################
277 add_subdirectory(include)
278 add_subdirectory(portable)
279
280 target_sources(freertos_kernel PRIVATE
281     croutine.c
282     event_groups.c
283     list.c
284     queue.c
285     stream_buffer.c
286     tasks.c
287     timers.c
288
289     # If FREERTOS_HEAP is digit between 1 .. 5 - it is heap number, otherwise - it is path to custom heap source file
290     $<IF:$<BOOL:$<FILTER:${FREERTOS_HEAP},EXCLUDE,^[1-5]$>>,${FREERTOS_HEAP},portable/MemMang/heap_${FREERTOS_HEAP}.c>
291 )
292
293
294 target_link_libraries(freertos_kernel
295     PUBLIC
296         freertos_kernel_port
297         freertos_kernel_include
298 )
299
300 ########################################################################