blob: bc59f1ec06240dce705ee8563e403b5bee3ed267 [file] [log] [blame]
Anton Komlev94758d42023-06-15 16:39:36 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2022, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8# A string calibrating routine to the specified length by
9# appending to an input string a specified character.
10#
11# output - variable to return the calibrated string
12
13function(format_string output input size filler)
14 string(LENGTH ${input} length)
15 foreach(i RANGE ${length} ${size})
16 string(CONCAT input ${input} ${filler})
17 endforeach()
18 set(${output} ${input} PARENT_SCOPE)
19endfunction()
20
21# Prints formatted list of options with a title
22#
23# title - will be printed in a header
24# options - list of CMake options to print (semicolon separated)
25#
26# Example:
27# dump_options("Partitions" "TFM_PARTITION_CRYPTO; TFM_PARTITION_FIRMWARE_UPDATE ")
28# will produce:
29# -- -------- Partitions ---------------------
30# -- TFM_PARTITION_CRYPTO ON
31# -- TFM_PARTITION_FIRMWARE_UPDATE OFF
32# -- -----------------------------------------
33
34function(dump_options title options)
35
36 if (CONFIG_TFM_PARTITION_QUIET)
37 return()
38 endif()
39
40 format_string(header "-------- ${title} " 50 "-")
41 message(STATUS )
42 message(STATUS "${header}")
43
44 foreach (option ${options})
45 string(STRIP ${option} option)
46 # avoid errors on empty strings to tolerate ';' at the end of list
47 if((DEFINED ${option}) AND NOT ${option} STREQUAL "")
48 format_string(option_name ${option} 40 " ")
49 message(STATUS "${option_name} ${${option}}")
50 endif()
51 endforeach()
52
53 format_string(footer "-" 50 "-")
54 message(STATUS "${footer}")
55endfunction()
56
David Hu479ef002023-10-20 14:44:32 +080057# Collect arguments via command line.
58# cmd_line: the output argument to collect the arguments via command line
59#
60# Those command line arguments will be passed to ExternalProject_Add().
61# Those arguments shall not be populated by the settings parsed inside each ExternalProject_Add()
62function(collect_build_cmd_args cmd_line)
63
64 get_cmake_property(CACHE_ARGS CACHE_VARIABLES)
65 foreach(CACHE_ARG ${CACHE_ARGS})
66 get_property(ARG_HELPSTRING CACHE "${CACHE_ARG}" PROPERTY HELPSTRING)
67 if("${ARG_HELPSTRING}" MATCHES "variable specified on the command line")
68 get_property(CACHE_ARG_TYPE CACHE ${CACHE_ARG} PROPERTY TYPE)
69 set(ARG_VAL ${${CACHE_ARG}})
70
71 # CMake automatically converts relative paths passed via command line into absolute
72 # ones. Since external projects have different base directories compared to root
73 # directory, relative paths will be incorrectly converted inside external projects.
74 # Enforce all the relative paths into abosulte paths before collecting them in the
75 # build command argument list.
76 if(NOT ${ARG_VAL} STREQUAL "")
77 if(IS_DIRECTORY ${ARG_VAL} AND NOT IS_ABSOLUTE ${ARG_VAL})
78 get_filename_component(ABS_PATH ${ARG_VAL} ABSOLUTE)
79 set(ARG_VAL ${ABS_PATH})
80 endif()
81 endif()
82 list(APPEND TEMP_CMD_LINE "-D${CACHE_ARG}:${CACHE_ARG_TYPE}=${ARG_VAL}")
83 endif()
84 endforeach()
85
86 set(${cmd_line} ${TEMP_CMD_LINE} PARENT_SCOPE)
87endfunction()
Jianliang Shene8525112023-10-20 17:18:43 +080088
89function(tfm_invalid_config)
90 if (${ARGV})
91 string (REPLACE ";" " " ARGV_STRING "${ARGV}")
92 string (REPLACE "STREQUAL" "=" ARGV_STRING "${ARGV_STRING}")
93 string (REPLACE "GREATER" ">" ARGV_STRING "${ARGV_STRING}")
94 string (REPLACE "LESS" "<" ARGV_STRING "${ARGV_STRING}")
95 string (REPLACE "VERSION_LESS" "<" ARGV_STRING "${ARGV_STRING}")
96 string (REPLACE "EQUAL" "=" ARGV_STRING "${ARGV_STRING}")
97 string (REPLACE "IN_LIST" "in" ARGV_STRING "${ARGV_STRING}")
98
99 message(FATAL_ERROR "INVALID CONFIG: ${ARGV_STRING}")
100 endif()
101endfunction()