blob: eeed0e458b66d964041f7960bc664fec84f9eb7c [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 Favergeond0048572020-02-04 14:42:25 +010018 target_compile_options(${PROJECTNAME} PUBLIC "-mfp16-format=alternative")
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" )
46 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
47 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
48 endif()
49
Christophe Favergeonfeb73932020-05-20 14:48:06 +020050 if (ARM_CPU STREQUAL "cortex-m33" )
51 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16")
52 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020053 endif()
Christophe Favergeon93b52c82019-12-17 11:37:34 +010054
Christophe Favergeonfeb73932020-05-20 14:48:06 +020055 if (ARM_CPU STREQUAL "cortex-m7" )
56 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
57 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
Christophe Favergeon93b52c82019-12-17 11:37:34 +010058 endif()
Christophe Favergeonfeb73932020-05-20 14:48:06 +020059
60 if (ARM_CPU STREQUAL "cortex-m4" )
61 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16")
62 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16")
63 endif()
64
65 #if (ARM_CPU STREQUAL "cortex-m0" )
66 # target_compile_options(${PROJECTNAME} PUBLIC "")
67 # target_link_options(${PROJECTNAME} PUBLIC "")
68 #endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020069
70
71 if (ARM_CPU STREQUAL "cortex-a9" )
72 if (NOT (NEON OR NEONEXPERIMENTAL))
73 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
74 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
75 endif()
76 endif()
77
78 if (ARM_CPU STREQUAL "cortex-a7" )
79 if (NOT (NEON OR NEONEXPERIMENTAL))
80 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
81 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
82 endif()
83 endif()
84
85 if (ARM_CPU STREQUAL "cortex-a5" )
86 if ((NEON OR NEONEXPERIMENTAL))
Christophe Favergeonc1593422019-10-21 13:50:41 +020087 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
88 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020089 else()
90 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
91 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
92 endif()
93 endif()
94
95endfunction()
96
97function(preprocessScatter CORE PLATFORMFOLDER SCATTERFILE)
98
99
100 file(REMOVE ${SCATTERFILE})
101
102 # Copy the mem file to the build directory
103 # so that it can be find when preprocessing the scatter file
104 # since we cannot pass an include path to armlink
105 add_custom_command(
106 OUTPUT
107 ${SCATTERFILE}
108 COMMAND
109 ${CMAKE_C_COMPILER} -E -x c -I${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC -o ${SCATTERFILE} ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld
110 COMMAND
111 python ${ROOT}/CMSIS/DSP/filterLinkScript.py ${SCATTERFILE}
112 DEPENDS
113 "${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld;${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
114 )
115
116 add_custom_target(
117 scatter ALL
118 DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
119 )
120
121 add_dependencies(${PROJECTNAME} scatter)
122endfunction()
123
Christophe Favergeon26c2f682019-09-06 14:43:32 +0100124function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200125 if (HASCSTARTUP)
126 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
127 else()
128 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.S)
129 endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200130 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
131
132 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
133
Christophe Favergeonc4c34802019-09-24 14:05:01 +0200134 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200135 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
136 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
137
138 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
139
140 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
141endfunction()
142
143function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER)
144 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
145 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
146
147 # RTE Components
148 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100149 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200150
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100151 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200152 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
153 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
154
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100155
156 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200157
158 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
159endfunction()
160
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200161function(toolchainSpecificLinkForCortexR PROJECTNAME ROOT CORE PLATFORMFOLDER)
162 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
163 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
164
165 # RTE Components
166 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
167 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
168
169 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
170 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
171 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
172
173
174 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
175
176 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
177endfunction()
178
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200179function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT)
180 if (SEMIHOSTING)
181 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
182 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
183 else()
184 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
185 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
186 endif()
187endfunction()
188
189function(compilerSpecificPlatformConfigLibForA PROJECTNAME ROOT)
190 if (SEMIHOSTING)
191 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
192 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
193 else()
194 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
195 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
196 endif()
197endfunction()
198
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200199function(compilerSpecificPlatformConfigLibForR PROJECTNAME ROOT)
200 if (SEMIHOSTING)
201 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
202 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
203 else()
204 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
205 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
206 endif()
207endfunction()
208
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200209function(compilerSpecificPlatformConfigAppForM PROJECTNAME ROOT)
210 if (SEMIHOSTING)
211 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
212 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
213 else()
214 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
215 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
216 endif()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200217
218 target_link_options(${PROJECTNAME} PUBLIC "-Wl,--gc-sections")
219
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200220endfunction()
221
222function(compilerSpecificPlatformConfigAppForA PROJECTNAME ROOT)
223 if (SEMIHOSTING)
224 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
225 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
226 else()
227 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
228 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
229 endif()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200230
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200231endfunction()
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200232
233function(compilerSpecificPlatformConfigAppForR PROJECTNAME ROOT)
234 if (SEMIHOSTING)
235 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
236 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
237 else()
238 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
239 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
240 endif()
241
242endfunction()