Ronald Cron | c0c38fa | 2019-09-23 09:36:56 +0200 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2020, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | #This file contains settings to specify how ARMCLANG shall be used |
| 9 | |
| 10 | #Include some dependencies |
| 11 | Include(Common/CompilerArmClangCommon) |
| 12 | Include(Common/Utils) |
| 13 | |
| 14 | check_armclang_input_vars("6.13") |
| 15 | |
| 16 | if(NOT DEFINED ARM_CPU_ARCHITECTURE) |
| 17 | set(_NO_ARM_CPU_ARCHITECTURE true) |
Ronald Cron | 06fa1e4 | 2019-09-23 10:05:29 +0200 | [diff] [blame^] | 18 | elseif(${ARM_CPU_ARCHITECTURE} STREQUAL "ARMv8.1-M.MAIN") |
| 19 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 20 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-march=" VAL "-march=armv8.1-m.main+mve") |
| 21 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 22 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv8.1-m.main+mve") |
| 23 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8.1-M.Main.dsp") |
| 24 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8.1-M.Main.dsp") |
| 25 | |
| 26 | # FIXME |
| 27 | # When compiling for a given architecture, compilers define a flag identifying |
| 28 | # the architecture like __ARM_ARCH_7M__ or __ARM_ARCH_8M_MAIN__ or |
| 29 | # __ARM_ARCH_8_1M_MAIN__. Those flags are used in CMSIS headers like |
| 30 | # cmsis_armclang.h or cmsis_gcc.h to restrict the definition of some symbols |
| 31 | # to particular architectures. For the new Armv8.1-M.Main architecture, some |
| 32 | # CMSIS headers like cmsis_armclang.h or cmsis_gcc.h have not been updated yet |
| 33 | # to use __ARM_ARCH_8_1M_MAIN__. To mitigate this, core_armv81mml.h header |
| 34 | # defines __ARM_ARCH_8M_MAIN__: #define __ARM_ARCH_8M_MAIN__ 1. Concerning |
| 35 | # cmsis_armclang.h or cmsis_gcc.h includes, for this solution to work, wherever |
| 36 | # cmsis_compiler.h (which includes cmsis_armclang.h or cmsis_gcc.h) is included |
| 37 | # core_armv81mml.h has to be included as well. This is not the case in several |
| 38 | # places in TF-M code leading to compilation failures for some C files for |
| 39 | # Armv8.1-M architecture. When the CMSIS headers are updated to fully support |
| 40 | # the __ARM_ARCH_8_1M_MAIN__ flag, the compilation issues should disappear thus |
| 41 | # we don't want to change the header inclusions in TF-M code. Thus the below |
| 42 | # definition as a compile parameter of _ARM_ARCH_8M_MAIN__ that must be removed |
| 43 | # in the future. |
| 44 | |
| 45 | add_definitions(-D__ARM_ARCH_8M_MAIN__=1) |
| 46 | |
Ronald Cron | c0c38fa | 2019-09-23 09:36:56 +0200 | [diff] [blame] | 47 | elseif (${ARM_CPU_ARCHITECTURE} STREQUAL "ARMv8-M.BASE") |
| 48 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 49 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-march=" VAL "-march=armv8-m.base") |
| 50 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 51 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv8-m.base") |
| 52 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8-M.Base") |
| 53 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8-M.Base") |
| 54 | elseif(${ARM_CPU_ARCHITECTURE} STREQUAL "ARMv8-M.MAIN") |
| 55 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 56 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-march=" VAL "-march=armv8-m.main") |
| 57 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 58 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv8-m.main") |
| 59 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8-M.Main") |
| 60 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8-M.Main") |
| 61 | elseif(${ARM_CPU_ARCHITECTURE} STREQUAL "ARMv7-M") |
| 62 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 63 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-march=" VAL "-march=armv7-m") |
| 64 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 65 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv7-m") |
| 66 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=7-M") |
| 67 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=7-M") |
| 68 | elseif (${ARM_CPU_ARCHITECTURE} STREQUAL "ARMv6-M") |
| 69 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 70 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-march=" VAL "-march=armv6-m") |
| 71 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 72 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv6-m") |
| 73 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=6-M") |
| 74 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=6-M") |
| 75 | else() |
| 76 | message(FATAL_ERROR "Unknown or unsupported ARM cpu architecture setting.") |
| 77 | endif() |
| 78 | |
| 79 | #Prefer architecture definition over cpu type. |
| 80 | if(NOT DEFINED ARM_CPU_ARCHITECTURE) |
| 81 | if(NOT DEFINED ARM_CPU_TYPE) |
| 82 | string_append_unique_item(_NO_ARM_CPU_TYPE true) |
| 83 | elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M3") |
| 84 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 85 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-mcpu=" VAL "-mcpu=cortex-m3") |
| 86 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 87 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-mcpu=" VAL "-mcpu=cortex-m3") |
| 88 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu" VAL "--cpu=Cortex-M3") |
| 89 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu" VAL "--cpu=Cortex-M3") |
| 90 | elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M33") |
| 91 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 92 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-mcpu=" VAL "-mcpu=cortex-m33") |
| 93 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 94 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-mcpu=" VAL "-mcpu=cortex-m33") |
| 95 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu" VAL "--cpu=Cortex-M33") |
| 96 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu" VAL "--cpu=Cortex-M33") |
| 97 | elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M23") |
| 98 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 99 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-mcpu=" VAL "-mcpu=cortex-m23") |
| 100 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 101 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-mcpu=" VAL "-mcpu=cortex-m23") |
| 102 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu" VAL "--cpu=Cortex-M23") |
| 103 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu" VAL "--cpu=Cortex-M23") |
| 104 | elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M4") |
| 105 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 106 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-march=" VAL "-march=armv7-m") |
| 107 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 108 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv7-m") |
| 109 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=Cortex-M4") |
| 110 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=Cortex-M4") |
| 111 | set(ARM_CPU_ARCHITECTURE "ARMv7-M") |
| 112 | elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M0p") |
| 113 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 114 | string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-march=" VAL "-march=armv6-m") |
| 115 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi") |
| 116 | string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv6-m") |
| 117 | string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=Cortex-M0plus") |
| 118 | string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=Cortex-M0plus") |
| 119 | set(ARM_CPU_ARCHITECTURE "ARMv6-M") |
| 120 | else() |
| 121 | message(FATAL_ERROR "Unknown ARM cpu setting.") |
| 122 | endif() |
| 123 | endif() |
| 124 | |
| 125 | if (_NO_ARM_CPU_TYPE AND _NO_ARM_CPU_ARCHITECTURE) |
| 126 | message(FATAL_ERROR "Can not set CPU specific compiler flags: neither the ARM CPU type nor the architecture is set.") |
| 127 | endif() |