blob: 8d8068bef9a9a130fd6c04d2015f9dc5620399f0 [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
38 if (CORTEXM)
39 target_compile_options(${PROJECTNAME} PUBLIC "-mthumb")
40 endif()
41
42 # Need to add other gcc config for other cortex-m cores
Christophe Favergeonfeb73932020-05-20 14:48:06 +020043
44 if (ARM_CPU STREQUAL "cortex-m33" )
45 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16")
46 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020047 endif()
Christophe Favergeon93b52c82019-12-17 11:37:34 +010048
Christophe Favergeonfeb73932020-05-20 14:48:06 +020049 if (ARM_CPU STREQUAL "cortex-m7" )
50 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
51 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16")
Christophe Favergeon93b52c82019-12-17 11:37:34 +010052 endif()
Christophe Favergeonfeb73932020-05-20 14:48:06 +020053
54 if (ARM_CPU STREQUAL "cortex-m4" )
55 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16")
56 target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16")
57 endif()
58
59 #if (ARM_CPU STREQUAL "cortex-m0" )
60 # target_compile_options(${PROJECTNAME} PUBLIC "")
61 # target_link_options(${PROJECTNAME} PUBLIC "")
62 #endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020063
64
65 if (ARM_CPU STREQUAL "cortex-a9" )
66 if (NOT (NEON OR NEONEXPERIMENTAL))
67 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
68 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
69 endif()
70 endif()
71
72 if (ARM_CPU STREQUAL "cortex-a7" )
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-a5" )
80 if ((NEON OR NEONEXPERIMENTAL))
Christophe Favergeonc1593422019-10-21 13:50:41 +020081 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
82 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020083 else()
84 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
85 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
86 endif()
87 endif()
88
89endfunction()
90
91function(preprocessScatter CORE PLATFORMFOLDER SCATTERFILE)
92
93
94 file(REMOVE ${SCATTERFILE})
95
96 # Copy the mem file to the build directory
97 # so that it can be find when preprocessing the scatter file
98 # since we cannot pass an include path to armlink
99 add_custom_command(
100 OUTPUT
101 ${SCATTERFILE}
102 COMMAND
103 ${CMAKE_C_COMPILER} -E -x c -I${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC -o ${SCATTERFILE} ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld
104 COMMAND
105 python ${ROOT}/CMSIS/DSP/filterLinkScript.py ${SCATTERFILE}
106 DEPENDS
107 "${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld;${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
108 )
109
110 add_custom_target(
111 scatter ALL
112 DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
113 )
114
115 add_dependencies(${PROJECTNAME} scatter)
116endfunction()
117
Christophe Favergeon26c2f682019-09-06 14:43:32 +0100118function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200119 if (HASCSTARTUP)
120 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
121 else()
122 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.S)
123 endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200124 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
125
126 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
127
Christophe Favergeonc4c34802019-09-24 14:05:01 +0200128 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200129 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
130 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
131
132 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
133
134 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
135endfunction()
136
137function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER)
138 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
139 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
140
141 # RTE Components
142 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100143 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200144
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100145 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200146 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
147 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
148
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100149
150 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200151
152 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
153endfunction()
154
155function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT)
156 if (SEMIHOSTING)
157 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
158 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
159 else()
160 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
161 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
162 endif()
163endfunction()
164
165function(compilerSpecificPlatformConfigLibForA PROJECTNAME ROOT)
166 if (SEMIHOSTING)
167 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
168 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
169 else()
170 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
171 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
172 endif()
173endfunction()
174
175function(compilerSpecificPlatformConfigAppForM PROJECTNAME ROOT)
176 if (SEMIHOSTING)
177 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
178 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
179 else()
180 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
181 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
182 endif()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200183
184 target_link_options(${PROJECTNAME} PUBLIC "-Wl,--gc-sections")
185
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200186endfunction()
187
188function(compilerSpecificPlatformConfigAppForA PROJECTNAME ROOT)
189 if (SEMIHOSTING)
190 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
191 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
192 else()
193 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
194 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
195 endif()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200196
197
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200198endfunction()