blob: c0e051d460255e5e628f19be09c32321f77fab13 [file] [log] [blame]
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +02001function(compilerVersion)
2 execute_process(COMMAND "${CMAKE_C_COMPILER}" -dumpversion
3 OUTPUT_VARIABLE CVERSION
4 ERROR_VARIABLE CVERSION
5 )
6 SET(COMPILERVERSION ${CVERSION} PARENT_SCOPE)
7 #cmake_print_variables(CVERSION)
8 #cmake_print_variables(CMAKE_C_COMPILER)
9 #MESSAGE( STATUS "CMD_OUTPUT:" ${CVERSION})
10endfunction()
11
Christophe Favergeond0048572020-02-04 14:42:25 +010012function(compilerSpecificCompileOptions PROJECTNAME ROOT)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020013 get_target_property(DISABLEOPTIM ${PROJECTNAME} DISABLEOPTIMIZATION)
Christophe Favergeond0048572020-02-04 14:42:25 +010014
15 # Add support for the type __fp16 even if there is no HW
16 # support for it.
Christophe Favergeonc46f1522020-04-21 14:04:25 +020017 if (FLOAT16)
Christophe Favergeon9ee38242020-08-04 09:22:18 +020018 target_compile_options(${PROJECTNAME} PUBLIC "-mfp16-format=ieee")
Christophe Favergeonc46f1522020-04-21 14:04:25 +020019 endif()
Christophe Favergeond0048572020-02-04 14:42:25 +010020
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020021 if ((OPTIMIZED) AND (NOT DISABLEOPTIM))
Christophe Favergeonfeb73932020-05-20 14:48:06 +020022 target_compile_options(${PROJECTNAME} PUBLIC "-Ofast")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020023 endif()
24
25 if (FASTMATHCOMPUTATIONS)
26 target_compile_options(${PROJECTNAME} PUBLIC "-ffast-math")
27 endif()
28
29 if (HARDFP)
30 target_compile_options(${PROJECTNAME} PUBLIC "-mfloat-abi=hard")
31 target_link_options(${PROJECTNAME} PUBLIC "-mfloat-abi=hard")
32 endif()
33
34 if (LITTLEENDIAN)
35 target_compile_options(${PROJECTNAME} PUBLIC "-mlittle-endian")
36 endif()
37
Christophe Favergeonfe27d872020-07-31 07:20:18 +020038 if (CORTEXM OR CORTEXR)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020039 target_compile_options(${PROJECTNAME} PUBLIC "-mthumb")
40 endif()
41
Christophe Favergeon4eadae92020-05-29 11:44:53 +020042 target_link_options(${PROJECTNAME} PUBLIC "-mcpu=${ARM_CPU}")
43
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020044 # Need to add other gcc config for other cortex-m cores
Christophe Favergeon4eadae92020-05-29 11:44:53 +020045 if (ARM_CPU STREQUAL "cortex-m55" )
Christophe Favergeona614de92021-01-20 13:26:22 +010046 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv8.1-m.main+mve.fp+fp.dp")
Christophe Favergeon4eadae92020-05-29 11:44:53 +020047 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
48 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
49 endif()
50
Christophe Favergeonfeb73932020-05-20 14:48:06 +020051 if (ARM_CPU STREQUAL "cortex-m33" )
52 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16")
53 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020054 endif()
Christophe Favergeon93b52c82019-12-17 11:37:34 +010055
Christophe Favergeonfeb73932020-05-20 14:48:06 +020056 if (ARM_CPU STREQUAL "cortex-m7" )
57 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
58 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
Christophe Favergeon93b52c82019-12-17 11:37:34 +010059 endif()
Christophe Favergeonfeb73932020-05-20 14:48:06 +020060
61 if (ARM_CPU STREQUAL "cortex-m4" )
62 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16")
63 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16")
64 endif()
65
66 #if (ARM_CPU STREQUAL "cortex-m0" )
67 # target_compile_options(${PROJECTNAME} PUBLIC "")
68 # target_link_options(${PROJECTNAME} PUBLIC "")
69 #endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020070
71
72 if (ARM_CPU STREQUAL "cortex-a9" )
73 if (NOT (NEON OR NEONEXPERIMENTAL))
74 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
75 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
76 endif()
77 endif()
78
79 if (ARM_CPU STREQUAL "cortex-a7" )
80 if (NOT (NEON OR NEONEXPERIMENTAL))
81 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
82 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
83 endif()
84 endif()
85
86 if (ARM_CPU STREQUAL "cortex-a5" )
87 if ((NEON OR NEONEXPERIMENTAL))
Christophe Favergeonc1593422019-10-21 13:50:41 +020088 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
89 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020090 else()
91 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
92 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
93 endif()
94 endif()
95
96endfunction()
97
98function(preprocessScatter CORE PLATFORMFOLDER SCATTERFILE)
99
100
101 file(REMOVE ${SCATTERFILE})
102
103 # Copy the mem file to the build directory
104 # so that it can be find when preprocessing the scatter file
105 # since we cannot pass an include path to armlink
106 add_custom_command(
107 OUTPUT
108 ${SCATTERFILE}
109 COMMAND
110 ${CMAKE_C_COMPILER} -E -x c -I${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC -o ${SCATTERFILE} ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld
111 COMMAND
112 python ${ROOT}/CMSIS/DSP/filterLinkScript.py ${SCATTERFILE}
113 DEPENDS
114 "${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld;${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
115 )
116
117 add_custom_target(
118 scatter ALL
119 DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
120 )
121
122 add_dependencies(${PROJECTNAME} scatter)
123endfunction()
124
Christophe Favergeon26c2f682019-09-06 14:43:32 +0100125function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200126 if (HASCSTARTUP)
127 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
128 else()
129 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.S)
130 endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200131 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
132
133 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
134
Christophe Favergeonc4c34802019-09-24 14:05:01 +0200135 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200136 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
137 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
138
139 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
140
141 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
142endfunction()
143
144function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER)
145 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
146 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
147
148 # RTE Components
149 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100150 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200151
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100152 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200153 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
154 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
155
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100156
157 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200158
159 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
160endfunction()
161
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200162function(toolchainSpecificLinkForCortexR PROJECTNAME ROOT CORE PLATFORMFOLDER)
163 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
164 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
165
166 # RTE Components
167 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
168 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
169
170 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
171 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
172 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
173
174
175 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
176
177 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
178endfunction()
179
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200180function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT)
181 if (SEMIHOSTING)
182 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
183 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
184 else()
185 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
186 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
187 endif()
188endfunction()
189
190function(compilerSpecificPlatformConfigLibForA PROJECTNAME ROOT)
191 if (SEMIHOSTING)
192 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
193 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
194 else()
195 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
196 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
197 endif()
198endfunction()
199
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200200function(compilerSpecificPlatformConfigLibForR PROJECTNAME ROOT)
201 if (SEMIHOSTING)
202 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
203 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
204 else()
205 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
206 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
207 endif()
208endfunction()
209
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200210function(compilerSpecificPlatformConfigAppForM PROJECTNAME ROOT)
211 if (SEMIHOSTING)
212 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
213 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
214 else()
215 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
216 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
217 endif()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200218
219 target_link_options(${PROJECTNAME} PUBLIC "-Wl,--gc-sections")
220
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200221endfunction()
222
223function(compilerSpecificPlatformConfigAppForA PROJECTNAME ROOT)
224 if (SEMIHOSTING)
225 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
226 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
227 else()
228 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
229 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
230 endif()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200231
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200232endfunction()
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200233
234function(compilerSpecificPlatformConfigAppForR PROJECTNAME ROOT)
235 if (SEMIHOSTING)
236 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
237 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
238 else()
239 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
240 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
241 endif()
242
243endfunction()