blob: 98b52b0571d614c8671061bdb1d203138d17d92a [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.
17 target_compile_options(${PROJECTNAME} PUBLIC "-mfp16-format=alternative")
18
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020019 if ((OPTIMIZED) AND (NOT DISABLEOPTIM))
20 target_compile_options(${PROJECTNAME} PUBLIC "-O2")
21 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 target_link_options(${PROJECTNAME} PUBLIC "-mfloat-abi=hard")
30 endif()
31
32 if (LITTLEENDIAN)
33 target_compile_options(${PROJECTNAME} PUBLIC "-mlittle-endian")
34 endif()
35
36 if (CORTEXM)
37 target_compile_options(${PROJECTNAME} PUBLIC "-mthumb")
38 endif()
39
40 # Need to add other gcc config for other cortex-m cores
41 if (ARM_CPU STREQUAL "cortex-m7" )
42 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7e-m;-mfpu=fpv5-d16")
43 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7e-m;-mfpu=fpv5-d16")
44 endif()
Christophe Favergeon93b52c82019-12-17 11:37:34 +010045
46 if (ARM_CPU STREQUAL "cortex-m0" )
47 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv6-m")
48 target_link_options(${PROJECTNAME} PUBLIC "-march=armv6-m")
49 endif()
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020050
51
52 if (ARM_CPU STREQUAL "cortex-a9" )
53 if (NOT (NEON OR NEONEXPERIMENTAL))
54 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
55 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
56 endif()
57 endif()
58
59 if (ARM_CPU STREQUAL "cortex-a7" )
60 if (NOT (NEON OR NEONEXPERIMENTAL))
61 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
62 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
63 endif()
64 endif()
65
66 if (ARM_CPU STREQUAL "cortex-a5" )
67 if ((NEON OR NEONEXPERIMENTAL))
Christophe Favergeonc1593422019-10-21 13:50:41 +020068 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
69 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020070 else()
71 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
72 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
73 endif()
74 endif()
75
76endfunction()
77
78function(preprocessScatter CORE PLATFORMFOLDER SCATTERFILE)
79
80
81 file(REMOVE ${SCATTERFILE})
82
83 # Copy the mem file to the build directory
84 # so that it can be find when preprocessing the scatter file
85 # since we cannot pass an include path to armlink
86 add_custom_command(
87 OUTPUT
88 ${SCATTERFILE}
89 COMMAND
90 ${CMAKE_C_COMPILER} -E -x c -I${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC -o ${SCATTERFILE} ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld
91 COMMAND
92 python ${ROOT}/CMSIS/DSP/filterLinkScript.py ${SCATTERFILE}
93 DEPENDS
94 "${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld;${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
95 )
96
97 add_custom_target(
98 scatter ALL
99 DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
100 )
101
102 add_dependencies(${PROJECTNAME} scatter)
103endfunction()
104
Christophe Favergeon26c2f682019-09-06 14:43:32 +0100105function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200106 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.S)
107 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
108
109 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
110
Christophe Favergeonc4c34802019-09-24 14:05:01 +0200111 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200112 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
113 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
114
115 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
116
117 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
118endfunction()
119
120function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER)
121 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
122 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
123
124 # RTE Components
125 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100126 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200127
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100128 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
Christophe Favergeon93b52c82019-12-17 11:37:34 +0100132
133 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200134
135 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
136endfunction()
137
138function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT)
139 if (SEMIHOSTING)
140 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
141 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
142 else()
143 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
144 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
145 endif()
146endfunction()
147
148function(compilerSpecificPlatformConfigLibForA PROJECTNAME ROOT)
149 if (SEMIHOSTING)
150 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
151 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
152 else()
153 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
154 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
155 endif()
156endfunction()
157
158function(compilerSpecificPlatformConfigAppForM PROJECTNAME ROOT)
159 if (SEMIHOSTING)
160 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
161 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
162 else()
163 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
164 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
165 endif()
166endfunction()
167
168function(compilerSpecificPlatformConfigAppForA PROJECTNAME ROOT)
169 if (SEMIHOSTING)
170 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
171 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
172 else()
173 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
174 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
175 endif()
176endfunction()