alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
| 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 | ######################################################### |
| 21 | cmake_minimum_required(VERSION 3.15.6) |
| 22 | |
| 23 | set(CMSIS_DEVICE_TARGET cmsis_device) |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 24 | set(CPU_HEADER_TARGET cmsis_device_cpu_header) |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 25 | |
| 26 | project(${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) |
| 31 | if (NOT ${CMAKE_CROSSCOMPILING}) |
| 32 | message(FATAL_ERROR "No ${CMSIS_DEVICE_TARGET} support for this target.") |
| 33 | endif() |
| 34 | |
| 35 | # 2. Check if CMSIS sources have been defined |
| 36 | if (NOT DEFINED CMSIS_SRC_PATH) |
| 37 | message(FATAL_ERROR "CMSIS_SRC_PATH path should be defined for ${CMSIS_DEVICE_TARGET}.") |
| 38 | endif() |
| 39 | |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 40 | # 3.1 Create an interface library for CPU header only |
| 41 | add_library(${CPU_HEADER_TARGET} INTERFACE) |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 42 | |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 43 | ## Interface include directories: |
| 44 | target_include_directories(${CPU_HEADER_TARGET} |
| 45 | INTERFACE |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 46 | 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 Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 51 | # 3.2 Create static library |
| 52 | add_library(${CMSIS_DEVICE_TARGET} STATIC) |
| 53 | |
| 54 | ## Sources - public |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 55 | target_sources(${CMSIS_DEVICE_TARGET} |
Liam Barry | 7a8f44d | 2022-03-01 10:43:31 +0000 | [diff] [blame] | 56 | PUBLIC |
| 57 | source/handlers.c) |
| 58 | |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 59 | ## Sources - private |
Liam Barry | 7a8f44d | 2022-03-01 10:43:31 +0000 | [diff] [blame] | 60 | target_sources(${CMSIS_DEVICE_TARGET} |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 61 | PRIVATE |
Kshitij Sisodia | fb93fa7 | 2022-02-24 09:51:02 +0000 | [diff] [blame] | 62 | ${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 |
| 66 | target_compile_definitions(${CMSIS_DEVICE_TARGET} PUBLIC ${ARM_CPU}) |
| 67 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 68 | # Tell linker that reset interrupt handler is our entry point |
| 69 | target_link_options( |
| 70 | ${CMSIS_DEVICE_TARGET} |
| 71 | INTERFACE |
| 72 | --entry Reset_Handler) |
| 73 | |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 74 | # Link libraries |
| 75 | target_link_libraries(${CMSIS_DEVICE_TARGET} |
| 76 | PUBLIC |
| 77 | ${CPU_HEADER_TARGET}) |
| 78 | |
Kshitij Sisodia | acc6b85 | 2022-03-01 10:23:11 +0000 | [diff] [blame] | 79 | # Check if semihosting configuration is available |
| 80 | if (COMMAND configure_semihosting) |
Kshitij Sisodia | 6a2ac46 | 2022-03-01 17:36:06 +0000 | [diff] [blame] | 81 | configure_semihosting(${CMSIS_DEVICE_TARGET} OFF) |
Kshitij Sisodia | acc6b85 | 2022-03-01 10:23:11 +0000 | [diff] [blame] | 82 | endif() |
| 83 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 84 | # 4 Display status: |
| 85 | message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) |
| 86 | message(STATUS "*******************************************************") |
| 87 | message(STATUS "Library : " ${CMSIS_DEVICE_TARGET}) |
| 88 | message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) |
| 89 | message(STATUS "*******************************************************") |