nRF Connect SDK Subfolders

Hi,

I'm wondering if there is anyone that can help me with the follwoing issue; I have a question about subfolders and source files within the nRF Connect SDK. I've read that zephyr prefers that all source and header files should be in the same 'src' folder, however by doing this my project is becoming a big mess. To organize the project, it would be nice to be able to create subfolders within the project holding header- and source files which also can be seen in the nRF Connect view under 'Source files --> Application --> src'.

It looks like this is a bit too much to ask. I would expect an option when right-clicking on the 'Source Files', 'Add source/header files'. But no, I have to go back to the Explorer to create subfolder and files and add someting like...

add_subdirectory(src/common)

Or is it...

zephyr_include_directories(src/common)

Or maybe even...

target_include_directories(app PRIVATE src/common)

to the CmakeLists.txt? Who knows, I cannot find any proper documentation on how to add subfolders/files to a project which then become visible under the nRF Connect view 'Source files'-view. I also tried to add a CmakeLists.txt file in each subfolder with zero effect.

zephyr_include_directories(.)

FILE(GLOB ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
target_sources(app PRIVATE
	${app_sources}
)

Question; is there any step-by-step documentation available on how to organize a project in a neat way instead of throwing all source- and header files in the same folder making it one big garbage bin?

Thank again!

  • I have organized my source into multiple directories.  Here is what I use.

    For adding a directory:

    add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/libs)

    For adding a sub-directory conditionally based on a KConfig value:

    if(CONFIG_SHELL)
    add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/custom_shell)
    endif()

    For adding a sub-directory as an include directory:

    zephyr_include_directories(include)

    For adding source files from a directory:

    target_sources(app PRIVATE
    custom_shell_comm.c
    )

    For adding source files conditionally based on a KCONFIG there is a convenience function:

    target_sources_ifdef(CONFIG_PROVISIONING_FNS app PRIVATE custom_shell_provision.c)

    BTW if you know anyone looking for an experience firmware developer, I'm currently looking for new clients.  I've been working with Nordic Bluetooth and Cellular SoC's since 2013 and made the switch to NCS/Zephyr last year.

    Here's my linkedin profile:

    www.linkedin.com/.../

Related