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. |
| 17 | target_compile_options(${PROJECTNAME} PUBLIC "-mfp16-format=alternative") |
| 18 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 19 | 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 Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 45 | |
| 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 Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 50 | |
| 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 Favergeon | c159342 | 2019-10-21 13:50:41 +0200 | [diff] [blame] | 68 | target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4") |
| 69 | target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=neon-vfpv4") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 70 | 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 | |
| 76 | endfunction() |
| 77 | |
| 78 | function(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) |
| 103 | endfunction() |
| 104 | |
Christophe Favergeon | 26c2f68 | 2019-09-06 14:43:32 +0100 | [diff] [blame] | 105 | function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER HASCSTARTUP) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 106 | 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 Favergeon | c4c3480 | 2019-09-24 14:05:01 +0200 | [diff] [blame] | 111 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tempLink) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 112 | 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}") |
| 118 | endfunction() |
| 119 | |
| 120 | function(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 Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 126 | target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 127 | |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [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 | |
Christophe Favergeon | 93b52c8 | 2019-12-17 11:37:34 +0100 | [diff] [blame] | 132 | |
| 133 | set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 134 | |
| 135 | target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}") |
| 136 | endfunction() |
| 137 | |
| 138 | function(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() |
| 146 | endfunction() |
| 147 | |
| 148 | function(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() |
| 156 | endfunction() |
| 157 | |
| 158 | function(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() |
| 166 | endfunction() |
| 167 | |
| 168 | function(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() |
| 176 | endfunction() |