blob: d2173ec710b79bf0a1f5d99f11c50b0a4599eacb [file] [log] [blame]
alexander31ae9f02022-02-10 16:15:54 +00001#----------------------------------------------------------------------------
2# Copyright (c) 2022 Arm Limited. All rights reserved.
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://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,
13# WITHOUT 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#########################################################
19# Generic CMSIS Start up library for Cortex-M targets #
20#########################################################
Kshitij Sisodia9c6f9f82022-05-20 14:30:02 +010021cmake_minimum_required(VERSION 3.21.0)
alexander31ae9f02022-02-10 16:15:54 +000022
23set(CMSIS_DEVICE_TARGET cmsis_device)
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +000024set(CPU_HEADER_TARGET rte_components)
alexander31ae9f02022-02-10 16:15:54 +000025
26project(${CMSIS_DEVICE_TARGET}
27 DESCRIPTION "Generic CMSIS start up file for Cortex-M targets"
28 LANGUAGES C CXX ASM)
29
30# 1. We should be cross-compiling (non-native target)
31if (NOT ${CMAKE_CROSSCOMPILING})
32 message(FATAL_ERROR "No ${CMSIS_DEVICE_TARGET} support for this target.")
33endif()
34
35# 2. Check if CMSIS sources have been defined
36if (NOT DEFINED CMSIS_SRC_PATH)
37 message(FATAL_ERROR "CMSIS_SRC_PATH path should be defined for ${CMSIS_DEVICE_TARGET}.")
38endif()
39
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000040# 3.1 Create an interface library for CPU header only
41add_library(${CPU_HEADER_TARGET} INTERFACE)
alexander31ae9f02022-02-10 16:15:54 +000042
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000043## Interface include directories:
44target_include_directories(${CPU_HEADER_TARGET}
45 INTERFACE
alexander31ae9f02022-02-10 16:15:54 +000046 include
47 ${CMSIS_SRC_PATH}/CMSIS/Core/Include
48 ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Include
49 ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Include/Template)
50
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000051# 3.2 Create static library
52add_library(${CMSIS_DEVICE_TARGET} STATIC)
53
54## Sources - public
alexander31ae9f02022-02-10 16:15:54 +000055target_sources(${CMSIS_DEVICE_TARGET}
Liam Barry7a8f44d2022-03-01 10:43:31 +000056 PUBLIC
57 source/handlers.c)
58
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000059## Sources - private
Liam Barry7a8f44d2022-03-01 10:43:31 +000060target_sources(${CMSIS_DEVICE_TARGET}
alexander31ae9f02022-02-10 16:15:54 +000061 PRIVATE
Kshitij Sisodiafb93fa72022-02-24 09:51:02 +000062 ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Source/system_${ARM_CPU}.c
63 ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c)
64
65# Device definition needs to be set, is checked in source files to include correct header
66target_compile_definitions(${CMSIS_DEVICE_TARGET} PUBLIC ${ARM_CPU})
67
alexander31ae9f02022-02-10 16:15:54 +000068# Tell linker that reset interrupt handler is our entry point
69target_link_options(
70 ${CMSIS_DEVICE_TARGET}
71 INTERFACE
72 --entry Reset_Handler)
73
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000074# Link libraries
75target_link_libraries(${CMSIS_DEVICE_TARGET}
76 PUBLIC
77 ${CPU_HEADER_TARGET})
78
Kshitij Sisodiaacc6b852022-03-01 10:23:11 +000079# Check if semihosting configuration is available
80if (COMMAND configure_semihosting)
Kshitij Sisodia6a2ac462022-03-01 17:36:06 +000081 configure_semihosting(${CMSIS_DEVICE_TARGET} OFF)
Kshitij Sisodiaacc6b852022-03-01 10:23:11 +000082endif()
83
alexander31ae9f02022-02-10 16:15:54 +000084# 4 Display status:
85message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
86message(STATUS "*******************************************************")
87message(STATUS "Library : " ${CMSIS_DEVICE_TARGET})
88message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR})
alexander31ae9f02022-02-10 16:15:54 +000089message(STATUS "*******************************************************")