blob: 44b0029d7351cf78511432b0c9711876d8b51d74 [file] [log] [blame]
Gyorgy Szing30fa9872017-12-05 01:08:47 +00001#-------------------------------------------------------------------------------
Mate Toth-Palef4b26e2018-01-17 19:52:35 +01002# Copyright (c) 2017-2018, Arm Limited. All rights reserved.
Gyorgy Szing30fa9872017-12-05 01:08:47 +00003#
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.7")
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")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000019 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")
Mate Toth-Pal2e94d132018-01-26 17:27:52 +010021 #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")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000023 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")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000028 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")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000035 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)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000047 if(NOT DEFINED ARM_CPU_TYPE)
Mate Toth-Pal2e94d132018-01-26 17:27:52 +010048 string_append_unique_item(_NO_ARM_CPU_TYPE true)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000049 elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M3")
Mate Toth-Pal2e94d132018-01-26 17:27:52 +010050 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")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000054 elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M33")
Mate Toth-Pal2e94d132018-01-26 17:27:52 +010055 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")
Mate Toth-Palef4b26e2018-01-17 19:52:35 +010059 elseif(${ARM_CPU_TYPE} STREQUAL "Cortex-M23")
Mate Toth-Pal2e94d132018-01-26 17:27:52 +010060 #-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")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000066 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)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000072 message(FATAL_ERROR "Can not set CPU specific compiler flags: neither the ARM CPU type nor the architecture is set.")
73endif()