This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Suggestions for project structure using NCS/Zephyr?

The project I'm working on will have multiple subsystems which will be reused by multiple applications.  Similar to zephyr/samples and zephyr/subsys, and nrf/samples and nrf/subsys.

I have a west.yml in my repository:

manifest:

  remotes:

    - name: nordic

      url-base: https://github.com/nrfconnect

  projects:

    - name: sdk-nrf

      path: nrf

      remote: nordic

      revision: v1.5.0

      import: true

  self:

      path: mystuff/foundation

This gives me a nice tree with mystuff and zephyr, ncs, etc, all in one place.

Inside mystuff/foundation I have subsys and samples directories:

mystuff

  foundation

    CMakeLists.txt

    subsys

      CMakeLists.txt

      base

        CMakeLists.txt

        src

          foo.c

        include

          foo.h

    samples

      CMakeLists.txt

       hello

         CMakeLists.txt

         prj.conf

         src

           main.c

zephyr

...

nrf

...

...

I can build the mystuff/foundation/samples/hello app with an empty main.c. Now I'm trying to figure out how to include and link the subsystem mystuff/foundation/subsys/base (adding #include "foo.h" to main.c). How do zephyr and ncs do this? I see add_subdirectory in all of the levels (and have that in mine as well), but west build doesn't seem to be picking mine up (the include can't be found). How do I tell the build system to find my base subsystem from my hello sample?

Parents
  • Yes.  The part I don't understand may be more of a cmake question.  I have west setup to checkout the repositories and that works fine.  I can build my hello app when it doesn't use any of my subsystems fine using west.  However, when try to use one of my subsystems from my hello app the subsystem isn't found (include isn't found).  If I put the subsystem in a subdirectory of the hello app then it is found and the build is fine.

    However, I have multiple apps that want to use the subsystems.  So I want the subsystem directory to be outside any particular app directory (as shown in the tree of my initial post).  In that case my subsystem isn't found.  It looks like Zephyr and NCS both work this way.  I just haven't discovered how that is configured.  Any idea how the setup is done so that apps find subsystems that aren't in child directories?

  • Learning CMake...  "add_subdirectory(../../subsys, ${CMAKE_BINARY_DIR}/subsys)" seems to be what I was looking for.

Reply Children
No Data
Related