blob: 256bbf928be6d04196827de6ec28d7e6637b5bb0 [file] [log] [blame]
Gyorgy Szing49091802020-11-24 00:33:09 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8#[===[.rst:
9Misc utilities
10--------------
11#]===]
12
13include_guard(DIRECTORY)
14
15#[===[.rst:
16.. cmake:command:: check_args
17
18 .. code-block:: cmake
19
20 check_args(func_name REQ_ARG1 REQ_ARG2)
21
22 Helper macro for argument checking in functions. First argument *func_name* is
23 the name of the function, other arguments are the names of the required
24 arguments to that function. The macro iterates through the list, and prints
25 and error message if not all arguments are defined.
26
27#]===]
28macro(check_args)
29 set(_argv "${ARGV}")
30 list(SUBLIST _argv 0 1 _func)
31 list(SUBLIST _argv 1 -1 _args)
32 foreach(_arg IN LISTS _args)
33 if (NOT DEFINED _MY_PARAMS_${_arg})
34 message(FATAL_ERROR "${_func}(): mandatory parameter '${_arg}' missing.")
35 endif()
36 endforeach()
37endmacro()
38
39# Verify MSYS environment.
40function(ts_verify_build_env)
41 if (WIN32)
42 #On MSYS2 64 bit builds do not work. Verify environment.
43 execute_process(COMMAND uname -s
44 OUTPUT_VARIABLE _os_name)
45 #If uname is present we assume MSYS environment and the os name must
46 #contain MING32.
47 if(_os_name STREQUAL "" AND NOT _os_name MATCHES ".*MINGW32.*")
48 message(FATAL_ERROR "This seems to be a 64 bit MINGW shell, which has issues. Please run the 32bit version.")
49 endif()
50 endif()
51endFunction()
Gyorgy Szingb8d6f262023-06-05 12:36:02 +020052
53#[===[.rst:
54.. cmake:command:: ts_add_uuid_to_exe_name
55
56 .. code-block:: cmake
57
58 ts_add_uuid_to_exe_name(TGT <target name> UUID "canonical string")
59
60 A function to modify the file name of the binary produced by a deployment to allow the OP-TEE symbolize.py tool to
61 find it when analyzing stack dumps. This is only useful for SP deployments targeting OP-TEE.
62 The filename will follow the template <file name>_<UUID>.elf format, where
63 - file name is the original name already configured for the target
64 - UUID is an argument of this function
65
66 INPUTS:
67
68 ``TGT``
69 Mandatory. The name of the target to manipulate.
70
71 ``UUID``
72 Mandatory. The UUID to be used to identify the SP. This has to match the UUID used by OP-TEE OS to identify the SP
73 runtime.
74
75#]===]
76function(ts_add_uuid_to_exe_name)
77 set(options)
78 set(oneValueArgs TGT UUID)
79 set(multiValueArgs)
80 cmake_parse_arguments(_MY_PARAMS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
81
82 check_args(ts_add_uuid_to_exe_name TGT)
83
84 get_target_property(_tgt_type ${_MY_PARAMS_TGT} TYPE)
85 if ("${_tgt_type}" STREQUAL "EXECUTABLE")
86 check_args(ts_add_uuid_to_exe_name UUID)
87 get_target_property(_out_name ${_MY_PARAMS_TGT} OUTPUT_NAME)
88 if (NOT _out_name)
89 set(_out_name "${_MY_PARAMS_TGT}")
90 endif()
91 get_target_property(_suffix ${_MY_PARAMS_TGT} SUFFIX)
92 if (NOT _suffix)
93 # Note CMAKE_EXECUTABLE_SUFFIX_<lang> might be needed here. Unfortunately
94 # this is only set, when it is set manually. It overrides the EXE_SUFFIX
95 # when set.
96 set(_suffix ${CMAKE_EXECUTABLE_SUFFIX})
97 endif()
98 # If executable suffix is still not set at this point, use the full name as basename.
99 if (_suffix)
100 string(REGEX REPLACE "${_suffix}$" "" _base_name "${_out_name}")
101 else()
102 set(_base_name "${_out_name}")
103 endif()
104
105 set(_out_name "${_base_name}_${_MY_PARAMS_UUID}${_suffix}")
106 set_target_properties(${_MY_PARAMS_TGT} PROPERTIES OUTPUT_NAME "${_out_name}")
107 endif()
108endfunction()