0

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"
DurandA
  • 1,095
  • 1
  • 17
  • 35

1 Answers1

1

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]