1#-------------------------------------------------------------------------------
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
57