Almir Okato | fa173df | 2022-04-19 01:10:30 -0300 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD |
| 2 | # |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | |
| 5 | # Parse config files (.conf, format: <CONFIG_NAME>=<VALUE>) and set each as |
| 6 | # definitions and variables |
| 7 | function(parse_and_set_config_file CONFIG_FILE) |
| 8 | file(STRINGS ${CONFIG_FILE} BOOTLOADER_CONF) |
| 9 | foreach(config ${BOOTLOADER_CONF}) |
| 10 | if (NOT (${config} MATCHES "#")) |
| 11 | string(REGEX REPLACE "^[ ]+" "" config ${config}) |
| 12 | string(REGEX MATCH "^[^=]+" CONFIG_NAME ${config}) |
| 13 | string(REPLACE "${CONFIG_NAME}=" "" CONFIG_VALUE ${config}) |
| 14 | # Overrides if already defined (definitions from latter file prevails over the former) |
| 15 | if (DEFINED ${CONFIG_NAME}) |
| 16 | set(CONFIG_OLD "${CONFIG_NAME}") |
| 17 | remove_definitions(-D${CONFIG_NAME}=${${CONFIG_OLD}}) |
| 18 | endif() |
| 19 | if (NOT ("${CONFIG_VALUE}" STREQUAL "n" |
| 20 | OR "${CONFIG_VALUE}" STREQUAL "N")) |
| 21 | |
| 22 | if (("${CONFIG_VALUE}" STREQUAL "y") |
| 23 | OR ("${CONFIG_VALUE}" STREQUAL "Y")) |
| 24 | set(CONFIG_VALUE 1) |
| 25 | endif() |
| 26 | add_definitions(-D${CONFIG_NAME}=${CONFIG_VALUE}) |
| 27 | set(${CONFIG_NAME} ${CONFIG_VALUE} PARENT_SCOPE) |
| 28 | endif() |
| 29 | endif() |
| 30 | endforeach() |
| 31 | endfunction() |