Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 1 | function(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}) |
| 10 | endfunction() |
| 11 | |
Christophe Favergeon | d004857 | 2020-02-04 14:42:25 +0100 | [diff] [blame] | 12 | function(compilerSpecificCompileOptions PROJECTNAME ROOT) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 13 | get_target_property(DISABLEOPTIM ${PROJECTNAME} DISABLEOPTIMIZATION) |
Christophe Favergeon | d004857 | 2020-02-04 14:42:25 +0100 | [diff] [blame] | 14 | |
| 15 | # Add support for the type __fp16 even if there is no HW |
| 16 | # support for it. |
Christophe Favergeon | c46f152 | 2020-04-21 14:04:25 +0200 | [diff] [blame] | 17 | if (FLOAT16) |
Christophe Favergeon | d004857 | 2020-02-04 14:42:25 +0100 | [diff] [blame] | 18 | target_compile_options(${PROJECTNAME} PUBLIC "-mfp16-format=alternative") |
Christophe Favergeon | c46f152 | 2020-04-21 14:04:25 +0200 | [diff] [blame] | 19 | endif() |
Christophe Favergeon | d004857 | 2020-02-04 14:42:25 +0100 | [diff] [blame] | 20 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 21 | if ((OPTIMIZED) AND (NOT DISABLEOPTIM)) |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame] | 22 | target_compile_options(${PROJECTNAME} PUBLIC "-Ofast") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 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 | |
Christophe Favergeon | fe27d87 | 2020-07-31 07:20:18 +0200 | [diff] [blame^] | 38 | if (CORTEXM OR CORTEXR) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 39 | target_compile_options(${PROJECTNAME} PUBLIC "-mthumb") |
| 40 | endif() |
| 41 | |
Christophe Favergeon | 4eadae9 | 2020-05-29 11:44:53 +0200 | [diff] [blame] | 42 | target_link_options(${PROJECTNAME} PUBLIC "-mcpu=${ARM_CPU}") |
| 43 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 44 | # Need to add other gcc config for other cortex-m cores |
Christophe Favergeon | 4eadae9 | 2020-05-29 11:44:53 +0200 | [diff] [blame] | 45 | if (ARM_CPU STREQUAL "cortex-m55" ) |
| 46 | target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16") |
| 47 | target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16") |
| 48 | endif() |
| 49 | |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame] | 50 | if (ARM_CPU STREQUAL "cortex-m33" ) |
| 51 | target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16") |
| 52 | target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 53 | endif() |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 54 | |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame] | 55 | if (ARM_CPU STREQUAL "cortex-m7" ) |
| 56 | target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16") |
| 57 | target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16") |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 58 | endif() |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame] | 59 | |
| 60 | if (ARM_CPU STREQUAL "cortex-m4" ) |
| 61 | target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16") |
| 62 | target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16") |
| 63 | endif() |
| 64 | |
| 65 | #if (ARM_CPU STREQUAL "cortex-m0" ) |
| 66 | # target_compile_options(${PROJECTNAME} PUBLIC "") |
| 67 | # target_link_options(${PROJECTNAME} PUBLIC "") |
| 68 | #endif() |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 69 | |
| 70 | |
| 71 | if (ARM_CPU STREQUAL "cortex-a9" ) |
| 72 | if (NOT (NEON OR NEONEXPERIMENTAL)) |
| 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 | |
| 78 | if (ARM_CPU STREQUAL "cortex-a7" ) |
| 79 | if (NOT (NEON OR NEONEXPERIMENTAL)) |
| 80 | target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 81 | target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 82 | endif() |
| 83 | endif() |
| 84 | |
| 85 | if (ARM_CPU STREQUAL "cortex-a5" ) |
| 86 | if ((NEON OR NEONEXPERIMENTAL)) |
Christophe Favergeon | c159342 | 2019-10-21 13:50:41 +0200 | [diff] [blame] | 87 | target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4") |
| 88 | target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 89 | else() |
| 90 | target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 91 | target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 92 | endif() |
| 93 | endif() |
| 94 | |
| 95 | endfunction() |
| 96 | |
| 97 | function(preprocessScatter CORE PLATFORMFOLDER SCATTERFILE) |
| 98 | |
| 99 | |
| 100 | file(REMOVE ${SCATTERFILE}) |
| 101 | |
| 102 | # Copy the mem file to the build directory |
| 103 | # so that it can be find when preprocessing the scatter file |
| 104 | # since we cannot pass an include path to armlink |
| 105 | add_custom_command( |
| 106 | OUTPUT |
| 107 | ${SCATTERFILE} |
| 108 | COMMAND |
| 109 | ${CMAKE_C_COMPILER} -E -x c -I${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC -o ${SCATTERFILE} ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld |
| 110 | COMMAND |
| 111 | python ${ROOT}/CMSIS/DSP/filterLinkScript.py ${SCATTERFILE} |
| 112 | DEPENDS |
| 113 | "${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld;${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h" |
| 114 | ) |
| 115 | |
| 116 | add_custom_target( |
| 117 | scatter ALL |
| 118 | DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h" |
| 119 | ) |
| 120 | |
| 121 | add_dependencies(${PROJECTNAME} scatter) |
| 122 | endfunction() |
| 123 | |
Christophe Favergeon | 26c2f68 | 2019-09-06 14:43:32 +0100 | [diff] [blame] | 124 | function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP) |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame] | 125 | if (HASCSTARTUP) |
| 126 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c) |
| 127 | else() |
| 128 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.S) |
| 129 | endif() |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 130 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c) |
| 131 | |
| 132 | target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC) |
| 133 | |
Christophe Favergeon | c4c3480 | 2019-09-24 14:05:01 +0200 | [diff] [blame] | 134 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 135 | set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld) |
| 136 | preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE}) |
| 137 | |
| 138 | set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}") |
| 139 | |
| 140 | target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}") |
| 141 | endfunction() |
| 142 | |
| 143 | function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER) |
| 144 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c) |
| 145 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c) |
| 146 | |
| 147 | # RTE Components |
| 148 | target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing) |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 149 | target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 150 | |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 151 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 152 | set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld) |
| 153 | preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE}) |
| 154 | |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 155 | |
| 156 | set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 157 | |
| 158 | target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}") |
| 159 | endfunction() |
| 160 | |
Christophe Favergeon | 0e0449a | 2020-07-28 09:44:14 +0200 | [diff] [blame] | 161 | function(toolchainSpecificLinkForCortexR PROJECTNAME ROOT CORE PLATFORMFOLDER) |
| 162 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c) |
| 163 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c) |
| 164 | |
| 165 | # RTE Components |
| 166 | target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing) |
| 167 | target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC) |
| 168 | |
| 169 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink) |
| 170 | set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld) |
| 171 | preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE}) |
| 172 | |
| 173 | |
| 174 | set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}") |
| 175 | |
| 176 | target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}") |
| 177 | endfunction() |
| 178 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 179 | function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT) |
| 180 | if (SEMIHOSTING) |
| 181 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 182 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 183 | else() |
| 184 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 185 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 186 | endif() |
| 187 | endfunction() |
| 188 | |
| 189 | function(compilerSpecificPlatformConfigLibForA PROJECTNAME ROOT) |
| 190 | if (SEMIHOSTING) |
| 191 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 192 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 193 | else() |
| 194 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 195 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 196 | endif() |
| 197 | endfunction() |
| 198 | |
Christophe Favergeon | 0e0449a | 2020-07-28 09:44:14 +0200 | [diff] [blame] | 199 | function(compilerSpecificPlatformConfigLibForR PROJECTNAME ROOT) |
| 200 | if (SEMIHOSTING) |
| 201 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 202 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 203 | else() |
| 204 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 205 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 206 | endif() |
| 207 | endfunction() |
| 208 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 209 | function(compilerSpecificPlatformConfigAppForM PROJECTNAME ROOT) |
| 210 | if (SEMIHOSTING) |
| 211 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 212 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 213 | else() |
| 214 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 215 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 216 | endif() |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame] | 217 | |
| 218 | target_link_options(${PROJECTNAME} PUBLIC "-Wl,--gc-sections") |
| 219 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 220 | endfunction() |
| 221 | |
| 222 | function(compilerSpecificPlatformConfigAppForA PROJECTNAME ROOT) |
| 223 | if (SEMIHOSTING) |
| 224 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 225 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 226 | else() |
| 227 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 228 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 229 | endif() |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame] | 230 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 231 | endfunction() |
Christophe Favergeon | 0e0449a | 2020-07-28 09:44:14 +0200 | [diff] [blame] | 232 | |
| 233 | function(compilerSpecificPlatformConfigAppForR PROJECTNAME ROOT) |
| 234 | if (SEMIHOSTING) |
| 235 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 236 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 237 | else() |
| 238 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 239 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 240 | endif() |
| 241 | |
| 242 | endfunction() |