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 | |
| 12 | function(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)) |
| 58 | target_compile_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 59 | target_link_options(${PROJECTNAME} PUBLIC "-march=armv7-a;-mfpu=vfpv3-d16") |
| 60 | 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 | |
| 66 | endfunction() |
| 67 | |
| 68 | function(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) |
| 93 | endfunction() |
| 94 | |
| 95 | function(toolchainSpecificLinkForCortexM PROJECTNAME ROOT CORE PLATFORMFOLDER) |
| 96 | 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 | |
| 101 | set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld) |
| 102 | preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE}) |
| 103 | |
| 104 | set_target_properties(${PROJECTNAME} PROPERTIES LINK_DEPENDS "${SCATTERFILE}") |
| 105 | |
| 106 | target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}") |
| 107 | endfunction() |
| 108 | |
| 109 | function(toolchainSpecificLinkForCortexA PROJECTNAME ROOT CORE PLATFORMFOLDER) |
| 110 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/startup_${CORE}.c) |
| 111 | target_sources(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/Startup/GCC/support.c) |
| 112 | |
| 113 | # RTE Components |
| 114 | target_include_directories(${PROJECTNAME} PRIVATE ${ROOT}/CMSIS/DSP/Testing) |
| 115 | |
| 116 | # Using the mem file which is included. |
| 117 | # Since meme file in same temp directory, it is found by linker |
| 118 | # when processing the scatter file |
| 119 | set(SCATTERFILE ${CMAKE_CURRENT_BINARY_DIR}/tempLink/lnk.ld) |
| 120 | preprocessScatter(${CORE} ${PLATFORMFOLDER} ${SCATTERFILE}) |
| 121 | |
| 122 | target_include_directories(${PROJECTNAME} PRIVATE ${PLATFORMFOLDER}/${CORE}/LinkScripts/GCC) |
| 123 | |
| 124 | target_link_options(${PROJECTNAME} PRIVATE "--entry=Reset_Handler;-T${SCATTERFILE}") |
| 125 | endfunction() |
| 126 | |
| 127 | function(compilerSpecificPlatformConfigLibForM PROJECTNAME ROOT) |
| 128 | if (SEMIHOSTING) |
| 129 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 130 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 131 | else() |
| 132 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 133 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 134 | endif() |
| 135 | endfunction() |
| 136 | |
| 137 | function(compilerSpecificPlatformConfigLibForA PROJECTNAME ROOT) |
| 138 | if (SEMIHOSTING) |
| 139 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 140 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 141 | else() |
| 142 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 143 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 144 | endif() |
| 145 | endfunction() |
| 146 | |
| 147 | function(compilerSpecificPlatformConfigAppForM PROJECTNAME ROOT) |
| 148 | if (SEMIHOSTING) |
| 149 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 150 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 151 | else() |
| 152 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 153 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 154 | endif() |
| 155 | endfunction() |
| 156 | |
| 157 | function(compilerSpecificPlatformConfigAppForA PROJECTNAME ROOT) |
| 158 | if (SEMIHOSTING) |
| 159 | target_link_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 160 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=rdimon.specs") |
| 161 | else() |
| 162 | target_link_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 163 | target_compile_options(${PROJECTNAME} PRIVATE "--specs=nosys.specs") |
| 164 | endif() |
| 165 | endfunction() |