How to import header files in the zephyr\subsys\bluetooth\mesh\shell path in a project

zephyr\subsys\bluetooth\mesh

zephyr\subsys\bluetooth\mesh\shell

I need to use APIs for certain files in the path mentioned above. Currently, I can only copy the files I need to use to the project folder in order to import and call them. Can I directly call the source files in NCS by modifying cmake or other methods, without having to copy these files to the project folder every time?

  • You don’t actually have to copy any of the Mesh‐shell code into your app—what you need to do is:


    In your application’s CMakeLists.txt (next to the usual find_package(Zephyr …)), add the Mesh subsystem and the Mesh‐shell directory to your include path:

    # assume you already have
    #   find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    #   project(my_mesh_app)
    
    # add the top‐level mesh include dir (for public APIs)
    zephyr_include_directories(
      ${ZEPHYR_BASE}/subsys/bluetooth/mesh/include
    )
    # add the shell frontend headers
    zephyr_include_directories(
      ${ZEPHYR_BASE}/subsys/bluetooth/mesh/shell
    )
    With that in place you can do e.g.
    #include <bluetooth/mesh/dfu_srv.h>
    #include <bluetooth/mesh/dfu_cli.h>
    #include <mesh/shell/dfu.h> 
    Link against the Mesh libraries
    If you’ve enabled CONFIG_BT_MESH (and the DFU options) then the Mesh libraries will automatically be pulled in. Just make sure you’re calling the public DFU APIs—in most cases you should be able to do something like:
    extern struct bt_mesh_dfu_cli *dfu_cli;
    bt_mesh_dfu_cli_start_upgrade(dfu_cli, ...);
    

    rather than poking at the internal shell command source.

Related