best practice directory structure with libraries

I have done VERY little in the way of compiled programing and having to learn the likes of cmake is part of why. For now the context of my questions are all Raspberry Pico projects. I may delve into Pi or windows later, but for now just Pico. I have a series of questions, but will start with this one…

I have seen several ways that seem to organize libraries such as in the pico sdk that are like this:

-library(one library in a folder of several libraries)
code.c
CMakeLists.txt
-include (nothing in include but the some_name folder)
-some_name
code.h

Why bury the .h file so deep. Also the CMakeLists.txt in the library root has target_include_directories(pico_stdio INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include). There is nothing but a folder in include, so I assume target_include_directories includes all sub directories as well. Also why is the keyword INTERFACE used? Is that because all pico libraries are interfaces?

Bob

I guess as a follow up would this be a best practice (yes I am sure there are as many thoughts on this as there are people, but looking for what us usual, and will lead into add_library type cmake commands)

Is this a good way to organize my code?

-Pico
-pico-sdk
-Projects
-My libraries
-LCD library
-NRF library
-My projects
-project 1
-project 2

And so on.

Do you now this repos?

1 Like

Will check them out. Thank you.

Bob

To answer directly your question on the header structure, I also have:
include → some_name → my_header.h

The main reason for this particular structure is that the include statement in the source code becomes:
#include <some_name/my_header.h>

and this helps to document which particular library or module the header comes from, and helps to avoid naming clashes between header files.

1 Like