NCS Project Folder Structure Using CMake

I want to build a NCS project with a folder structure that might be something like this

project_folder
|
|
|-- components
|   |
|   |-- adc
|   |   |-- include
|   |   |   | adc.h
|   |   |
|   |   |-- src
|   |   |   | adc.c
|   |   |
|   |   | CMakeLists.txt
|   |
|   |
|   |-- twi
|   |   |-- include
|   |   |   | twi.h
|   |   |
|   |   |-- src
|   |   |   | twi.c
|   |   |
|   |   | CMakeLists.txt
|
|
|-- main
|   | main.c
|   | CMakeLists.txt
|
|
| CMakeLists.txt
| prj.conf
| README.md
| .gitignore

How can I achieve this using CMake? Is there an alternate way of doing this? Right now I'm including all the libraries in the CMakeLists.txt inside the parent directory, which I do not want to do.

Any help would be greatly appreciated. 

Parents
  • Hi,

     

    You use the add_subdirectory() in your root CMakeLists.txt to point to your other CMakeLists.txt files.

    folder_project/CMakeLists.txt should then hold:

    ...
    
    add_subdirectory(components/adc)
    add_subdirectory(components/twi)
    add_subdirectory(main)

     

    Our sample "modem_shell" does something similar by adding many folders and components within its own src/ catalog.

    You can look at that as a reference.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    You use the add_subdirectory() in your root CMakeLists.txt to point to your other CMakeLists.txt files.

    folder_project/CMakeLists.txt should then hold:

    ...
    
    add_subdirectory(components/adc)
    add_subdirectory(components/twi)
    add_subdirectory(main)

     

    Our sample "modem_shell" does something similar by adding many folders and components within its own src/ catalog.

    You can look at that as a reference.

     

    Kind regards,

    Håkon

Children
Related