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