Gyorgy Szing | 4909180 | 2020-11-24 00:33:09 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Imre Kis | eeee964 | 2021-12-17 13:59:46 +0100 | [diff] [blame] | 2 | # Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
Gyorgy Szing | 4909180 | 2020-11-24 00:33:09 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
Gyorgy Szing | b8d6f26 | 2023-06-05 12:36:02 +0200 | [diff] [blame] | 8 | # Check mandatory variables. |
| 9 | foreach(_var IN ITEMS TGT) |
| 10 | if (NOT DEFINED ${_var}) |
| 11 | message(FATAL_ERROR "Mandatory parameter '${_var}' missing.") |
| 12 | endif() |
| 13 | endforeach() |
| 14 | |
Gyorgy Szing | 3e3db70 | 2023-07-21 14:18:19 +0200 | [diff] [blame] | 15 | # Ensure elf output naming is symbolize.py compatible. |
| 16 | # If binary UUID is not defined, fall back to using the SP UUID value. |
| 17 | if (NOT SP_BIN_UUID_CANON) |
| 18 | set(SP_BIN_UUID_CANON "${SP_UUID_CANON}") |
| 19 | endif() |
| 20 | ts_add_uuid_to_exe_name(TGT "${TGT}" UUID "${SP_BIN_UUID_CANON}" ) |
Gyorgy Szing | 4909180 | 2020-11-24 00:33:09 +0100 | [diff] [blame] | 21 | |
Gyorgy Szing | 6a0d992 | 2023-07-20 14:55:42 +0200 | [diff] [blame] | 22 | get_target_property(_tgt_type ${TGT} TYPE) |
| 23 | if ("${_tgt_type}" STREQUAL "EXECUTABLE") |
| 24 | compiler_generate_stripped_elf(TARGET ${TGT} NAME "${SP_BIN_UUID_CANON}.stripped.elf" RES STRIPPED_ELF) |
| 25 | install(FILES ${STRIPPED_ELF} DESTINATION ${TS_ENV}/bin) |
Gyorgy Szing | 8a1e7f4 | 2023-07-26 18:26:48 +0200 | [diff] [blame] | 26 | |
| 27 | # Get the name of the SP. |
| 28 | get_target_property(_tgt_name ${TGT} NAME ) |
| 29 | set(SP_NAME "${_tgt_name}" CACHE STRING "Name of the SP.") |
| 30 | |
| 31 | include(${TS_ROOT}/tools/cmake/common/TargetCompileDefinitions.cmake) |
| 32 | set_target_uuids( |
| 33 | SP_UUID ${SP_UUID_CANON} |
Gyorgy Szing | fd03e0a | 2023-07-27 20:04:24 +0200 | [diff] [blame^] | 34 | TGT ${SP_NAME} |
Gyorgy Szing | 8a1e7f4 | 2023-07-26 18:26:48 +0200 | [diff] [blame] | 35 | ) |
Gyorgy Szing | 6a0d992 | 2023-07-20 14:55:42 +0200 | [diff] [blame] | 36 | endif() |
| 37 | |
Gyorgy Szing | 4909180 | 2020-11-24 00:33:09 +0100 | [diff] [blame] | 38 | target_sources(${TGT} PRIVATE |
Imre Kis | e6d7341 | 2021-10-18 14:01:47 +0200 | [diff] [blame] | 39 | "${CMAKE_CURRENT_LIST_DIR}/optee_sp_header.c" |
Imre Kis | ef5c264 | 2021-12-17 14:07:35 +0100 | [diff] [blame] | 40 | "${CMAKE_CURRENT_LIST_DIR}/sp_assert.c" |
Imre Kis | e6d7341 | 2021-10-18 14:01:47 +0200 | [diff] [blame] | 41 | "${CMAKE_CURRENT_LIST_DIR}/sp_entry.c" |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 42 | "${CMAKE_CURRENT_LIST_DIR}/sp_trace.c" |
Imre Kis | e6d7341 | 2021-10-18 14:01:47 +0200 | [diff] [blame] | 43 | ) |
Andrew Beggs | 97a00d4 | 2021-06-15 15:45:46 +0000 | [diff] [blame] | 44 | |
| 45 | target_include_directories(${TGT} |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 46 | PUBLIC |
| 47 | "${CMAKE_CURRENT_LIST_DIR}/include" |
| 48 | ) |
| 49 | |
Imre Kis | e6d7341 | 2021-10-18 14:01:47 +0200 | [diff] [blame] | 50 | # Default trace configuration, can be overwritten by setting the same variables |
| 51 | # in the deployment specific file before including this file. |
| 52 | set(TRACE_PREFIX "SP" CACHE STRING "Trace prefix") |
| 53 | set(TRACE_LEVEL "TRACE_LEVEL_ERROR" CACHE STRING "Trace level") |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 54 | |
Imre Kis | eeee964 | 2021-12-17 13:59:46 +0100 | [diff] [blame] | 55 | if (NOT DEFINED SP_HEAP_SIZE) |
| 56 | message(FATAL_ERROR "SP_HEAP_SIZE is not defined") |
| 57 | endif() |
| 58 | |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 59 | target_compile_definitions(${TGT} PRIVATE |
| 60 | TRACE_LEVEL=${TRACE_LEVEL} |
| 61 | TRACE_PREFIX="${TRACE_PREFIX}" |
Imre Kis | eeee964 | 2021-12-17 13:59:46 +0100 | [diff] [blame] | 62 | SP_HEAP_SIZE=${SP_HEAP_SIZE} |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 63 | ) |
Imre Kis | e6d7341 | 2021-10-18 14:01:47 +0200 | [diff] [blame] | 64 | |
Julian Hall | 8ad6043 | 2022-08-15 14:11:47 +0100 | [diff] [blame] | 65 | include(${TS_ROOT}/external/newlib/newlib.cmake) |
Imre Kis | e6d7341 | 2021-10-18 14:01:47 +0200 | [diff] [blame] | 66 | |
| 67 | target_link_libraries(${TGT} PRIVATE |
Gyorgy Szing | 693877e | 2021-12-12 02:51:10 +0100 | [diff] [blame] | 68 | stdlib::c |
Imre Kis | e6d7341 | 2021-10-18 14:01:47 +0200 | [diff] [blame] | 69 | ) |
| 70 | |
| 71 | target_link_options(${TGT} PRIVATE |
| 72 | -Wl,--hash-style=sysv |
| 73 | -Wl,--as-needed |
| 74 | -Wl,--gc-sections |
| 75 | ) |
| 76 | |
| 77 | compiler_set_linker_script(TARGET ${TGT} FILE ${CMAKE_CURRENT_LIST_DIR}/sp.ld.S DEF ARM64=1) |