Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2020-2023, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | set(CMAKE_SYSTEM_NAME Generic) |
| 9 | |
| 10 | set(CMAKE_C_COMPILER_FORCED TRUE) |
| 11 | set(CMAKE_CXX_COMPILER_FORCED TRUE) |
| 12 | |
| 13 | find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}-gcc) |
| 14 | find_program(CMAKE_CXX_COMPILER ${CROSS_COMPILE}-g++) |
| 15 | |
| 16 | if(CMAKE_C_COMPILER STREQUAL "CMAKE_C_COMPILER-NOTFOUND") |
| 17 | message(FATAL_ERROR "Could not find compiler: '${CROSS_COMPILE}-gcc'") |
| 18 | endif() |
| 19 | |
| 20 | if(CMAKE_CXX_COMPILER STREQUAL "CMAKE_CXX_COMPILER-NOTFOUND") |
| 21 | message(FATAL_ERROR "Could not find compiler: '${CROSS_COMPILE}-g++'") |
| 22 | endif() |
| 23 | |
| 24 | set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) |
| 25 | |
| 26 | # Set compiler ID explicitly as it's not detected at this moment |
| 27 | set(CMAKE_C_COMPILER_ID GNU) |
Anton Komlev | dd0a722 | 2023-09-19 18:49:39 +0100 | [diff] [blame] | 28 | |
| 29 | # A platfomr sprecific MCPU and architecture flags for NS side |
| 30 | include(${CONFIG_SPE_PATH}/platform/cpuarch.cmake) |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 31 | |
| 32 | add_compile_options( |
| 33 | -specs=nano.specs |
| 34 | -Wall |
| 35 | -Wno-format |
| 36 | -Wno-return-type |
| 37 | -Wno-unused-but-set-variable |
| 38 | -c |
| 39 | -fdata-sections |
| 40 | -ffunction-sections |
| 41 | -fno-builtin |
| 42 | -fshort-enums |
| 43 | -funsigned-char |
| 44 | -mthumb |
| 45 | -nostdlib |
| 46 | ) |
| 47 | |
| 48 | add_link_options( |
| 49 | --entry=Reset_Handler |
| 50 | -specs=nano.specs |
| 51 | LINKER:-check-sections |
| 52 | LINKER:-fatal-warnings |
| 53 | LINKER:--gc-sections |
| 54 | LINKER:--no-wchar-size-warning |
| 55 | LINKER:--print-memory-usage |
| 56 | LINKER:-Map=tfm_ns.map |
| 57 | -T $<TARGET_OBJECTS:tfm_ns_scatter> |
| 58 | ) |
| 59 | |
| 60 | EXECUTE_PROCESS( COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION ) |
| 61 | if (GCC_VERSION VERSION_LESS 7.3.1) |
| 62 | message(FATAL_ERROR "Please use newer GNU Arm compiler version starting from 7.3.1.") |
| 63 | endif() |
| 64 | |
David Hu | 500ea2f | 2023-10-13 12:15:08 +0800 | [diff] [blame^] | 65 | # Specify the linker script used to link `target`. |
| 66 | # Behaviour for handling linker scripts is so wildly divergent between compilers |
| 67 | # that this macro is required. |
| 68 | # |
| 69 | # Vendor platform can set a linker script as property INTERFACE_LINK_DEPENDS of platform_ns. |
| 70 | # `target` can fetch the linker script from platform_ns. |
| 71 | # |
| 72 | # Alternatively, NS build can call target_add_scatter_file() with the install directory of |
| 73 | # linker script. |
| 74 | # target_add_scatter_file(target, install_dir) |
| 75 | # |
| 76 | # target_add_scatter_file() fetch a linker script from the install directory. |
| 77 | macro(target_add_scatter_file target) |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 78 | |
David Hu | 500ea2f | 2023-10-13 12:15:08 +0800 | [diff] [blame^] | 79 | get_target_property(scatter_file |
| 80 | platform_ns |
| 81 | INTERFACE_LINK_DEPENDS |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 82 | ) |
| 83 | |
David Hu | 500ea2f | 2023-10-13 12:15:08 +0800 | [diff] [blame^] | 84 | # If scatter_file is not passed from platform_ns |
| 85 | # Try if any linker script is exported in install directory |
| 86 | # The intall directory is passed as an optinal argument |
| 87 | if(${scatter_file} STREQUAL "scatter_file-NOTFOUND") |
| 88 | set(install_dir ${ARGN}) |
| 89 | list(LENGTH install_dir nr_install_dir) |
| 90 | |
| 91 | # If nr_install_dir == 1, search for sct file under install dir |
| 92 | if(${nr_install_dir} EQUAL 1) |
| 93 | file(GLOB scatter_file "${install_dir}/*.ld") |
| 94 | endif() |
| 95 | endif() |
| 96 | |
| 97 | if(NOT EXISTS ${scatter_file}) |
| 98 | message(FATAL_ERROR "Unable to find NS scatter file ${scatter_file}") |
| 99 | endif() |
| 100 | |
| 101 | add_library(${target}_scatter OBJECT) |
| 102 | target_sources(${target}_scatter |
| 103 | PRIVATE |
| 104 | ${scatter_file} |
| 105 | ) |
| 106 | |
| 107 | set_source_files_properties(${scatter_file} PROPERTIES |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 108 | LANGUAGE C |
| 109 | KEEP_EXTENSION True) |
| 110 | |
David Hu | 500ea2f | 2023-10-13 12:15:08 +0800 | [diff] [blame^] | 111 | target_compile_options(${target}_scatter |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 112 | PRIVATE |
| 113 | -E |
| 114 | -P |
| 115 | -xc |
| 116 | ) |
| 117 | |
David Hu | 500ea2f | 2023-10-13 12:15:08 +0800 | [diff] [blame^] | 118 | target_link_libraries(${target}_scatter platform_ns) |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 119 | |
David Hu | 500ea2f | 2023-10-13 12:15:08 +0800 | [diff] [blame^] | 120 | add_dependencies(${target} ${target}_scatter) |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 121 | |
| 122 | endmacro() |