blob: 61b4319b89e2fb0f5b900169cc0c9004c80b57de [file] [log] [blame]
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +02001#include(CMakePrintHelpers)
2include(AddFileDependencies)
3
4function(compilerVersion)
5 execute_process(COMMAND "${CMAKE_C_COMPILER}" --version_number
6 OUTPUT_VARIABLE CVERSION
7 ERROR_VARIABLE CVERSION
8 )
9 SET(COMPILERVERSION ${CVERSION} PARENT_SCOPE)
10 #cmake_print_variables(CVERSION)
11 #cmake_print_variables(CMAKE_C_COMPILER)
12 #MESSAGE( STATUS "CMD_OUTPUT:" ${CVERSION})
13endfunction()
14
15function(compilerSpecificCompileOptions PROJECTNAME ROOT)
16 #cmake_print_properties(TARGETS ${PROJECTNAME} PROPERTIES DISABLEOPTIMIZATION)
17 get_target_property(DISABLEOPTIM ${PROJECTNAME} DISABLEOPTIMIZATION)
18 if ((OPTIMIZED) AND (NOT DISABLEOPTIM))
19 #cmake_print_variables(DISABLEOPTIM)
Christophe Favergeon8cb37302020-05-13 13:06:58 +020020 target_compile_options(${PROJECTNAME} PRIVATE "-Ofast")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020021 endif()
22
23 if (FASTMATHCOMPUTATIONS)
24 target_compile_options(${PROJECTNAME} PUBLIC "-ffast-math")
25 endif()
26
27 if (HARDFP)
28 target_compile_options(${PROJECTNAME} PUBLIC "-mfloat-abi=hard")
29 endif()
30
31 if (LITTLEENDIAN)
32 target_compile_options(${PROJECTNAME} PUBLIC "-mlittle-endian")
33 endif()
Christophe Favergeonfe27d872020-07-31 07:20:18 +020034
35 if (CORTEXM OR CORTEXR)
36 target_compile_options(${PROJECTNAME} PUBLIC "-mthumb")
37 endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020038
39 # Core specific config
40
Christophe Favergeon512b1482020-02-07 11:25:11 +010041 if (ARM_CPU STREQUAL "cortex-m55" )
42 target_compile_options(${PROJECTNAME} PUBLIC "-fshort-enums")
43 target_compile_options(${PROJECTNAME} PUBLIC "-fshort-wchar")
44 endif()
45
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020046 if (ARM_CPU STREQUAL "cortex-m33" )
47 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16")
Christophe Favergeon122be852019-07-30 10:36:30 +020048 endif()
49
50 if (ARM_CPU STREQUAL "cortex-m7" )
51 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16")
52 endif()
53
54 if (ARM_CPU STREQUAL "cortex-m4" )
55 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020056 endif()
57
58 if (ARM_CPU STREQUAL "cortex-a9" )
59 if (NOT (NEON OR NEONEXPERIMENTAL))
60 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=vfpv3-d16-fp16")
61 endif()
62 endif()
63
Christophe Favergeonea3ac962020-06-19 08:31:36 +020064
65 if (ARM_CPU STREQUAL "cortex-a32" )
66 if (NEON OR NEONEXPERIMENTAL)
67 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=neon-fp-armv8")
68 endif()
69 endif()
70
71
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020072 if (ARM_CPU STREQUAL "cortex-a7" )
73 if (NOT (NEON OR NEONEXPERIMENTAL))
74 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=vfpv4-d16")
75 endif()
76 endif()
Christophe Favergeonc67252c2020-06-18 11:11:51 +020077
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020078
79 if (ARM_CPU STREQUAL "cortex-a5" )
80 if ((NEON OR NEONEXPERIMENTAL))
81 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=neon-vfpv4")
82 else()
83 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=vfpv4-d16")
84 endif()
85 endif()
Christophe Favergeon26c2f682019-09-06 14:43:32 +010086
Christophe Favergeonfe27d872020-07-31 07:20:18 +020087 if (ARM_CPU STREQUAL "cortex-r52" )
88 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=neon-fp-armv8")
89 endif()
90
Christophe Favergeon0e0449a2020-07-28 09:44:14 +020091 if (ARM_CPU STREQUAL "cortex-r8" )
92 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=vfpv3-d16-fp16")
93 endif()
94
95 if (ARM_CPU STREQUAL "cortex-r5" )
96 target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=vfpv3")
97 endif()
98
Christophe Favergeonc67252c2020-06-18 11:11:51 +020099
Christophe Favergeon26c2f682019-09-06 14:43:32 +0100100 if(EXPERIMENTAL)
101 experimentalCompilerSpecificCompileOptions(${PROJECTNAME} ${ROOT})
102 endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200103endfunction()
104
105
Christophe Favergeon26c2f682019-09-06 14:43:32 +0100106function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200107 # A specific library is created for ASM file
108 # since we do not want standard compile flags (for C) to be applied to
109 # ASM files.
Christophe Favergeon26c2f682019-09-06 14:43:32 +0100110 if (HASCSTARTUP)
111 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/AC6/startup_${CORE}.c)
112 else()
113 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/AC6/startup_${CORE}.s)
114 endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200115 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/AC6)
116
117 set(SCATTERFILE "${PLATFORMFOLDER}/${CORE}/LinkScripts/AC6/lnk.sct")
118
119 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/AC6/mem_${CORE}.h")
120
121 #target_link_options(${PROJECTNAME} PRIVATE "--info=sizes")
122 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;--scatter=${SCATTERFILE}")
123
124endfunction()
125
126function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER)
127 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/AC6/startup_${CORE}.c)
128
129
130 # RTE Components.h
131 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
132
133 set(SCATTERFILE "${PLATFORMFOLDER}/${CORE}/LinkScripts/AC6/lnk.sct")
134
135 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/AC6/mem_${CORE}.h")
136
137 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/AC6)
138
139 #target_link_options(${PROJECTNAME} PRIVATE "--info=sizes")
140 target_link_options(${PROJECTNAME} PRIVATE "--entry=Vectors;--scatter=${SCATTERFILE}")
141
142endfunction()
143
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200144function(toolchainSpecificLinkForCortexR PROJECTNAME ROOT CORE PLATFORMFOLDER)
145 #target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/AC6/startup_${CORE}.c)
146 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/AC6/startup.s)
147
148
149 # RTE Components.h
150 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
151
152 set(SCATTERFILE "${PLATFORMFOLDER}/${CORE}/LinkScripts/AC6/lnk.sct")
153
154 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/AC6/mem_${CORE}.h")
155
156 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/AC6)
157
158 #target_link_options(${PROJECTNAME} PRIVATE "--info=sizes")
159 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;--scatter=${SCATTERFILE}")
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200160endfunction()
161
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200162function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT)
163endfunction()
164
165function(compilerSpecificPlatformConfigLibForA PROJECTNAME ROOT)
166endfunction()
167
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200168function(compilerSpecificPlatformConfigLibForR PROJECTNAME ROOT)
169endfunction()
170
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200171function(compilerSpecificPlatformConfigAppForM PROJECTNAME ROOT)
172endfunction()
173
174function(compilerSpecificPlatformConfigAppForA PROJECTNAME ROOT)
Christophe Favergeon0e0449a2020-07-28 09:44:14 +0200175endfunction()
176
177function(compilerSpecificPlatformConfigAppForR PROJECTNAME ROOT)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200178endfunction()