Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 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 (NOT TARGET_CPU) |
| 20 | set(TARGET_CPU "cortex-m4") |
| 21 | endif() |
| 22 | |
| 23 | set(CMAKE_SYSTEM_NAME Generic) |
| 24 | set(CMAKE_C_COMPILER "arm-none-eabi-gcc") |
| 25 | set(CMAKE_CXX_COMPILER "arm-none-eabi-g++") |
| 26 | |
| 27 | # Convert TARGET_CPU=Cortex-M33+nofp+nodsp into |
| 28 | # - CMAKE_SYSTEM_PROCESSOR=cortex-m33 |
| 29 | # - TARGET_CPU_FEATURES=no-fp;no-dsp |
| 30 | string(REPLACE "+" ";" TARGET_CPU_FEATURES ${TARGET_CPU}) |
| 31 | list(POP_FRONT TARGET_CPU_FEATURES CMAKE_SYSTEM_PROCESSOR) |
| 32 | string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR) |
| 33 | |
| 34 | set(CMAKE_EXECUTABLE_SUFFIX ".elf") |
| 35 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
| 36 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| 37 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 38 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| 39 | |
| 40 | # Select C/C++ version |
| 41 | set(CMAKE_C_STANDARD 99) |
| 42 | set(CMAKE_CXX_STANDARD 14) |
| 43 | |
| 44 | # Compile options |
| 45 | add_compile_options( |
| 46 | -mcpu=${TARGET_CPU} |
| 47 | -mthumb |
| 48 | "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>") |
| 49 | |
| 50 | # Link options |
| 51 | add_link_options( |
| 52 | -mcpu=${TARGET_CPU} |
| 53 | -mthumb |
| 54 | --specs=nosys.specs) |
| 55 | |
| 56 | # Set floating point unit |
| 57 | if("${TARGET_CPU}" MATCHES "\\+fp") |
| 58 | set(FLOAT hard) |
| 59 | elseif("${TARGET_CPU}" MATCHES "\\+nofp") |
| 60 | set(FLOAT soft) |
| 61 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m33" OR |
| 62 | "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55") |
| 63 | set(FLOAT hard) |
| 64 | else() |
| 65 | set(FLOAT soft) |
| 66 | endif() |
| 67 | |
| 68 | if (FLOAT) |
| 69 | add_compile_options(-mfloat-abi=${FLOAT}) |
| 70 | add_link_options(-mfloat-abi=${FLOAT}) |
| 71 | endif() |
| 72 | |
| 73 | # Compilation warnings |
| 74 | add_compile_options( |
| 75 | -Wall |
| 76 | -Wextra |
| 77 | -Wsign-compare |
| 78 | -Wunused |
| 79 | -Wswitch-default |
| 80 | # -Wformat |
| 81 | -Wdouble-promotion |
| 82 | -Wredundant-decls |
| 83 | -Wshadow |
| 84 | # -Wcast-align |
| 85 | -Wnull-dereference |
| 86 | -Wno-format-extra-args |
| 87 | -Wno-unused-function |
| 88 | -Wno-unused-parameter |
| 89 | -Wno-unused-label |
| 90 | -Wno-missing-field-initializers |
| 91 | -Wno-return-type) |