blob: de35f329e596257c0dd1c5656fe44aa6531619b6 [file] [log] [blame]
Joakim Bech6e44d8b2018-02-13 17:21:19 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2017-2018, 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
11Include(Common/CompilerArmClangCommon)
12Include(Common/Utils)
13
14check_armclang_input_vars("6.9")
15
Antonio de Angelisf1f7ebd2018-11-23 23:11:41 +000016if(NOT DEFINED ARM_CPU_ARCHITECTURE)
17 set(_NO_ARM_CPU_ARCHITECTURE true)
18elseif (${ARM_CPU_ARCHITECTURE} STREQUAL "ARMv8-M.BASE")
Joakim Bech6e44d8b2018-02-13 17:21:19 +010019 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-m.base")
21 #following is to work around an armclang compiler bug that is fixed in 6.10
22 string_append_unique_item(STRING CMAKE_C_FLAGS KEY "-fno-optimize-sibling-calls" VAL "-fno-optimize-sibling-calls")
23 string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi")
24 string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv8-m.base")
25 string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8-M.Base")
26 string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8-M.Base")
Antonio de Angelisf1f7ebd2018-11-23 23:11:41 +000027elseif(${ARM_CPU_ARCHITECTURE} STREQUAL "ARMv8-M.MAIN")
Joakim Bech6e44d8b2018-02-13 17:21:19 +010028 string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi")
29 string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-march=" VAL "-march=armv8-m.main")
30 string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi")
31 string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv8-m.main")
32 string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8-M.Main")
33 string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=8-M.Main")
Antonio de Angelisf1f7ebd2018-11-23 23:11:41 +000034elseif(${ARM_CPU_ARCHITECTURE} STREQUAL "ARMv7-M")
Joakim Bech6e44d8b2018-02-13 17:21:19 +010035 string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi")
36 string_append_unique_item(STRING CMAKE_C_FLAGS_CPU KEY "-march=" VAL "-march=armv8-m")
37 string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "--target=" VAL "--target=arm-arm-none-eabi")
38 string_append_unique_item(STRING CMAKE_CXX_FLAGS_CPU KEY "-march=" VAL "-march=armv7-m")
39 string_append_unique_item(STRING CMAKE_ASM_FLAGS_CPU KEY "--cpu=" VAL "--cpu=7-M")
40 string_append_unique_item(STRING CMAKE_LINK_FLAGS_CPU KEY "--cpu=" VAL "--cpu=7-M")
41else()
42 message(FATAL_ERROR "Unknown or unsupported ARM cpu architecture setting.")
43endif()
44
Antonio de Angelisf1f7ebd2018-11-23 23:11:41 +000045#Prefer architecture definition over cpu type.
46if(NOT DEFINED ARM_CPU_ARCHITECTURE)
Joakim Bech6e44d8b2018-02-13 17:21:19 +010047 if(NOT DEFINED ARM_CPU_TYPE)
48 string_append_unique_item(_NO_ARM_CPU_TYPE true)
49 elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M3")
50 string_append_unique_item (CMAKE_C_FLAGS_CPU "--target=arm-arm-none-eabi -mcpu=cortex-m3")
51 string_append_unique_item (CMAKE_CXX_FLAGS_CPU "--target=arm-arm-none-eabi -mcpu=cortex-m3")
52 string_append_unique_item (CMAKE_ASM_FLAGS_CPU "--cpu=Cortex-M3")
53 string_append_unique_item (CMAKE_LINK_FLAGS_CPU "--cpu=Cortex-M3")
54 elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M33")
55 string_append_unique_item (CMAKE_C_FLAGS_CPU "--target=arm-arm-none-eabi -mcpu=cortex-m33")
56 string_append_unique_item (CMAKE_CXX_FLAGS_CPU "--target=arm-arm-none-eabi -mcpu=cortex-m33")
57 string_append_unique_item (CMAKE_ASM_FLAGS_CPU "--cpu=Cortex-M33")
58 string_append_unique_item (CMAKE_LINK_FLAGS_CPU "--cpu=Cortex-M33")
59 elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M23")
60 #-fno-optimize-sibling-calls is here to work around an armclang compiler
61 #bug that is fixed in 6.10
62 string_append_unique_item (CMAKE_C_FLAGS_CPU "--target=arm-arm-none-eabi -mcpu=cortex-m23 -fno-optimize-sibling-calls")
63 string_append_unique_item (CMAKE_CXX_FLAGS_CPU "--target=arm-arm-none-eabi -mcpu=cortex-m23 -fno-optimize-sibling-calls")
64 string_append_unique_item (CMAKE_ASM_FLAGS_CPU "--cpu=Cortex-M23")
65 string_append_unique_item (CMAKE_LINK_FLAGS_CPU "--cpu=Cortex-M23")
66 else()
67 message(FATAL_ERROR "Unknown ARM cpu setting.")
68 endif()
69endif()
70
Antonio de Angelisf1f7ebd2018-11-23 23:11:41 +000071if (_NO_ARM_CPU_TYPE AND _NO_ARM_CPU_ARCHITECTURE)
Joakim Bech6e44d8b2018-02-13 17:21:19 +010072 message(FATAL_ERROR "Can not set CPU specific compiler flags: neither the ARM CPU type nor the architecture is set.")
73endif()