Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 1 | # |
Rajasekaran Kalidoss | f922fd1 | 2024-04-24 12:55:29 +0200 | [diff] [blame] | 2 | # Copyright (c) 2019-2022, 2024 Arm Limited. |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 6 | # not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | # Extract the CPU number from the system processor |
Kristofer Jonsson | dace45a | 2022-09-13 13:13:30 +0200 | [diff] [blame] | 19 | 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] | 20 | if(NOT CPU_NUMBER) |
| 21 | message(FATAL_ERROR "System processor '${CMAKE_SYSTEM_PROCESSOR}' not supported. Should be cortex-m<nr>.") |
| 22 | endif() |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 23 | |
Ledion Daja | 449c8d8 | 2022-06-21 12:22:13 +0200 | [diff] [blame] | 24 | string(TOUPPER "ARMCM${CPU_NUMBER}" ARM_CPU) |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 25 | |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 26 | # Set CPU specific features |
Ledion Daja | 5845f3d | 2022-09-21 16:23:49 +0200 | [diff] [blame] | 27 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)") |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 28 | set(ARM_FEATURES "_DSP_FP") |
Ledion Daja | 5845f3d | 2022-09-21 16:23:49 +0200 | [diff] [blame] | 29 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)") |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 30 | set(ARM_FEATURES "_FP") |
Ledion Daja | 5845f3d | 2022-09-21 16:23:49 +0200 | [diff] [blame] | 31 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)") |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 32 | set(ARM_FEATURES "_DP") |
| 33 | else() |
| 34 | set(ARM_FEATURES "") |
| 35 | endif() |
| 36 | |
| 37 | # CMSIS core |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 38 | add_library(cmsis_core INTERFACE) |
| 39 | target_include_directories(cmsis_core INTERFACE ${CMSIS_PATH}/CMSIS/Core/Include) |
| 40 | |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 41 | # CMSIS device |
| 42 | add_library(cmsis_device INTERFACE) |
Rajasekaran Kalidoss | f922fd1 | 2024-04-24 12:55:29 +0200 | [diff] [blame] | 43 | |
| 44 | if (${CMSIS_VER} EQUAL 5) |
| 45 | cmake_path(SET CMSIS_DEVICE_PATH "${CMSIS_PATH}/Device/ARM") |
| 46 | cmake_path(SET CMSIS_DEVICE_CPU_FEATURE "${ARM_CPU}${ARM_FEATURES}") |
| 47 | else() |
| 48 | cmake_path(APPEND CMSIS_PATH "Cortex_DFP/Device/" OUTPUT_VARIABLE CMSIS_DEVICE_PATH) |
| 49 | cmake_path(SET CMSIS_DEVICE_CPU_FEATURE "${ARM_CPU}") |
| 50 | endif() |
| 51 | |
| 52 | target_include_directories(cmsis_device INTERFACE ${CMSIS_DEVICE_PATH}/${ARM_CPU}/Include) |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 53 | |
Kristofer Jonsson | 1efcc3f | 2021-02-16 17:40:25 +0100 | [diff] [blame] | 54 | target_compile_options(cmsis_device INTERFACE |
Rajasekaran Kalidoss | f922fd1 | 2024-04-24 12:55:29 +0200 | [diff] [blame] | 55 | "$<$<COMPILE_LANGUAGE:C>:-include${CMSIS_DEVICE_CPU_FEATURE}.h>" |
| 56 | "$<$<COMPILE_LANGUAGE:CXX>:-include${CMSIS_DEVICE_CPU_FEATURE}.h>") |
| 57 | |
Kristofer Jonsson | 7cfa570 | 2020-12-16 09:17:51 +0100 | [diff] [blame] | 58 | target_link_libraries(cmsis_device INTERFACE cmsis_core) |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 59 | |
| 60 | # CMSIS startup |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 61 | add_library(cmsis_startup INTERFACE) |
| 62 | target_sources(cmsis_startup INTERFACE |
Rajasekaran Kalidoss | f922fd1 | 2024-04-24 12:55:29 +0200 | [diff] [blame] | 63 | ${CMSIS_DEVICE_PATH}/${ARM_CPU}/Source/startup_${ARM_CPU}.c) |
Per Åstrand | 19a22ae | 2020-11-27 19:47:58 +0100 | [diff] [blame] | 64 | |
Rajasekaran Kalidoss | f922fd1 | 2024-04-24 12:55:29 +0200 | [diff] [blame] | 65 | set_source_files_properties(${CMSIS_DEVICE_PATH}/${ARM_CPU}/Source/startup_${ARM_CPU}.c |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 66 | PROPERTIES COMPILE_FLAGS -Wno-redundant-decls) |
Per Åstrand | 19a22ae | 2020-11-27 19:47:58 +0100 | [diff] [blame] | 67 | |
Rajasekaran Kalidoss | f922fd1 | 2024-04-24 12:55:29 +0200 | [diff] [blame] | 68 | target_compile_definitions(cmsis_startup INTERFACE ${CMSIS_DEVICE_CPU_FEATURE}) |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 69 | target_link_libraries(cmsis_startup INTERFACE cmsis_device) |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 70 | |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 71 | # CMSIS system |
| 72 | add_library(cmsis_system INTERFACE) |
| 73 | target_sources(cmsis_system INTERFACE |
Rajasekaran Kalidoss | f922fd1 | 2024-04-24 12:55:29 +0200 | [diff] [blame] | 74 | ${CMSIS_DEVICE_PATH}/${ARM_CPU}/Source/system_${ARM_CPU}.c) |
| 75 | target_compile_definitions(cmsis_system INTERFACE ${CMSIS_DEVICE_CPU_FEATURE}) |
Per Åstrand | 83e4996 | 2021-01-28 11:13:12 +0100 | [diff] [blame] | 76 | target_link_libraries(cmsis_system INTERFACE cmsis_startup) |