blob: 069c382073e2ebae638ea2e3e093341cc8f69fe1 [file] [log] [blame]
Jelle Selsf1cb0522022-06-30 11:31:31 +02001#-------------------------------------------------------------------------------
2# Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
Jelle Selsf1cb0522022-06-30 11:31:31 +02007
Gyorgy Szingfd03e0a2023-07-27 20:04:24 +02008include(${CMAKE_CURRENT_LIST_DIR}/Uuid.cmake)
Jelle Selsf1cb0522022-06-30 11:31:31 +02009
10#[===[.rst:
11.. cmake:command:: set_target_uuids
12
13.. code:: cmake
14
15set_target_uuids(
16 SP_UUID <uuid>
17 SP_NAME <name>
18 )
19
20INPUTS:
21
22``SP_UUID``
23The UUID of the SP as a string.
24
25``SP_NAME``
26The name of the SP.
27
Jelle Selsf1cb0522022-06-30 11:31:31 +020028#]===]
29
30function (set_target_uuids)
31 set(options)
Gyorgy Szingfd03e0a2023-07-27 20:04:24 +020032 set(oneValueArgs TGT SP_UUID)
Jelle Selsf1cb0522022-06-30 11:31:31 +020033 set(multiValueArgs)
Gyorgy Szingfd03e0a2023-07-27 20:04:24 +020034 cmake_parse_arguments(_MY_PARAMS "${options}" "${oneValueArgs}"
Jelle Selsf1cb0522022-06-30 11:31:31 +020035 "${multiValueArgs}" ${ARGN} )
36
Gyorgy Szingfd03e0a2023-07-27 20:04:24 +020037 check_args(SP_UUID TGT)
Jelle Selsf1cb0522022-06-30 11:31:31 +020038
Gyorgy Szingfd03e0a2023-07-27 20:04:24 +020039 # Convert the UUID to a C char array initializer e.g.
40 # { 0x01, 0x10, 0x9c, 0xf8, 0xe5, 0xca, 0x44, 0x6f,
41 # 0x9b, 0x55, 0xf3, 0xcd, 0xc6, 0x51, 0x10, 0xc8, }
42 # and "pass it" to C files.
43 uuid_canon_to_octets(UUID ${_MY_PARAMS_SP_UUID} RES UUID_OCTETS)
44 list(JOIN UUID_OCTETS ", 0x" UUID_BYTES )
45 set(UUID_BYTES "{ 0x${UUID_BYTES} }")
46 target_compile_definitions(${_MY_PARAMS_TGT}
Jelle Selsf1cb0522022-06-30 11:31:31 +020047 PRIVATE OPTEE_SP_UUID_BYTES=${UUID_BYTES}
48 )
Gyorgy Szingfd03e0a2023-07-27 20:04:24 +020049
50 # Create a UUID structure with the UUID fileds
51 # { 0x01109cf8, 0xe5ca, 0x446f, \
52 # { 0x9b, 0x55, 0xf3, 0xcd, 0xc6, 0x51, 0x10, 0xc8 } }
53 # and "pass it" to C files
54 uuid_canon_to_fields(UUID ${_MY_PARAMS_SP_UUID}
55 TIME_LOW "_uuid_timeLow"
56 TIME_MID "_uuid_timeMid"
57 TIME_HI_AND_VER "_uuid_timeHiAndVersion"
58 CLOCK_AND_SEQ "_uuid_clockSeqAndNode")
59 string(REGEX MATCHALL ".." _uuid_clockSeqAndNode "${_uuid_clockSeqAndNode}")
60 list(JOIN _uuid_clockSeqAndNode ", 0x" _uuid_clockSeqAndNode)
61 set(UUID_STRUCT "{ 0x${_uuid_timeLow}, 0x${_uuid_timeMid}, 0x${_uuid_timeHiAndVersion}, { 0x${_uuid_clockSeqAndNode} }}")
62 target_compile_definitions(${_MY_PARAMS_TGT}
63 PRIVATE OPTEE_SP_UUID=${UUID_STRUCT}
64 )
Jelle Selsf1cb0522022-06-30 11:31:31 +020065endfunction()