blob: 9322240f30ad01962df10da631ec557690494946 [file] [log] [blame]
Kristofer Jonsson18239302020-04-17 08:45:38 +02001#
2# Copyright (c) 2019-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# Extract the CPU number from the system processor
20string(REGEX MATCH "^cortex-m([0-9]+)$" CPU_NUMBER ${CMAKE_SYSTEM_PROCESSOR})
21if(NOT CPU_NUMBER)
22 message(FATAL_ERROR "System processor '${CMAKE_SYSTEM_PROCESSOR}' not supported. Should be cortex-m<nr>.")
23endif()
24string(REGEX REPLACE "^cortex-m([0-9]+)$" "\\1" CPU_NUMBER ${CMAKE_SYSTEM_PROCESSOR})
25
26set(ARM_CPU "ARMCM${CPU_NUMBER}")
27
Bhavik Patel50aa51d2020-07-27 17:23:31 +020028# Set CPU specific features
29if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "cortex-m33")
30 set(ARM_FEATURES "_DSP_FP")
31elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "cortex-m4")
32 set(ARM_FEATURES "_FP")
33elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "cortex-m7")
34 set(ARM_FEATURES "_DP")
35else()
36 set(ARM_FEATURES "")
37endif()
38
39# CMSIS core
Kristofer Jonsson18239302020-04-17 08:45:38 +020040add_library(cmsis_core INTERFACE)
41target_include_directories(cmsis_core INTERFACE ${CMSIS_PATH}/CMSIS/Core/Include)
42
Bhavik Patel50aa51d2020-07-27 17:23:31 +020043# CMSIS device
44add_library(cmsis_device INTERFACE)
45target_include_directories(cmsis_device INTERFACE ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Include)
Per Åstrand19a22ae2020-11-27 19:47:58 +010046if (TRUSTZONE_BUILD)
47 # Use Cortex-M Secure Extension when compiling
48 target_compile_options(cmsis_device INTERFACE -mcmse)
49 target_compile_definitions(cmsis_device INTERFACE TRUSTZONE_BUILD)
50 if (TRUSTZONE_SIDE STREQUAL secure)
51 target_compile_definitions(cmsis_device INTERFACE TRUSTZONE_SECURE)
52 else()
53 target_compile_definitions(cmsis_device INTERFACE TRUSTZONE_NONSECURE)
54 endif()
55endif()
Bhavik Patel50aa51d2020-07-27 17:23:31 +020056target_compile_options(cmsis_device INTERFACE -include${ARM_CPU}${ARM_FEATURES}.h)
Kristofer Jonsson7cfa5702020-12-16 09:17:51 +010057target_link_libraries(cmsis_device INTERFACE cmsis_core)
Bhavik Patel50aa51d2020-07-27 17:23:31 +020058
59# CMSIS startup
Per Åstrand19a22ae2020-11-27 19:47:58 +010060add_library(cmsis_startup STATIC)
61if (TRUSTZONE_BUILD)
62 if (TRUSTZONE_SIDE STREQUAL secure)
63 target_sources(cmsis_startup PRIVATE
64 ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c
65 ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/system_${ARM_CPU}.c)
66 # Bring in the partion header
67 target_include_directories(cmsis_startup PRIVATE ${TRUSTZONE_PARTITION_DIRECTORY})
68 elseif(TRUSTZONE_SIDE STREQUAL nonsecure)
69 target_sources(cmsis_startup PRIVATE
70 ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c)
71 endif()
72else()
73 target_sources(cmsis_startup PRIVATE
74 ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c
75 ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/system_${ARM_CPU}.c)
76endif()
77
Bhavik Patel97906eb2020-12-17 15:32:16 +010078set_source_files_properties(${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c PROPERTIES COMPILE_FLAGS
79 -Wno-redundant-decls)
Per Åstrand19a22ae2020-11-27 19:47:58 +010080
Bhavik Patel50aa51d2020-07-27 17:23:31 +020081target_compile_definitions(cmsis_startup PRIVATE ${ARM_CPU}${ARM_FEATURES})
Kristofer Jonsson7cfa5702020-12-16 09:17:51 +010082target_link_libraries(cmsis_startup PRIVATE cmsis_device)
Bhavik Patel50aa51d2020-07-27 17:23:31 +020083
84# Install libraries
85install(TARGETS cmsis_startup LIBRARY DESTINATION "lib")