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 | |
| 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 |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame^] | 43 | |
| 44 | if (ARM_CPU STREQUAL "cortex-m33" ) |
| 45 | target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16") |
| 46 | target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-sp-d16") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 47 | endif() |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 48 | |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame^] | 49 | if (ARM_CPU STREQUAL "cortex-m7" ) |
| 50 | target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16") |
| 51 | target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv5-d16") |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 52 | endif() |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame^] | 53 | |
| 54 | if (ARM_CPU STREQUAL "cortex-m4" ) |
| 55 | target_compile_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16") |
| 56 | target_link_options(${PROJECTNAME} PUBLIC "-mfpu=fpv4-sp-d16") |
| 57 | endif() |
| 58 | |
| 59 | #if (ARM_CPU STREQUAL "cortex-m0" ) |
| 60 | # target_compile_options(${PROJECTNAME} PUBLIC "") |
| 61 | # target_link_options(${PROJECTNAME} PUBLIC "") |
| 62 | #endif() |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 63 | |
| 64 | |
| 65 | if (ARM_CPU STREQUAL "cortex-a9" ) |
| 66 | if (NOT (NEON OR NEONEXPERIMENTAL)) |
| 67 | target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 68 | target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 69 | endif() |
| 70 | endif() |
| 71 | |
| 72 | if (ARM_CPU STREQUAL "cortex-a7" ) |
| 73 | if (NOT (NEON OR NEONEXPERIMENTAL)) |
| 74 | target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 75 | target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 76 | endif() |
| 77 | endif() |
| 78 | |
| 79 | if (ARM_CPU STREQUAL "cortex-a5" ) |
| 80 | if ((NEON OR NEONEXPERIMENTAL)) |
Christophe Favergeon | c159342 | 2019-10-21 13:50:41 +0200 | [diff] [blame] | 81 | target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4") |
| 82 | target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 83 | else() |
| 84 | target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 85 | target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 86 | endif() |
| 87 | endif() |
| 88 | |
| 89 | endfunction() |
| 90 | |
| 91 | function(preprocessScatter CORE PLATFORMFOLDER SCATTERFILE) |
| 92 | |
| 93 | |
| 94 | file(REMOVE ${SCATTERFILE}) |
| 95 | |
| 96 | # Copy the mem file to the build directory |
| 97 | # so that it can be find when preprocessing the scatter file |
| 98 | # since we cannot pass an include path to armlink |
| 99 | add_custom_command( |
| 100 | OUTPUT |
| 101 | ${SCATTERFILE} |
| 102 | COMMAND |
| 103 | ${CMAKE_C_COMPILER} -E -x c -I${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC -o ${SCATTERFILE} ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld |
| 104 | COMMAND |
| 105 | python ${ROOT}/CMSIS/DSP/filterLinkScript.py ${SCATTERFILE} |
| 106 | DEPENDS |
| 107 | "${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/lnk.ld;${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h" |
| 108 | ) |
| 109 | |
| 110 | add_custom_target( |
| 111 | scatter ALL |
| 112 | DEPENDS "${SCATTERFILE};${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC/mem_${CORE}.h" |
| 113 | ) |
| 114 | |
| 115 | add_dependencies(${PROJECTNAME} scatter) |
| 116 | endfunction() |
| 117 | |
Christophe Favergeon | 26c2f68 | 2019-09-06 14:43:32 +0100 | [diff] [blame] | 118 | function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP) |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame^] | 119 | if (HASCSTARTUP) |
| 120 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c) |
| 121 | else() |
| 122 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.S) |
| 123 | endif() |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 124 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c) |
| 125 | |
| 126 | target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC) |
| 127 | |
Christophe Favergeon | c4c3480 | 2019-09-24 14:05:01 +0200 | [diff] [blame] | 128 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 129 | set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld) |
| 130 | preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE}) |
| 131 | |
| 132 | set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}") |
| 133 | |
| 134 | target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}") |
| 135 | endfunction() |
| 136 | |
| 137 | function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER) |
| 138 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c) |
| 139 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c) |
| 140 | |
| 141 | # RTE Components |
| 142 | target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing) |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 143 | target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 144 | |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 145 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 146 | set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld) |
| 147 | preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE}) |
| 148 | |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 149 | |
| 150 | set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 151 | |
| 152 | target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}") |
| 153 | endfunction() |
| 154 | |
| 155 | function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT) |
| 156 | if (SEMIHOSTING) |
| 157 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 158 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 159 | else() |
| 160 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 161 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 162 | endif() |
| 163 | endfunction() |
| 164 | |
| 165 | function(compilerSpecificPlatformConfigLibForA PROJECTNAME ROOT) |
| 166 | if (SEMIHOSTING) |
| 167 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 168 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 169 | else() |
| 170 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 171 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 172 | endif() |
| 173 | endfunction() |
| 174 | |
| 175 | function(compilerSpecificPlatformConfigAppForM PROJECTNAME ROOT) |
| 176 | if (SEMIHOSTING) |
| 177 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 178 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 179 | else() |
| 180 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 181 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 182 | endif() |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame^] | 183 | |
| 184 | target_link_options(${PROJECTNAME} PUBLIC "-Wl,--gc-sections") |
| 185 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 186 | endfunction() |
| 187 | |
| 188 | function(compilerSpecificPlatformConfigAppForA PROJECTNAME ROOT) |
| 189 | if (SEMIHOSTING) |
| 190 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 191 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 192 | else() |
| 193 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 194 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 195 | endif() |
Christophe Favergeon | feb7393 | 2020-05-20 14:48:06 +0200 | [diff] [blame^] | 196 | |
| 197 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 198 | endfunction() |