blob: 2b4d71cca0d0c3ac6bfed7d09060ee680297588e [file] [log] [blame]
Anton Komlevaee4b612023-05-14 17:38:36 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8set(CMAKE_SYSTEM_NAME Generic)
9
10set(CMAKE_C_COMPILER_FORCED TRUE)
11set(CMAKE_CXX_COMPILER_FORCED TRUE)
12
13find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}-gcc)
14find_program(CMAKE_CXX_COMPILER ${CROSS_COMPILE}-g++)
15
16if(CMAKE_C_COMPILER STREQUAL "CMAKE_C_COMPILER-NOTFOUND")
17 message(FATAL_ERROR "Could not find compiler: '${CROSS_COMPILE}-gcc'")
18endif()
19
20if(CMAKE_CXX_COMPILER STREQUAL "CMAKE_CXX_COMPILER-NOTFOUND")
21 message(FATAL_ERROR "Could not find compiler: '${CROSS_COMPILE}-g++'")
22endif()
23
24set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
25
26# Set compiler ID explicitly as it's not detected at this moment
27set(CMAKE_C_COMPILER_ID GNU)
Anton Komlevdd0a7222023-09-19 18:49:39 +010028
29# A platfomr sprecific MCPU and architecture flags for NS side
30include(${CONFIG_SPE_PATH}/platform/cpuarch.cmake)
Anton Komlevaee4b612023-05-14 17:38:36 +010031
32add_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
48add_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
60EXECUTE_PROCESS( COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION )
61if (GCC_VERSION VERSION_LESS 7.3.1)
62 message(FATAL_ERROR "Please use newer GNU Arm compiler version starting from 7.3.1.")
63endif()
64
David Hu500ea2f2023-10-13 12:15:08 +080065# 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.
77macro(target_add_scatter_file target)
Anton Komlevaee4b612023-05-14 17:38:36 +010078
David Hu500ea2f2023-10-13 12:15:08 +080079 get_target_property(scatter_file
80 platform_ns
81 INTERFACE_LINK_DEPENDS
Anton Komlevaee4b612023-05-14 17:38:36 +010082 )
83
David Hu500ea2f2023-10-13 12:15:08 +080084 # 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 Komlevaee4b612023-05-14 17:38:36 +0100108 LANGUAGE C
109 KEEP_EXTENSION True)
110
David Hu500ea2f2023-10-13 12:15:08 +0800111 target_compile_options(${target}_scatter
Anton Komlevaee4b612023-05-14 17:38:36 +0100112 PRIVATE
113 -E
114 -P
115 -xc
116 )
117
David Hu500ea2f2023-10-13 12:15:08 +0800118 target_link_libraries(${target}_scatter platform_ns)
Anton Komlevaee4b612023-05-14 17:38:36 +0100119
David Hu500ea2f2023-10-13 12:15:08 +0800120 add_dependencies(${target} ${target}_scatter)
Anton Komlevaee4b612023-05-14 17:38:36 +0100121
122endmacro()