Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2019-2020 Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 7 | # not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | if (__TOOLCHAIN_LOADED) |
| 20 | return() |
| 21 | endif() |
| 22 | set(__TOOLCHAIN_LOADED TRUE) |
| 23 | |
| 24 | set(CMAKE_SYSTEM_NAME Generic) |
| 25 | set(CMAKE_C_COMPILER "arm-none-eabi-gcc") |
| 26 | set(CMAKE_CXX_COMPILER "arm-none-eabi-g++") |
| 27 | set(CMAKE_SYSTEM_PROCESSOR "cortex-m33+nodsp" CACHE STRING "Select Cortex-M architure. (cortex-m0, cortex-m3, cortex-m33, cortex-m4, cortex-m55, cortex-m7, etc)") |
| 28 | |
| 29 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
| 30 | |
| 31 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| 32 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 33 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| 34 | |
| 35 | set(CMAKE_C_STANDARD 99) |
Per Åstrand | 5014a44 | 2020-11-05 11:24:09 +0100 | [diff] [blame] | 36 | set(CMAKE_CXX_STANDARD 14) |
Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 37 | |
| 38 | # The system processor could for example be set to cortex-m33+nodsp+nofp. |
| 39 | set(__CPU_COMPILE_TARGET ${CMAKE_SYSTEM_PROCESSOR}) |
| 40 | string(REPLACE "+" ";" __CPU_FEATURES ${__CPU_COMPILE_TARGET}) |
| 41 | list(POP_FRONT __CPU_FEATURES CMAKE_SYSTEM_PROCESSOR) |
| 42 | |
| 43 | string(FIND ${__CPU_COMPILE_TARGET} "+" __OFFSET) |
| 44 | if(__OFFSET GREATER_EQUAL 0) |
| 45 | string(SUBSTRING ${__CPU_COMPILE_TARGET} ${__OFFSET} -1 CPU_FEATURES) |
| 46 | endif() |
| 47 | |
| 48 | # Add -mcpu to the compile options to override the -mcpu the CMake toolchain adds |
| 49 | add_compile_options(-mcpu=${__CPU_COMPILE_TARGET}) |
| 50 | |
| 51 | # Set floating point unit |
| 52 | if("${__CPU_COMPILE_TARGET}" MATCHES "\\+fp") |
| 53 | set(FLOAT hard) |
| 54 | elseif("${__CPU_COMPILE_TARGET}" MATCHES "\\+nofp") |
| 55 | set(FLOAT soft) |
| 56 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m33" OR |
| 57 | "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55") |
| 58 | set(FLOAT hard) |
| 59 | else() |
| 60 | set(FLOAT soft) |
| 61 | endif() |
| 62 | |
| 63 | add_compile_options(-mfloat-abi=${FLOAT}) |
| 64 | add_link_options(-mfloat-abi=${FLOAT}) |
| 65 | |
| 66 | # Link target |
| 67 | add_link_options(-mcpu=${__CPU_COMPILE_TARGET}) |
| 68 | add_link_options(-Xlinker -Map=output.map) |
| 69 | |
| 70 | # |
| 71 | # Compile options |
| 72 | # |
| 73 | set(cxx_flags "-fno-unwind-tables;-fno-rtti;-fno-exceptions") |
| 74 | |
| 75 | add_compile_options("-Wall;-Wextra;-Wsign-compare;-Wunused;-Wswitch-default;-Wformat;\ |
| 76 | -Wdouble-promotion;-Wredundant-decls;-Wshadow;-Wcast-align;-Wnull-dereference;\ |
| 77 | -Wno-format-extra-args;-Wno-unused-function;-Wno-unused-label;\ |
| 78 | -Wno-missing-field-initializers;-Wno-return-type" |
| 79 | "$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>" |
| 80 | ) |
| 81 | |