How to check if a Kconfig string is empty using Zephyr?

751 views Asked by At

Given this Kconfig:

config MY_STR
    string "A string"

The directive #if defined(CONFIG_MY_STR) will eval to true for the default empty string.

How to check if CONFIG_MY_STR is an empty string at compile time? Is it a better practice to use a second boolean value (e.g. CONFIG_USE_MY_STR) like the following?

config MY_STR
    string "A string"
    depends on USE_MY_STR

config USE_MY_STR
    bool "Enable MY_STR"
1

There are 1 answers

0
Alexey Markevich On

Since string symbols implicitly default to the empty string the BUILD_ASSERT() can be used to perform compile time check:

BUILD_ASSERT(1 != sizeof(CONFIG_SOMEPROPERTY), "SOMEPROPERTY required");

And pass it during the build like

west build -- -DCONFIG_SOMEPROPERTY=\"1.0\" [other arguments]