Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 1 | # |
| 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 | cmake_minimum_required(VERSION 3.15.6) |
| 20 | |
| 21 | project(ethosu_core_driver VERSION 0.0.1) |
| 22 | |
| 23 | # |
| 24 | # Build options |
| 25 | # |
| 26 | |
Kristofer Jonsson | 537c71c | 2020-05-05 14:17:22 +0200 | [diff] [blame] | 27 | option(DRIVER_PMU_AUTOINIT "Enable PMU boot auto-initialization" OFF) |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 28 | |
Kristofer Jonsson | 537c71c | 2020-05-05 14:17:22 +0200 | [diff] [blame] | 29 | set(CMSIS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmsis" CACHE PATH "Path to CMSIS.") |
Bhavik Patel | f505781 | 2020-07-16 22:36:02 +0200 | [diff] [blame^] | 30 | set(DRIVER_LOG_SEVERITY "6" CACHE STRING "Driver log severity level 0=emerg, 1=alert, 2=crit, 3=err, 4=warning, 5=notice, 6=info, 7=debug") |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 31 | |
| 32 | # |
| 33 | # Global settings |
| 34 | # |
| 35 | |
| 36 | if(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m0") |
| 37 | add_compile_definitions(CPU_CORTEX_M0) |
| 38 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m3") |
| 39 | add_compile_definitions(CPU_CORTEX_M3) |
| 40 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m33") |
| 41 | add_compile_definitions(CPU_CORTEX_M33) |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 42 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m4") |
| 43 | add_compile_definitions(CPU_CORTEX_M4) |
| 44 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m55") |
| 45 | add_compile_definitions(CPU_CORTEX_M55) |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 46 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m7") |
| 47 | add_compile_definitions(CPU_CORTEX_M7) |
| 48 | else() |
| 49 | message(FATAL_ERROR "Unsupported compiler ${CMAKE_SYSTEM_PROCESSOR}.") |
| 50 | endif() |
| 51 | |
Bhavik Patel | f505781 | 2020-07-16 22:36:02 +0200 | [diff] [blame^] | 52 | # Check that DRIVER_LOG_SEVERITY has one of the supported |
| 53 | # levels. |
| 54 | set(LOG_SEVERITY_VALUE 0 1 2 3 4 5 6 7) |
| 55 | set(LOG_SEVERITY_NAME EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG) |
| 56 | if(NOT ${DRIVER_LOG_SEVERITY} IN_LIST LOG_SEVERITY_VALUE) |
| 57 | message(FATAL_ERROR "Unsupported driver log severity level ${DRIVER_LOG_SEVERITY}") |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 58 | endif() |
| 59 | |
Jonny Svärd | b64628f | 2020-06-02 15:24:54 +0200 | [diff] [blame] | 60 | # Enable PMU boot auto-initialization |
| 61 | if(DRIVER_PMU_AUTOINIT) |
| 62 | add_compile_definitions(PMU_AUTOINIT) |
| 63 | endif() |
| 64 | |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 65 | # Make include directories available for current- and sub projects |
| 66 | include_directories(include src) |
| 67 | include_directories(${CMSIS_PATH}/CMSIS/Core/Include) |
| 68 | |
| 69 | # |
| 70 | # Build libraries |
| 71 | # |
| 72 | |
| 73 | # Build driver library |
| 74 | add_library(ethosu_core_driver STATIC) |
Kristofer Jonsson | 537c71c | 2020-05-05 14:17:22 +0200 | [diff] [blame] | 75 | target_include_directories(ethosu_core_driver PUBLIC include) |
| 76 | target_sources(ethosu_core_driver PRIVATE src/ethosu_driver.c src/ethosu_device.c src/ethosu_pmu.c) |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 77 | |
Bhavik Patel | f505781 | 2020-07-16 22:36:02 +0200 | [diff] [blame^] | 78 | # Set the DRIVER_LOG_SEVERITY level for the target |
| 79 | target_compile_definitions(ethosu_core_driver PRIVATE DRIVER_LOG_SEVERITY=${DRIVER_LOG_SEVERITY}) |
| 80 | |
| 81 | foreach(S IN ZIP_LISTS LOG_SEVERITY_VALUE LOG_SEVERITY_NAME) |
| 82 | # This will add a define in the form of LOG_SEVERITY_INFO=6. |
| 83 | # This is to make the conditional check like |
| 84 | # (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_INFO) possible. |
| 85 | target_compile_definitions(ethosu_core_driver PRIVATE LOG_SEVERITY_${S_1}=${S_0}) |
| 86 | if(${DRIVER_LOG_SEVERITY} STREQUAL ${S_0}) |
| 87 | set(DRIVER_LOG_SEVERITY_NAME ${S_1}) |
| 88 | endif() |
| 89 | endforeach() |
| 90 | |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 91 | # |
| 92 | # Print build status |
| 93 | # |
| 94 | |
| 95 | message(STATUS "*******************************************************") |
| 96 | message(STATUS "PROJECT_NAME : ${PROJECT_NAME}") |
| 97 | message(STATUS "CMAKE_SYSTEM_PROCESSOR : ${CMAKE_SYSTEM_PROCESSOR}") |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 98 | message(STATUS "CMSIS_PATH : ${CMSIS_PATH}") |
Bhavik Patel | f505781 | 2020-07-16 22:36:02 +0200 | [diff] [blame^] | 99 | message(STATUS "DRIVER_LOG_SEVERITY : ${DRIVER_LOG_SEVERITY} (${DRIVER_LOG_SEVERITY_NAME})") |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 100 | message(STATUS "*******************************************************") |