Anton Komlev | 94758d4 | 2023-06-15 16:39:36 +0100 | [diff] [blame] | 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 | |
| 13 | function(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) |
| 19 | endfunction() |
| 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 | |
| 34 | function(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}") |
| 55 | endfunction() |
| 56 | |
David Hu | 479ef00 | 2023-10-20 14:44:32 +0800 | [diff] [blame] | 57 | # 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() |
| 62 | function(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) |
| 87 | endfunction() |
Jianliang Shen | e852511 | 2023-10-20 17:18:43 +0800 | [diff] [blame] | 88 | |
| 89 | function(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() |
| 101 | endfunction() |