blob: c2c96a4e1b0ab5e1ce4380fb6338afff3ec9c832 [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
12function(compilerSpecificCompileOptions PROJECTNAME)
13 get_target_property(DISABLEOPTIM ${PROJECTNAME} DISABLEOPTIMIZATION)
14 if ((OPTIMIZED) AND (NOT DISABLEOPTIM))
15 target_compile_options(${PROJECTNAME} PUBLIC "-O2")
16 endif()
17
18 if (FASTMATHCOMPUTATIONS)
19 target_compile_options(${PROJECTNAME} PUBLIC "-ffast-math")
20 endif()
21
22 if (HARDFP)
23 target_compile_options(${PROJECTNAME} PUBLIC "-mfloat-abi=hard")
24 target_link_options(${PROJECTNAME} PUBLIC "-mfloat-abi=hard")
25 endif()
26
27 if (LITTLEENDIAN)
28 target_compile_options(${PROJECTNAME} PUBLIC "-mlittle-endian")
29 endif()
30
31 if (CORTEXM)
32 target_compile_options(${PROJECTNAME} PUBLIC "-mthumb")
33 endif()
34
35 # Need to add other gcc config for other cortex-m cores
36 if (ARM_CPU STREQUAL "cortex-m7" )
37 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7e-m;-mfpu=fpv5-d16")
38 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7e-m;-mfpu=fpv5-d16")
39 endif()
40
41
42 if (ARM_CPU STREQUAL "cortex-a9" )
43 if (NOT (NEON OR NEONEXPERIMENTAL))
44 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
45 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
46 endif()
47 endif()
48
49 if (ARM_CPU STREQUAL "cortex-a7" )
50 if (NOT (NEON OR NEONEXPERIMENTAL))
51 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
52 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16")
53 endif()
54 endif()
55
56 if (ARM_CPU STREQUAL "cortex-a5" )
57 if ((NEON OR NEONEXPERIMENTAL))
Christophe Favergeonc1593422019-10-21 13:50:41 +020058 target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
59 target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4")
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020060 else()
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
66endfunction()
67
68function(preprocessScatter CORE PLATFORMFOLDER SCATTERFILE)
69
70
71 file(REMOVE ${SCATTERFILE})
72
73 # Copy the mem file to the build directory
74 # so that it can be find when preprocessing the scatter file
75 # since we cannot pass an include path to armlink
76 add_custom_command(
77 OUTPUT
78 ${SCATTERFILE}
79 COMMAND
80 ${CMAKE_C_COMPILER} -E -x c -I${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC -o ${SCATTERFILE} ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld
81 COMMAND
82 python ${ROOT}/CMSIS/DSP/filterLinkScript.py ${SCATTERFILE}
83 DEPENDS
84 "${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld;${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
85 )
86
87 add_custom_target(
88 scatter ALL
89 DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h"
90 )
91
92 add_dependencies(${PROJECTNAME} scatter)
93endfunction()
94
Christophe Favergeon26c2f682019-09-06 14:43:32 +010095function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +020096 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.S)
97 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
98
99 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
100
Christophe Favergeonc4c34802019-09-24 14:05:01 +0200101 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink)
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +0200102 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
103 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
104
105 set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}")
106
107 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
108endfunction()
109
110function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER)
111 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c)
112 target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c)
113
114 # RTE Components
115 target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing)
116
117 # Using the mem file which is included.
118 # Since meme file in same temp directory, it is found by linker
119 # when processing the scatter file
120 set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld)
121 preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE})
122
123 target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC)
124
125 target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}")
126endfunction()
127
128function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT)
129 if (SEMIHOSTING)
130 target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
131 target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs")
132 else()
133 target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
134 target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs")
135 endif()
136endfunction()
137
138function(compilerSpecificPlatformConfigLibForA 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(compilerSpecificPlatformConfigAppForM 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(compilerSpecificPlatformConfigAppForA 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()