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