blob: 6e1cc4f3612be0bf398cf41c98c38e601bf0ecdd [file] [log] [blame]
Kristofer Jonsson18239302020-04-17 08:45:38 +02001#
Rajasekaran Kalidossf922fd12024-04-24 12:55:29 +02002# Copyright (c) 2019-2022, 2024 Arm Limited.
Kristofer Jonsson18239302020-04-17 08:45:38 +02003# 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 Jonssondace45a2022-09-13 13:13:30 +020019string(REGEX REPLACE "^cortex-m([0-9]+[a-z]*).*" "\\1" CPU_NUMBER ${CMAKE_SYSTEM_PROCESSOR})
Kristofer Jonsson18239302020-04-17 08:45:38 +020020if(NOT CPU_NUMBER)
21 message(FATAL_ERROR "System processor '${CMAKE_SYSTEM_PROCESSOR}' not supported. Should be cortex-m<nr>.")
22endif()
Kristofer Jonsson18239302020-04-17 08:45:38 +020023
Ledion Daja449c8d82022-06-21 12:22:13 +020024string(TOUPPER "ARMCM${CPU_NUMBER}" ARM_CPU)
Kristofer Jonsson18239302020-04-17 08:45:38 +020025
Bhavik Patel50aa51d2020-07-27 17:23:31 +020026# Set CPU specific features
Ledion Daja5845f3d2022-09-21 16:23:49 +020027if(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)")
Bhavik Patel50aa51d2020-07-27 17:23:31 +020028 set(ARM_FEATURES "_DSP_FP")
Ledion Daja5845f3d2022-09-21 16:23:49 +020029elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)")
Bhavik Patel50aa51d2020-07-27 17:23:31 +020030 set(ARM_FEATURES "_FP")
Ledion Daja5845f3d2022-09-21 16:23:49 +020031elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)")
Bhavik Patel50aa51d2020-07-27 17:23:31 +020032 set(ARM_FEATURES "_DP")
33else()
34 set(ARM_FEATURES "")
35endif()
36
37# CMSIS core
Kristofer Jonsson18239302020-04-17 08:45:38 +020038add_library(cmsis_core INTERFACE)
39target_include_directories(cmsis_core INTERFACE ${CMSIS_PATH}/CMSIS/Core/Include)
40
Bhavik Patel50aa51d2020-07-27 17:23:31 +020041# CMSIS device
42add_library(cmsis_device INTERFACE)
Rajasekaran Kalidossf922fd12024-04-24 12:55:29 +020043
44if (${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}")
47else()
48 cmake_path(APPEND CMSIS_PATH "Cortex_DFP/Device/" OUTPUT_VARIABLE CMSIS_DEVICE_PATH)
49 cmake_path(SET CMSIS_DEVICE_CPU_FEATURE "${ARM_CPU}")
50endif()
51
52target_include_directories(cmsis_device INTERFACE ${CMSIS_DEVICE_PATH}/${ARM_CPU}/Include)
Per Åstrand83e49962021-01-28 11:13:12 +010053
Kristofer Jonsson1efcc3f2021-02-16 17:40:25 +010054target_compile_options(cmsis_device INTERFACE
Rajasekaran Kalidossf922fd12024-04-24 12:55:29 +020055 "$<$<COMPILE_LANGUAGE:C>:-include${CMSIS_DEVICE_CPU_FEATURE}.h>"
56 "$<$<COMPILE_LANGUAGE:CXX>:-include${CMSIS_DEVICE_CPU_FEATURE}.h>")
57
Kristofer Jonsson7cfa5702020-12-16 09:17:51 +010058target_link_libraries(cmsis_device INTERFACE cmsis_core)
Bhavik Patel50aa51d2020-07-27 17:23:31 +020059
60# CMSIS startup
Per Åstrand83e49962021-01-28 11:13:12 +010061add_library(cmsis_startup INTERFACE)
62target_sources(cmsis_startup INTERFACE
Rajasekaran Kalidossf922fd12024-04-24 12:55:29 +020063 ${CMSIS_DEVICE_PATH}/${ARM_CPU}/Source/startup_${ARM_CPU}.c)
Per Åstrand19a22ae2020-11-27 19:47:58 +010064
Rajasekaran Kalidossf922fd12024-04-24 12:55:29 +020065set_source_files_properties(${CMSIS_DEVICE_PATH}/${ARM_CPU}/Source/startup_${ARM_CPU}.c
Per Åstrand83e49962021-01-28 11:13:12 +010066 PROPERTIES COMPILE_FLAGS -Wno-redundant-decls)
Per Åstrand19a22ae2020-11-27 19:47:58 +010067
Rajasekaran Kalidossf922fd12024-04-24 12:55:29 +020068target_compile_definitions(cmsis_startup INTERFACE ${CMSIS_DEVICE_CPU_FEATURE})
Per Åstrand83e49962021-01-28 11:13:12 +010069target_link_libraries(cmsis_startup INTERFACE cmsis_device)
Bhavik Patel50aa51d2020-07-27 17:23:31 +020070
Per Åstrand83e49962021-01-28 11:13:12 +010071# CMSIS system
72add_library(cmsis_system INTERFACE)
73target_sources(cmsis_system INTERFACE
Rajasekaran Kalidossf922fd12024-04-24 12:55:29 +020074 ${CMSIS_DEVICE_PATH}/${ARM_CPU}/Source/system_${ARM_CPU}.c)
75target_compile_definitions(cmsis_system INTERFACE ${CMSIS_DEVICE_CPU_FEATURE})
Per Åstrand83e49962021-01-28 11:13:12 +010076target_link_libraries(cmsis_system INTERFACE cmsis_startup)