Using application defined Kconfig option in CMakeLists

Hi,

In our application we have custom Kconfig flag defined to wrap other Kconfig options and conditionally compile application files. However this Kconfig, name it CONFIG_X, is not visible in the application CMakeList.txt file unless it's forwarded along the build command instead of being set in prj.conf file or enabled by default. In all cases it gets set properly because it ends up in the resulting .config file but it's like "too late" for the cmake to grab it.

To clarify:

In the application directory there is Kconfig file with:

Now the CONFIG_X is only equal to true in the CMakeLists.txt when using:
west build -b nrf52840dk_nrf52840 -- -DCONFIG_X=y

although with:

west build -b nrf52840dk_nrf52840

This Kconfig is still enabled in the .config/autoconf.h.

Is there any way to use Kconfig/CMake combination in such a way or it's not expected to work?

Thanks in advance!

Parents
  • Hi,

     

    Could you try to use the target_sources_ifdef() instead?

    Here is an example:

    https://github.com/nrfconnect/sdk-nrf/blob/v2.5.1/applications/asset_tracker_v2/src/modules/CMakeLists.txt#L9C1-L9C1

     

    Kind regards,

    Håkon

  • Sorry, I guess I limited the scope of operations executed in the if branch to compilation of files, where in fact apart from that I need to, among others, set PM_STATIC_YML_FILE and EXTRA_CONFIG_FILE.

    I guess target_sources_ifdef will work for pulling the files in, but it won't solve my problem.

  • Ahhh I see. Kconfig is simply parsed after I do the check because `find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})` is executed too late in my CMakeList.txt... sorry for bothering.

  • Hi,

     

    george232 said:
    Ahhh I see. Kconfig is simply parsed after I do the check the reason because `find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})` executed to late in my CMakeList.txt... sorry for bothering.

    No bother! I'm glad to hear that you found a solution. Let me know if there's anything else that pops up. Hope you have a wonderful day!

     

    Kind regards,

    Håkon

  • I have a similar issue. I need to set a build flag related to a device tree overlay based on my prj.conf. However, this doesn't seem to work since the prj.conf doesn't get loaded in until after the find_package(...). But after the find_package(...) it's too late to configure the device tree (according to the error I get.

    I don't know what to do

  • Hi,

     

    Nathan45 said:
    I need to set a build flag related to a device tree overlay based on my prj.conf.

    prj.conf::CONFIG_X=y, should then include a dts overlay.

    I have not seen any samples of doing this directly, as you mention; the ordering will be incorrect.

     

    Could you try to differentiate based on the board itself instead?

      

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Nathan45 said:
    I need to set a build flag related to a device tree overlay based on my prj.conf.

    prj.conf::CONFIG_X=y, should then include a dts overlay.

    I have not seen any samples of doing this directly, as you mention; the ordering will be incorrect.

     

    Could you try to differentiate based on the board itself instead?

      

    Kind regards,

    Håkon

Children
No Data