Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 1 | # |
Kristofer Jonsson | 1efcc3f | 2021-02-16 17:40:25 +0100 | [diff] [blame] | 2 | # Copyright (c) 2019-2021 Arm Limited. All rights reserved. |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 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 | # Extract the CPU number from the system processor |
| 20 | string(REGEX MATCH "^cortex-m([0-9]+)$" CPU_NUMBER ${CMAKE_SYSTEM_PROCESSOR}) |
| 21 | if(NOT CPU_NUMBER) |
| 22 | message(FATAL_ERROR "System processor '${CMAKE_SYSTEM_PROCESSOR}' not supported. Should be cortex-m<nr>.") |
| 23 | endif() |
| 24 | string(REGEX REPLACE "^cortex-m([0-9]+)$" "\\1" CPU_NUMBER ${CMAKE_SYSTEM_PROCESSOR}) |
| 25 | |
| 26 | set(ARM_CPU "ARMCM${CPU_NUMBER}") |
| 27 | |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 28 | # Set CPU specific features |
| 29 | if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "cortex-m33") |
| 30 | set(ARM_FEATURES "_DSP_FP") |
| 31 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "cortex-m4") |
| 32 | set(ARM_FEATURES "_FP") |
| 33 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "cortex-m7") |
| 34 | set(ARM_FEATURES "_DP") |
| 35 | else() |
| 36 | set(ARM_FEATURES "") |
| 37 | endif() |
| 38 | |
| 39 | # CMSIS core |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 40 | add_library(cmsis_core INTERFACE) |
| 41 | target_include_directories(cmsis_core INTERFACE ${CMSIS_PATH}/CMSIS/Core/Include) |
| 42 | |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 43 | # CMSIS device |
| 44 | add_library(cmsis_device INTERFACE) |
| 45 | target_include_directories(cmsis_device INTERFACE ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Include) |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 46 | |
Kristofer Jonsson | 1efcc3f | 2021-02-16 17:40:25 +0100 | [diff] [blame] | 47 | target_compile_options(cmsis_device INTERFACE |
| 48 | "$<$<COMPILE_LANGUAGE:C>:-include${ARM_CPU}${ARM_FEATURES}.h>" |
| 49 | "$<$<COMPILE_LANGUAGE:CXX>:-include${ARM_CPU}${ARM_FEATURES}.h>") |
Kristofer Jonsson | 7cfa570 | 2020-12-16 09:17:51 +0100 | [diff] [blame] | 50 | target_link_libraries(cmsis_device INTERFACE cmsis_core) |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 51 | |
| 52 | # CMSIS startup |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 53 | add_library(cmsis_startup INTERFACE) |
| 54 | target_sources(cmsis_startup INTERFACE |
| 55 | ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c) |
Per Åstrand | 19a22ae | 2020-11-27 19:47:58 +0100 | [diff] [blame] | 56 | |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 57 | set_source_files_properties(${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c |
| 58 | PROPERTIES COMPILE_FLAGS -Wno-redundant-decls) |
Per Åstrand | 19a22ae | 2020-11-27 19:47:58 +0100 | [diff] [blame] | 59 | |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 60 | target_compile_definitions(cmsis_startup INTERFACE ${ARM_CPU}${ARM_FEATURES}) |
| 61 | target_link_libraries(cmsis_startup INTERFACE cmsis_device) |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 62 | |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 63 | # CMSIS system |
| 64 | add_library(cmsis_system INTERFACE) |
| 65 | target_sources(cmsis_system INTERFACE |
| 66 | ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/system_${ARM_CPU}.c) |
| 67 | target_compile_definitions(cmsis_system INTERFACE ${ARM_CPU}${ARM_FEATURES}) |
| 68 | target_link_libraries(cmsis_system INTERFACE cmsis_startup) |