Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +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 | # Wrapper for enabling stdout and stderr facility # |
| 20 | ######################################################### |
| 21 | # This is a wrapper around the UART module for CMSDK # |
| 22 | # and PL011 UART drivers with retarget functions. # |
| 23 | ######################################################### |
| 24 | |
| 25 | cmake_minimum_required(VERSION 3.15.6) |
| 26 | |
| 27 | project(stdout |
| 28 | DESCRIPTION "Standard output and err redirection over UART" |
| 29 | LANGUAGES C CXX) |
| 30 | |
| 31 | |
| 32 | set(STDOUT_RETARGET OFF CACHE BOOL "Retarget stdout/err to UART") |
| 33 | |
| 34 | # Interface library for standard output: |
| 35 | set(STDOUT_IFACE_TARGET stdout_iface) |
| 36 | add_library(${STDOUT_IFACE_TARGET} INTERFACE) |
| 37 | target_include_directories(${STDOUT_IFACE_TARGET} INTERFACE include) |
| 38 | |
| 39 | if (STDOUT_RETARGET) |
| 40 | |
| 41 | set(STDOUT_COMPONENT_CMSDK stdout_retarget_cmsdk) |
| 42 | set(STDOUT_COMPONENT_PL011 stdout_retarget_pl011) |
| 43 | |
| 44 | add_library(${STDOUT_COMPONENT_CMSDK} STATIC) |
| 45 | add_library(${STDOUT_COMPONENT_PL011} STATIC) |
| 46 | |
| 47 | # Check prerequisites |
| 48 | ## Core platform directory is required to add the UART library project. |
| 49 | if (NOT DEFINED CORE_PLATFORM_DIR) |
| 50 | message(FATAL_ERROR "CORE_PLATFORM_DIR undefined") |
| 51 | endif() |
| 52 | |
| 53 | ## UART0_BASE is the base address for UART configuration. The platform |
| 54 | ## should define it prior to including this library. |
| 55 | if (NOT DEFINED UART0_BASE) |
| 56 | message(WARNING "UART0_BASE undefined, default will be used.") |
| 57 | endif() |
| 58 | |
| 59 | ## Platform component: UART |
| 60 | add_subdirectory(${CORE_PLATFORM_DIR}/drivers/uart ${CMAKE_BINARY_DIR}/uart) |
| 61 | |
| 62 | ## Component sources - public |
| 63 | target_sources(${STDOUT_COMPONENT_CMSDK} |
| 64 | PUBLIC |
| 65 | source/retarget.c) |
| 66 | |
| 67 | ## Component sources - public |
| 68 | target_sources(${STDOUT_COMPONENT_PL011} |
| 69 | PUBLIC |
| 70 | source/retarget.c) |
| 71 | |
| 72 | # Link |
| 73 | target_link_libraries(${STDOUT_COMPONENT_CMSDK} |
| 74 | PUBLIC |
| 75 | ${STDOUT_IFACE_TARGET} |
| 76 | ethosu_uart_cmsdk_apb) |
| 77 | |
| 78 | target_link_libraries(${STDOUT_COMPONENT_PL011} |
| 79 | PUBLIC |
| 80 | ${STDOUT_IFACE_TARGET} |
| 81 | ethosu_uart_pl011) |
| 82 | |
| 83 | # Display status |
| 84 | message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) |
| 85 | message(STATUS "*******************************************************") |
| 86 | message(STATUS "Library: " ${STDOUT_COMPONENT_CMSDK}) |
| 87 | message(STATUS "Library: " ${STDOUT_COMPONENT_PL011}) |
| 88 | message(STATUS "*******************************************************") |
| 89 | |
| 90 | else() |
| 91 | |
| 92 | # Create static library for retarget (stdout/err over UART) |
| 93 | set(STDOUT_COMPONENT stdout) |
| 94 | add_library(${STDOUT_COMPONENT} STATIC) |
| 95 | |
| 96 | ## Component sources - public |
| 97 | target_sources(${STDOUT_COMPONENT} |
| 98 | PUBLIC |
| 99 | source/user_input.c) |
| 100 | |
| 101 | target_link_libraries(${STDOUT_COMPONENT} |
| 102 | PUBLIC |
| 103 | ${STDOUT_IFACE_TARGET}) |
| 104 | |
| 105 | # Display status |
| 106 | message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) |
| 107 | message(STATUS "*******************************************************") |
| 108 | message(STATUS "Library: " ${STDOUT_COMPONENT}) |
| 109 | message(STATUS "*******************************************************") |
| 110 | endif() |