Kconfig: multiple defaults?

Hi.

Is it possible to define multiple defaults for a value in Kconfig? This is the specific case:

config GCOAP_PORT
    int "Server port"
    default 5683
    help
        Server port, the default is the one specified in RFC 7252. 

If in a submenu DTLS is set to active the default port for CoAP should be, specified in RFC 7252, 5684. Is it possible to define multiple defaults here depending on variables?

In the long run, a split between coap-port and coaps-port would make sense anyway, but for now it would not be necessary.

Thanks!

Hi @janosbrodbeck, and welcome to the forum :smiley:

Yes, it is possible to add more than one default. They are evaluated in order of appearance and the first one with a true condition is applied. I think you want to do something like the following:

config GCOAP_PORT
   int "Server port"
   default 5684 if DTLS
   default 5683
   help
       Server port, the default is the one specified in RFC 7252. 

Keep in mind the particular behaviour of Kconfig when using interfaces like menuconfig, explained here https://docs.zephyrproject.org/latest/guides/kconfig/tips.html#stuck-symbols-in-menuconfig-and-guiconfig.

For more info regarding attributes you could check https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html#menu-attributes.

Thank you! :slightly_smiling_face:

Exactly what I was looking for. Thank you. And thanks for the links, I’ll take a look!