blob: ebbe6c32508646a43e803ef582a410ac86ec7f53 [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))
22 target_compile_options(${PROJECTNAME} PUBLIC "-O2")
23 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
43 if (ARM_CPU STREQUAL "cortex-m7" )
44 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7e-m;-mfpu=fpv5-d16")
45 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7e-m;-mfpu=fpv5-d16")
46 endif()
Christophe Favergeon93b52c82019-12-17 11:37:34 +010047
48 if (ARM_CPU STREQUAL "cortex-m0" )
49 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv6-m")
50 target_link_options(${PROJECTNAME} PUBLIC "-march=armv6-m")
51 endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020052
53
54 if (ARM_CPU STREQUAL "cortex-a9" )
55 if (NOT (NEON OR NEONEXPERIMENTAL))
56 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
57 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
58 endif()
59 endif()
60
61 if (ARM_CPU STREQUAL "cortex-a7" )
62 if (NOT (NEON OR NEONEXPERIMENTAL))
63 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
64 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
65 endif()
66 endif()
67
68 if (ARM_CPU STREQUAL "cortex-a5" )
69 if ((NEON OR NEONEXPERIMENTAL))
Christophe Favergeonc1593422019-10-21 13:50:41 +020070 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
71 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020072 else()
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
78endfunction()
79
80function(preprocessScatter CORE PLATFORMFOLDER SCATTERFILE)
81
82
83 file(REMOVE ${SCATTERFILE})
84
85 # Copy the mem file to the build directory
86 # so that it can be find when preprocessing the scatter file
87 # since we cannot pass an include path to armlink
88 add_custom_command(
89 OUTPUT
90 ${SCATTERFILE}
91 COMMAND
92 ${CMAKE_C_COMPILER} -E -x c -I${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC -o ${SCATTERFILE} ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld
93 COMMAND
94 python ${ROOT}/CMSIS/DSP/filterLinkScript.py ${SCATTERFILE}
95 DEPENDS
96 "${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld;${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
97 )
98
99 add_custom_target(
100 scatter ALL
101 DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
102 )
103
104 add_dependencies(${PROJECTNAME} scatter)
105endfunction()
106
Christophe Favergeon26c2f682019-09-06 14:43:32 +0100107function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200108 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.S)
109 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
110
111 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
112
Christophe Favergeonc4c34802019-09-24 14:05:01 +0200113 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200114 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
115 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
116
117 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
118
119 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
120endfunction()
121
122function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER)
123 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
124 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
125
126 # RTE Components
127 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100128 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200129
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100130 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200131 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
132 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
133
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100134
135 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200136
137 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
138endfunction()
139
140function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT)
141 if (SEMIHOSTING)
142 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
143 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
144 else()
145 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
146 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
147 endif()
148endfunction()
149
150function(compilerSpecificPlatformConfigLibForA PROJECTNAME ROOT)
151 if (SEMIHOSTING)
152 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
153 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
154 else()
155 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
156 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
157 endif()
158endfunction()
159
160function(compilerSpecificPlatformConfigAppForM PROJECTNAME ROOT)
161 if (SEMIHOSTING)
162 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
163 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
164 else()
165 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
166 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
167 endif()
168endfunction()
169
170function(compilerSpecificPlatformConfigAppForA PROJECTNAME ROOT)
171 if (SEMIHOSTING)
172 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
173 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
174 else()
175 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
176 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
177 endif()
178endfunction()